Convert ext lib to typescript

This commit is contained in:
hensm
2019-02-27 16:46:09 +00:00
parent 7eaa97a556
commit 8cef999afb
6 changed files with 58 additions and 31 deletions

View File

@@ -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

View File

@@ -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
}
};

View File

@@ -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
View 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)
};
}

View File

@@ -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;
}

View File

@@ -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" ]