gate chrome service with a flag

This commit is contained in:
Arjun 2026-03-28 00:34:28 +05:30
parent 0128ce697d
commit 70201b82b8

View file

@ -238,9 +238,19 @@ function cleanUpOldFiles(): void {
} }
} }
export async function init(): Promise<void> { function isServerEnabled(): boolean {
if (!fs.existsSync(CONFIG_FILE)) return false;
try {
const raw = fs.readFileSync(CONFIG_FILE, 'utf-8');
const config = JSON.parse(raw);
return config.serverEnabled === true;
} catch {
return false;
}
}
function startServer(): void {
fs.mkdirSync(CAPTURED_PAGES_DIR, { recursive: true }); fs.mkdirSync(CAPTURED_PAGES_DIR, { recursive: true });
fs.mkdirSync(CONFIG_DIR, { recursive: true });
cleanUpOldFiles(); cleanUpOldFiles();
setInterval(cleanUpOldFiles, CLEANUP_INTERVAL_MS); setInterval(cleanUpOldFiles, CLEANUP_INTERVAL_MS);
@ -252,3 +262,20 @@ export async function init(): Promise<void> {
console.log(` Listening on http://localhost:${PORT}`); console.log(` Listening on http://localhost:${PORT}`);
}); });
} }
export async function init(): Promise<void> {
fs.mkdirSync(CONFIG_DIR, { recursive: true });
if (isServerEnabled()) {
startServer();
return;
}
console.log('[ChromeSync] Server disabled, watching config for changes...');
fs.watch(CONFIG_DIR, (_, filename) => {
if (filename === 'chrome-plugin.json' && isServerEnabled()) {
console.log('[ChromeSync] serverEnabled set to true, starting server...');
startServer();
}
});
}