فهرست منبع

Add consent open file handler (#666)

Lutz Roeder 5 سال پیش
والد
کامیت
c11046b68e
2فایلهای تغییر یافته به همراه20 افزوده شده و 8 حذف شده
  1. 3 3
      source/app.js
  2. 17 5
      source/electron.js

+ 3 - 3
source/app.js

@@ -95,10 +95,10 @@ class Application {
             this._configuration.set('userId', this._uuid());
         }
         if (this._openFileQueue) {
-            const openFileQueue = this._openFileQueue;
+            const queue = this._openFileQueue;
             this._openFileQueue = null;
-            while (openFileQueue.length > 0) {
-                const file = openFileQueue.shift();
+            while (queue.length > 0) {
+                const file = queue.shift();
                 this._openFile(file);
             }
         }

+ 17 - 5
source/electron.js

@@ -30,6 +30,7 @@ host.ElectronHost = class {
         this._version = electron.remote.app.getVersion();
         this._environment = new Map();
         this._environment.set('zoom', 'd3');
+        this._openFileQueue = [];
     }
 
     get document() {
@@ -50,6 +51,9 @@ host.ElectronHost = class {
 
     initialize(view) {
         this._view = view;
+        electron.ipcRenderer.on('open', (_, data) => {
+            this._openFile(data.file);
+        });
         return new Promise((resolve /*, reject */) => {
             const accept = () => {
                 if (electron.remote.app.isPackaged) {
@@ -97,11 +101,15 @@ host.ElectronHost = class {
     start() {
         this._view.show('welcome');
 
-        electron.ipcRenderer.on('open', (_, data) => {
-            if (this._view.accept(data.file)) {
-                this._openFile(data.file);
+        if (this._openFileQueue !== null) {
+            const queue = this._openFileQueue;
+            this._openFileQueue = null;
+            if (queue.length > 0) {
+                const file = queue.pop();
+                this._openFile(file);
             }
-        });
+        }
+
         electron.ipcRenderer.on('export', (_, data) => {
             this._view.export(data.file);
         });
@@ -343,7 +351,11 @@ host.ElectronHost = class {
     }
 
     _openFile(file) {
-        if (file) {
+        if (this._openFileQueue) {
+            this._openFileQueue.push(file);
+            return;
+        }
+        if (file && this._view.accept(file)) {
             this._view.show('welcome spinner');
             const dirname = path.dirname(file);
             const basename = path.basename(file);