Add bridge application name to options storage

This commit is contained in:
hensm
2019-05-17 15:03:27 +01:00
parent 964f54a06b
commit c16566cfad
4 changed files with 26 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
"use strict";
export interface Options {
bridgeApplicationName: string;
mediaEnabled: boolean;
mediaSyncElement: boolean;
mediaStopOnUnload: boolean;

View File

@@ -1,7 +1,10 @@
"use strict";
import semver from "semver";
import nativeMessaging from "./nativeMessaging";
import options from "./options";
export interface BridgeInfo {
name: string;
@@ -14,12 +17,16 @@ export interface BridgeInfo {
}
export default async function getBridgeInfo (): Promise<BridgeInfo> {
const applicationName = await options.get("bridgeApplicationName");
let applicationVersion: string;
try {
const { version } = browser.runtime.getManifest();
applicationVersion = await nativeMessaging.sendNativeMessage(
APPLICATION_NAME
applicationName
, { subject: "bridge:/getInfo"
, data: EXTENSION_VERSION });
, data: version });
} catch (err) {
return null;
}
@@ -40,14 +47,14 @@ export default async function getBridgeInfo (): Promise<BridgeInfo> {
// Print compatibility info to console
if (!isVersionCompatible) {
console.error(`Expecting ${APPLICATION_NAME} v${APPLICATION_VERSION}, found v${applicationVersion}.`
console.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}.`
, isVersionOlder
? "Try updating the native app to the latest version."
: "Try updating the extension to the latest version");
}
return {
name: APPLICATION_NAME
name: applicationName
, version: applicationVersion
, expectedVersion: APPLICATION_VERSION

View File

@@ -535,8 +535,10 @@ const statusBridgeReceivers = new Map<string, Receiver>();
/**
* Create status bridge, set event handlers and initialize.
*/
function initStatusBridge () {
statusBridge = nativeMessaging.connectNative(APPLICATION_NAME);
async function initStatusBridge () {
const applicationName = await options.get("bridgeApplicationName");
statusBridge = nativeMessaging.connectNative(applicationName);
statusBridge.onDisconnect.addListener(onStatusBridgeDisconnect);
statusBridge.onMessage.addListener(onStatusBridgeMessage);
@@ -705,11 +707,14 @@ async function onConnectShim (port: browser.runtime.Port) {
shimMap.delete(shimId);
}
const applicationName = await options.get("bridgeApplicationName");
// Spawn bridge app instance
const bridgePort = nativeMessaging.connectNative(APPLICATION_NAME);
const bridgePort = nativeMessaging.connectNative(applicationName);
if (bridgePort.error) {
console.error(`Failed connect to ${APPLICATION_NAME}:`
console.error(`Failed connect to ${applicationName}:`
, bridgePort.error.message);
}
@@ -722,10 +727,10 @@ async function onConnectShim (port: browser.runtime.Port) {
bridgePort.onDisconnect.addListener(() => {
if (bridgePort.error) {
console.error(`${APPLICATION_NAME} disconnected:`
console.error(`${applicationName} disconnected:`
, bridgePort.error.message);
} else {
console.info(`${APPLICATION_NAME} disconnected`);
console.info(`${applicationName} disconnected`);
}
});

View File

@@ -1,5 +1,6 @@
"use strict";
import options from "../../lib/options";
import nativeMessaging from "../../lib/nativeMessaging";
import ReceiverSelectorManager, {
@@ -29,7 +30,8 @@ export default class NativeMacReceiverSelectorManager
receivers: Receiver[]
, defaultMediaType: ReceiverSelectorMediaType): Promise<void> {
this.bridgePort = nativeMessaging.connectNative(APPLICATION_NAME);
const applicationName = await options.get("bridgeApplicationName");
this.bridgePort = nativeMessaging.connectNative(applicationName);
this.bridgePort.onMessage.addListener((message: Message) => {
switch (message.subject) {