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