Browse Source

support open download directory

MaysWind 6 years ago
parent
commit
3d2b8e9ccf

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

@@ -1,7 +1,7 @@
 (function () {
     'use strict';
 
-    angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'clipboard', 'aria2RpcErrors', 'ariaNgFileTypes', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $routeParams, $interval, clipboard, aria2RpcErrors, ariaNgFileTypes, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, aria2TaskService, aria2SettingService) {
+    angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'clipboard', 'aria2RpcErrors', 'ariaNgFileTypes', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'aria2TaskService', 'aria2SettingService', 'ariaNgNativeElectronService', function ($rootScope, $scope, $routeParams, $interval, clipboard, aria2RpcErrors, ariaNgFileTypes, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, aria2TaskService, aria2SettingService, ariaNgNativeElectronService) {
         var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers'];
         var downloadTaskRefreshPromise = null;
         var pauseDownloadTaskRefresh = false;
@@ -30,6 +30,10 @@
                 $scope.context.availableOptions = getAvailableOptions(task.status, !!task.bittorrent);
             }
 
+            if (angular.isUndefined($scope.nativeContext.directoryExists)) {
+                $scope.nativeContext.directoryExists = ariaNgNativeElectronService.isLocalFSExists(task.dir);
+            }
+
             $scope.task = ariaNgCommonService.copyObjectTo(task, $scope.task);
 
             $rootScope.taskContext.list = [$scope.task];
@@ -204,6 +208,10 @@
             options: []
         };
 
+        $scope.nativeContext = {
+            directoryExists: undefined
+        };
+
         $scope.changeTab = function (tabName) {
             if (tabName === 'settings') {
                 $scope.loadTaskOption($scope.task);
@@ -646,6 +654,10 @@
             clipboard.copyText(info);
         };
 
+        $scope.openLocalDirectory = function (dir, filename) {
+            ariaNgNativeElectronService.openFileInDirectory(dir, filename);
+        };
+
         if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
             downloadTaskRefreshPromise = $interval(function () {
                 if ($scope.task && ($scope.task.status === 'complete' || $scope.task.status === 'error' || $scope.task.status === 'removed')) {

+ 8 - 0
app/scripts/services/ariaNgNativeElectronService.js

@@ -22,6 +22,7 @@
         };
         var cmd = remote.require('./cmd');
         var tray = remote.require('./tray');
+        var localfs = remote.require('./localfs');
 
         return {
             remote: remote,
@@ -59,9 +60,16 @@
             getCurrentWindow: function () {
                 return remote.getCurrentWindow();
             },
+            isLocalFSExists: function (fullpath) {
+                return localfs.isExists(fullpath);
+            },
             openExternalLink: function (url) {
                 return shell.openExternal(url);
             },
+            openFileInDirectory: function (dir, filename) {
+                var fullpath = localfs.getFullPath(dir, filename);
+                return shell.showItemInFolder(fullpath);
+            },
             registerEvent: function (event, callback) {
                 this.getCurrentWindow().on && this.getCurrentWindow().on(event, callback);
             },

+ 2 - 1
app/views/task-detail.html

@@ -138,7 +138,8 @@
                             <span translate>Download Dir</span>
                         </div>
                         <div class="setting-value col-sm-8">
-                            <span class="allow-word-break" ng-bind="task.dir"></span>
+                            <span class="allow-word-break" ng-if="!nativeContext.directoryExists || !task.files.length || !task.files[0].fileName" ng-bind="task.dir"></span>
+                            <a class="allow-word-break pointer-cursor" ng-if="nativeContext.directoryExists && task.files.length && task.files[0].fileName" ng-bind="task.dir" ng-click="openLocalDirectory(task.dir, task.files[0].fileName)"></a>
                         </div>
                     </div>
                     <div class="row" ng-if="task && task.bittorrent && task.bittorrent.announceList && task.bittorrent.announceList.length > 0">

+ 21 - 0
localfs.js

@@ -0,0 +1,21 @@
+'use strict';
+
+const fs = require('fs');
+const path = require('path');
+
+let localfs = (function () {
+    let getFullPath = function (dir, filename) {
+        return path.join(dir, filename);
+    };
+
+    let isExists = function (fullpath) {
+        return fs.existsSync(fullpath);
+    };
+
+    return {
+        getFullPath: getFullPath,
+        isExists: isExists
+    }
+})();
+
+module.exports = localfs;

+ 1 - 5
package.json

@@ -82,11 +82,7 @@
     "files": [
       "app/**",
       "assets/**",
-      "core.js",
-      "config.js",
-      "cmd.js",
-      "tray.js",
-      "app.js",
+      "*.js",
       "package.json"
     ],
     "win": {