Explorar o código

fix cannot create new download task via opening file when AriaNg Native already run

MaysWind %!s(int64=3) %!d(string=hai) anos
pai
achega
d23b8141e0
Modificáronse 2 ficheiros con 41 adicións e 5 borrados
  1. 24 1
      main/cmd.js
  2. 17 4
      main/main.js

+ 24 - 1
main/cmd.js

@@ -27,6 +27,29 @@ const argv = yargs(process.argv.slice(1))
     })
     .argv;
 
+function parseFilePath(argv) {
+    if (!argv || argv.length < 2) {
+        return undefined;
+    }
+
+    const actualArgv = [];
+
+    for (let i = 1; i < argv.length; i++) {
+        if (argv[i][0] !== '-') {
+            actualArgv.push(argv[i]);
+        }
+    }
+
+    const ret = yargs(actualArgv)
+        .command({
+            command: '$0 <file>'
+        })
+        .argv;
+
+    return ret ? ret.file : undefined;
+}
+
 module.exports = {
-    argv: argv
+    argv: argv,
+    parseFilePath: parseFilePath
 };

+ 17 - 4
main/main.js

@@ -16,10 +16,13 @@ const tray = require('./tray');
 const app = electron.app;
 const BrowserWindow = electron.BrowserWindow;
 
-const singletonLock = app.requestSingleInstanceLock();
+const singletonLock = app.requestSingleInstanceLock({
+    argv: cmd.argv
+});
 
 if (!singletonLock) {
     app.quit();
+    return;
 }
 
 let filePathInCommandLine = cmd.argv.file;
@@ -70,7 +73,7 @@ app.on('window-all-closed', () => {
     app.quit();
 });
 
-app.on('second-instance', (event, argv, workingDirectory) => {
+app.on('second-instance', (event, argv, workingDirectory, additionalData) => {
     if (core.mainWindow) {
         if (core.mainWindow.isMinimized()) {
             core.mainWindow.restore();
@@ -80,8 +83,18 @@ app.on('second-instance', (event, argv, workingDirectory) => {
 
         core.mainWindow.focus();
 
-        if (ipc.isContainsSupportedFileArg(argv[1])) {
-            ipc.asyncNewTaskFromFile(argv[1]);
+        let filePath = null;
+
+        if (additionalData && additionalData.argv) {
+            filePath = additionalData.argv.file;
+        }
+
+        if (!filePath) {
+            filePath = cmd.parseFilePath(argv);
+        }
+
+        if (filePath && ipc.isContainsSupportedFileArg(filePath)) {
+            ipc.asyncNewTaskFromFile(filePath);
             ipc.navigateToNewTask();
         }
     }