11const { app, protocol } = require ( 'electron' )
22const ipc = require ( './ipc-event' )
33const settings = require ( 'electron-settings' )
4- const { initWindow } = require ( './window' )
4+ const { initWindow, getWindow } = require ( './window' )
55const OAuthRequestManager = require ( './oauth/OAuthRequestManager' )
66
77const PROTOCOL = "tistory-editor"
@@ -10,6 +10,9 @@ settings.configure({
1010 fileName : 'Settings'
1111} )
1212
13+ let deeplinkingUrl
14+ app . setAsDefaultProtocolClient ( PROTOCOL )
15+
1316app . showExitPrompt = false
1417app . on ( 'ready' , ( ) => {
1518 initWindow ( )
@@ -25,13 +28,33 @@ app.on('window-all-closed', () => {
2528} )
2629
2730app . on ( "open-url" , ( e , urlString ) => {
28- console . log ( "OPEN-URL" , urlString )
29- const url = new URL ( urlString )
30- let requestHandler = OAuthRequestManager . loadRequestInfo ( "oauth" )
31- if ( requestHandler ) {
32- requestHandler ( url . searchParams )
33- }
31+ e . preventDefault ( )
32+ deeplinkingUrl = urlString
3433} )
3534
36- app . setAsDefaultProtocolClient ( PROTOCOL )
35+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
36+ if ( ! gotTheLock ) {
37+ app . quit ( ) ;
38+ return ;
39+ } else {
40+ app . on ( 'second-instance' , ( e , argv ) => {
41+ if ( process . platform === 'darwin' ) {
42+ deeplinkingUrl = argv . find ( ( arg ) => arg . startsWith ( 'tistory-editor://' ) ) ;
43+ }
44+
45+ const window = getWindow ( )
46+
47+ if ( window ) {
48+ if ( window . isMinimized ( ) ) window . restore ( ) ;
49+ window . focus ( ) ;
50+
51+ console . log ( "OPEN-URL" , deeplinkingUrl )
52+ const url = new URL ( deeplinkingUrl )
53+ let requestHandler = OAuthRequestManager . loadRequestInfo ( "oauth" )
54+ if ( requestHandler ) {
55+ requestHandler ( url . searchParams )
56+ }
57+ }
58+ } ) ;
59+ }
3760
0 commit comments