mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Convert ext lib to typescript
This commit is contained in:
@@ -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<BridgeInfo> {
|
||||
let applicationVersion: string;
|
||||
try {
|
||||
applicationVersion = await browser.runtime.sendNativeMessage(
|
||||
APPLICATION_NAME
|
||||
@@ -1,17 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const routeMap = new Map();
|
||||
type SenderCallback = (message: any, details: any) => void;
|
||||
|
||||
const routeMap = new Map<string, SenderCallback>();
|
||||
|
||||
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
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
33
ext/src/lib/utils.ts
Normal file
33
ext/src/lib/utils.ts
Normal file
@@ -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)
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
Reference in New Issue
Block a user