summaryrefslogtreecommitdiff
path: root/ext/js/extension
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/extension
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/extension')
-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 (