Skip to content

Commit cf9dde7

Browse files
committed
windows second-instance 처리 추가
windows는 protocol로 오픈시 새로운 instance를 여는데 이를 사용해서 인증하도록 수정
1 parent 2ce5513 commit cf9dde7

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/main/main.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { app, protocol } = require('electron')
22
const ipc = require('./ipc-event')
33
const settings = require('electron-settings')
4-
const { initWindow } = require('./window')
4+
const { initWindow, getWindow } = require('./window')
55
const OAuthRequestManager = require('./oauth/OAuthRequestManager')
66

77
const PROTOCOL = "tistory-editor"
@@ -10,6 +10,9 @@ settings.configure({
1010
fileName: 'Settings'
1111
})
1212

13+
let deeplinkingUrl
14+
app.setAsDefaultProtocolClient(PROTOCOL)
15+
1316
app.showExitPrompt = false
1417
app.on('ready', () => {
1518
initWindow()
@@ -25,13 +28,33 @@ app.on('window-all-closed', () => {
2528
})
2629

2730
app.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

src/main/window.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ module.exports.initWindow = function initWindow() {
128128
createWindow(getWindowConfig())
129129
}
130130

131+
module.exports.getWindow = () => mainWindow
131132

0 commit comments

Comments
 (0)