From 63356e6b7d3d403e4f0ef05eb3ee36d50b87830d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 11 Aug 2018 12:41:55 +0800 Subject: [PATCH] prompt error message when localstroage and cookies are unavailable --- src/langs/zh_Hans.txt | 1 + src/langs/zh_Hant.txt | 1 + src/scripts/config/defaultLanguage.js | 1 + src/scripts/core/root.js | 26 +++++++++++++++++++- src/scripts/services/ariaNgSettingService.js | 21 ++++++++++++++++ src/styles/core/core.css | 18 ++++++++++++++ 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index 328e5a9..faadcfc 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -212,6 +212,7 @@ URL is not base64 encoded!=指定 URL 不是 Base64 编码后的字符串! Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置. Cannot initialize WebSocket!=无法初始化 WebSocket! Access Denied!=拒绝访问! +You cannot use AriaNg because this browser does not support data storage.=您无法使用 AriaNg, 您的浏览器不支持数据存储. [error] unknown=未知错误. diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 121dfa3..21a73a8 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -212,6 +212,7 @@ URL is not base64 encoded!=指定 URL 不是 Base64 編碼後的字串! Tap to configure and get started with AriaNg.=您還沒有進行過設定, 點選這裡進行設定. Cannot initialize WebSocket!=無法初始化 WebSocket! Access Denied!=拒絕訪問! +You cannot use AriaNg because this browser does not support data storage.=您無法使用 AriaNg, 您的瀏覽器不支援資料儲存. [error] unknown=不詳錯誤. diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 809f09b..4694dd3 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -217,6 +217,7 @@ 'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.', 'Cannot initialize WebSocket!': 'Cannot initialize WebSocket!', 'Access Denied!': 'Access Denied!', + 'You cannot use AriaNg because this browser does not support data storage.': 'You cannot use AriaNg because this browser does not support data storage.', 'error': { 'unknown': 'Unknown error occurred.', 'operation.timeout': 'Operation timed out.', diff --git a/src/scripts/core/root.js b/src/scripts/core/root.js index 9acebef..a802785 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', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $location, $document, SweetAlert, ariaNgNotificationService, ariaNgSettingService, aria2TaskService) { + angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'SweetAlert', 'ariaNgNotificationService', 'ariaNgSettingService', 'ariaNgLogService', 'aria2TaskService', function ($rootScope, $location, $document, SweetAlert, ariaNgNotificationService, ariaNgSettingService, ariaNgLogService, aria2TaskService) { var isUrlMatchUrl2 = function (url, url2) { if (url === url2) { return true; @@ -22,6 +22,29 @@ return false; }; + var initCheck = function () { + var browserFeatures = ariaNgSettingService.getBrowserFeatures(); + + if (!browserFeatures.localStroage) { + ariaNgLogService.warn('[root.initCheck] LocalStorage is not supported!'); + } + + if (!browserFeatures.cookies) { + ariaNgLogService.warn('[root.initCheck] Cookies is not supported!'); + } + + if (!ariaNgSettingService.isBrowserSupportStorage()) { + angular.element('body').prepend('
'); + angular.element('.main-sidebar').addClass('blur'); + angular.element('.navbar').addClass('blur'); + angular.element('.content-body').addClass('blur'); + ariaNgNotificationService.notifyInPage('', 'You cannot use AriaNg because this browser does not support data storage.', { + type: 'error', + delay: false + }); + } + }; + var initNavbar = function () { angular.element('section.sidebar > ul > li[data-href-match] > a').click(function () { angular.element('section.sidebar > ul li').removeClass('active'); @@ -219,6 +242,7 @@ $document.unbind('keypress'); }); + initCheck(); initNavbar(); }]); }()); diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 59371de..10fb453 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -2,6 +2,17 @@ 'use strict'; angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService) { + var browserFeatures = (function () { + var supportLocalStroage = localStorageService.isSupported; + var supportCookies = $window.navigator.cookieEnabled; + + return { + localStroage: supportLocalStroage, + cookies: supportCookies + }; + })(); + var browserSupportStorage = browserFeatures.localStroage || browserFeatures.cookies; + var onFirstVisitCallbacks = []; var firstVisitCallbackfired = false; var sessionSettings = { @@ -9,6 +20,10 @@ }; var fireFirstVisitEvent = function () { + if (!browserSupportStorage) { + return; + } + if (firstVisitCallbackfired || !angular.isArray(onFirstVisitCallbacks) || onFirstVisitCallbacks.length < 1) { return; } @@ -182,6 +197,12 @@ }; return { + isBrowserSupportStorage: function () { + return browserSupportStorage; + }, + getBrowserFeatures: function () { + return browserFeatures; + }, getAllOptions: function () { var options = angular.extend({}, ariaNgDefaultOptions, getOptions()); diff --git a/src/styles/core/core.css b/src/styles/core/core.css index 1a735ec..1247d2c 100644 --- a/src/styles/core/core.css +++ b/src/styles/core/core.css @@ -22,6 +22,24 @@ td { vertical-align: middle !important; } +.blur { + -webkit-filter: blur(5px); + -moz-filter: blur(5px); + -ms-filter: blur(5px); + filter: blur(5px); + filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=5, MakeShadow=false); +} + +.disable-overlay { + position: fixed; + left: 0; + top: 0; + right: 0; + bottom: 0; + z-index: 9999; + cursor: not-allowed; +} + .main-header .logo { overflow: visible; }