diff --git a/.github/workflows/macos-arm.yml b/.github/workflows/macos-arm.yml index 8d4f025..d545d69 100644 --- a/.github/workflows/macos-arm.yml +++ b/.github/workflows/macos-arm.yml @@ -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 \ No newline at end of file + run: DEBUG=electron-packager yarn electron-forge publish --platform=darwin --arch=arm64 \ No newline at end of file diff --git a/forge.config.js b/forge.config.js index c49cfba..6500cf5 100644 --- a/forge.config.js +++ b/forge.config.js @@ -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, diff --git a/src/deeplink.js b/src/deeplink.js index 789a8bb..8442be3 100644 --- a/src/deeplink.js +++ b/src/deeplink.js @@ -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) }) } \ No newline at end of file diff --git a/src/platform.js b/src/platform.js index 9b09dcf..81c0d76 100644 --- a/src/platform.js +++ b/src/platform.js @@ -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{ diff --git a/src/window.js b/src/window.js index 0941bbf..3134cf9 100644 --- a/src/window.js +++ b/src/window.js @@ -70,7 +70,7 @@ class Window { return false } - this.window.webContents.executeJavaScript(`location.hash='${path}'`) + this.window.webContents.executeJavaScript(`location.hash='#${path}'`) } }