@@ -13,6 +13,8 @@ let powerMonitor;
1313let splashScreen , hostHook ;
1414let mainWindowId , nativeTheme ;
1515let dock ;
16+ let launchFile ;
17+ let launchUrl ;
1618
1719let manifestJsonFileName = 'electron.manifest.json' ;
1820let watchable = false ;
@@ -33,6 +35,18 @@ if (watchable) {
3335 manifestJsonFilePath = path . join ( currentBinPath , manifestJsonFileName ) ;
3436}
3537
38+ // handle macOS events for opening the app with a file, etc
39+ app . on ( 'will-finish-launching' , ( ) => {
40+ app . on ( 'open-file' , ( evt , file ) => {
41+ evt . preventDefault ( ) ;
42+ launchFile = file ;
43+ } )
44+ app . on ( 'open-url' , ( evt , url ) => {
45+ evt . preventDefault ( ) ;
46+ launchUrl = url ;
47+ } )
48+ } ) ;
49+
3650const manifestJsonFile = require ( manifestJsonFilePath ) ;
3751if ( manifestJsonFile . singleInstance || manifestJsonFile . aspCoreBackendPort ) {
3852 const mainInstance = app . requestSingleInstanceLock ( ) ;
@@ -177,7 +191,7 @@ function startSocketApiBridge(port) {
177191 global [ 'electronsocket' ] . setMaxListeners ( 0 ) ;
178192 console . log ( 'ASP.NET Core Application connected...' , 'global.electronsocket' , global [ 'electronsocket' ] . id , new Date ( ) ) ;
179193
180- appApi = require ( './api/app' ) ( socket , app ) ;
194+ appApi = require ( './api/app' ) ( socket , app ) ;
181195 browserWindows = require ( './api/browserWindows' ) ( socket , app ) ;
182196 commandLine = require ( './api/commandLine' ) ( socket , app ) ;
183197 autoUpdater = require ( './api/autoUpdater' ) ( socket ) ;
@@ -194,7 +208,35 @@ function startSocketApiBridge(port) {
194208 browserView = require ( './api/browserView' ) ( socket ) ;
195209 powerMonitor = require ( './api/powerMonitor' ) ( socket ) ;
196210 nativeTheme = require ( './api/nativeTheme' ) ( socket ) ;
197- dock = require ( './api/dock' ) ( socket ) ;
211+ dock = require ( './api/dock' ) ( socket ) ;
212+
213+ socket . on ( 'register-app-open-file-event' , ( id ) => {
214+ electronSocket = socket ;
215+
216+ app . on ( 'open-file' , ( event , file ) => {
217+ event . preventDefault ( ) ;
218+
219+ electronSocket . emit ( 'app-open-file' + id , file ) ;
220+ } ) ;
221+
222+ if ( launchFile ) {
223+ electronSocket . emit ( 'app-open-file' + id , launchFile ) ;
224+ }
225+ } ) ;
226+
227+ socket . on ( 'register-app-open-url-event' , ( id ) => {
228+ electronSocket = socket ;
229+
230+ app . on ( 'open-url' , ( event , url ) => {
231+ event . preventDefault ( ) ;
232+
233+ electronSocket . emit ( 'app-open-url' + id , url ) ;
234+ } ) ;
235+
236+ if ( launchUrl ) {
237+ electronSocket . emit ( 'app-open-url' + id , launchUrl ) ;
238+ }
239+ } ) ;
198240
199241 try {
200242 const hostHookScriptFilePath = path . join ( __dirname , 'ElectronHostHook' , 'index.js' ) ;
0 commit comments