2020-12-12 17:35:56 +00:00
|
|
|
/*
|
2022-02-03 01:43:10 +00:00
|
|
|
* Copyright (C) 2020-2022 Yomichan Authors
|
2020-12-12 17:35:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global
|
2020-12-28 22:41:59 +00:00
|
|
|
* DocumentFocusController
|
2022-05-29 01:57:25 +00:00
|
|
|
* ExtensionContentController
|
2021-04-09 02:52:28 +00:00
|
|
|
* ModalController
|
|
|
|
* PermissionsOriginController
|
2021-02-08 22:52:41 +00:00
|
|
|
* PermissionsToggleController
|
2021-03-03 03:08:34 +00:00
|
|
|
* PersistentStorageController
|
2021-02-08 22:52:41 +00:00
|
|
|
* SettingsController
|
2021-03-03 03:46:26 +00:00
|
|
|
* SettingsDisplayController
|
2020-12-12 17:35:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
async function setupEnvironmentInfo() {
|
2020-12-18 22:00:34 +00:00
|
|
|
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
|
2021-02-14 20:53:35 +00:00
|
|
|
const {browser, platform} = await yomichan.api.getEnvironmentInfo();
|
2020-12-12 17:35:56 +00:00
|
|
|
document.documentElement.dataset.browser = browser;
|
|
|
|
document.documentElement.dataset.os = platform.os;
|
2020-12-18 22:00:34 +00:00
|
|
|
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
|
2020-12-12 17:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function isAllowedIncognitoAccess() {
|
|
|
|
return await new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function isAllowedFileSchemeAccess() {
|
|
|
|
return await new Promise((resolve) => chrome.extension.isAllowedFileSchemeAccess(resolve));
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:52:41 +00:00
|
|
|
function setupPermissionsToggles() {
|
|
|
|
const manifest = chrome.runtime.getManifest();
|
|
|
|
let optionalPermissions = manifest.optional_permissions;
|
|
|
|
if (!Array.isArray(optionalPermissions)) { optionalPermissions = []; }
|
|
|
|
optionalPermissions = new Set(optionalPermissions);
|
2020-12-12 17:35:56 +00:00
|
|
|
|
2021-02-08 22:52:41 +00:00
|
|
|
const hasAllPermisions = (set, values) => {
|
|
|
|
for (const value of values) {
|
|
|
|
if (!set.has(value)) { return false; }
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2021-01-30 20:05:08 +00:00
|
|
|
|
2021-02-08 22:52:41 +00:00
|
|
|
for (const toggle of document.querySelectorAll('.permissions-toggle')) {
|
|
|
|
let permissions = toggle.dataset.requiredPermissions;
|
|
|
|
permissions = (typeof permissions === 'string' && permissions.length > 0 ? permissions.split(' ') : []);
|
|
|
|
toggle.disabled = !hasAllPermisions(optionalPermissions, permissions);
|
|
|
|
}
|
2021-01-30 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 17:35:56 +00:00
|
|
|
(async () => {
|
|
|
|
try {
|
2020-12-28 22:41:59 +00:00
|
|
|
const documentFocusController = new DocumentFocusController();
|
|
|
|
documentFocusController.prepare();
|
|
|
|
|
2022-05-29 01:57:25 +00:00
|
|
|
const extensionContentController = new ExtensionContentController();
|
|
|
|
extensionContentController.prepare();
|
2020-12-12 17:35:56 +00:00
|
|
|
|
2022-05-29 01:57:25 +00:00
|
|
|
setupPermissionsToggles();
|
2021-03-03 03:46:26 +00:00
|
|
|
|
2020-12-12 17:35:56 +00:00
|
|
|
await yomichan.prepare();
|
|
|
|
|
|
|
|
setupEnvironmentInfo();
|
|
|
|
|
|
|
|
const permissionsCheckboxes = [
|
|
|
|
document.querySelector('#permission-checkbox-allow-in-private-windows'),
|
|
|
|
document.querySelector('#permission-checkbox-allow-file-url-access')
|
|
|
|
];
|
|
|
|
|
|
|
|
const permissions = await Promise.all([
|
|
|
|
isAllowedIncognitoAccess(),
|
|
|
|
isAllowedFileSchemeAccess()
|
|
|
|
]);
|
|
|
|
|
|
|
|
for (let i = 0, ii = permissions.length; i < ii; ++i) {
|
|
|
|
permissionsCheckboxes[i].checked = permissions[i];
|
|
|
|
}
|
|
|
|
|
2021-04-09 02:52:28 +00:00
|
|
|
const modalController = new ModalController();
|
|
|
|
modalController.prepare();
|
|
|
|
|
2022-08-20 15:31:50 +00:00
|
|
|
const settingsController = new SettingsController();
|
|
|
|
await settingsController.prepare();
|
2021-02-08 22:52:41 +00:00
|
|
|
|
|
|
|
const permissionsToggleController = new PermissionsToggleController(settingsController);
|
|
|
|
permissionsToggleController.prepare();
|
2020-12-12 17:35:56 +00:00
|
|
|
|
2021-04-09 02:52:28 +00:00
|
|
|
const permissionsOriginController = new PermissionsOriginController(settingsController);
|
|
|
|
permissionsOriginController.prepare();
|
|
|
|
|
2021-03-03 03:08:34 +00:00
|
|
|
const persistentStorageController = new PersistentStorageController();
|
|
|
|
persistentStorageController.prepare();
|
|
|
|
|
2020-12-12 17:35:56 +00:00
|
|
|
await promiseTimeout(100);
|
|
|
|
|
|
|
|
document.documentElement.dataset.loaded = 'true';
|
2021-03-03 03:46:26 +00:00
|
|
|
|
2021-04-09 02:52:28 +00:00
|
|
|
const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
|
2021-03-03 03:46:26 +00:00
|
|
|
settingsDisplayController.prepare();
|
2020-12-12 17:35:56 +00:00
|
|
|
} catch (e) {
|
2021-02-14 22:52:01 +00:00
|
|
|
log.error(e);
|
2020-12-12 17:35:56 +00:00
|
|
|
}
|
|
|
|
})();
|