Add apiGetEnvironmentInfo function

This commit is contained in:
toasted-nutbread 2019-10-13 17:20:55 -04:00
parent c92fc11fcd
commit cb236a7430
4 changed files with 35 additions and 19 deletions

View File

@ -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';
}
}

View File

@ -186,7 +186,8 @@ Backend.messageHandlers = {
screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender), screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender),
forward: ({action, params}, sender) => apiForward(action, params, sender), forward: ({action, params}, sender) => apiForward(action, params, sender),
frameInformationGet: (params, sender) => apiFrameInformationGet(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(); window.yomichan_backend = new Backend();

View File

@ -819,23 +819,6 @@ async function onAnkiFieldTemplatesReset(e) {
* Storage * 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) { function storageBytesToLabeledString(size) {
const base = 1000; const base = 1000;
const labels = [' bytes', 'KB', 'MB', 'GB']; const labels = [' bytes', 'KB', 'MB', 'GB'];
@ -865,7 +848,7 @@ async function isStoragePeristent() {
async function storageInfoInitialize() { async function storageInfoInitialize() {
storagePersistInitialize(); storagePersistInitialize();
const browser = await getBrowser(); const {browser} = await apiGetEnvironmentInfo();
const container = document.querySelector('#storage-info'); const container = document.querySelector('#storage-info');
container.setAttribute('data-browser', browser); container.setAttribute('data-browser', browser);

View File

@ -68,3 +68,7 @@ function apiFrameInformationGet() {
function apiInjectStylesheet(css) { function apiInjectStylesheet(css) {
return utilInvoke('injectStylesheet', {css}); return utilInvoke('injectStylesheet', {css});
} }
function apiGetEnvironmentInfo() {
return utilInvoke('getEnvironmentInfo');
}