diff --git a/app/src/main.js b/app/src/main.js index 0e3252d..c3c269c 100755 --- a/app/src/main.js +++ b/app/src/main.js @@ -97,11 +97,11 @@ async function handleMessage (message) { switch (message.subject) { - case "bridge:initialize": { + case "bridge:getInfo": { const extensionVersion = message.data; return { - subject: "main:bridgeInitialized" + subject: "main:bridgeInfo" , data: __applicationVersion }; }; diff --git a/ext/src/_locales/en/messages.json b/ext/src/_locales/en/messages.json index eb20c60..477992c 100755 --- a/ext/src/_locales/en/messages.json +++ b/ext/src/_locales/en/messages.json @@ -18,6 +18,34 @@ } + , "optionsBridgeCategoryName": { + "message": "Bridge" + } + , "optionsBridgeCategoryDescription": { + "message": "Native bridge application." + } + , "optionsBridgeLoading": { + "message": "Loading bridge info..." + } + , "optionsBridgeMissing": { + "message": "Bridge application not found. Try downloading and installing the latest version." + } + , "optionsBridgeInfo": { + "message": "Bridge info:" + } + , "optionsBridgeStatusCompatible": { + "message": "STATUS: COMPATIBLE" + } + , "optionsBridgeStatusIncompatible": { + "message": "STATUS: INCOMPATIBLE" + } + , "optionsBridgeOlder": { + "message": "Bridge version older than expected, try updating bridge to the latest bridge version." + } + , "optionsBridgeNewer": { + "message": "Bridge version newer than expected, try updating extension to the latest bridge version." + } + , "optionsMediaCategoryName": { "message": "Media casting" } diff --git a/ext/src/lib/getBridgeInfo.js b/ext/src/lib/getBridgeInfo.js new file mode 100644 index 0000000..56b9043 --- /dev/null +++ b/ext/src/lib/getBridgeInfo.js @@ -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) + }; +} diff --git a/ext/src/main.js b/ext/src/main.js index d515d8a..603de3d 100755 --- a/ext/src/main.js +++ b/ext/src/main.js @@ -340,12 +340,6 @@ function initBridge (tabId, frameId) { bridgeMap.set(tabId, port); } - // Start version handoff - port.postMessage({ - subject: "bridge:initialize" - , data: EXTENSION_VERSION - }); - port.onDisconnect.addListener(p => { if (p.error) { console.error(`${APPLICATION_NAME} disconnected:`, p.error.message); @@ -431,27 +425,6 @@ messageRouter.register("main", async (message, sender) => { break; }; - case "main:bridgeInitialized": { - const applicationVersion = message.data; - - /** - * 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"); - } - - break; - }; - case "main:openPopup": { await openPopup(tabId); break; diff --git a/ext/src/options/index.jsx b/ext/src/options/index.jsx index df0721a..f246f4c 100644 --- a/ext/src/options/index.jsx +++ b/ext/src/options/index.jsx @@ -6,6 +6,8 @@ import ReactDOM from "react-dom"; import defaultOptions from "./defaultOptions"; import EditableList from "./EditableList"; +import getBridgeInfo from "../lib/getBridgeInfo"; + const _ = browser.i18n.getMessage; @@ -41,6 +43,8 @@ class App extends Component { this.state = { options: props.options + , bridgeInfo: null + , bridgeLoading: true , isFormValid: true }; @@ -54,6 +58,14 @@ class App extends Component { = this.getWhitelistItemPatternError.bind(this); } + async componentDidMount () { + const bridgeInfo = await getBridgeInfo(); + this.setState({ + bridgeInfo + , bridgeLoading: false + }); + } + /** * Set stored option values to current state */ @@ -126,140 +138,199 @@ class App extends Component { return _("optionsUserAgentWhitelistInvalidMatchPattern", info); } + async updateBridgeInfo () { + this.setState({ + bridgeLoading: true + }); + + const bridgeInfo = await getBridgeInfo(); + + this.setState({ + bridgeInfo + , bridgeLoading: false + }); + } + render () { return ( -