Skip to content

A full-featured download manager.

fix: protocol handler undefined error

Dr_rOot426c0f2c90e2
diff --git a/src/main/Application.js b/src/main/Application.js
index d53e8bbb..ac158d84 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -109,11 +109,11 @@ export default class Application extends EventEmitter {
this.protocolManager = new ProtocolManager()
}
- handleProtocol (event, url) {
+ handleProtocol (url) {
if (is.mas()) {
return
}
- this.protocolManager.handle(event, url)
+ this.protocolManager.handle(url)
this.showPage('index')
}
diff --git a/src/main/core/ProtocolManager.js b/src/main/core/ProtocolManager.js
index 1f9b5ff6..8e8cd89c 100644
--- a/src/main/core/ProtocolManager.js
+++ b/src/main/core/ProtocolManager.js
@@ -15,10 +15,15 @@ export default class ProtocolManager extends EventEmitter {
init () {
// package.json:build.mac.protocols[].schemes[]
- app.setAsDefaultProtocolClient('motrix')
+ if (!app.isDefaultProtocolClient('mo')) {
+ app.setAsDefaultProtocolClient('mo')
+ }
+ if (!app.isDefaultProtocolClient('motrix')) {
+ app.setAsDefaultProtocolClient('motrix')
+ }
}
- handle (event, url) {
+ handle (url) {
logger.info(`[Motrix] protocol url: ${url}`)
const parsed = URL.parse(url)
const { host } = parsed
diff --git a/src/main/index.js b/src/main/index.js
index dbc0f235..2539cf6d 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -9,10 +9,25 @@ if (process.env.NODE_ENV !== 'development') {
}
function init () {
+ let openURL = null
+ if (!is.mas()) {
+ app.on('open-url', (event, url) => {
+ logger.info(`You arrived from: ${url}`)
+ event.preventDefault()
+ openURL = url
+ if (global.application) {
+ global.application.handleProtocol(openURL)
+ }
+ })
+ }
+
app.on('ready', () => {
global.application = new Application()
-
global.application.start('index')
+
+ if (openURL) {
+ global.application.handleProtocol(openURL)
+ }
})
app.on('will-quit', () => {
@@ -31,18 +46,6 @@ function init () {
app.on('activate', () => {
global.application.showPage('index')
})
-
- if (is.mas()) {
- return
- }
- /**
- * May not working on MAS build
- * https://stackoverflow.com/questions/26601840/making-app-default-handler-on-osx-10-10-with-sandbox-enabled
- */
- app.on('open-url', (event, url) => {
- logger.info(`You arrived from: ${url}`)
- global.application.handleProtocol(event, url)
- })
}
// Mac App Store Sandboxed App Not support requestSingleInstanceLock