Skip to content

Commit

Permalink
Improve deeplink handling in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustem Mussabekov committed Feb 3, 2021
1 parent 244268e commit a48d3a5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
run: yarn electron-forge publish --platform=darwin --arch=arm64
run: DEBUG=electron-packager yarn electron-forge publish --platform=darwin --arch=arm64
6 changes: 6 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module.exports = {
appleId: process.env['APPLE_ID'],
appleIdPassword: process.env['APPLE_ID_PASSWORD']
},

//deeplink
protocols:[{
name: 'Raindrop-io-deeplink',
schemes: ['rnio']
}],

asar: true,
prune: true,
Expand Down
27 changes: 25 additions & 2 deletions src/deeplink.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
const { app } = require('electron')
const isDev = require('electron-is-dev')
const path = require('path')
const protocol = 'rnio'

module.exports = function(window) {
app.setAsDefaultProtocolClient(protocol)
app.removeAsDefaultProtocolClient(protocol);

app.on('open-url', (e, url)=>{
//fix dev build on windows
if(isDev && process.platform === 'win32')
app.setAsDefaultProtocolClient(protocol, process.execPath, [path.resolve(process.argv[1])])
else
app.setAsDefaultProtocolClient(protocol)

function onDeepLink(url) {
if (!url) return

window.window.show()
window.setPath(url.replace(`${protocol}:/`, ''))
}

//on windows deeplinks handeled differently
if (process.platform=='win32')
app.on('second-instance', (e, commandLine) =>{
const url = commandLine[commandLine.length-1]
//validate
try{new URL(url)} catch(e) {}
onDeepLink(url)
})

//macos and other platforms
app.on('open-url', (e, url)=>{
e.preventDefault()
onDeepLink(url)
})
}
15 changes: 15 additions & 0 deletions src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ const { enforceMacOSAppLocation } = require('electron-util')

module.exports = function() {
switch(process.platform) {
//Prevent multiple copies, in case of run of second instance bring main app to front
case 'win32':
if (!app.requestSingleInstanceLock())
return app.quit()
else
app.on('second-instance', () => {
const windows = BrowserWindow.getAllWindows()
if (!windows.length) return

if (windows[0].isMinimized())
windows[0].restore()
windows[0].focus()
})
break

//Hide instead closing of last window on darwin
case 'darwin':
try{
Expand Down
2 changes: 1 addition & 1 deletion src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Window {
return false
}

this.window.webContents.executeJavaScript(`location.hash='${path}'`)
this.window.webContents.executeJavaScript(`location.hash='#${path}'`)
}
}

Expand Down

0 comments on commit a48d3a5

Please sign in to comment.