From df1c926c67a622d3b89b82e3a9c276e7134e11f3 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 2 Oct 2018 21:20:53 +0900 Subject: [PATCH] ing --- src/electron/main.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/electron/main.ts b/src/electron/main.ts index 0f63e92..e439b8d 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -33,6 +33,10 @@ const launchTime = now(); let preventQuit = false; let readyTime: number | null = null; +let db: sqlite3.Database; +let probeProcess: ChildProcess.ChildProcess; + + type OnDidLoadFn = (window: AppWindow) => void; /** See the `onDidLoad` function. */ let onDidLoadFns: Array | null = []; @@ -186,7 +190,9 @@ app.on('ready', () => { path.join(__dirname, '..', '..', 'config', '_database.sqlite') : path.join(__dirname, '..', '..', 'bin', 'database.sqlite'); - const db = new sqlite3.Database(dbPath, sqlite3.OPEN_READONLY, (err: Error) => { + + + db = new sqlite3.Database(dbPath, sqlite3.OPEN_READONLY, (err: Error) => { if (err) { console.error(err.message); } @@ -195,7 +201,7 @@ app.on('ready', () => { if (!__DEV__) { const probePath = path.join(__dirname, '..', '..', 'bin', 'probe'); - ChildProcess.spawn(probePath); + probeProcess = ChildProcess.spawn(probePath); } readyTime = now() - launchTime; @@ -403,6 +409,19 @@ app.on('web-contents-created', (event, contents) => { }); }); +app.on('before-quit', function (event) { + event.preventDefault(); + + if (null !== db) { + db.close(); + } + + if (null !== probeProcess && !probeProcess.killed) { + probeProcess.kill(); + } + +}); + // app.on( // 'certificate-error', // (event, webContents, url, error, certificate, callback) => {