"Bookmark watching setup"
This commit is contained in:
parent
1535940558
commit
485adf7a10
|
@ -1,18 +1,24 @@
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import chokidar from 'chokidar';
|
import {watch} from 'chokidar';
|
||||||
|
|
||||||
|
import {DEBUG} from './common.js';
|
||||||
|
|
||||||
// Chrome user data directories by platform.
|
// Chrome user data directories by platform.
|
||||||
// Source 1: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md
|
// Source 1: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md
|
||||||
// Source 2: https://superuser.com/questions/329112/where-are-the-user-profile-directories-of-google-chrome-located-in
|
// Source 2: https://superuser.com/questions/329112/where-are-the-user-profile-directories-of-google-chrome-located-in
|
||||||
|
|
||||||
|
const CHOK_OPTS = {
|
||||||
|
};
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
// Not all the below are now used or supported by this code
|
// Not all the below are now used or supported by this code
|
||||||
const UDD_PATHS = {
|
const UDD_PATHS = {
|
||||||
'win': '%LOCALAPPDATA%\\Google\\Chrome\\User Data',
|
'win': '%LOCALAPPDATA%\\Google\\Chrome\\User Data',
|
||||||
'winxp' : '%USERPROFILE%\\Local Settings\\Application Data\\Google\\Chrome\\User Data',
|
'winxp' : '%USERPROFILE%\\Local Settings\\Application Data\\Google\\Chrome\\User Data',
|
||||||
'macos' : '~/Library/Application Support/Google/Chrome',
|
'macos' : path.resolve(os.homedir(), 'Library/Application Support/Google/Chrome'),
|
||||||
'nix' : '~/.config/google-chrome',
|
'nix' : path.resolve(os.homedir(), '.config/google-chrome'),
|
||||||
'chromeos': '/home/chronos', /* no support */
|
'chromeos': '/home/chronos', /* no support */
|
||||||
'ios': 'Library/Application Support/Google/Chrome', /* no support */
|
'ios': 'Library/Application Support/Google/Chrome', /* no support */
|
||||||
};
|
};
|
||||||
|
@ -32,32 +38,63 @@ function findDefaultChromeProfile() {
|
||||||
throw new TypeError(`Sorry! The directory where we thought the Chrome profile directories may be found (${rootDir}), does not exist. We can't monitor changes to your bookmarks, so Bookmark Select Mode is not supported.`);
|
throw new TypeError(`Sorry! The directory where we thought the Chrome profile directories may be found (${rootDir}), does not exist. We can't monitor changes to your bookmarks, so Bookmark Select Mode is not supported.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bookmarkWatchGlob = path.resolve(rootDir, '**', 'book*');
|
const bookmarkWatchGlobs = [
|
||||||
|
path.resolve(rootDir, '**', 'Book*'),
|
||||||
|
path.resolve(rootDir, '**', 'book*')
|
||||||
|
];
|
||||||
|
|
||||||
|
console.log({bookmarkWatchGlobs});
|
||||||
|
|
||||||
|
const observer = watch(bookmarkWatchGlobs, CHOK_OPTS);
|
||||||
|
observer.on('ready', () => {
|
||||||
|
console.log(`Ready to watch`);
|
||||||
|
});
|
||||||
|
observer.on('all', (event, path) => {
|
||||||
|
console.log(event, path);
|
||||||
|
});
|
||||||
|
observer.on('error', error => {
|
||||||
|
console.warn(`Watcher error`, error);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGINT', shutdown);
|
||||||
|
process.on('SIGHUP', shutdown);
|
||||||
|
process.on('SIGUSR1', shutdown);
|
||||||
|
|
||||||
|
async function shutdown() {
|
||||||
|
console.log('Shutdown');
|
||||||
|
await observer.close();
|
||||||
|
console.log('No longer observing.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProfileRootDir() {
|
function getProfileRootDir() {
|
||||||
|
const DEBUG = true;
|
||||||
const plat = os.platform();
|
const plat = os.platform();
|
||||||
let name = PLAT_TABLE[plat];
|
let name = PLAT_TABLE[plat];
|
||||||
let rootDir;
|
let rootDir;
|
||||||
|
|
||||||
if ( !name && plat === 'win32' ) {
|
DEBUG && console.log({plat, name});
|
||||||
// because Chrome profile dir location only changes in XP
|
|
||||||
// we only care if it's XP or not and so
|
if ( !name ) {
|
||||||
// we try to resolve based on the version major and minor (given by release)
|
if ( plat === 'win32' ) {
|
||||||
// source: https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version?redirectedfrom=MSDN
|
// because Chrome profile dir location only changes in XP
|
||||||
const rel = os.release();
|
// we only care if it's XP or not and so
|
||||||
const ver = parseFloat(rel);
|
// we try to resolve based on the version major and minor (given by release)
|
||||||
if ( !Number.isNaN(ver) && ver <= 5.2 ) {
|
// source: https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version?redirectedfrom=MSDN
|
||||||
// this should be reliable
|
const rel = os.release();
|
||||||
name = 'winxp';
|
const ver = parseFloat(rel);
|
||||||
|
if ( !Number.isNaN(ver) && ver <= 5.2 ) {
|
||||||
|
// this should be reliable
|
||||||
|
name = 'winxp';
|
||||||
|
} else {
|
||||||
|
// this may not be reliable, but we just do it
|
||||||
|
name = 'win';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// this may not be reliable, but we just do it
|
throw new TypeError(
|
||||||
name = 'win';
|
`Sorry! We don't know how to find the default Chrome profile on OS platform: ${plat}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new TypeError(
|
|
||||||
`Sorry! We don't know how to find the default Chrome profile on OS platform: ${plat}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( UDD_PATHS[name] ) {
|
if ( UDD_PATHS[name] ) {
|
||||||
|
|
Loading…
Reference in New Issue