@@ -6,14 +6,15 @@ const OAuthRequestManager = require('./oauth/OAuthRequestManager')
66
77const PROTOCOL = "tistory-editor"
88
9+ console . log ( "DEBUG: platform" , process . platform )
910settings . configure ( {
1011 fileName : 'Settings'
1112} )
1213
1314let deeplinkingUrl
1415app . setAsDefaultProtocolClient ( PROTOCOL )
15-
1616app . showExitPrompt = false
17+
1718app . on ( 'ready' , ( ) => {
1819 initWindow ( )
1920 ipc . init ( )
@@ -29,32 +30,48 @@ app.on('window-all-closed', () => {
2930
3031app . on ( "open-url" , ( e , urlString ) => {
3132 e . preventDefault ( )
32- deeplinkingUrl = urlString
33+
34+ if ( process . platform === 'darwin' ) {
35+ execOAuthRequestHandler ( urlString )
36+ } else {
37+ deeplinkingUrl = urlString
38+ }
3339} )
3440
41+ function execOAuthRequestHandler ( deeplinkingUrl ) {
42+ console . log ( "OPEN-URL" , deeplinkingUrl )
43+ const url = new URL ( deeplinkingUrl )
44+ let requestHandler = OAuthRequestManager . loadRequestInfo ( "oauth" )
45+ if ( requestHandler ) {
46+ requestHandler ( url . searchParams )
47+ }
48+ }
49+
50+ function restoreWindow ( ) {
51+ const window = getWindow ( )
52+ if ( ! window ) {
53+ return
54+ }
55+ if ( window . isMinimized ( ) ) {
56+ window . restore ( )
57+ }
58+
59+ window . focus ( ) ;
60+ }
61+
3562const gotTheLock = app . requestSingleInstanceLock ( ) ;
63+ console . log ( "DEBUG: gotTheLock" , gotTheLock )
3664if ( ! gotTheLock ) {
37- app . quit ( ) ;
38- return ;
65+ app . quit ( )
3966} else {
4067 app . on ( 'second-instance' , ( e , argv ) => {
41- if ( process . platform === 'darwin' ) {
68+ console . log ( "DEBUG: second-instance argv" , argv )
69+ if ( process . platform !== 'darwin' ) {
4270 deeplinkingUrl = argv . find ( ( arg ) => arg . startsWith ( 'tistory-editor://' ) ) ;
4371 }
4472
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- } ) ;
73+ restoreWindow ( )
74+ execOAuthRequestHandler ( deeplinkingUrl )
75+ } )
5976}
6077
0 commit comments