mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 00:16:29 +02:00
gate chrome service with a flag
This commit is contained in:
parent
0128ce697d
commit
70201b82b8
1 changed files with 29 additions and 2 deletions
|
|
@ -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(CONFIG_DIR, { recursive: true });
|
||||
|
||||
cleanUpOldFiles();
|
||||
setInterval(cleanUpOldFiles, CLEANUP_INTERVAL_MS);
|
||||
|
|
@ -252,3 +262,20 @@ export async function init(): Promise<void> {
|
|||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue