git ssb

10+

Matt McKegg / patchwork



Commit ae310201bc0006d9868d9730b64042feb9cea984

Focus existing patchwork if it is already running. Fixes #703

Gordon Martin committed on 12/26/2017, 10:14:44 PM
Parent: d03c7f58d6304a8be28e2f1640185c01a4f231d1

Files changed

index.jschanged
index.jsView
@@ -18,8 +18,31 @@
1818 }
1919 var ssbConfig = null
2020 var quitting = false
2121
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+
2245 electron.app.on('ready', () => {
2346 setupContext('ssb', {
2447 server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
2548 }, () => {

Built with git-ssb-web