@@ -23,6 +23,7 @@ import installExtension, {
23
23
REDUX_DEVTOOLS ,
24
24
} from 'electron-devtools-installer' ;
25
25
import devtron from 'devtron' ;
26
+ import fs from 'fs' ;
26
27
27
28
const path = require ( 'path' ) ;
28
29
@@ -41,6 +42,7 @@ export default class AppUpdater {
41
42
}
42
43
43
44
let mainWindow = null ;
45
+ let urlToOpen = null ;
44
46
45
47
let httpAuthCallbacks = { } ;
46
48
@@ -67,11 +69,44 @@ const installExtensions = async () => {
67
69
}
68
70
} ;
69
71
72
+ const openUrl = url => {
73
+ mainWindow . webContents . send (
74
+ 'address-change' ,
75
+ url . replace ( 'responsively://' , '' )
76
+ ) ;
77
+ mainWindow . show ( ) ;
78
+ } ;
79
+
70
80
/**
71
81
* Add event listeners...
72
82
*/
73
83
84
+ app . on ( 'will-finish-launching' , ( ) => {
85
+ if ( [ 'win32' , 'darwin' ] . includes ( process . platform ) ) {
86
+ if ( process . argv . length >= 2 ) {
87
+ app . setAsDefaultProtocolClient ( 'responsively' , process . execPath , [
88
+ path . resolve ( process . argv [ 1 ] ) ,
89
+ ] ) ;
90
+ } else {
91
+ app . setAsDefaultProtocolClient ( 'responsively' ) ;
92
+ }
93
+ }
94
+ } ) ;
95
+
96
+ app . on ( 'open-url' , async ( event , url ) => {
97
+ log . info ( 'Open-url' , url ) ;
98
+ if ( mainWindow ) {
99
+ openUrl ( url ) ;
100
+ } else {
101
+ urlToOpen = url ;
102
+ }
103
+ } ) ;
104
+
74
105
app . on ( 'window-all-closed' , ( ) => {
106
+ if ( process . env . NODE_ENV === 'development' ) {
107
+ [ 'win32' , 'darwin' ] . includes ( process . platform ) &&
108
+ app . removeAsDefaultProtocolClient ( 'responsively' ) ;
109
+ }
75
110
// Respect the OSX convention of having the application in memory even
76
111
// after all windows have been closed
77
112
if ( process . platform !== 'darwin' ) {
@@ -144,6 +179,10 @@ const createWindow = async () => {
144
179
} ) ;
145
180
146
181
mainWindow . once ( 'ready-to-show' , ( ) => {
182
+ if ( urlToOpen ) {
183
+ openUrl ( urlToOpen ) ;
184
+ urlToOpen = null ;
185
+ }
147
186
mainWindow . show ( ) ;
148
187
} ) ;
149
188
0 commit comments