aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/pages')
-rw-r--r--ext/js/pages/action-popup-main.js12
-rw-r--r--ext/js/pages/info-main.js83
-rw-r--r--ext/js/pages/permissions-main.js82
-rw-r--r--ext/js/pages/settings/popup-preview-frame-main.js43
-rw-r--r--ext/js/pages/settings/settings-main.js165
-rw-r--r--ext/js/pages/welcome-main.js83
6 files changed, 202 insertions, 266 deletions
diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js
index 6d2c85ab..e5738878 100644
--- a/ext/js/pages/action-popup-main.js
+++ b/ext/js/pages/action-popup-main.js
@@ -305,17 +305,9 @@ class DisplayController {
}
}
-/** Entry point. */
-async function main() {
- const application = new Application();
- await application.prepare();
-
+await Application.main(async (application) => {
application.api.logIndicatorClear();
const displayController = new DisplayController(application.api);
displayController.prepare();
-
- application.ready();
-}
-
-await main();
+});
diff --git a/ext/js/pages/info-main.js b/ext/js/pages/info-main.js
index ca5094b1..7d7d56a5 100644
--- a/ext/js/pages/info-main.js
+++ b/ext/js/pages/info-main.js
@@ -17,7 +17,6 @@
*/
import {Application} from '../application.js';
-import {log} from '../core/logger.js';
import {promiseTimeout} from '../core/utilities.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
@@ -116,59 +115,49 @@ async function showDictionaryInfo(api) {
container.appendChild(fragment);
}
-/** Entry point. */
-async function main() {
- try {
- const documentFocusController = new DocumentFocusController();
- documentFocusController.prepare();
-
- const manifest = chrome.runtime.getManifest();
- const language = chrome.i18n.getUILanguage();
-
- const application = new Application();
- await application.prepare();
+await Application.main(async (application) => {
+ const documentFocusController = new DocumentFocusController();
+ documentFocusController.prepare();
- const {userAgent} = navigator;
- const {name, version} = manifest;
- const {browser, platform: {os}} = await application.api.getEnvironmentInfo();
+ const manifest = chrome.runtime.getManifest();
+ const language = chrome.i18n.getUILanguage();
- /** @type {HTMLLinkElement} */
- const thisVersionLink = querySelectorNotNull(document, '#release-notes-this-version-link');
- const {hrefFormat} = thisVersionLink.dataset;
- thisVersionLink.href = typeof hrefFormat === 'string' ? hrefFormat.replace(/\{version\}/g, version) : '';
+ const {userAgent} = navigator;
+ const {name, version} = manifest;
+ const {browser, platform: {os}} = await application.api.getEnvironmentInfo();
- /** @type {HTMLElement} */
- const versionElement = querySelectorNotNull(document, '#version');
- /** @type {HTMLElement} */
- const browserElement = querySelectorNotNull(document, '#browser');
- /** @type {HTMLElement} */
- const platformElement = querySelectorNotNull(document, '#platform');
- /** @type {HTMLElement} */
- const languageElement = querySelectorNotNull(document, '#language');
- /** @type {HTMLElement} */
- const userAgentElement = querySelectorNotNull(document, '#user-agent');
+ /** @type {HTMLLinkElement} */
+ const thisVersionLink = querySelectorNotNull(document, '#release-notes-this-version-link');
+ const {hrefFormat} = thisVersionLink.dataset;
+ thisVersionLink.href = typeof hrefFormat === 'string' ? hrefFormat.replace(/\{version\}/g, version) : '';
- versionElement.textContent = `${name} ${version}`;
- browserElement.textContent = getBrowserDisplayName(browser);
- platformElement.textContent = getOperatingSystemDisplayName(os);
- languageElement.textContent = `${language}`;
- userAgentElement.textContent = userAgent;
+ /** @type {HTMLElement} */
+ const versionElement = querySelectorNotNull(document, '#version');
+ /** @type {HTMLElement} */
+ const browserElement = querySelectorNotNull(document, '#browser');
+ /** @type {HTMLElement} */
+ const platformElement = querySelectorNotNull(document, '#platform');
+ /** @type {HTMLElement} */
+ const languageElement = querySelectorNotNull(document, '#language');
+ /** @type {HTMLElement} */
+ const userAgentElement = querySelectorNotNull(document, '#user-agent');
- showAnkiConnectInfo(application.api);
- showDictionaryInfo(application.api);
+ versionElement.textContent = `${name} ${version}`;
+ browserElement.textContent = getBrowserDisplayName(browser);
+ platformElement.textContent = getOperatingSystemDisplayName(os);
+ languageElement.textContent = `${language}`;
+ userAgentElement.textContent = userAgent;
- const settingsController = new SettingsController(application);
- await settingsController.prepare();
+ showAnkiConnectInfo(application.api);
+ showDictionaryInfo(application.api);
- const backupController = new BackupController(settingsController, null);
- await backupController.prepare();
+ const settingsController = new SettingsController(application);
+ await settingsController.prepare();
- await promiseTimeout(100);
+ const backupController = new BackupController(settingsController, null);
+ await backupController.prepare();
- document.documentElement.dataset.loaded = 'true';
- } catch (e) {
- log.error(e);
- }
-}
+ await promiseTimeout(100);
-await main();
+ document.documentElement.dataset.loaded = 'true';
+});
diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js
index 1659bea5..3092782b 100644
--- a/ext/js/pages/permissions-main.js
+++ b/ext/js/pages/permissions-main.js
@@ -17,7 +17,6 @@
*/
import {Application} from '../application.js';
-import {log} from '../core/logger.js';
import {promiseTimeout} from '../core/utilities.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
@@ -87,63 +86,52 @@ function setupPermissionsToggles() {
}
}
-/** Entry point. */
-async function main() {
- try {
- const application = new Application();
+await Application.main(async (application) => {
+ const documentFocusController = new DocumentFocusController();
+ documentFocusController.prepare();
- const documentFocusController = new DocumentFocusController();
- documentFocusController.prepare();
+ const extensionContentController = new ExtensionContentController();
+ extensionContentController.prepare();
- const extensionContentController = new ExtensionContentController();
- extensionContentController.prepare();
+ setupPermissionsToggles();
- setupPermissionsToggles();
+ setupEnvironmentInfo(application.api);
- await application.prepare();
+ /** @type {HTMLInputElement} */
+ const permissionCheckbox1 = querySelectorNotNull(document, '#permission-checkbox-allow-in-private-windows');
+ /** @type {HTMLInputElement} */
+ const permissionCheckbox2 = querySelectorNotNull(document, '#permission-checkbox-allow-file-url-access');
+ /** @type {HTMLInputElement[]} */
+ const permissionsCheckboxes = [permissionCheckbox1, permissionCheckbox2];
- setupEnvironmentInfo(application.api);
+ const permissions = await Promise.all([
+ isAllowedIncognitoAccess(),
+ isAllowedFileSchemeAccess()
+ ]);
- /** @type {HTMLInputElement} */
- const permissionCheckbox1 = querySelectorNotNull(document, '#permission-checkbox-allow-in-private-windows');
- /** @type {HTMLInputElement} */
- const permissionCheckbox2 = querySelectorNotNull(document, '#permission-checkbox-allow-file-url-access');
- /** @type {HTMLInputElement[]} */
- const permissionsCheckboxes = [permissionCheckbox1, permissionCheckbox2];
-
- const permissions = await Promise.all([
- isAllowedIncognitoAccess(),
- isAllowedFileSchemeAccess()
- ]);
-
- for (let i = 0, ii = permissions.length; i < ii; ++i) {
- permissionsCheckboxes[i].checked = permissions[i];
- }
-
- const modalController = new ModalController();
- modalController.prepare();
+ for (let i = 0, ii = permissions.length; i < ii; ++i) {
+ permissionsCheckboxes[i].checked = permissions[i];
+ }
- const settingsController = new SettingsController(application);
- await settingsController.prepare();
+ const modalController = new ModalController();
+ modalController.prepare();
- const permissionsToggleController = new PermissionsToggleController(settingsController);
- permissionsToggleController.prepare();
+ const settingsController = new SettingsController(application);
+ await settingsController.prepare();
- const permissionsOriginController = new PermissionsOriginController(settingsController);
- permissionsOriginController.prepare();
+ const permissionsToggleController = new PermissionsToggleController(settingsController);
+ permissionsToggleController.prepare();
- const persistentStorageController = new PersistentStorageController(application);
- persistentStorageController.prepare();
+ const permissionsOriginController = new PermissionsOriginController(settingsController);
+ permissionsOriginController.prepare();
- await promiseTimeout(100);
+ const persistentStorageController = new PersistentStorageController(application);
+ persistentStorageController.prepare();
- document.documentElement.dataset.loaded = 'true';
+ await promiseTimeout(100);
- const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
- settingsDisplayController.prepare();
- } catch (e) {
- log.error(e);
- }
-}
+ document.documentElement.dataset.loaded = 'true';
-await main();
+ const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
+ settingsDisplayController.prepare();
+});
diff --git a/ext/js/pages/settings/popup-preview-frame-main.js b/ext/js/pages/settings/popup-preview-frame-main.js
index fd08bf1d..cffbf01b 100644
--- a/ext/js/pages/settings/popup-preview-frame-main.js
+++ b/ext/js/pages/settings/popup-preview-frame-main.js
@@ -18,37 +18,26 @@
import {PopupFactory} from '../../app/popup-factory.js';
import {Application} from '../../application.js';
-import {log} from '../../core/logger.js';
import {HotkeyHandler} from '../../input/hotkey-handler.js';
import {PopupPreviewFrame} from './popup-preview-frame.js';
-/** Entry point. */
-async function main() {
- try {
- const application = new Application();
- await application.prepare();
-
- const {tabId, frameId} = await application.api.frameInformationGet();
- if (typeof tabId === 'undefined') {
- throw new Error('Failed to get tabId');
- }
- if (typeof frameId === 'undefined') {
- throw new Error('Failed to get frameId');
- }
-
- const hotkeyHandler = new HotkeyHandler();
- hotkeyHandler.prepare(application.crossFrame);
+await Application.main(async (application) => {
+ const {tabId, frameId} = await application.api.frameInformationGet();
+ if (typeof tabId === 'undefined') {
+ throw new Error('Failed to get tabId');
+ }
+ if (typeof frameId === 'undefined') {
+ throw new Error('Failed to get frameId');
+ }
- const popupFactory = new PopupFactory(application, frameId);
- popupFactory.prepare();
+ const hotkeyHandler = new HotkeyHandler();
+ hotkeyHandler.prepare(application.crossFrame);
- const preview = new PopupPreviewFrame(application, tabId, frameId, popupFactory, hotkeyHandler);
- await preview.prepare();
+ const popupFactory = new PopupFactory(application, frameId);
+ popupFactory.prepare();
- document.documentElement.dataset.loaded = 'true';
- } catch (e) {
- log.error(e);
- }
-}
+ const preview = new PopupPreviewFrame(application, tabId, frameId, popupFactory, hotkeyHandler);
+ await preview.prepare();
-await main();
+ document.documentElement.dataset.loaded = 'true';
+});
diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js
index c3391173..dc4b36c9 100644
--- a/ext/js/pages/settings/settings-main.js
+++ b/ext/js/pages/settings/settings-main.js
@@ -17,7 +17,6 @@
*/
import {Application} from '../../application.js';
-import {log} from '../../core/logger.js';
import {DocumentFocusController} from '../../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {ExtensionContentController} from '../common/extension-content-controller.js';
@@ -58,124 +57,114 @@ async function setupGenericSettingController(genericSettingController) {
await genericSettingController.refresh();
}
-/** Entry point. */
-async function main() {
- try {
- const documentFocusController = new DocumentFocusController();
- documentFocusController.prepare();
+await Application.main(async (application) => {
+ const documentFocusController = new DocumentFocusController();
+ documentFocusController.prepare();
- const extensionContentController = new ExtensionContentController();
- extensionContentController.prepare();
+ const extensionContentController = new ExtensionContentController();
+ extensionContentController.prepare();
- /** @type {HTMLElement} */
- const statusFooterElement = querySelectorNotNull(document, '.status-footer-container');
- const statusFooter = new StatusFooter(statusFooterElement);
- statusFooter.prepare();
+ /** @type {HTMLElement} */
+ const statusFooterElement = querySelectorNotNull(document, '.status-footer-container');
+ const statusFooter = new StatusFooter(statusFooterElement);
+ statusFooter.prepare();
- /** @type {?number} */
- let prepareTimer = window.setTimeout(() => {
- prepareTimer = null;
- document.documentElement.dataset.loadingStalled = 'true';
- }, 1000);
+ /** @type {?number} */
+ let prepareTimer = window.setTimeout(() => {
+ prepareTimer = null;
+ document.documentElement.dataset.loadingStalled = 'true';
+ }, 1000);
- const application = new Application();
- await application.prepare();
-
- if (prepareTimer !== null) {
- clearTimeout(prepareTimer);
- prepareTimer = null;
- }
- delete document.documentElement.dataset.loadingStalled;
-
- const preparePromises = [];
+ if (prepareTimer !== null) {
+ clearTimeout(prepareTimer);
+ prepareTimer = null;
+ }
+ delete document.documentElement.dataset.loadingStalled;
- const modalController = new ModalController();
- modalController.prepare();
+ const preparePromises = [];
- const settingsController = new SettingsController(application);
- await settingsController.prepare();
+ const modalController = new ModalController();
+ modalController.prepare();
- const persistentStorageController = new PersistentStorageController(application);
- persistentStorageController.prepare();
+ const settingsController = new SettingsController(application);
+ await settingsController.prepare();
- const storageController = new StorageController(persistentStorageController);
- storageController.prepare();
+ const persistentStorageController = new PersistentStorageController(application);
+ persistentStorageController.prepare();
- const dictionaryController = new DictionaryController(settingsController, modalController, statusFooter);
- dictionaryController.prepare();
+ const storageController = new StorageController(persistentStorageController);
+ storageController.prepare();
- const dictionaryImportController = new DictionaryImportController(settingsController, modalController, statusFooter);
- dictionaryImportController.prepare();
+ const dictionaryController = new DictionaryController(settingsController, modalController, statusFooter);
+ dictionaryController.prepare();
- const genericSettingController = new GenericSettingController(settingsController);
- preparePromises.push(setupGenericSettingController(genericSettingController));
+ const dictionaryImportController = new DictionaryImportController(settingsController, modalController, statusFooter);
+ dictionaryImportController.prepare();
- const audioController = new AudioController(settingsController, modalController);
- audioController.prepare();
+ const genericSettingController = new GenericSettingController(settingsController);
+ preparePromises.push(setupGenericSettingController(genericSettingController));
- const profileController = new ProfileController(settingsController, modalController);
- profileController.prepare();
+ const audioController = new AudioController(settingsController, modalController);
+ audioController.prepare();
- const settingsBackup = new BackupController(settingsController, modalController);
- settingsBackup.prepare();
+ const profileController = new ProfileController(settingsController, modalController);
+ profileController.prepare();
- const ankiController = new AnkiController(settingsController);
- ankiController.prepare();
+ const settingsBackup = new BackupController(settingsController, modalController);
+ settingsBackup.prepare();
- const ankiTemplatesController = new AnkiTemplatesController(settingsController, modalController, ankiController);
- ankiTemplatesController.prepare();
+ const ankiController = new AnkiController(settingsController);
+ ankiController.prepare();
- const popupPreviewController = new PopupPreviewController(settingsController);
- popupPreviewController.prepare();
+ const ankiTemplatesController = new AnkiTemplatesController(settingsController, modalController, ankiController);
+ ankiTemplatesController.prepare();
- const scanInputsController = new ScanInputsController(settingsController);
- scanInputsController.prepare();
+ const popupPreviewController = new PopupPreviewController(settingsController);
+ popupPreviewController.prepare();
- const simpleScanningInputController = new ScanInputsSimpleController(settingsController);
- simpleScanningInputController.prepare();
+ const scanInputsController = new ScanInputsController(settingsController);
+ scanInputsController.prepare();
- const nestedPopupsController = new NestedPopupsController(settingsController);
- nestedPopupsController.prepare();
+ const simpleScanningInputController = new ScanInputsSimpleController(settingsController);
+ simpleScanningInputController.prepare();
- const permissionsToggleController = new PermissionsToggleController(settingsController);
- permissionsToggleController.prepare();
+ const nestedPopupsController = new NestedPopupsController(settingsController);
+ nestedPopupsController.prepare();
- const secondarySearchDictionaryController = new SecondarySearchDictionaryController(settingsController);
- secondarySearchDictionaryController.prepare();
+ const permissionsToggleController = new PermissionsToggleController(settingsController);
+ permissionsToggleController.prepare();
- const translationTextReplacementsController = new TranslationTextReplacementsController(settingsController);
- translationTextReplacementsController.prepare();
+ const secondarySearchDictionaryController = new SecondarySearchDictionaryController(settingsController);
+ secondarySearchDictionaryController.prepare();
- const sentenceTerminationCharactersController = new SentenceTerminationCharactersController(settingsController);
- sentenceTerminationCharactersController.prepare();
+ const translationTextReplacementsController = new TranslationTextReplacementsController(settingsController);
+ translationTextReplacementsController.prepare();
- const keyboardShortcutController = new KeyboardShortcutController(settingsController);
- keyboardShortcutController.prepare();
+ const sentenceTerminationCharactersController = new SentenceTerminationCharactersController(settingsController);
+ sentenceTerminationCharactersController.prepare();
- const extensionKeyboardShortcutController = new ExtensionKeyboardShortcutController(settingsController);
- extensionKeyboardShortcutController.prepare();
+ const keyboardShortcutController = new KeyboardShortcutController(settingsController);
+ keyboardShortcutController.prepare();
- const popupWindowController = new PopupWindowController(application.api);
- popupWindowController.prepare();
+ const extensionKeyboardShortcutController = new ExtensionKeyboardShortcutController(settingsController);
+ extensionKeyboardShortcutController.prepare();
- const mecabController = new MecabController(application.api);
- mecabController.prepare();
+ const popupWindowController = new PopupWindowController(application.api);
+ popupWindowController.prepare();
- const collapsibleDictionaryController = new CollapsibleDictionaryController(settingsController);
- collapsibleDictionaryController.prepare();
+ const mecabController = new MecabController(application.api);
+ mecabController.prepare();
- const sortFrequencyDictionaryController = new SortFrequencyDictionaryController(settingsController);
- sortFrequencyDictionaryController.prepare();
+ const collapsibleDictionaryController = new CollapsibleDictionaryController(settingsController);
+ collapsibleDictionaryController.prepare();
- await Promise.all(preparePromises);
+ const sortFrequencyDictionaryController = new SortFrequencyDictionaryController(settingsController);
+ sortFrequencyDictionaryController.prepare();
- document.documentElement.dataset.loaded = 'true';
+ await Promise.all(preparePromises);
- const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
- settingsDisplayController.prepare();
- } catch (e) {
- log.error(e);
- }
-}
+ document.documentElement.dataset.loaded = 'true';
-await main();
+ const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
+ settingsDisplayController.prepare();
+});
diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js
index 030d2826..82afaacb 100644
--- a/ext/js/pages/welcome-main.js
+++ b/ext/js/pages/welcome-main.js
@@ -17,7 +17,6 @@
*/
import {Application} from '../application.js';
-import {log} from '../core/logger.js';
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {ExtensionContentController} from './common/extension-content-controller.js';
@@ -50,64 +49,54 @@ async function setupGenericSettingsController(genericSettingController) {
await genericSettingController.refresh();
}
-/** Entry point. */
-async function main() {
- try {
- const documentFocusController = new DocumentFocusController();
- documentFocusController.prepare();
+await Application.main(async (application) => {
+ const documentFocusController = new DocumentFocusController();
+ documentFocusController.prepare();
- const extensionContentController = new ExtensionContentController();
- extensionContentController.prepare();
+ const extensionContentController = new ExtensionContentController();
+ extensionContentController.prepare();
- /** @type {HTMLElement} */
- const statusFooterElement = querySelectorNotNull(document, '.status-footer-container');
- const statusFooter = new StatusFooter(statusFooterElement);
- statusFooter.prepare();
+ /** @type {HTMLElement} */
+ const statusFooterElement = querySelectorNotNull(document, '.status-footer-container');
+ const statusFooter = new StatusFooter(statusFooterElement);
+ statusFooter.prepare();
- const application = new Application();
- await application.prepare();
+ setupEnvironmentInfo(application.api);
- setupEnvironmentInfo(application.api);
+ chrome.storage.session.get({'needsCustomTemplatesWarning': false}).then((result) => {
+ if (result.needsCustomTemplatesWarning) {
+ document.documentElement.dataset.warnCustomTemplates = 'true';
+ chrome.storage.session.remove(['needsCustomTemplatesWarning']);
+ }
+ });
- chrome.storage.session.get({'needsCustomTemplatesWarning': false}).then((result) => {
- if (result.needsCustomTemplatesWarning) {
- document.documentElement.dataset.warnCustomTemplates = 'true';
- chrome.storage.session.remove(['needsCustomTemplatesWarning']);
- }
- });
+ const preparePromises = [];
- const preparePromises = [];
+ const modalController = new ModalController();
+ modalController.prepare();
- const modalController = new ModalController();
- modalController.prepare();
+ const settingsController = new SettingsController(application);
+ await settingsController.prepare();
- const settingsController = new SettingsController(application);
- await settingsController.prepare();
+ const dictionaryController = new DictionaryController(settingsController, modalController, statusFooter);
+ dictionaryController.prepare();
- const dictionaryController = new DictionaryController(settingsController, modalController, statusFooter);
- dictionaryController.prepare();
+ const dictionaryImportController = new DictionaryImportController(settingsController, modalController, statusFooter);
+ dictionaryImportController.prepare();
- const dictionaryImportController = new DictionaryImportController(settingsController, modalController, statusFooter);
- dictionaryImportController.prepare();
+ const genericSettingController = new GenericSettingController(settingsController);
+ preparePromises.push(setupGenericSettingsController(genericSettingController));
- const genericSettingController = new GenericSettingController(settingsController);
- preparePromises.push(setupGenericSettingsController(genericSettingController));
+ const simpleScanningInputController = new ScanInputsSimpleController(settingsController);
+ simpleScanningInputController.prepare();
- const simpleScanningInputController = new ScanInputsSimpleController(settingsController);
- simpleScanningInputController.prepare();
+ const recommendedPermissionsController = new RecommendedPermissionsController(settingsController);
+ recommendedPermissionsController.prepare();
- const recommendedPermissionsController = new RecommendedPermissionsController(settingsController);
- recommendedPermissionsController.prepare();
+ await Promise.all(preparePromises);
- await Promise.all(preparePromises);
+ document.documentElement.dataset.loaded = 'true';
- document.documentElement.dataset.loaded = 'true';
-
- const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
- settingsDisplayController.prepare();
- } catch (e) {
- log.error(e);
- }
-}
-
-await main();
+ const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
+ settingsDisplayController.prepare();
+});