root.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').run(['$window', '$rootScope', '$location', '$document', '$timeout', 'ariaNgCommonService', 'ariaNgKeyboardService', 'ariaNgNotificationService', 'ariaNgLogService', 'ariaNgLocalizationService', 'ariaNgSettingService', 'aria2TaskService', 'ariaNgNativeElectronService', 'ariaNgVersionService', function ($window, $rootScope, $location, $document, $timeout, ariaNgCommonService, ariaNgKeyboardService, ariaNgNotificationService, ariaNgLogService, ariaNgLocalizationService, ariaNgSettingService, aria2TaskService, ariaNgNativeElectronService, ariaNgVersionService) {
  4. var autoRefreshAfterPageLoad = false;
  5. var isAnyTextboxOrTextareaFocus = function () {
  6. return angular.element('input[type="text"],textarea').is(':focus');
  7. };
  8. var isUrlMatchUrl2 = function (url, url2) {
  9. if (url === url2) {
  10. return true;
  11. }
  12. var index = url2.indexOf(url);
  13. if (index !== 0) {
  14. return false;
  15. }
  16. var lastPart = url2.substring(url.length);
  17. if (lastPart.indexOf('/') === 0) {
  18. return true;
  19. }
  20. return false;
  21. };
  22. var setLightTheme = function () {
  23. $rootScope.currentTheme = 'light';
  24. angular.element('body').removeClass('theme-dark');
  25. };
  26. var setDarkTheme = function () {
  27. $rootScope.currentTheme = 'dark';
  28. angular.element('body').addClass('theme-dark');
  29. };
  30. var setThemeBySystemSettings = function () {
  31. if (!ariaNgSettingService.isBrowserSupportDarkMode()) {
  32. setLightTheme();
  33. return;
  34. }
  35. var matchPreferColorScheme = $window.matchMedia('(prefers-color-scheme: dark)');
  36. ariaNgLogService.info('[root.setThemeBySystemSettings] system uses ' + (matchPreferColorScheme.matches ? 'dark' : 'light') + ' theme');
  37. if (matchPreferColorScheme.matches) {
  38. setDarkTheme();
  39. } else {
  40. setLightTheme();
  41. }
  42. };
  43. var initTheme = function () {
  44. if (ariaNgSettingService.getTheme() === 'system') {
  45. setThemeBySystemSettings();
  46. } else if (ariaNgSettingService.getTheme() === 'dark') {
  47. setDarkTheme();
  48. } else {
  49. setLightTheme();
  50. }
  51. };
  52. var initCheck = function () {
  53. var browserFeatures = ariaNgSettingService.getBrowserFeatures();
  54. if (!browserFeatures.localStroage) {
  55. ariaNgLogService.warn('[root.initCheck] LocalStorage is not supported!');
  56. }
  57. if (!browserFeatures.cookies) {
  58. ariaNgLogService.warn('[root.initCheck] Cookies is not supported!');
  59. }
  60. if (!ariaNgSettingService.isBrowserSupportStorage()) {
  61. angular.element('body').prepend('<div class="disable-overlay"></div>');
  62. angular.element('.main-sidebar').addClass('blur');
  63. angular.element('.navbar').addClass('blur');
  64. angular.element('.content-body').addClass('blur');
  65. ariaNgNotificationService.notifyInPage('', 'You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.', {
  66. type: 'error',
  67. delay: false
  68. });
  69. throw new Error('You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.');
  70. }
  71. };
  72. var initNavbar = function () {
  73. angular.element('section.sidebar > ul > li[data-href-match] > a').click(function () {
  74. angular.element('section.sidebar > ul li').removeClass('active');
  75. angular.element(this).parent().addClass('active');
  76. });
  77. angular.element('section.sidebar > ul > li.treeview > ul.treeview-menu > li[data-href-match] > a').click(function () {
  78. angular.element('section.sidebar > ul li').removeClass('active');
  79. angular.element(this).parent().addClass('active').parent().parent().addClass('active');
  80. });
  81. };
  82. var setNavbarSelected = function (location) {
  83. angular.element('section.sidebar > ul li').removeClass('active');
  84. angular.element('section.sidebar > ul > li[data-href-match]').each(function (index, element) {
  85. var match = angular.element(element).attr('data-href-match');
  86. if (isUrlMatchUrl2(match, location)) {
  87. angular.element(element).addClass('active');
  88. }
  89. });
  90. angular.element('section.sidebar > ul > li.treeview > ul.treeview-menu > li[data-href-match]').each(function (index, element) {
  91. var match = angular.element(element).attr('data-href-match');
  92. if (isUrlMatchUrl2(match, location)) {
  93. angular.element(element).addClass('active').parent().parent().addClass('active');
  94. }
  95. });
  96. };
  97. var initContentWrapper = function () {
  98. //copy from AdminLTE app.js
  99. var defaultNavbarWithAppTitleHeight = 74; // defined in "min-height" of ".custom-app-title .main-header .navbar" in app-title.css
  100. var defaultNavbarHeight = 50; // defined in "min-height" of ".main-header .navbar" in AdminLTE.css
  101. var defaultFooterHeight = 1 + 15 + 15 + 17; // defined in "border-top" of ".main-footer" in AdminLTE.css, "padding" of ".main-footer" in AdminLTE.css and "line-height" of ".skin-aria-ng .main-footer > .navbar > .navbar-toolbar > .nav > li > a" in default.css;
  102. var windowHeight = $(window).height();
  103. var headerHeight = $('.main-header').outerHeight() || (ariaNgNativeElectronService.useCustomAppTitle() ? defaultNavbarWithAppTitleHeight : defaultNavbarHeight);
  104. var footerHeight = $('.main-footer').outerHeight() || defaultFooterHeight;
  105. var neg = headerHeight + footerHeight;
  106. $('.content-wrapper').css('min-height', windowHeight - footerHeight);
  107. $('.content-body').css('height', windowHeight - neg);
  108. };
  109. var initFileDragSupport = function () {
  110. var getDropFile = function (e) {
  111. if (!e || !e.dataTransfer) {
  112. return null;
  113. }
  114. if (e.dataTransfer.items && e.dataTransfer.items[0] && e.dataTransfer.items[0].kind === 'file') {
  115. return e.dataTransfer.items[0].getAsFile();
  116. } else if (e.dataTransfer.files && e.dataTransfer.files[0]) {
  117. return e.dataTransfer.files[0];
  118. } else {
  119. return null;
  120. }
  121. };
  122. var getDropText = function (e) {
  123. if (!e || !e.dataTransfer) {
  124. return null;
  125. }
  126. return e.dataTransfer.getData('text');
  127. };
  128. var dropzone = angular.element('#dropzone');
  129. var dropzoneFileZone = angular.element('#dropzone-filezone');
  130. angular.element($window).on('dragenter', function (e) {
  131. dropzone.show();
  132. e.preventDefault();
  133. });
  134. dropzoneFileZone.on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
  135. e.preventDefault();
  136. e.stopPropagation();
  137. }).on('dragleave dragend drop', function() {
  138. dropzone.hide();
  139. }).on('drop', function(e) {
  140. var file = getDropFile(e.originalEvent);
  141. if (file) {
  142. ariaNgNativeElectronService.notifyMainProcessorNewDropFile({
  143. filePath: file.path,
  144. location: $location.url()
  145. });
  146. return;
  147. }
  148. var text = getDropText(e.originalEvent);
  149. if (text) {
  150. ariaNgNativeElectronService.notifyMainProcessorNewDropText({
  151. text: text,
  152. location: $location.url()
  153. });
  154. }
  155. });
  156. };
  157. var showSidebar = function () {
  158. angular.element('body').removeClass('sidebar-collapse').addClass('sidebar-open');
  159. };
  160. var hideSidebar = function () {
  161. angular.element('body').addClass('sidebar-collapse').removeClass('sidebar-open');
  162. };
  163. var isSidebarShowInSmallScreen = function () {
  164. return angular.element('body').hasClass('sidebar-open');
  165. };
  166. var toggleMaximizeButton = function () {
  167. angular.element('#native-title-maximize-icon').addClass('fa-window-maximize').removeClass('fa-window-restore');
  168. angular.element('#native-title-maximize-btn').attr('title', ariaNgLocalizationService.getLocalizedText('Maximize'));
  169. };
  170. var toggleRestoreButton = function () {
  171. angular.element('#native-title-maximize-icon').addClass('fa-window-restore').removeClass('fa-window-maximize');
  172. angular.element('#native-title-maximize-btn').attr('title', ariaNgLocalizationService.getLocalizedText('Restore Down'));
  173. };
  174. var autoCheckUpdates = function () {
  175. ariaNgVersionService.getTheLatestVersion()
  176. .then(function onSuccess(response) {
  177. ariaNgLogService.debug('[root.autoCheckUpdates] latest version info', response);
  178. if (!response || !response.data || !response.data.tag_name) {
  179. return;
  180. }
  181. var latestVersion = response.data.tag_name;
  182. if (ariaNgVersionService.compareVersion(ariaNgVersionService.getBuildVersion(), latestVersion) < 0) {
  183. ariaNgNotificationService.notifyViaBrowser('AriaNg Native Updates', 'A new version has been released', {
  184. contentParams: {
  185. version: latestVersion
  186. }
  187. });
  188. }
  189. }).catch(function onError(response) {
  190. ariaNgLogService.error('[root.autoCheckUpdates] failed to get latest version', response);
  191. });
  192. };
  193. $rootScope.currentTheme = 'light';
  194. $rootScope.searchContext = {
  195. text: '',
  196. setSearchBoxFocused: function () {
  197. angular.element('#search-box').focus();
  198. }
  199. };
  200. $rootScope.taskContext = {
  201. rpcStatus: 'Connecting',
  202. list: [],
  203. selected: {},
  204. enableSelectAll: false,
  205. getSelectedTaskIds: function () {
  206. var result = [];
  207. if (!this.list || !this.selected || this.list.length < 1) {
  208. return result;
  209. }
  210. for (var i = 0; i < this.list.length; i++) {
  211. var task = this.list[i];
  212. if (this.selected[task.gid]) {
  213. result.push(task.gid);
  214. }
  215. }
  216. return result;
  217. },
  218. getSelectedTasks: function () {
  219. var result = [];
  220. if (!this.list || !this.selected || this.list.length < 1) {
  221. return result;
  222. }
  223. for (var i = 0; i < this.list.length; i++) {
  224. var task = this.list[i];
  225. if (this.selected[task.gid]) {
  226. result.push(task);
  227. }
  228. }
  229. return result;
  230. },
  231. isAllSelected: function () {
  232. var isAllSelected = true;
  233. for (var i = 0; i < this.list.length; i++) {
  234. var task = this.list[i];
  235. if (!$rootScope.filterTask(task)) {
  236. continue;
  237. }
  238. if (!this.selected[task.gid]) {
  239. isAllSelected = false;
  240. break;
  241. }
  242. }
  243. return isAllSelected;
  244. },
  245. hasRetryableTask: function () {
  246. for (var i = 0; i < this.list.length; i++) {
  247. var task = this.list[i];
  248. if (!$rootScope.filterTask(task)) {
  249. continue;
  250. }
  251. if ($rootScope.isTaskRetryable(task)) {
  252. return true;
  253. }
  254. }
  255. return false;
  256. },
  257. hasCompletedTask: function () {
  258. for (var i = 0; i < this.list.length; i++) {
  259. var task = this.list[i];
  260. if (!$rootScope.filterTask(task)) {
  261. continue;
  262. }
  263. if (task.status === 'complete') {
  264. return true;
  265. }
  266. }
  267. return false;
  268. },
  269. selectAll: function () {
  270. if (!this.list || !this.selected || this.list.length < 1) {
  271. return;
  272. }
  273. if (!this.enableSelectAll) {
  274. return;
  275. }
  276. var isAllSelected = this.isAllSelected();
  277. for (var i = 0; i < this.list.length; i++) {
  278. var task = this.list[i];
  279. if (!$rootScope.filterTask(task)) {
  280. continue;
  281. }
  282. this.selected[task.gid] = !isAllSelected;
  283. }
  284. },
  285. selectAllFailed: function () {
  286. if (!this.list || !this.selected || this.list.length < 1) {
  287. return;
  288. }
  289. if (!this.enableSelectAll) {
  290. return;
  291. }
  292. var isAllFailedSelected = true;
  293. for (var i = 0; i < this.list.length; i++) {
  294. var task = this.list[i];
  295. if (!$rootScope.filterTask(task)) {
  296. continue;
  297. }
  298. if (!$rootScope.isTaskRetryable(task)) {
  299. continue;
  300. }
  301. if (!this.selected[task.gid]) {
  302. isAllFailedSelected = false;
  303. }
  304. }
  305. for (var i = 0; i < this.list.length; i++) {
  306. var task = this.list[i];
  307. if (!$rootScope.filterTask(task)) {
  308. continue;
  309. }
  310. if (!$rootScope.isTaskRetryable(task)) {
  311. this.selected[task.gid] = false;
  312. continue;
  313. }
  314. this.selected[task.gid] = !isAllFailedSelected;
  315. }
  316. },
  317. selectAllCompleted: function () {
  318. if (!this.list || !this.selected || this.list.length < 1) {
  319. return;
  320. }
  321. if (!this.enableSelectAll) {
  322. return;
  323. }
  324. var isAllFailedSelected = true;
  325. for (var i = 0; i < this.list.length; i++) {
  326. var task = this.list[i];
  327. if (!$rootScope.filterTask(task)) {
  328. continue;
  329. }
  330. if (task.status !== 'complete') {
  331. continue;
  332. }
  333. if (!this.selected[task.gid]) {
  334. isAllFailedSelected = false;
  335. }
  336. }
  337. for (var i = 0; i < this.list.length; i++) {
  338. var task = this.list[i];
  339. if (!$rootScope.filterTask(task)) {
  340. continue;
  341. }
  342. if (task.status !== 'complete') {
  343. this.selected[task.gid] = false;
  344. continue;
  345. }
  346. this.selected[task.gid] = !isAllFailedSelected;
  347. }
  348. }
  349. };
  350. $rootScope.filterTask = function (task) {
  351. if (!task || !angular.isString(task.taskName)) {
  352. return false;
  353. }
  354. if (!$rootScope.searchContext || !$rootScope.searchContext.text) {
  355. return true;
  356. }
  357. return (task.taskName.toLowerCase().indexOf($rootScope.searchContext.text.toLowerCase()) >= 0);
  358. };
  359. $rootScope.isTaskRetryable = function (task) {
  360. return task && task.status === 'error' && task.errorDescription && !task.bittorrent;
  361. };
  362. $rootScope.keydownActions = {
  363. find: function (event) {
  364. if (event.preventDefault) {
  365. event.preventDefault();
  366. }
  367. $rootScope.searchContext.setSearchBoxFocused();
  368. return false;
  369. }
  370. };
  371. $rootScope.swipeActions = {
  372. leftSwipe: function () {
  373. if (!ariaNgSettingService.getSwipeGesture()) {
  374. return;
  375. }
  376. if (isSidebarShowInSmallScreen()) {
  377. hideSidebar();
  378. return;
  379. }
  380. if (!this.extendLeftSwipe ||
  381. (angular.isFunction(this.extendLeftSwipe) && !this.extendLeftSwipe())) {
  382. hideSidebar();
  383. }
  384. },
  385. rightSwipe: function () {
  386. if (!ariaNgSettingService.getSwipeGesture()) {
  387. return;
  388. }
  389. if (!this.extendRightSwipe ||
  390. (angular.isFunction(this.extendRightSwipe) && !this.extendRightSwipe())) {
  391. showSidebar();
  392. }
  393. }
  394. };
  395. $rootScope.refreshPage = function () {
  396. $window.location.reload();
  397. };
  398. $rootScope.setAutoRefreshAfterPageLoad = function () {
  399. autoRefreshAfterPageLoad = true;
  400. };
  401. $rootScope.setTheme = function (theme) {
  402. if (theme === 'system') {
  403. setThemeBySystemSettings();
  404. } else if (theme === 'dark') {
  405. setDarkTheme();
  406. } else {
  407. setLightTheme();
  408. }
  409. };
  410. $rootScope.useCustomAppTitle = ariaNgNativeElectronService.useCustomAppTitle();
  411. ariaNgNativeElectronService.getWindowMaximizedAsync(function (maximized) {
  412. if (maximized) {
  413. toggleRestoreButton();
  414. } else {
  415. toggleMaximizeButton();
  416. }
  417. });
  418. $window.addEventListener('contextmenu', function (event) {
  419. event.preventDefault();
  420. event.stopPropagation();
  421. var context = {};
  422. if (angular.isFunction($window.getSelection)) {
  423. var selection = $window.getSelection().toString();
  424. context.selected = !!selection && selection.length > 0;
  425. }
  426. if (angular.element(event.target).attr('readonly') === 'readonly') {
  427. context.editable = false;
  428. }
  429. if (event.target.nodeName.match(/^(input|textarea)$/i) || event.target.isContentEditable) {
  430. ariaNgNativeElectronService.showTextboxContextMenu(context);
  431. }
  432. });
  433. $window.addEventListener('keydown', function (event) {
  434. if (!ariaNgSettingService.getKeyboardShortcuts()) {
  435. return;
  436. }
  437. var isTextboxOrTextareaFocus = isAnyTextboxOrTextareaFocus();
  438. if (ariaNgKeyboardService.isCtrlAPressed(event) && !isTextboxOrTextareaFocus) {
  439. if (angular.isFunction($rootScope.keydownActions.selectAll)) {
  440. return $rootScope.keydownActions.selectAll(event);
  441. }
  442. } else if (ariaNgKeyboardService.isCtrlFPressed(event)) {
  443. if (angular.isFunction($rootScope.keydownActions.find)) {
  444. return $rootScope.keydownActions.find(event);
  445. }
  446. } else if (ariaNgKeyboardService.isDeletePressed(event) && !isTextboxOrTextareaFocus) {
  447. if (angular.isFunction($rootScope.keydownActions.delete)) {
  448. return $rootScope.keydownActions.delete(event);
  449. }
  450. }
  451. }, true);
  452. ariaNgNativeElectronService.onMainWindowMaximize(function () {
  453. toggleRestoreButton();
  454. });
  455. ariaNgNativeElectronService.onMainWindowUnmaximize(function () {
  456. toggleMaximizeButton();
  457. });
  458. ariaNgNativeElectronService.onMainProcessNavigateTo(function (event, routeUrl) {
  459. $location.path(routeUrl);
  460. });
  461. ariaNgNativeElectronService.onMainProcessShowError(function (event, message) {
  462. ariaNgCommonService.showError(message);
  463. });
  464. ariaNgSettingService.setDebugMode(ariaNgNativeElectronService.isDevMode());
  465. ariaNgSettingService.onFirstAccess(function () {
  466. ariaNgNotificationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', {
  467. delay: false,
  468. onClose: function () {
  469. $location.path('/settings/ariang');
  470. }
  471. });
  472. });
  473. aria2TaskService.onFirstSuccess(function (event) {
  474. ariaNgNotificationService.notifyInPage('', 'is connected', {
  475. type: 'success',
  476. contentPrefix: event.rpcName + ' '
  477. });
  478. });
  479. aria2TaskService.onConnectionSuccess(function () {
  480. $timeout(function () {
  481. if ($rootScope.taskContext.rpcStatus !== 'Connected') {
  482. $rootScope.taskContext.rpcStatus = 'Connected';
  483. }
  484. });
  485. });
  486. aria2TaskService.onConnectionFailed(function () {
  487. $timeout(function () {
  488. if ($rootScope.taskContext.rpcStatus !== 'Disconnected') {
  489. $rootScope.taskContext.rpcStatus = 'Disconnected';
  490. }
  491. });
  492. });
  493. aria2TaskService.onConnectionReconnecting(function () {
  494. $timeout(function () {
  495. if ($rootScope.taskContext.rpcStatus !== 'Reconnecting') {
  496. $rootScope.taskContext.rpcStatus = 'Reconnecting';
  497. }
  498. });
  499. });
  500. aria2TaskService.onConnectionWaitingToReconnect(function () {
  501. $timeout(function () {
  502. if ($rootScope.taskContext.rpcStatus !== 'Waiting to reconnect') {
  503. $rootScope.taskContext.rpcStatus = 'Waiting to reconnect';
  504. }
  505. });
  506. });
  507. aria2TaskService.onTaskCompleted(function (event) {
  508. ariaNgNotificationService.notifyTaskComplete(event.task);
  509. });
  510. aria2TaskService.onBtTaskCompleted(function (event) {
  511. ariaNgNotificationService.notifyBtTaskComplete(event.task);
  512. });
  513. aria2TaskService.onTaskErrorOccur(function (event) {
  514. ariaNgNotificationService.notifyTaskError(event.task);
  515. });
  516. $rootScope.$on('$locationChangeStart', function (event) {
  517. ariaNgCommonService.closeAllDialogs();
  518. $rootScope.loadPromise = null;
  519. delete $rootScope.keydownActions.selectAll;
  520. delete $rootScope.keydownActions.delete;
  521. delete $rootScope.swipeActions.extendLeftSwipe;
  522. delete $rootScope.swipeActions.extendRightSwipe;
  523. if (angular.isArray($rootScope.taskContext.list) && $rootScope.taskContext.list.length > 0) {
  524. $rootScope.taskContext.list.length = 0;
  525. }
  526. if (angular.isObject($rootScope.taskContext.selected)) {
  527. $rootScope.taskContext.selected = {};
  528. }
  529. $rootScope.taskContext.enableSelectAll = false;
  530. });
  531. $rootScope.$on('$routeChangeStart', function (event, next, current) {
  532. var location = $location.path();
  533. setNavbarSelected(location);
  534. $document.unbind('keypress');
  535. });
  536. $rootScope.$on('$viewContentLoaded', function () {
  537. ariaNgNativeElectronService.notifyMainProcessViewLoaded($location.path());
  538. });
  539. $rootScope.$on('$translateChangeSuccess', function(event, current, previous) {
  540. ariaNgNativeElectronService.setMainWindowLanguage();
  541. });
  542. if (ariaNgSettingService.isBrowserSupportDarkMode()) {
  543. var matchPreferColorScheme = $window.matchMedia('(prefers-color-scheme: dark)');
  544. matchPreferColorScheme.addEventListener('change', function (e) {
  545. ariaNgLogService.info('[root] system switches to ' + (e.matches ? 'dark' : 'light') + ' theme');
  546. if (ariaNgSettingService.getTheme() === 'system') {
  547. if (e.matches) {
  548. setDarkTheme();
  549. } else {
  550. setLightTheme();
  551. }
  552. }
  553. });
  554. }
  555. if (ariaNgSettingService.getAutoCheckUpdates() && ariaNgSettingService.getAutoCheckUpdates() !== 'never') {
  556. ariaNgNativeElectronService.getLastCheckUpdatesTimeAsync(function (lastCheckUpdatesTime) {
  557. var checkFrequency = ariaNgSettingService.getAutoCheckUpdates();
  558. var currentTime = parseInt(ariaNgCommonService.getCurrentUnixTime());
  559. var oneDaySeconds = 86400; // s
  560. var needCheckUpdates = false;
  561. if (!angular.isNumber(lastCheckUpdatesTime)) {
  562. needCheckUpdates = true;
  563. } else if (checkFrequency === 'daily' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds) {
  564. needCheckUpdates = true;
  565. } else if (checkFrequency === 'weekly' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds * 7) {
  566. needCheckUpdates = true;
  567. } else if (checkFrequency === 'monthly' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds * 31) {
  568. needCheckUpdates = true;
  569. }
  570. if (needCheckUpdates) {
  571. ariaNgLogService.debug('[root] need check for updates, last check time is ' + lastCheckUpdatesTime);
  572. autoCheckUpdates();
  573. ariaNgNativeElectronService.setLastCheckUpdatesTime(currentTime);
  574. } else {
  575. ariaNgLogService.debug('[root] do not need check for updates, last check time is ' + lastCheckUpdatesTime);
  576. }
  577. });
  578. }
  579. $rootScope.$on('$locationChangeSuccess', function (event, newUrl) {
  580. if (autoRefreshAfterPageLoad) {
  581. $window.location.reload();
  582. }
  583. });
  584. initTheme();
  585. initCheck();
  586. initNavbar();
  587. initContentWrapper();
  588. initFileDragSupport();
  589. }]);
  590. }());