mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-29 21:21:15 +02:00
Electron: Fixes #256: Check that no other instance of Joplin is running before launching a new one
This commit is contained in:
parent
8a96cf3434
commit
c6698eaea6
@ -138,7 +138,7 @@ class ElectronAppWrapper {
|
|||||||
output = '16x16.png';
|
output = '16x16.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (this.env_ === 'dev') output = '16x16-dev.png'
|
if (this.env_ === 'dev') output = '16x16-dev.png'
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -164,11 +164,30 @@ class ElectronAppWrapper {
|
|||||||
this.tray_ = null;
|
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() {
|
async start() {
|
||||||
// Since we are doing other async things before creating the window, we might miss
|
// 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.
|
// the "ready" event. So we use the function below to make sure that the app is ready.
|
||||||
await this.waitForElectronAppReady();
|
await this.waitForElectronAppReady();
|
||||||
|
|
||||||
|
const alreadyRunning = await this.ensureSingleInstance();
|
||||||
|
if (alreadyRunning) return;
|
||||||
|
|
||||||
this.createWindow();
|
this.createWindow();
|
||||||
|
|
||||||
this.electronApp_.on('before-quit', () => {
|
this.electronApp_.on('before-quit', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user