aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/environment.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-06-27 19:04:19 -0700
committerAlex Yatskov <alex@foosoft.net>2020-06-27 19:04:19 -0700
commit88af95d20bfdbeb59d44bf0f0d46e772a329f839 (patch)
treed1dfa7268f274fed32061221c0f030e3647f9ae2 /ext/mixed/js/environment.js
parent19197a9a5d6a1f54a179d894577dfac513b97401 (diff)
parent0a6c08d0f53090a4ad48663bc5846ddae5723d52 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/mixed/js/environment.js')
-rw-r--r--ext/mixed/js/environment.js44
1 files changed, 37 insertions, 7 deletions
diff --git a/ext/mixed/js/environment.js b/ext/mixed/js/environment.js
index e5bc20a7..5bd84010 100644
--- a/ext/mixed/js/environment.js
+++ b/ext/mixed/js/environment.js
@@ -32,17 +32,40 @@ class Environment {
async _loadEnvironmentInfo() {
const browser = await this._getBrowser();
- const platform = await new Promise((resolve) => chrome.runtime.getPlatformInfo(resolve));
- const modifierInfo = this._getModifierInfo(browser, platform.os);
+ const os = await this._getOperatingSystem();
+ const modifierInfo = this._getModifierInfo(browser, os);
return {
browser,
- platform: {
- os: platform.os
- },
+ platform: {os},
modifiers: modifierInfo
};
}
+ async _getOperatingSystem() {
+ try {
+ const {os} = await this._getPlatformInfo();
+ if (typeof os === 'string') {
+ return os;
+ }
+ } catch (e) {
+ // NOP
+ }
+ return 'unknown';
+ }
+
+ _getPlatformInfo() {
+ return new Promise((resolve, reject) => {
+ chrome.runtime.getPlatformInfo((result) => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(error);
+ } else {
+ resolve(result);
+ }
+ });
+ });
+ }
+
async _getBrowser() {
if (EXTENSION_IS_BROWSER_EDGE) {
return 'edge';
@@ -96,8 +119,15 @@ class Environment {
['meta', 'Super']
];
break;
- default:
- throw new Error(`Invalid OS: ${os}`);
+ default: // 'unknown', etc
+ separator = ' + ';
+ osKeys = [
+ ['alt', 'Alt'],
+ ['ctrl', 'Ctrl'],
+ ['shift', 'Shift'],
+ ['meta', 'Meta']
+ ];
+ break;
}
const isFirefox = (browser === 'firefox' || browser === 'firefox-mobile');