diff --git a/ext/src/lib/getBridgeInfo.js b/ext/src/lib/getBridgeInfo.ts similarity index 81% rename from ext/src/lib/getBridgeInfo.js rename to ext/src/lib/getBridgeInfo.ts index 6ef2cef..449d98c 100644 --- a/ext/src/lib/getBridgeInfo.js +++ b/ext/src/lib/getBridgeInfo.ts @@ -1,7 +1,19 @@ +"use strict"; + import semver from "semver"; -export default async function getBridgeInfo () { - let applicationVersion; +export interface BridgeInfo { + name: string; + version: string; + expectedVersion: string; + isVersionExact: boolean; + isVersionCompatible: boolean; + isVersionOlder: boolean; + isVersionNewer: boolean; +} + +export default async function getBridgeInfo (): Promise { + let applicationVersion: string; try { applicationVersion = await browser.runtime.sendNativeMessage( APPLICATION_NAME diff --git a/ext/src/lib/messageRouter.js b/ext/src/lib/messageRouter.ts similarity index 52% rename from ext/src/lib/messageRouter.js rename to ext/src/lib/messageRouter.ts index 69de90d..b5a1780 100644 --- a/ext/src/lib/messageRouter.js +++ b/ext/src/lib/messageRouter.ts @@ -1,17 +1,18 @@ "use strict"; -const routeMap = new Map(); +type SenderCallback = (message: any, details: any) => void; +const routeMap = new Map(); -function register (routeName, senderCallback) { +function register (routeName: string, senderCallback: SenderCallback) { routeMap.set(routeName, senderCallback); } -function deregister (routeName) { +function deregister (routeName: string) { routeMap.delete(routeName); } -function handleMessage (message, details) { +function handleMessage (message: any, details?: any) { const destination = message.subject.split(":")[0]; if (routeMap.has(destination)) { routeMap.get(destination)(message, details); @@ -22,4 +23,4 @@ export default { register , deregister , handleMessage -} +}; diff --git a/ext/src/lib/utils.js b/ext/src/lib/utils.js deleted file mode 100644 index 0ef08a5..0000000 --- a/ext/src/lib/utils.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; - -export function getNextEllipsis (ellipsis) { - return { - "": "." - , ".": ".." - , "..": "..." - , "...": "" - }[ellipsis]; -} - -export function getWindowCenteredProps (refWin, width, height) { - const centerX = refWin.left + (refWin.width / 2); - const centerY = refWin.top + (refWin.height / 3); - - return { - width, height - , left: Math.floor(centerX - width / 2) - , top: Math.floor(centerY - height / 2) - }; -} diff --git a/ext/src/lib/utils.ts b/ext/src/lib/utils.ts new file mode 100644 index 0000000..962238f --- /dev/null +++ b/ext/src/lib/utils.ts @@ -0,0 +1,33 @@ +"use strict"; + +export function getNextEllipsis (ellipsis: string): string { + /* tslint:disable:curly */ + if (ellipsis === "") return "."; + if (ellipsis === ".") return ".."; + if (ellipsis === "..") return "..."; + if (ellipsis === "...") return ""; + /* tslint:enable:curly */ +} + + +interface WindowCenteredProps { + width: number; + height: number; + left: number; + top: number; +} + +export function getWindowCenteredProps ( + refWin: browser.windows.Window + , width: number + , height: number): WindowCenteredProps { + + const centerX = refWin.left + (refWin.width / 2); + const centerY = refWin.top + (refWin.height / 3); + + return { + width, height + , left: Math.floor(centerX - width / 2) + , top: Math.floor(centerY - height / 2) + }; +} diff --git a/ext/src/options/Bridge.tsx b/ext/src/options/Bridge.tsx index 2b6867f..f071efc 100644 --- a/ext/src/options/Bridge.tsx +++ b/ext/src/options/Bridge.tsx @@ -7,6 +7,8 @@ import semver from "semver"; import { getNextEllipsis , getWindowCenteredProps } from "../lib/utils"; +import { BridgeInfo } from "../lib/getBridgeInfo"; + const _ = browser.i18n.getMessage; const ENDPOINT_URL = "https://api.github.com/repos/hensm/fx_cast/releases/14720978"; @@ -53,7 +55,7 @@ const BridgeDownloads = (props: BridgeDownloadsProps) => ( interface BridgeStatsProps { - info: any; + info: BridgeInfo; } const BridgeStats = (props: BridgeStatsProps) => ( @@ -99,7 +101,7 @@ const BridgeStats = (props: BridgeStatsProps) => ( interface BridgeProps { - info: any; + info: BridgeInfo; platform: string; loading: boolean; } diff --git a/tslintCommon.json b/tslintCommon.json index 013976d..0e18b50 100644 --- a/tslintCommon.json +++ b/tslintCommon.json @@ -11,7 +11,7 @@ , "max-classes-per-file": false , "max-line-length": [ true, { "limit": 80 - , "ignore-pattern": "//|.*\";$" + , "ignore-pattern": "//|.*(\"|`);?$" }] , "member-access": [ true, "no-public" ] , "no-console": [ true, "log" ]