mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Add bridge debug info to options page
This commit is contained in:
37
ext/src/lib/getBridgeInfo.js
Normal file
37
ext/src/lib/getBridgeInfo.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import semver from "semver";
|
||||
|
||||
export default async function getBridgeInfo () {
|
||||
let applicationVersion;
|
||||
try {
|
||||
const response = await browser.runtime.sendNativeMessage(
|
||||
APPLICATION_NAME
|
||||
, { subject: "bridge:getInfo"
|
||||
, data: EXTENSION_VERSION });
|
||||
|
||||
applicationVersion = response.data;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare installed bridge version to the version the
|
||||
* extension was built alongside and is known to be
|
||||
* compatible with.
|
||||
*
|
||||
* TODO: Determine compatibility with semver and enforce/notify
|
||||
* user.
|
||||
*/
|
||||
if (applicationVersion !== APPLICATION_VERSION) {
|
||||
console.error(`Expecting ${APPLICATION_NAME} v${APPLICATION_VERSION}, found v${applicationVersion}.`
|
||||
, semver.lt(applicationVersion, APPLICATION_VERSION)
|
||||
? "Try updating the native app to the latest version."
|
||||
: "Try updating the extension to the latest version");
|
||||
}
|
||||
|
||||
return {
|
||||
version: applicationVersion
|
||||
, isVersionCompatible: applicationVersion === APPLICATION_VERSION
|
||||
, isVersionOlder: semver.lt(applicationVersion, APPLICATION_VERSION)
|
||||
, isVersionNewer: semver.gt(applicationVersion, APPLICATION_VERSION)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user