From 797d548ec3a62352d6aae89a89199f13d1e0d1c4 Mon Sep 17 00:00:00 2001 From: Meet Godhani Date: Sat, 6 Mar 2021 21:53:43 -0500 Subject: [PATCH] Fixed inoreader issue for Windows --- src/background.js | 108 +++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 69 deletions(-) diff --git a/src/background.js b/src/background.js index 75d74068..a632c6fb 100644 --- a/src/background.js +++ b/src/background.js @@ -214,75 +214,7 @@ function registerLocalResourceProtocol () { }) } -app.setAsDefaultProtocolClient('ravenreader') - -const primaryInstance = app.requestSingleInstanceLock() -if (!primaryInstance) { - app.quit() -} else { - app.on('second-instance', (event, argv, cmd) => { - event.preventDefault() - const url = argv[argv.length - 1] - if (win) { - if (win.isMinimized()) { - win.restore() - } - win.focus() - } - if (process.platform !== 'darwin') { - if (url.includes('ravenreader://inoreader/auth')) { - const q = new URL(url).searchParams - if (q.has('code')) { - axios.post('https://www.inoreader.com/oauth2/token', { - code: q.get('code'), - client_id: process.env.VUE_APP_INOREADER_CLIENT_ID, - client_secret: process.env.VUE_APP_INOREADER_CLIENT_SECRET, - redirect_uri: 'ravenreader://inoreader/auth', - scope: null, - grant_type: 'authorization_code' - }).then((data) => { - data.data.expires_in = dayjs().add(data.data.expires_in, 'second').valueOf() - win.webContents.send('inoreader-authenticated', data.data) - }) - } - } - if (url === 'ravenreader://pocket/auth') { - axios - .post( - 'https://getpocket.com/v3/oauth/authorize', { - consumer_key: consumerKey, - code: code - }, { - withCredentials: true, - headers: { - 'Content-Type': 'application/json', - 'X-Accept': 'application/json' - } - } - ) - .then(data => { - data.data.consumer_key = consumerKey - win.webContents.send('pocket-authenticated', data.data) - }) - } - } - }) -} - -app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') - -// Quit when all windows are closed. -app.on('window-all-closed', () => { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit() - } else { - i18nextBackend.clearMainBindings(ipcMain) - } -}) - -app.on('open-url', (event, url) => { +function handleInoreader (url) { if (url.includes('ravenreader://inoreader/auth')) { const q = new URL(url).searchParams if (q.has('code')) { @@ -318,6 +250,44 @@ app.on('open-url', (event, url) => { win.webContents.send('pocket-authenticated', data.data) }) } +} + +app.setAsDefaultProtocolClient('ravenreader') + +const primaryInstance = app.requestSingleInstanceLock() +if (!primaryInstance) { + app.quit() +} else { + app.on('second-instance', (event, argv, cmd) => { + event.preventDefault() + const url = argv[argv.length - 1] + if (win) { + if (win.isMinimized()) { + win.restore() + } + win.focus() + } + if (process.platform !== 'darwin') { + handleInoreader(url) + } + }) +} + +app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') + +// Quit when all windows are closed. +app.on('window-all-closed', () => { + // On macOS it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + if (process.platform !== 'darwin') { + app.quit() + } else { + i18nextBackend.clearMainBindings(ipcMain) + } +}) + +app.on('open-url', (event, url) => { + handleInoreader(url) }) nativeTheme.on('updated', () => {