From 624f9617e2b63a21e5583119da32d1d8e63e48b8 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 23 Jul 2016 00:17:47 +0800 Subject: [PATCH] show welcome tip when first access AriaNg --- src/langs/zh_CN.json | 1 + src/scripts/config/defaultLanguage.js | 1 + src/scripts/core/root.js | 11 +++++++++- src/scripts/services/ariaNgSettingService.js | 21 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/langs/zh_CN.json b/src/langs/zh_CN.json index 02e64eb..98891ea 100644 --- a/src/langs/zh_CN.json +++ b/src/langs/zh_CN.json @@ -149,6 +149,7 @@ "Input number is below min value!": "输入的数字小于最小值 {{value}} !", "Input number is above max value!": "输入的数字大于最大值 {{value}} !", "Input value is invalid!": "输入的内容无效!", + "Tap to configure and get started with AriaNg.": "您还没有进行过设置, 点击这里进行设置.", "format": { "longdate": "YYYY年MM月DD日 HH:mm:ss", "time.millisecond": "{{value}} 毫秒", diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 8824f1f..4d3c3a2 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -153,6 +153,7 @@ 'Input number is below min value!': 'Input number is below min value {{value}}!', 'Input number is above max value!': 'Input number is above max value {{value}}!', 'Input value is invalid!': 'Input value is invalid!', + 'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.', 'format': { 'longdate': 'MM/DD/YYYY HH:mm:ss', 'time.millisecond': '{{value}} Millisecond', diff --git a/src/scripts/core/root.js b/src/scripts/core/root.js index b5cd0a6..ed18809 100644 --- a/src/scripts/core/root.js +++ b/src/scripts/core/root.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'SweetAlert', 'ariaNgNotificationService', 'aria2TaskService', function ($rootScope, $location, $document, SweetAlert, ariaNgNotificationService, aria2TaskService) { + angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'SweetAlert', 'ariaNgNotificationService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $location, $document, SweetAlert, ariaNgNotificationService, ariaNgSettingService, aria2TaskService) { var isUrlMatchUrl2 = function (url, url2) { if (url === url2) { return true; @@ -154,6 +154,15 @@ } }; + ariaNgSettingService.onFirstAccess(function () { + ariaNgNotificationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', { + delay: false, + onClose: function () { + $location.path('/settings/ariang'); + } + }); + }); + aria2TaskService.onFirstSuccess(function () { ariaNgNotificationService.notifyInPage('', 'Connection Succeeded', { type: 'success' diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 3ea7628..53e7646 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -2,6 +2,19 @@ 'use strict'; angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages) { + var onFirstVisitCallbacks = []; + + var fireFirstVisitEvent = function () { + if (!angular.isArray(onFirstVisitCallbacks) || onFirstVisitCallbacks.length < 1) { + return; + } + + for (var i = 0; i < onFirstVisitCallbacks.length; i++) { + var callback = onFirstVisitCallbacks[i]; + callback(); + } + }; + var getDefaultLanguage = function () { var browserLang = $window.navigator.browserLanguage ? $window.navigator.browserLanguage : $window.navigator.language; @@ -34,6 +47,7 @@ options.language = getDefaultLanguage(); setOptions(options); + fireFirstVisitEvent(); } return options; @@ -215,6 +229,13 @@ }, setPeerListDisplayOrder: function (value) { setOption('peerListDisplayOrder', value); + }, + onFirstAccess: function (callback) { + if (!callback) { + return; + } + + onFirstVisitCallbacks.push(callback); } }; }]);