Commit ae310201bc0006d9868d9730b64042feb9cea984
Focus existing patchwork if it is already running. Fixes #703
Gordon Martin committed on 12/26/2017, 10:14:44 PMParent: d03c7f58d6304a8be28e2f1640185c01a4f231d1
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