mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
prettier: Re-format .ts files
This commit is contained in:
@@ -7,7 +7,6 @@ import { Port } from "../messaging";
|
||||
import nativeMessaging from "./nativeMessaging";
|
||||
import options from "./options";
|
||||
|
||||
|
||||
export const BRIDGE_TIMEOUT = 5000;
|
||||
|
||||
/**
|
||||
@@ -15,13 +14,16 @@ export const BRIDGE_TIMEOUT = 5000;
|
||||
*/
|
||||
async function connect(): Promise<Port> {
|
||||
const applicationName = await options.get("bridgeApplicationName");
|
||||
const bridgePort = nativeMessaging.connectNative(applicationName) as
|
||||
unknown as Port;
|
||||
const bridgePort = nativeMessaging.connectNative(
|
||||
applicationName
|
||||
) as unknown as Port;
|
||||
|
||||
bridgePort.onDisconnect.addListener(() => {
|
||||
if (bridgePort.error) {
|
||||
console.error(`${applicationName} disconnected:`
|
||||
, bridgePort.error.message);
|
||||
console.error(
|
||||
`${applicationName} disconnected:`,
|
||||
bridgePort.error.message
|
||||
);
|
||||
} else {
|
||||
console.info(`${applicationName} disconnected`);
|
||||
}
|
||||
@@ -30,7 +32,6 @@ async function connect(): Promise<Port> {
|
||||
return bridgePort;
|
||||
}
|
||||
|
||||
|
||||
export interface BridgeInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
@@ -50,77 +51,81 @@ export class BridgeTimedOutError extends Error {}
|
||||
* rules to determine compatiblity, then returns a
|
||||
* BridgeInfo object.
|
||||
*/
|
||||
const getInfo = () => new Promise<BridgeInfo>(async (resolve, reject) => {
|
||||
const applicationName = await options.get("bridgeApplicationName");
|
||||
if (!applicationName) {
|
||||
reject(logger.error("Bridge application name not found."));
|
||||
return;
|
||||
}
|
||||
const getInfo = () =>
|
||||
new Promise<BridgeInfo>(async (resolve, reject) => {
|
||||
const applicationName = await options.get("bridgeApplicationName");
|
||||
if (!applicationName) {
|
||||
reject(logger.error("Bridge application name not found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const bridgeTimeoutId = setTimeout(() => {
|
||||
logger.error("Bridge timed out.");
|
||||
reject(new BridgeTimedOutError());
|
||||
}, BRIDGE_TIMEOUT);
|
||||
const bridgeTimeoutId = setTimeout(() => {
|
||||
logger.error("Bridge timed out.");
|
||||
reject(new BridgeTimedOutError());
|
||||
}, BRIDGE_TIMEOUT);
|
||||
|
||||
let applicationVersion: string;
|
||||
try {
|
||||
const { version } = browser.runtime.getManifest();
|
||||
let applicationVersion: string;
|
||||
try {
|
||||
const { version } = browser.runtime.getManifest();
|
||||
|
||||
applicationVersion = await nativeMessaging.sendNativeMessage(
|
||||
applicationName,
|
||||
{ subject: "bridge:/getInfo", data: version }
|
||||
);
|
||||
} catch (err) {
|
||||
logger.error("Bridge connection failed.");
|
||||
reject(new BridgeConnectionError());
|
||||
clearTimeout(bridgeTimeoutId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
applicationVersion = await nativeMessaging.sendNativeMessage(
|
||||
applicationName
|
||||
, { subject: "bridge:/getInfo"
|
||||
, data: version });
|
||||
} catch (err) {
|
||||
logger.error("Bridge connection failed.");
|
||||
reject(new BridgeConnectionError());
|
||||
clearTimeout(bridgeTimeoutId);
|
||||
|
||||
return;
|
||||
}
|
||||
const extensionVersion = browser.runtime.getManifest().version;
|
||||
const extensionVersionMajor = semver.major(extensionVersion);
|
||||
|
||||
clearTimeout(bridgeTimeoutId);
|
||||
const versionDiff = semver.diff(applicationVersion, extensionVersion);
|
||||
|
||||
const extensionVersion = browser.runtime.getManifest().version;
|
||||
const extensionVersionMajor = semver.major(extensionVersion);
|
||||
/**
|
||||
* If the target version is above 0.x.x range, API is stable
|
||||
* and versions with minor or patch level changes should be
|
||||
* compatible.
|
||||
*/
|
||||
const isVersionCompatible =
|
||||
semver.eq(applicationVersion, extensionVersion) ||
|
||||
(versionDiff !== "major" && extensionVersionMajor !== 0) ||
|
||||
(versionDiff === "patch" && extensionVersionMajor === 0);
|
||||
|
||||
const versionDiff = semver.diff(applicationVersion, extensionVersion);
|
||||
const isVersionExact = semver.eq(applicationVersion, extensionVersion);
|
||||
const isVersionOlder = semver.lt(applicationVersion, extensionVersion);
|
||||
const isVersionNewer = semver.gt(applicationVersion, extensionVersion);
|
||||
|
||||
/**
|
||||
* If the target version is above 0.x.x range, API is stable
|
||||
* and versions with minor or patch level changes should be
|
||||
* compatible.
|
||||
*/
|
||||
const isVersionCompatible =
|
||||
semver.eq(applicationVersion, extensionVersion)
|
||||
|| (versionDiff !== "major" && extensionVersionMajor !== 0)
|
||||
|| (versionDiff === "patch" && extensionVersionMajor === 0);
|
||||
// Print compatibility info to console
|
||||
if (!isVersionCompatible) {
|
||||
logger.error(
|
||||
`Expecting ${applicationName} v${BRIDGE_VERSION}, found v${applicationVersion}. ${
|
||||
isVersionOlder
|
||||
? "Try updating the native app to the latest version."
|
||||
: "Try updating the extension to the latest version"
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
const isVersionExact = semver.eq(applicationVersion, extensionVersion);
|
||||
const isVersionOlder = semver.lt(applicationVersion, extensionVersion);
|
||||
const isVersionNewer = semver.gt(applicationVersion, extensionVersion);
|
||||
resolve({
|
||||
name: applicationName,
|
||||
version: applicationVersion,
|
||||
expectedVersion: BRIDGE_VERSION,
|
||||
|
||||
// Print compatibility info to console
|
||||
if (!isVersionCompatible) {
|
||||
logger.error(`Expecting ${applicationName} v${BRIDGE_VERSION}, found v${applicationVersion}. ${
|
||||
isVersionOlder
|
||||
? "Try updating the native app to the latest version."
|
||||
: "Try updating the extension to the latest version"}`);
|
||||
}
|
||||
|
||||
resolve({
|
||||
name: applicationName
|
||||
, version: applicationVersion
|
||||
, expectedVersion: BRIDGE_VERSION
|
||||
|
||||
// Version info
|
||||
, isVersionExact
|
||||
, isVersionCompatible
|
||||
, isVersionOlder
|
||||
, isVersionNewer
|
||||
// Version info
|
||||
isVersionExact,
|
||||
isVersionCompatible,
|
||||
isVersionOlder,
|
||||
isVersionNewer
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export default {
|
||||
connect
|
||||
, getInfo
|
||||
connect,
|
||||
getInfo
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user