support show success message after connect to aria2 first
This commit is contained in:
parent
e441549aaa
commit
068c80d877
|
@ -45,6 +45,7 @@
|
|||
"angular-utf8-base64": "^0.0.5",
|
||||
"angular-local-storage": "^0.2.7",
|
||||
"angular-notification": "775ee861c1737b284588bcb878ba1f4e43c70c97",
|
||||
"angular-ui-notification": "^0.2.0",
|
||||
"angular-bittorrent-peerid": "^1.0.2",
|
||||
"angular-busy": "^4.1.3",
|
||||
"angular-promise-buttons": "^0.1.14",
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<link rel="stylesheet" href="../bower_components/sweetalert/dist/sweetalert.css"/>
|
||||
<link rel="stylesheet" href="../bower_components/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"/>
|
||||
<link rel="stylesheet" href="../bower_components/angular/angular-csp.css"/>
|
||||
<link rel="stylesheet" href="../bower_components/angular-ui-notification/dist/angular-ui-notification.min.css"/>
|
||||
<link rel="stylesheet" href="../bower_components/angular-busy/dist/angular-busy.min.css"/>
|
||||
<link rel="stylesheet" href="../bower_components/angular-dragula/dist/dragula.min.css"/>
|
||||
<!-- endbuild -->
|
||||
|
@ -276,6 +277,7 @@
|
|||
<script src="../bower_components/angular-utf8-base64/angular-utf8-base64.min.js"></script>
|
||||
<script src="../bower_components/angular-local-storage/dist/angular-local-storage.min.js"></script>
|
||||
<script src="../bower_components/angular-notification/angular-notification.js"></script>
|
||||
<script src="../bower_components/angular-ui-notification/dist/angular-ui-notification.min.js"></script>
|
||||
<script src="../bower_components/angular-bittorrent-peerid/angular-bittorrent-peerid.min.js"></script>
|
||||
<script src="../bower_components/angular-busy/dist/angular-busy.min.js"></script>
|
||||
<script src="../bower_components/angular-promise-buttons/dist/angular-promise-buttons.min.js"></script>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"Simplified Chinese": "简体中文",
|
||||
"Operation Succeeded": "操作成功",
|
||||
"Connection Succeeded": "连接成功",
|
||||
"Error": "错误",
|
||||
"OK": "确定",
|
||||
"Confirm": "确认",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').config(['$translateProvider', 'localStorageServiceProvider', 'ariaNgConstants', function ($translateProvider, localStorageServiceProvider, ariaNgConstants) {
|
||||
angular.module('ariaNg').config(['$translateProvider', 'localStorageServiceProvider', 'NotificationProvider', 'ariaNgConstants', function ($translateProvider, localStorageServiceProvider, NotificationProvider, ariaNgConstants) {
|
||||
localStorageServiceProvider
|
||||
.setPrefix(ariaNgConstants.appPrefix)
|
||||
.setStorageType('localStorage')
|
||||
|
@ -14,5 +14,9 @@
|
|||
.preferredLanguage('en')
|
||||
.fallbackLanguage('en')
|
||||
.useSanitizeValueStrategy('escapeParameters');
|
||||
|
||||
NotificationProvider.setOptions({
|
||||
delay: ariaNgConstants.notificationInPageTimeout
|
||||
});
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
globalStatStorageCapacity: 120,
|
||||
taskStatStorageCapacity: 300,
|
||||
lazySaveTimeout: 500,
|
||||
errorTooltipDelay: 200
|
||||
errorTooltipDelay: 200,
|
||||
notificationInPageTimeout: 2000
|
||||
}).constant('ariaNgFileTypes', {
|
||||
video: [
|
||||
'.3gp',
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
$translateProvider.translations('en', {
|
||||
'English': 'English',
|
||||
'Operation Succeeded': 'Operation Succeeded',
|
||||
'Connection Succeeded': 'Connection Succeeded',
|
||||
'Error': 'Error',
|
||||
'OK': 'OK',
|
||||
'Confirm': 'Confirm',
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
'ab-base64',
|
||||
'LocalStorageModule',
|
||||
'notification',
|
||||
'ui-notification',
|
||||
'angularBittorrentPeerid',
|
||||
'cgBusy',
|
||||
'angularPromiseButtons',
|
||||
|
|
|
@ -154,6 +154,12 @@
|
|||
}
|
||||
};
|
||||
|
||||
aria2TaskService.onFirstSuccess(function () {
|
||||
ariaNgNotificationService.notifyInPage('', 'Connection Succeeded', {
|
||||
type: 'success'
|
||||
});
|
||||
});
|
||||
|
||||
aria2TaskService.onTaskCompleted(function (event) {
|
||||
ariaNgNotificationService.notifyTaskComplete(event.task);
|
||||
});
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
|
||||
angular.module('ariaNg').factory('aria2RpcService', ['$q', 'aria2RpcConstants', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2HttpRpcService', 'aria2WebSocketRpcService', function ($q, aria2RpcConstants, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, aria2HttpRpcService, aria2WebSocketRpcService) {
|
||||
var rpcImplementService = ariaNgSettingService.isUseWebSocket() ? aria2WebSocketRpcService : aria2HttpRpcService;
|
||||
var isConnected = false;
|
||||
var secret = ariaNgSettingService.getSecret();
|
||||
|
||||
var onFirstSuccessCallbacks = [];
|
||||
var onDownloadStartCallbacks = [];
|
||||
var onDownloadPauseCallbacks = [];
|
||||
var onDownloadStopCallbacks = [];
|
||||
|
@ -63,6 +65,17 @@
|
|||
});
|
||||
};
|
||||
|
||||
var fireFirstSuccessEvent = function () {
|
||||
if (!angular.isArray(onFirstSuccessCallbacks) || onFirstSuccessCallbacks.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < onFirstSuccessCallbacks.length; i++) {
|
||||
var callback = onFirstSuccessCallbacks[i];
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
var invokeMulti = function (methodFunc, contexts, callback) {
|
||||
var promises = [];
|
||||
|
||||
|
@ -123,6 +136,11 @@
|
|||
var innerContext = arguments[1];
|
||||
|
||||
context.successCallback = function (id, result) {
|
||||
if (!isConnected) {
|
||||
isConnected = true;
|
||||
fireFirstSuccessEvent();
|
||||
}
|
||||
|
||||
if (innerContext.callback) {
|
||||
innerContext.callback({
|
||||
id: id,
|
||||
|
@ -397,6 +415,9 @@
|
|||
listMethods: function (context) {
|
||||
return invoke(buildRequestContext('system.listMethods', context));
|
||||
},
|
||||
onFirstSuccess: function (context) {
|
||||
onFirstSuccessCallbacks.push(context.callback);
|
||||
},
|
||||
onDownloadStart: function (context) {
|
||||
onDownloadStartCallbacks.push(context.callback);
|
||||
},
|
||||
|
|
|
@ -204,7 +204,7 @@
|
|||
return peers;
|
||||
};
|
||||
|
||||
var createEventCallback = function (getTaskStatusFunc, callback, type) {
|
||||
var createTaskEventCallback = function (getTaskStatusFunc, callback, type) {
|
||||
return function (event) {
|
||||
var context = {
|
||||
type: type,
|
||||
|
@ -472,13 +472,22 @@
|
|||
callback: callback
|
||||
});
|
||||
},
|
||||
onFirstSuccess: function (callback) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
aria2RpcService.onFirstSuccess({
|
||||
callback: callback
|
||||
});
|
||||
},
|
||||
onTaskCompleted: function (callback) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
aria2RpcService.onDownloadComplete({
|
||||
callback: createEventCallback(this.getTaskStatus, callback, 'completed')
|
||||
callback: createTaskEventCallback(this.getTaskStatus, callback, 'completed')
|
||||
});
|
||||
},
|
||||
onBtTaskCompleted: function (callback) {
|
||||
|
@ -487,7 +496,7 @@
|
|||
}
|
||||
|
||||
aria2RpcService.onBtDownloadComplete({
|
||||
callback: createEventCallback(this.getTaskStatus, callback, 'btcompleted')
|
||||
callback: createTaskEventCallback(this.getTaskStatus, callback, 'btcompleted')
|
||||
});
|
||||
},
|
||||
onTaskErrorOccur: function (callback) {
|
||||
|
@ -496,7 +505,7 @@
|
|||
}
|
||||
|
||||
aria2RpcService.onDownloadError({
|
||||
callback: createEventCallback(this.getTaskStatus, callback, 'error')
|
||||
callback: createTaskEventCallback(this.getTaskStatus, callback, 'error')
|
||||
});
|
||||
},
|
||||
processDownloadTasks: function (tasks) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', '$translate', 'ariaNgSettingService', function ($notification, $translate, ariaNgSettingService) {
|
||||
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', '$translate', 'Notification', 'ariaNgSettingService', function ($notification, $translate, Notification, ariaNgSettingService) {
|
||||
var isSupportBrowserNotification = $notification.isSupported;
|
||||
|
||||
var isPermissionGranted = function (permission) {
|
||||
|
@ -37,21 +37,50 @@
|
|||
}
|
||||
});
|
||||
},
|
||||
notify: function (title, content) {
|
||||
notifyViaBrowser: function (title, content) {
|
||||
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
|
||||
$notification($translate.instant(title), {
|
||||
body: $translate.instant(content)
|
||||
});
|
||||
}
|
||||
},
|
||||
notifyInPage: function (title, content, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (title) {
|
||||
title = $translate.instant(title);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
content = $translate.instant(content);
|
||||
}
|
||||
|
||||
if (!content) {
|
||||
options.message = title;
|
||||
} else {
|
||||
options.title = title;
|
||||
options.message = content;
|
||||
}
|
||||
|
||||
if (!options.type || !Notification[options.type]) {
|
||||
options.type = 'primary';
|
||||
}
|
||||
|
||||
Notification[options.type](options);
|
||||
},
|
||||
notifyTaskComplete: function (task) {
|
||||
this.notify('Download Completed', (task && task.taskName ? task.taskName : ''));
|
||||
this.notifyViaBrowser('Download Completed', (task && task.taskName ? task.taskName : ''));
|
||||
},
|
||||
notifyBtTaskComplete: function (task) {
|
||||
this.notify('BT Download Completed', (task && task.taskName ? task.taskName : ''));
|
||||
this.notifyViaBrowser('BT Download Completed', (task && task.taskName ? task.taskName : ''));
|
||||
},
|
||||
notifyTaskError: function (task) {
|
||||
this.notify('Download Error', (task && task.taskName ? task.taskName : ''));
|
||||
this.notifyViaBrowser('Download Error', (task && task.taskName ? task.taskName : ''));
|
||||
},
|
||||
clearNotificationInPage: function () {
|
||||
Notification.clearAll();
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
|
Reference in a new issue