@@ -8,20 +8,38 @@ const WebContents = electron.WebContents
88// Open devtools with F12
99const remote = electron . remote ;
1010const { ipcMain} = require ( 'electron' )
11+ var exec = require ( 'child_process' ) . exec ;
1112
1213// Keep a global reference of the window object, if you don't, the window will
1314// be closed automatically when the JavaScript object is garbage collected.
1415let win ;
1516
16- app . setAsDefaultProtocolClient ( 'devination' )
17-
18- app . on ( 'open-url' , function ( event , url ) {
19- if ( win )
20- {
21- win . webContents . send ( 'external-link' , { msg : url } ) ;
17+ var shouldQuit = app . makeSingleInstance ( function ( commandLine , workingDirectory ) {
18+ // Someone tried to run a second instance, we should focus our window
19+ if ( win ) {
20+ if ( win . isMinimized ( ) ) win . restore ( ) ;
21+ win . focus ( ) ;
2222 }
23+ return true ;
2324} ) ;
2425
26+ if ( shouldQuit ) {
27+ app . quit ( ) ;
28+ return ;
29+ }
30+
31+ app . setAsDefaultProtocolClient ( 'devination' ) ;
32+
33+ if ( os . platform ( ) == "linux" ) {
34+ var execute = function ( command , callback ) {
35+ exec ( command , function ( error , stdout , stderr ) { callback ( stdout ) ; } ) ;
36+ } ;
37+
38+ execute ( 'xdg-mime default devination-app.desktop x-scheme-handler/devination' , function ( output ) {
39+ console . log ( output ) ;
40+ } ) ;
41+ }
42+
2543function createWindow ( ) {
2644 // Create the browser window.
2745 win = new BrowserWindow ( { width : 1400 , height : 900 , frame : false } ) ;
@@ -40,7 +58,16 @@ function createWindow() {
4058 app . on ( 'uncaughtException' , function ( error ) {
4159 dialog . showMessageBox ( { type : 'info' , buttons : [ 'Report' , 'Cancel' ] , message : "An error has occured: " + error } , function ( buttonIndex ) { } ) ;
4260 } ) ;
43-
61+
62+ app . on ( 'open-url' , function ( event , url ) {
63+ event . preventDefault ( ) ;
64+ app . quit ( ) ;
65+ win . webContents . send ( 'external-link' , { msg : url } ) ;
66+ } ) ;
67+ app . on ( 'open-file' , function ( event , url ) {
68+ event . preventDefault ( ) ;
69+ win . webContents . send ( 'external-link' , { msg : url } ) ;
70+ } ) ;
4471
4572 new AppUpdater ( win )
4673
@@ -60,6 +87,7 @@ function createWindow() {
6087// Some APIs can only be used after this event occurs.
6188app . on ( 'ready' , createWindow ) ;
6289
90+
6391// Quit when all windows are closed.
6492app . on ( 'window-all-closed' , ( ) => {
6593 // On macOS it is common for applications and their menu bar
0 commit comments