From cb236a743081e8ea4809a8a559abf9f0f22e771c Mon Sep 17 00:00:00 2001
From: toasted-nutbread <toasted-nutbread@users.noreply.github.com>
Date: Sun, 13 Oct 2019 17:20:55 -0400
Subject: Add apiGetEnvironmentInfo function

---
 ext/bg/js/api.js      | 28 ++++++++++++++++++++++++++++
 ext/bg/js/backend.js  |  3 ++-
 ext/bg/js/settings.js | 19 +------------------
 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');
+}
-- 
cgit v1.2.3