diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 17:20:55 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 17:20:55 -0400 |
commit | cb236a743081e8ea4809a8a559abf9f0f22e771c (patch) | |
tree | 581b4ccc531d2191a2855aefd1bfe556ac228443 /ext | |
parent | c92fc11fcdad294059931a0927ec7f7701eb5be5 (diff) |
Add apiGetEnvironmentInfo function
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/api.js | 28 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 3 | ||||
-rw-r--r-- | ext/bg/js/settings.js | 19 | ||||
-rw-r--r-- | ext/fg/js/api.js | 4 |
4 files changed, 35 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); diff --git a/ext/fg/js/api.js b/ext/fg/js/api.js index dcfb2a09..2294cb8b 100644 --- a/ext/fg/js/api.js +++ b/ext/fg/js/api.js @@ -68,3 +68,7 @@ function apiFrameInformationGet() { function apiInjectStylesheet(css) { return utilInvoke('injectStylesheet', {css}); } + +function apiGetEnvironmentInfo() { + return utilInvoke('getEnvironmentInfo'); +} |