Move apiGetEnvironmentInfo implementation into Backend

This commit is contained in:
toasted-nutbread 2019-12-09 21:58:32 -05:00
parent f786713466
commit 2fef2bf5a8
2 changed files with 30 additions and 30 deletions

View File

@ -89,34 +89,8 @@ function apiInjectStylesheet(css, sender) {
return utilBackend()._onApiInjectStylesheet({css}, sender); return utilBackend()._onApiInjectStylesheet({css}, sender);
} }
async function apiGetEnvironmentInfo() { function apiGetEnvironmentInfo() {
const browser = await _apiGetBrowser(); return utilBackend()._onApiGetEnvironmentInfo();
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) {
// NOP
}
return 'firefox';
} else {
return 'chrome';
}
} }
async function apiClipboardGet() { async function apiClipboardGet() {

View File

@ -464,8 +464,15 @@ class Backend {
}); });
} }
_onApiGetEnvironmentInfo() { async _onApiGetEnvironmentInfo() {
return apiGetEnvironmentInfo(); const browser = await Backend._getBrowser();
const platform = await new Promise((resolve) => chrome.runtime.getPlatformInfo(resolve));
return {
browser,
platform: {
os: platform.os
}
};
} }
_onApiClipboardGet() { _onApiClipboardGet() {
@ -638,6 +645,25 @@ class Backend {
// Edge throws exception for no reason here. // Edge throws exception for no reason here.
} }
} }
static async _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) {
// NOP
}
return 'firefox';
} else {
return 'chrome';
}
}
} }
Backend._messageHandlers = new Map([ Backend._messageHandlers = new Map([