Commit fcc4d4dd295cf9fad639e12cd83d8030f311fda9
Merge pull request #704 from Happy0/window
Focus existing patchwork if it is already running. Fixes #703Matt McKegg authored on 2/12/2018, 1:09:39 AM
GitHub committed on 2/12/2018, 1:09:39 AM
Parent: 122ab3c45058060aa304d66629e51a45dbcda3aa
Parent: ae310201bc0006d9868d9730b64042feb9cea984
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -18,8 +18,31 @@ | ||
18 | 18 | } |
19 | 19 | var ssbConfig = null |
20 | 20 | var quitting = false |
21 | 21 | |
22 | +/** | |
23 | + * It's not possible to run two instances of patchwork as it would create two | |
24 | + * scuttlebot instances that conflict on the same port. Before opening patchwork, | |
25 | + * we check if it's already running and if it is we focus the existing window | |
26 | + * rather than opening a new instance. | |
27 | + */ | |
28 | +function quitIfAlreadyRunning() { | |
29 | + var shouldQuit = electron.app.makeSingleInstance(function(commandLine, workingDirectory) { | |
30 | + // Someone tried to run a second instance, we should focus our window. | |
31 | + if (windows.main) { | |
32 | + if (windows.main.isMinimized()) windows.main.restore(); | |
33 | + windows.main.focus(); | |
34 | + } | |
35 | + }); | |
36 | + | |
37 | + if (shouldQuit) { | |
38 | + electron.app.quit(); | |
39 | + return; | |
40 | + } | |
41 | +} | |
42 | + | |
43 | +quitIfAlreadyRunning(); | |
44 | + | |
22 | 45 | electron.app.on('ready', () => { |
23 | 46 | setupContext('ssb', { |
24 | 47 | server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb')) |
25 | 48 | }, () => { |
Built with git-ssb-web