root.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. ariaNgCommonService.closeAllDialogs();
  132. dropzone.show();
  133. e.preventDefault();
  134. });
  135. dropzoneFileZone.on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
  136. e.preventDefault();
  137. e.stopPropagation();
  138. }).on('dragleave dragend drop', function() {
  139. dropzone.hide();
  140. }).on('drop', function(e) {
  141. var file = getDropFile(e.originalEvent);
  142. if (file) {
  143. ariaNgNativeElectronService.notifyMainProcessorNewDropFile({
  144. filePath: file.path,
  145. location: $location.url()
  146. });
  147. return;
  148. }
  149. var text = getDropText(e.originalEvent);
  150. if (text) {
  151. ariaNgNativeElectronService.notifyMainProcessorNewDropText({
  152. text: text,
  153. location: $location.url()
  154. });
  155. }
  156. });
  157. };
  158. var showSidebar = function () {
  159. angular.element('body').removeClass('sidebar-collapse').addClass('sidebar-open');
  160. };
  161. var hideSidebar = function () {
  162. angular.element('body').addClass('sidebar-collapse').removeClass('sidebar-open');
  163. };
  164. var isSidebarShowInSmallScreen = function () {
  165. return angular.element('body').hasClass('sidebar-open');
  166. };
  167. var toggleMaximizeButton = function () {
  168. angular.element('#native-title-maximize-icon').addClass('fa-window-maximize').removeClass('fa-window-restore');
  169. angular.element('#native-title-maximize-btn').attr('title', ariaNgLocalizationService.getLocalizedText('Maximize'));
  170. };
  171. var toggleRestoreButton = function () {
  172. angular.element('#native-title-maximize-icon').addClass('fa-window-restore').removeClass('fa-window-maximize');
  173. angular.element('#native-title-maximize-btn').attr('title', ariaNgLocalizationService.getLocalizedText('Restore Down'));
  174. };
  175. var autoCheckUpdates = function () {
  176. ariaNgVersionService.getTheLatestVersion()
  177. .then(function onSuccess(response) {
  178. ariaNgLogService.debug('[root.autoCheckUpdates] latest version info', response);
  179. if (!response || !response.data || !response.data.tag_name) {
  180. return;
  181. }
  182. var latestVersion = response.data.tag_name;
  183. if (ariaNgVersionService.compareVersion(ariaNgVersionService.getBuildVersion(), latestVersion) < 0) {
  184. ariaNgNotificationService.notifyViaBrowser('AriaNg Native Updates', 'A new version has been released', {
  185. contentParams: {
  186. version: latestVersion
  187. }
  188. });
  189. }
  190. }).catch(function onError(response) {
  191. ariaNgLogService.error('[root.autoCheckUpdates] failed to get latest version', response);
  192. });
  193. };
  194. $rootScope.currentTheme = 'light';
  195. $rootScope.searchContext = {
  196. text: '',
  197. setSearchBoxFocused: function () {
  198. angular.element('#search-box').focus();
  199. }
  200. };
  201. $rootScope.taskContext = {
  202. rpcStatus: 'Connecting',
  203. list: [],
  204. selected: {},
  205. enableSelectAll: false,
  206. getSelectedTaskIds: function () {
  207. var result = [];
  208. if (!this.list || !this.selected || this.list.length < 1) {
  209. return result;
  210. }
  211. for (var i = 0; i < this.list.length; i++) {
  212. var task = this.list[i];
  213. if (this.selected[task.gid]) {
  214. result.push(task.gid);
  215. }
  216. }
  217. return result;
  218. },
  219. getSelectedTasks: function () {
  220. var result = [];
  221. if (!this.list || !this.selected || this.list.length < 1) {
  222. return result;
  223. }
  224. for (var i = 0; i < this.list.length; i++) {
  225. var task = this.list[i];
  226. if (this.selected[task.gid]) {
  227. result.push(task);
  228. }
  229. }
  230. return result;
  231. },
  232. isAllSelected: function () {
  233. var isAllSelected = true;
  234. for (var i = 0; i < this.list.length; i++) {
  235. var task = this.list[i];
  236. if (!$rootScope.filterTask(task)) {
  237. continue;
  238. }
  239. if (!this.selected[task.gid]) {
  240. isAllSelected = false;
  241. break;
  242. }
  243. }
  244. return isAllSelected;
  245. },
  246. hasRetryableTask: function () {
  247. for (var i = 0; i < this.list.length; i++) {
  248. var task = this.list[i];
  249. if (!$rootScope.filterTask(task)) {
  250. continue;
  251. }
  252. if ($rootScope.isTaskRetryable(task)) {
  253. return true;
  254. }
  255. }
  256. return false;
  257. },
  258. hasCompletedTask: function () {
  259. for (var i = 0; i < this.list.length; i++) {
  260. var task = this.list[i];
  261. if (!$rootScope.filterTask(task)) {
  262. continue;
  263. }
  264. if (task.status === 'complete') {
  265. return true;
  266. }
  267. }
  268. return false;
  269. },
  270. selectAll: function () {
  271. if (!this.list || !this.selected || this.list.length < 1) {
  272. return;
  273. }
  274. if (!this.enableSelectAll) {
  275. return;
  276. }
  277. var isAllSelected = this.isAllSelected();
  278. for (var i = 0; i < this.list.length; i++) {
  279. var task = this.list[i];
  280. if (!$rootScope.filterTask(task)) {
  281. continue;
  282. }
  283. this.selected[task.gid] = !isAllSelected;
  284. }
  285. },
  286. selectAllFailed: function () {
  287. if (!this.list || !this.selected || this.list.length < 1) {
  288. return;
  289. }
  290. if (!this.enableSelectAll) {
  291. return;
  292. }
  293. var isAllFailedSelected = true;
  294. for (var i = 0; i < this.list.length; i++) {
  295. var task = this.list[i];
  296. if (!$rootScope.filterTask(task)) {
  297. continue;
  298. }
  299. if (!$rootScope.isTaskRetryable(task)) {
  300. continue;
  301. }
  302. if (!this.selected[task.gid]) {
  303. isAllFailedSelected = false;
  304. }
  305. }
  306. for (var i = 0; i < this.list.length; i++) {
  307. var task = this.list[i];
  308. if (!$rootScope.filterTask(task)) {
  309. continue;
  310. }
  311. if (!$rootScope.isTaskRetryable(task)) {
  312. this.selected[task.gid] = false;
  313. continue;
  314. }
  315. this.selected[task.gid] = !isAllFailedSelected;
  316. }
  317. },
  318. selectAllCompleted: function () {
  319. if (!this.list || !this.selected || this.list.length < 1) {
  320. return;
  321. }
  322. if (!this.enableSelectAll) {
  323. return;
  324. }
  325. var isAllFailedSelected = true;
  326. for (var i = 0; i < this.list.length; i++) {
  327. var task = this.list[i];
  328. if (!$rootScope.filterTask(task)) {
  329. continue;
  330. }
  331. if (task.status !== 'complete') {
  332. continue;
  333. }
  334. if (!this.selected[task.gid]) {
  335. isAllFailedSelected = false;
  336. }
  337. }
  338. for (var i = 0; i < this.list.length; i++) {
  339. var task = this.list[i];
  340. if (!$rootScope.filterTask(task)) {
  341. continue;
  342. }
  343. if (task.status !== 'complete') {
  344. this.selected[task.gid] = false;
  345. continue;
  346. }
  347. this.selected[task.gid] = !isAllFailedSelected;
  348. }
  349. }
  350. };
  351. $rootScope.filterTask = function (task) {
  352. if (!task || !angular.isString(task.taskName)) {
  353. return false;
  354. }
  355. if (!$rootScope.searchContext || !$rootScope.searchContext.text) {
  356. return true;
  357. }
  358. return (task.taskName.toLowerCase().indexOf($rootScope.searchContext.text.toLowerCase()) >= 0);
  359. };
  360. $rootScope.isTaskRetryable = function (task) {
  361. return task && task.status === 'error' && task.errorDescription && !task.bittorrent;
  362. };
  363. $rootScope.keydownActions = {
  364. find: function (event) {
  365. if (event.preventDefault) {
  366. event.preventDefault();
  367. }
  368. $rootScope.searchContext.setSearchBoxFocused();
  369. return false;
  370. }
  371. };
  372. $rootScope.swipeActions = {
  373. leftSwipe: function () {
  374. if (!ariaNgSettingService.getSwipeGesture()) {
  375. return;
  376. }
  377. if (isSidebarShowInSmallScreen()) {
  378. hideSidebar();
  379. return;
  380. }
  381. if (!this.extendLeftSwipe ||
  382. (angular.isFunction(this.extendLeftSwipe) && !this.extendLeftSwipe())) {
  383. hideSidebar();
  384. }
  385. },
  386. rightSwipe: function () {
  387. if (!ariaNgSettingService.getSwipeGesture()) {
  388. return;
  389. }
  390. if (!this.extendRightSwipe ||
  391. (angular.isFunction(this.extendRightSwipe) && !this.extendRightSwipe())) {
  392. showSidebar();
  393. }
  394. }
  395. };
  396. $rootScope.refreshPage = function () {
  397. $window.location.reload();
  398. };
  399. $rootScope.setAutoRefreshAfterPageLoad = function () {
  400. autoRefreshAfterPageLoad = true;
  401. };
  402. $rootScope.setTheme = function (theme) {
  403. if (theme === 'system') {
  404. setThemeBySystemSettings();
  405. } else if (theme === 'dark') {
  406. setDarkTheme();
  407. } else {
  408. setLightTheme();
  409. }
  410. };
  411. $rootScope.useCustomAppTitle = ariaNgNativeElectronService.useCustomAppTitle();
  412. ariaNgNativeElectronService.getWindowMaximizedAsync(function (maximized) {
  413. if (maximized) {
  414. toggleRestoreButton();
  415. } else {
  416. toggleMaximizeButton();
  417. }
  418. });
  419. $window.addEventListener('contextmenu', function (event) {
  420. event.preventDefault();
  421. event.stopPropagation();
  422. var context = {};
  423. if (angular.isFunction($window.getSelection)) {
  424. var selection = $window.getSelection().toString();
  425. context.selected = !!selection && selection.length > 0;
  426. }
  427. if (angular.element(event.target).attr('readonly') === 'readonly') {
  428. context.editable = false;
  429. }
  430. if (event.target.nodeName.match(/^(input|textarea)$/i) || event.target.isContentEditable) {
  431. ariaNgNativeElectronService.showTextboxContextMenu(context);
  432. }
  433. });
  434. $window.addEventListener('keydown', function (event) {
  435. if (!ariaNgSettingService.getKeyboardShortcuts()) {
  436. return;
  437. }
  438. var isTextboxOrTextareaFocus = isAnyTextboxOrTextareaFocus();
  439. if (ariaNgKeyboardService.isCtrlAPressed(event) && !isTextboxOrTextareaFocus) {
  440. if (angular.isFunction($rootScope.keydownActions.selectAll)) {
  441. return $rootScope.keydownActions.selectAll(event);
  442. }
  443. } else if (ariaNgKeyboardService.isCtrlFPressed(event)) {
  444. if (angular.isFunction($rootScope.keydownActions.find)) {
  445. return $rootScope.keydownActions.find(event);
  446. }
  447. } else if (ariaNgKeyboardService.isDeletePressed(event) && !isTextboxOrTextareaFocus) {
  448. if (angular.isFunction($rootScope.keydownActions.delete)) {
  449. return $rootScope.keydownActions.delete(event);
  450. }
  451. }
  452. }, true);
  453. ariaNgNativeElectronService.onMainWindowMaximize(function () {
  454. toggleRestoreButton();
  455. });
  456. ariaNgNativeElectronService.onMainWindowUnmaximize(function () {
  457. toggleMaximizeButton();
  458. });
  459. ariaNgNativeElectronService.onMainProcessNavigateTo(function (event, routeUrl) {
  460. angular.element('.modal.in:visible').modal('hide');
  461. angular.element('.modal-backdrop').remove();
  462. $rootScope.$apply(function () {
  463. $location.path(routeUrl);
  464. });
  465. });
  466. ariaNgNativeElectronService.onMainProcessShowError(function (event, message) {
  467. ariaNgCommonService.showError(message);
  468. });
  469. ariaNgSettingService.setDebugMode(ariaNgNativeElectronService.isDevMode());
  470. ariaNgSettingService.onFirstAccess(function () {
  471. ariaNgNotificationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', {
  472. delay: false,
  473. onClose: function () {
  474. $location.path('/settings/ariang');
  475. }
  476. });
  477. });
  478. aria2TaskService.onFirstSuccess(function (event) {
  479. ariaNgNotificationService.notifyInPage('', 'is connected', {
  480. type: 'success',
  481. contentPrefix: event.rpcName + ' '
  482. });
  483. });
  484. aria2TaskService.onConnectionSuccess(function () {
  485. $timeout(function () {
  486. if ($rootScope.taskContext.rpcStatus !== 'Connected') {
  487. $rootScope.taskContext.rpcStatus = 'Connected';
  488. }
  489. });
  490. });
  491. aria2TaskService.onConnectionFailed(function () {
  492. $timeout(function () {
  493. if ($rootScope.taskContext.rpcStatus !== 'Disconnected') {
  494. $rootScope.taskContext.rpcStatus = 'Disconnected';
  495. }
  496. });
  497. });
  498. aria2TaskService.onConnectionReconnecting(function () {
  499. $timeout(function () {
  500. if ($rootScope.taskContext.rpcStatus !== 'Reconnecting') {
  501. $rootScope.taskContext.rpcStatus = 'Reconnecting';
  502. }
  503. });
  504. });
  505. aria2TaskService.onConnectionWaitingToReconnect(function () {
  506. $timeout(function () {
  507. if ($rootScope.taskContext.rpcStatus !== 'Waiting to reconnect') {
  508. $rootScope.taskContext.rpcStatus = 'Waiting to reconnect';
  509. }
  510. });
  511. });
  512. // AriaNg Native shows notification via main process
  513. // aria2TaskService.onTaskCompleted(function (event) {
  514. // ariaNgNotificationService.notifyTaskComplete(event.task);
  515. // });
  516. //
  517. // aria2TaskService.onBtTaskCompleted(function (event) {
  518. // ariaNgNotificationService.notifyBtTaskComplete(event.task);
  519. // });
  520. //
  521. // aria2TaskService.onTaskErrorOccur(function (event) {
  522. // ariaNgNotificationService.notifyTaskError(event.task);
  523. // });
  524. $rootScope.$on('$locationChangeStart', function (event) {
  525. ariaNgCommonService.closeAllDialogs();
  526. $rootScope.loadPromise = null;
  527. delete $rootScope.keydownActions.selectAll;
  528. delete $rootScope.keydownActions.delete;
  529. delete $rootScope.swipeActions.extendLeftSwipe;
  530. delete $rootScope.swipeActions.extendRightSwipe;
  531. if (angular.isArray($rootScope.taskContext.list) && $rootScope.taskContext.list.length > 0) {
  532. $rootScope.taskContext.list.length = 0;
  533. }
  534. if (angular.isObject($rootScope.taskContext.selected)) {
  535. $rootScope.taskContext.selected = {};
  536. }
  537. $rootScope.taskContext.enableSelectAll = false;
  538. });
  539. $rootScope.$on('$routeChangeStart', function (event, next, current) {
  540. var location = $location.path();
  541. setNavbarSelected(location);
  542. $document.unbind('keypress');
  543. });
  544. $rootScope.$on('$viewContentLoaded', function () {
  545. ariaNgNativeElectronService.notifyMainProcessViewLoaded($location.path());
  546. });
  547. $rootScope.$on('$translateChangeSuccess', function(event, current, previous) {
  548. ariaNgNativeElectronService.setMainWindowLanguage();
  549. });
  550. if (ariaNgSettingService.isBrowserSupportDarkMode()) {
  551. var matchPreferColorScheme = $window.matchMedia('(prefers-color-scheme: dark)');
  552. matchPreferColorScheme.addEventListener('change', function (e) {
  553. ariaNgLogService.info('[root] system switches to ' + (e.matches ? 'dark' : 'light') + ' theme');
  554. if (ariaNgSettingService.getTheme() === 'system') {
  555. if (e.matches) {
  556. setDarkTheme();
  557. } else {
  558. setLightTheme();
  559. }
  560. }
  561. });
  562. }
  563. if (ariaNgSettingService.getAutoCheckUpdates() && ariaNgSettingService.getAutoCheckUpdates() !== 'never') {
  564. ariaNgNativeElectronService.getLastCheckUpdatesTimeAsync(function (lastCheckUpdatesTime) {
  565. var checkFrequency = ariaNgSettingService.getAutoCheckUpdates();
  566. var currentTime = parseInt(ariaNgCommonService.getCurrentUnixTime());
  567. var oneDaySeconds = 86400; // s
  568. var needCheckUpdates = false;
  569. if (!angular.isNumber(lastCheckUpdatesTime)) {
  570. needCheckUpdates = true;
  571. } else if (checkFrequency === 'daily' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds) {
  572. needCheckUpdates = true;
  573. } else if (checkFrequency === 'weekly' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds * 7) {
  574. needCheckUpdates = true;
  575. } else if (checkFrequency === 'monthly' && (currentTime - lastCheckUpdatesTime) >= oneDaySeconds * 31) {
  576. needCheckUpdates = true;
  577. }
  578. if (needCheckUpdates) {
  579. ariaNgLogService.debug('[root] need check for updates, last check time is ' + lastCheckUpdatesTime);
  580. autoCheckUpdates();
  581. ariaNgNativeElectronService.setLastCheckUpdatesTime(currentTime);
  582. } else {
  583. ariaNgLogService.debug('[root] do not need check for updates, last check time is ' + lastCheckUpdatesTime);
  584. }
  585. });
  586. }
  587. $rootScope.$on('$locationChangeSuccess', function (event, newUrl) {
  588. if (autoRefreshAfterPageLoad) {
  589. $window.location.reload();
  590. }
  591. });
  592. initTheme();
  593. initCheck();
  594. initNavbar();
  595. initContentWrapper();
  596. initFileDragSupport();
  597. }]);
  598. }());