Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Fixed inoreader issue for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgodhani committed Mar 7, 2021
1 parent 2f0909b commit 797d548
Showing 1 changed file with 39 additions and 69 deletions.
108 changes: 39 additions & 69 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 797d548

Please sign in to comment.