From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- ext/js/extension/environment.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ext/js/extension') 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} + */ 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} + */ async _loadEnvironmentInfo() { const os = await this._getOperatingSystem(); const browser = await this._getBrowser(os); @@ -40,6 +51,9 @@ export class Environment { }; } + /** + * @returns {Promise} + */ async _getOperatingSystem() { try { const {os} = await this._getPlatformInfo(); @@ -52,6 +66,9 @@ export class Environment { return 'unknown'; } + /** + * @returns {Promise} + */ _getPlatformInfo() { return new Promise((resolve, reject) => { chrome.runtime.getPlatformInfo((result) => { @@ -65,6 +82,10 @@ export class Environment { }); } + /** + * @param {import('environment').OperatingSystem} os + * @returns {Promise} + */ 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 ( -- cgit v1.2.3