aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/api.js28
-rw-r--r--ext/bg/js/backend.js3
-rw-r--r--ext/bg/js/settings.js19
3 files changed, 31 insertions, 19 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 9fefadca..da5ae4fe 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -270,3 +270,31 @@ function apiInjectStylesheet(css, sender) {
});
});
}
+
+async function apiGetEnvironmentInfo() {
+ const browser = await apiGetBrowser();
+ const platform = await new Promise((resolve) => chrome.runtime.getPlatformInfo(resolve));
+ return {
+ browser,
+ platform: {
+ os: platform.os
+ }
+ };
+}
+
+async function apiGetBrowser() {
+ if (EXTENSION_IS_BROWSER_EDGE) {
+ return 'edge';
+ }
+ if (typeof browser !== 'undefined') {
+ try {
+ const info = await browser.runtime.getBrowserInfo();
+ if (info.name === 'Fennec') {
+ return 'firefox-mobile';
+ }
+ } catch (e) { }
+ return 'firefox';
+ } else {
+ return 'chrome';
+ }
+}
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 32ff1bef..7560f39e 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -186,7 +186,8 @@ Backend.messageHandlers = {
screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender),
forward: ({action, params}, sender) => apiForward(action, params, sender),
frameInformationGet: (params, sender) => apiFrameInformationGet(sender),
- injectStylesheet: ({css}, sender) => apiInjectStylesheet(css, sender)
+ injectStylesheet: ({css}, sender) => apiInjectStylesheet(css, sender),
+ getEnvironmentInfo: () => apiGetEnvironmentInfo()
};
window.yomichan_backend = new Backend();
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index acc47f69..ba02641b 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -819,23 +819,6 @@ async function onAnkiFieldTemplatesReset(e) {
* Storage
*/
-async function getBrowser() {
- if (EXTENSION_IS_BROWSER_EDGE) {
- return 'edge';
- }
- if (typeof browser !== 'undefined') {
- try {
- const info = await browser.runtime.getBrowserInfo();
- if (info.name === 'Fennec') {
- return 'firefox-mobile';
- }
- } catch (e) { }
- return 'firefox';
- } else {
- return 'chrome';
- }
-}
-
function storageBytesToLabeledString(size) {
const base = 1000;
const labels = [' bytes', 'KB', 'MB', 'GB'];
@@ -865,7 +848,7 @@ async function isStoragePeristent() {
async function storageInfoInitialize() {
storagePersistInitialize();
- const browser = await getBrowser();
+ const {browser} = await apiGetEnvironmentInfo();
const container = document.querySelector('#storage-info');
container.setAttribute('data-browser', browser);