Browse Source

code refactor

MaysWind 3 years ago
parent
commit
3c151b3b9c

+ 3 - 1
app/scripts/controllers/task-detail.js

@@ -86,7 +86,9 @@
             }
 
             if (angular.isUndefined($scope.nativeContext.directoryExists)) {
-                $scope.nativeContext.directoryExists = ariaNgNativeElectronService.isLocalFSExists(task.dir);
+                ariaNgNativeElectronService.getLocalFSExists(task.dir, function (exists) {
+                    $scope.nativeContext.directoryExists = exists;
+                });
             }
 
             if ($scope.task) {

+ 11 - 7
app/scripts/services/ariaNgNativeElectronService.js

@@ -9,7 +9,6 @@
             }
         };
         var ipcRenderer = electron.ipcRenderer || {};
-        var localfs = remote.require('./localfs') || {};
         var bittorrent = remote.require('./bittorrent') || {};
 
         var getSetting = function (item) {
@@ -157,12 +156,6 @@
             setMinimizedToTray: function (value) {
                 invokeMainProcessMethod('render-set-native-config-minimized-to-tray', value);
             },
-            isLocalFSExists: function (fullpath) {
-                return localfs.isExists(fullpath);
-            },
-            readPackageFile: function (path) {
-                return localfs.readPackageFile(path);
-            },
             parseBittorrentInfo: function (path) {
                 var info = angular.copy(bittorrent.parseBittorrentInfo(path));
                 info.type = 'bittorrent';
@@ -177,6 +170,17 @@
             openProjectReleaseLink: function () {
                 invokeMainProcessMethod('render-open-external-url', 'https://github.com/mayswind/AriaNg-Native/releases');
             },
+            readPackageFile: function (path) {
+                return invokeSyncMainProcessMethod('render-sync-get-package-file-content', path);
+            },
+            getLocalFSExists: function (fullpath, callback) {
+                return invokeAsyncMainProcessMethod('render-get-localfs-exists', fullpath)
+                    .then(function onReceive(value) {
+                        if (callback) {
+                            callback(value);
+                        }
+                    });
+            },
             openFileInDirectory: function (dir, filename) {
                 invokeMainProcessMethod('render-open-local-directory', dir, filename);
             },

+ 8 - 0
main/ipc.js

@@ -201,6 +201,14 @@ ipcMain.on('render-open-external-url', (event, url) => {
     shell.openExternal(url);
 });
 
+ipcMain.on('render-sync-get-package-file-content', (event, path) => {
+    event.returnValue = localfs.readPackageFile(path);
+});
+
+ipcMain.handle('render-get-localfs-exists', (event, fullpath) => {
+    return localfs.isExists(fullpath);
+});
+
 ipcMain.on('render-open-local-directory', (event, dir, filename) => {
     let fullpath = localfs.getFullPath(dir, filename);