Skip to content

A full-featured download manager.

fix: open url in win & linux

Dr_rOota705427ce24d
diff --git a/src/main/Launcher.js b/src/main/Launcher.js
index 78a945f3..1e2cf4e8 100644
--- a/src/main/Launcher.js
+++ b/src/main/Launcher.js
@@ -5,7 +5,7 @@ import is from 'electron-is'
import ExceptionHandler from './core/ExceptionHandler'
import logger from './core/Logger'
import Application from './Application'
-import { parseArgv } from './utils'
+import { parseArgvAsUrl, parseArgvAsFile } from './utils'
const EMPTY_STRING = ''
@@ -33,10 +33,10 @@ export default class Launcher extends EventEmitter {
app.quit()
} else {
app.on('second-instance', (event, argv, workingDirectory) => {
+ logger.warn('second-instance====>', event, argv, workingDirectory)
global.application.showPage('index')
if (!is.macOS() && argv.length > 1) { // Windows, Linux
- this.file = parseArgv(argv)
- this.sendFileToApplication()
+ this.handleAppArgv()
}
})
@@ -68,33 +68,50 @@ export default class Launcher extends EventEmitter {
return
}
app.on('open-url', (event, url) => {
- logger.info(`[Motrix] open-url path: ${url}`)
+ logger.info(`[Motrix] open-url: ${url}`)
event.preventDefault()
this.url = url
- if (this.url && global.application && global.application.isReady) {
- global.application.handleProtocol(this.url)
- this.url = EMPTY_STRING
- }
+ this.sendUrlToApplication()
})
}
/**
- * handleOpenFile [WIP]
+ * handleOpenFile
* handle open torrent file
*/
handleOpenFile () {
// macOS
if (is.macOS()) {
app.on('open-file', (event, path) => {
- logger.info(`[Motrix] open-file path: ${path}`)
+ logger.info(`[Motrix] open-file: ${path}`)
event.preventDefault()
this.file = path
this.sendFileToApplication()
})
} else if (process.argv.length > 1) { // Windows, Linux
- this.file = parseArgv(process.argv)
+ this.handleAppArgv()
+ }
+ }
+
+ handleAppArgv (argv) {
+ const file = parseArgvAsFile(argv)
+ if (file) {
+ this.file = file
this.sendFileToApplication()
}
+
+ const url = parseArgvAsUrl(argv)
+ if (url) {
+ this.url = url
+ this.sendUrlToApplication()
+ }
+ }
+
+ sendUrlToApplication () {
+ if (this.url && global.application && global.application.isReady) {
+ global.application.handleProtocol(this.url)
+ this.url = EMPTY_STRING
+ }
}
sendFileToApplication () {
diff --git a/src/main/configs/protocol.js b/src/main/configs/protocol.js
index 85408563..edd0d06a 100644
--- a/src/main/configs/protocol.js
+++ b/src/main/configs/protocol.js
@@ -1,6 +1,7 @@
export default {
'task-list': 'application:task-list',
'new-task': 'application:new-task',
+ 'new-bt-task': 'application:new-bt-task',
'pause-all-task': 'application:pause-all-task',
'resume-all-task': 'application:resume-all-task',
'preferences': 'application:preferences',
diff --git a/src/main/utils/index.js b/src/main/utils/index.js
index 88f850a4..5860538a 100644
--- a/src/main/utils/index.js
+++ b/src/main/utils/index.js
@@ -65,11 +65,25 @@ export function moveAppToApplicationsFolder (errorMsg = '') {
})
}
+export function parseArgvAsUrl (argv) {
+ let arg = argv[1]
+ if (!arg) {
+ return
+ }
+
+ if (
+ arg.toLowerCase().startsWith('magnet:') ||
+ arg.toLowerCase().startsWith('thunder:')
+ ) {
+ return arg
+ }
+}
+
export function isDirectory (path) {
return existsSync(path) && lstatSync(path).isDirectory()
}
-export function parseArgv (argv) {
+export function parseArgvAsFile (argv) {
let arg = argv[1]
if (!arg || isDirectory(arg)) {
return