aboutsummaryrefslogtreecommitdiff
path: root/ext/js/extension/environment.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/extension/environment.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/extension/environment.js')
-rw-r--r--ext/js/extension/environment.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/js/extension/environment.js b/ext/js/extension/environment.js
index 8c43f1a0..48a1a92c 100644
--- a/ext/js/extension/environment.js
+++ b/ext/js/extension/environment.js
@@ -18,18 +18,29 @@
export class Environment {
constructor() {
+ /** @type {?import('environment').Info} */
this._cachedEnvironmentInfo = null;
}
+ /**
+ * @returns {Promise<void>}
+ */
async prepare() {
this._cachedEnvironmentInfo = await this._loadEnvironmentInfo();
}
+ /**
+ * @returns {import('environment').Info}
+ * @throws {Error}
+ */
getInfo() {
if (this._cachedEnvironmentInfo === null) { throw new Error('Not prepared'); }
return this._cachedEnvironmentInfo;
}
+ /**
+ * @returns {Promise<import('environment').Info>}
+ */
async _loadEnvironmentInfo() {
const os = await this._getOperatingSystem();
const browser = await this._getBrowser(os);
@@ -40,6 +51,9 @@ export class Environment {
};
}
+ /**
+ * @returns {Promise<import('environment').OperatingSystem>}
+ */
async _getOperatingSystem() {
try {
const {os} = await this._getPlatformInfo();
@@ -52,6 +66,9 @@ export class Environment {
return 'unknown';
}
+ /**
+ * @returns {Promise<chrome.runtime.PlatformInfo>}
+ */
_getPlatformInfo() {
return new Promise((resolve, reject) => {
chrome.runtime.getPlatformInfo((result) => {
@@ -65,6 +82,10 @@ export class Environment {
});
}
+ /**
+ * @param {import('environment').OperatingSystem} os
+ * @returns {Promise<import('environment').Browser>}
+ */
async _getBrowser(os) {
try {
if (chrome.runtime.getURL('/').startsWith('ms-browser-extension://')) {
@@ -89,6 +110,9 @@ export class Environment {
}
}
+ /**
+ * @returns {boolean};
+ */
_isSafari() {
const {vendor, userAgent} = navigator;
return (