mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 18:19:58 +00:00
Add bridge application name to options storage
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
|
bridgeApplicationName: string;
|
||||||
mediaEnabled: boolean;
|
mediaEnabled: boolean;
|
||||||
mediaSyncElement: boolean;
|
mediaSyncElement: boolean;
|
||||||
mediaStopOnUnload: boolean;
|
mediaStopOnUnload: boolean;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
import nativeMessaging from "./nativeMessaging";
|
import nativeMessaging from "./nativeMessaging";
|
||||||
|
import options from "./options";
|
||||||
|
|
||||||
|
|
||||||
export interface BridgeInfo {
|
export interface BridgeInfo {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -14,12 +17,16 @@ export interface BridgeInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function getBridgeInfo (): Promise<BridgeInfo> {
|
export default async function getBridgeInfo (): Promise<BridgeInfo> {
|
||||||
|
const applicationName = await options.get("bridgeApplicationName");
|
||||||
let applicationVersion: string;
|
let applicationVersion: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const { version } = browser.runtime.getManifest();
|
||||||
|
|
||||||
applicationVersion = await nativeMessaging.sendNativeMessage(
|
applicationVersion = await nativeMessaging.sendNativeMessage(
|
||||||
APPLICATION_NAME
|
applicationName
|
||||||
, { subject: "bridge:/getInfo"
|
, { subject: "bridge:/getInfo"
|
||||||
, data: EXTENSION_VERSION });
|
, data: version });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -40,14 +47,14 @@ export default async function getBridgeInfo (): Promise<BridgeInfo> {
|
|||||||
|
|
||||||
// Print compatibility info to console
|
// Print compatibility info to console
|
||||||
if (!isVersionCompatible) {
|
if (!isVersionCompatible) {
|
||||||
console.error(`Expecting ${APPLICATION_NAME} v${APPLICATION_VERSION}, found v${applicationVersion}.`
|
console.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}.`
|
||||||
, isVersionOlder
|
, isVersionOlder
|
||||||
? "Try updating the native app to the latest version."
|
? "Try updating the native app to the latest version."
|
||||||
: "Try updating the extension to the latest version");
|
: "Try updating the extension to the latest version");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: APPLICATION_NAME
|
name: applicationName
|
||||||
, version: applicationVersion
|
, version: applicationVersion
|
||||||
, expectedVersion: APPLICATION_VERSION
|
, expectedVersion: APPLICATION_VERSION
|
||||||
|
|
||||||
|
|||||||
@@ -535,8 +535,10 @@ const statusBridgeReceivers = new Map<string, Receiver>();
|
|||||||
/**
|
/**
|
||||||
* Create status bridge, set event handlers and initialize.
|
* Create status bridge, set event handlers and initialize.
|
||||||
*/
|
*/
|
||||||
function initStatusBridge () {
|
async function initStatusBridge () {
|
||||||
statusBridge = nativeMessaging.connectNative(APPLICATION_NAME);
|
const applicationName = await options.get("bridgeApplicationName");
|
||||||
|
|
||||||
|
statusBridge = nativeMessaging.connectNative(applicationName);
|
||||||
statusBridge.onDisconnect.addListener(onStatusBridgeDisconnect);
|
statusBridge.onDisconnect.addListener(onStatusBridgeDisconnect);
|
||||||
statusBridge.onMessage.addListener(onStatusBridgeMessage);
|
statusBridge.onMessage.addListener(onStatusBridgeMessage);
|
||||||
|
|
||||||
@@ -705,11 +707,14 @@ async function onConnectShim (port: browser.runtime.Port) {
|
|||||||
shimMap.delete(shimId);
|
shimMap.delete(shimId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const applicationName = await options.get("bridgeApplicationName");
|
||||||
|
|
||||||
// Spawn bridge app instance
|
// Spawn bridge app instance
|
||||||
const bridgePort = nativeMessaging.connectNative(APPLICATION_NAME);
|
const bridgePort = nativeMessaging.connectNative(applicationName);
|
||||||
|
|
||||||
if (bridgePort.error) {
|
if (bridgePort.error) {
|
||||||
console.error(`Failed connect to ${APPLICATION_NAME}:`
|
console.error(`Failed connect to ${applicationName}:`
|
||||||
, bridgePort.error.message);
|
, bridgePort.error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -722,10 +727,10 @@ async function onConnectShim (port: browser.runtime.Port) {
|
|||||||
|
|
||||||
bridgePort.onDisconnect.addListener(() => {
|
bridgePort.onDisconnect.addListener(() => {
|
||||||
if (bridgePort.error) {
|
if (bridgePort.error) {
|
||||||
console.error(`${APPLICATION_NAME} disconnected:`
|
console.error(`${applicationName} disconnected:`
|
||||||
, bridgePort.error.message);
|
, bridgePort.error.message);
|
||||||
} else {
|
} else {
|
||||||
console.info(`${APPLICATION_NAME} disconnected`);
|
console.info(`${applicationName} disconnected`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import options from "../../lib/options";
|
||||||
import nativeMessaging from "../../lib/nativeMessaging";
|
import nativeMessaging from "../../lib/nativeMessaging";
|
||||||
|
|
||||||
import ReceiverSelectorManager, {
|
import ReceiverSelectorManager, {
|
||||||
@@ -29,7 +30,8 @@ export default class NativeMacReceiverSelectorManager
|
|||||||
receivers: Receiver[]
|
receivers: Receiver[]
|
||||||
, defaultMediaType: ReceiverSelectorMediaType): Promise<void> {
|
, 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) => {
|
this.bridgePort.onMessage.addListener((message: Message) => {
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
|
|||||||
Reference in New Issue
Block a user