1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Electron: Fixes #256: Check that no other instance of Joplin is running before launching a new one

This commit is contained in:
Laurent Cozic 2018-02-23 17:51:23 +00:00
parent 8a96cf3434
commit c6698eaea6

View File

@ -138,7 +138,7 @@ class ElectronAppWrapper {
output = '16x16.png';
}
//if (this.env_ === 'dev') output = '16x16-dev.png'
if (this.env_ === 'dev') output = '16x16-dev.png'
return output;
}
@ -164,11 +164,30 @@ class ElectronAppWrapper {
this.tray_ = null;
}
ensureSingleInstance() {
return new Promise((resolve, reject) => {
const alreadyRunning = this.electronApp_.makeSingleInstance((commandLine, workingDirectory) => {
const win = this.window();
if (!win) return;
if (win.isMinimized()) win.restore();
win.show();
win.focus();
});
if (alreadyRunning) this.electronApp_.quit();
resolve(alreadyRunning);
});
}
async start() {
// Since we are doing other async things before creating the window, we might miss
// the "ready" event. So we use the function below to make sure that the app is ready.
await this.waitForElectronAppReady();
const alreadyRunning = await this.ensureSingleInstance();
if (alreadyRunning) return;
this.createWindow();
this.electronApp_.on('before-quit', () => {