Add gate at start for chrome - closes #139

This commit is contained in:
Cris Stringfellow 2023-01-14 16:47:40 +08:00
parent a333dc7a79
commit 823da1d925
No known key found for this signature in database
4 changed files with 44 additions and 1 deletions

12
package-lock.json generated
View File

@ -19,6 +19,7 @@
"ndx-query": "^1.0.1",
"ndx-serializable": "^1.0.0",
"node-fetch": "latest",
"ps-list": "^8.1.1",
"ukkonen": "^1.4.0",
"ws": "latest"
},
@ -2189,6 +2190,17 @@
"node": ">= 0.10"
}
},
"node_modules/ps-list": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-8.1.1.tgz",
"integrity": "sha512-OPS9kEJYVmiO48u/B9qneqhkMvgCxT+Tm28VCEJpheTpl8cJ0ffZRRNgS5mrQRTrX5yRTpaJ+hRDeefXYmmorQ==",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",

View File

@ -56,6 +56,7 @@
"ndx-query": "^1.0.1",
"ndx-serializable": "^1.0.0",
"node-fetch": "latest",
"ps-list": "^8.1.1",
"ukkonen": "^1.4.0",
"ws": "latest"
},

View File

@ -1,7 +1,11 @@
import fs from 'fs';
import ChildProcess from 'child_process';
import readline from 'readline';
import util from 'util';
import {stdin as input, stdout as output} from 'process';
import ChromeLauncher from 'chrome-launcher';
import psList from 'ps-list';
import {DEBUG, sleep, NO_SANDBOX, GO_SECURE} from './common.js';
@ -56,7 +60,32 @@ async function start() {
console.log(`Importing dependencies...`);
const {launch:ChromeLaunch} = ChromeLauncher;
await killChrome();
let chromeOpen = false;
const list = await psList();
chromeOpen = list.some(({name,cmd}) => name.match(/chrome/g) || cmd.match(/chrome/g));
if ( chromeOpen ) {
console.info(`Seems Chrome is open`);
if ( DEBUG.askFirst ) {
const rl = readline.createInterface({input, output});
const question = util.promisify(rl.question).bind(rl);
console.info(`\nIf you don't shut down Chrome and restart it under DiskerNet control
you will not be able to save or serve your archives.\n`);
const answer = await question("Would you like to shutdown Chrome browser now (y/N) ? ");
if ( answer?.match(/^y/i) ) {
await killChrome();
} else {
console.log(`OK, not shutting it!\n`);
if ( chromeOpen ) {
process.exit(0);
}
}
} else {
await killChrome();
}
}
console.log(`Removing 22120's existing temporary browser cache if it exists...`);
if ( fs.existsSync(args.temp_browser_cache()) ) {

View File

@ -4,6 +4,7 @@ import fs from 'fs';
import os from 'os';
export const DEBUG = {
askFirst: true,
verboseSlow: false,
debug: process.env.DEBUG_22120 || false,
checkPred: false