mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 01:59:58 +00:00
Switch to eslint and fix issues
This commit is contained in:
@@ -12,25 +12,25 @@ interface TabConnectInfo {
|
||||
}
|
||||
|
||||
export default class Messenger<T> {
|
||||
connect (connectInfo: RuntimeConnectInfo) {
|
||||
connect(connectInfo: RuntimeConnectInfo) {
|
||||
return browser.runtime.connect(connectInfo) as
|
||||
unknown as TypedPort<T>;
|
||||
}
|
||||
|
||||
connectTab (tabId: number, connectInfo: TabConnectInfo) {
|
||||
connectTab(tabId: number, connectInfo: TabConnectInfo) {
|
||||
return browser.tabs.connect(tabId, connectInfo) as
|
||||
unknown as TypedPort<T>;
|
||||
}
|
||||
|
||||
onConnect = {
|
||||
addListener (cb: (port: TypedPort<T>) => void) {
|
||||
addListener(cb: (port: TypedPort<T>) => void) {
|
||||
browser.runtime.onConnect.addListener(cb as any);
|
||||
}
|
||||
, removeListener (cb: (port: TypedPort<T>) => void) {
|
||||
, removeListener(cb: (port: TypedPort<T>) => void) {
|
||||
browser.runtime.onConnect.removeListener(cb as any);
|
||||
}
|
||||
, hasListener (cb: (port: TypedPort<T>) => void) {
|
||||
, hasListener(cb: (port: TypedPort<T>) => void) {
|
||||
return browser.runtime.onConnect.hasListener(cb as any);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,20 +6,20 @@ interface TypedEvents {
|
||||
|
||||
export class TypedEventTarget<T extends TypedEvents> extends EventTarget {
|
||||
// @ts-ignore
|
||||
public addEventListener<K extends keyof T> (
|
||||
public addEventListener<K extends keyof T>(
|
||||
type: K, listener: (ev: CustomEvent<T[K]>) => void): void {
|
||||
// @ts-ignore
|
||||
super.addEventListener(type as string, listener);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
public removeEventListener<K extends keyof T> (
|
||||
public removeEventListener<K extends keyof T>(
|
||||
type: K, listener: (ev: CustomEvent<T[K]>) => void): void {
|
||||
// @ts-ignore
|
||||
super.removeEventListener(type as string, listener);
|
||||
}
|
||||
|
||||
public dispatchEvent<K extends keyof T> (ev: CustomEvent<T[K]>): boolean {
|
||||
public dispatchEvent<K extends keyof T>(ev: CustomEvent<T[K]>): boolean {
|
||||
return super.dispatchEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
export class TypedStorageArea<Schema extends { [key: string]: any }> {
|
||||
private storageArea: any;
|
||||
|
||||
constructor (storageArea: browser.storage.StorageArea) {
|
||||
constructor(storageArea: browser.storage.StorageArea) {
|
||||
this.storageArea = storageArea;
|
||||
}
|
||||
|
||||
public async get<SchemaKey extends keyof Schema
|
||||
, SchemaPartial extends Partial<Schema>> (
|
||||
, SchemaPartial extends Partial<Schema>>(
|
||||
keys?: SchemaKey
|
||||
| SchemaKey[]
|
||||
| SchemaPartial
|
||||
@@ -25,23 +25,23 @@ export class TypedStorageArea<Schema extends { [key: string]: any }> {
|
||||
return await this.storageArea.get(keys);
|
||||
}
|
||||
|
||||
public async getBytesInUse<SchemaKey extends keyof Schema> (
|
||||
public async getBytesInUse<SchemaKey extends keyof Schema>(
|
||||
keys?: Schema | SchemaKey[]): Promise<number> {
|
||||
|
||||
return await this.storageArea.getBytesInUse(keys);
|
||||
}
|
||||
|
||||
public async set (keys: Partial<Schema>): Promise<void> {
|
||||
public async set(keys: Partial<Schema>): Promise<void> {
|
||||
await this.storageArea.set(keys);
|
||||
}
|
||||
|
||||
public async remove<SchemaKey extends keyof Schema> (
|
||||
public async remove<SchemaKey extends keyof Schema>(
|
||||
keys: SchemaKey | SchemaKey[]): Promise<void> {
|
||||
|
||||
await this.storageArea.remove(keys);
|
||||
}
|
||||
|
||||
public async clear (): Promise<void> {
|
||||
public async clear(): Promise<void> {
|
||||
await this.storageArea.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ReceiverSelectionCast
|
||||
|
||||
export const BRIDGE_TIMEOUT = 5000;
|
||||
|
||||
async function connect (): Promise<Port> {
|
||||
async function connect(): Promise<Port> {
|
||||
const applicationName = await options.get("bridgeApplicationName");
|
||||
const bridgePort = nativeMessaging.connectNative(applicationName) as
|
||||
unknown as Port;
|
||||
|
||||
@@ -20,7 +20,7 @@ interface LoadSenderOptions {
|
||||
* Loads the appropriate sender for a given receiver
|
||||
* selector response.
|
||||
*/
|
||||
export default async function loadSender (opts: LoadSenderOptions) {
|
||||
export default async function loadSender(opts: LoadSenderOptions) {
|
||||
// Cancelled
|
||||
if (!opts.selection) {
|
||||
return;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
export class Logger {
|
||||
constructor (private prefix: string) {}
|
||||
constructor(private prefix: string) {}
|
||||
|
||||
public log (message: string, data?: any) {
|
||||
public log(message: string, data?: any) {
|
||||
const formattedMessage = `${this.prefix} (Log): ${message}`;
|
||||
if (data) {
|
||||
// tslint:disable-next-line:no-console
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(formattedMessage, data);
|
||||
} else {
|
||||
// tslint:disable-next-line:no-console
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(formattedMessage);
|
||||
}
|
||||
}
|
||||
public info (message: string, data?: any) {
|
||||
public info(message: string, data?: any) {
|
||||
const formattedMessage = `${this.prefix} (Info): ${message}`;
|
||||
if (data) {
|
||||
console.info(formattedMessage, data);
|
||||
@@ -21,7 +21,7 @@ export class Logger {
|
||||
console.info(formattedMessage);
|
||||
}
|
||||
}
|
||||
public error (message: string, data?: any) {
|
||||
public error(message: string, data?: any) {
|
||||
const formattedMessage = `${this.prefix} (Error): ${message}`;
|
||||
if (data) {
|
||||
console.error(formattedMessage, data);
|
||||
|
||||
@@ -6,11 +6,10 @@ import options from "./options";
|
||||
import { Message, Port } from "../messaging";
|
||||
|
||||
|
||||
|
||||
type DisconnectListener = (port: Port) => void;
|
||||
type MessageListener = (message: Message) => void;
|
||||
|
||||
function connectNative (application: string): Port {
|
||||
function connectNative(application: string): Port {
|
||||
/**
|
||||
* In order to preserve the synchronous API, messages are
|
||||
* queued before either the native messaging host or the
|
||||
@@ -39,35 +38,35 @@ function connectNative (application: string): Port {
|
||||
, name: ""
|
||||
|
||||
, onDisconnect: {
|
||||
addListener (cb: DisconnectListener) {
|
||||
addListener(cb: DisconnectListener) {
|
||||
onDisconnectListeners.add(cb);
|
||||
}
|
||||
, removeListener (cb: DisconnectListener) {
|
||||
, removeListener(cb: DisconnectListener) {
|
||||
onDisconnectListeners.delete(cb);
|
||||
}
|
||||
, hasListener (cb: DisconnectListener) {
|
||||
, hasListener(cb: DisconnectListener) {
|
||||
return onDisconnectListeners.has(cb);
|
||||
}
|
||||
, hasListeners () {
|
||||
, hasListeners() {
|
||||
return onDisconnectListeners.size > 0;
|
||||
}
|
||||
}
|
||||
, onMessage: {
|
||||
addListener (cb: MessageListener) {
|
||||
addListener(cb: MessageListener) {
|
||||
onMessageListeners.add(cb);
|
||||
}
|
||||
, removeListener (cb: MessageListener) {
|
||||
, removeListener(cb: MessageListener) {
|
||||
onMessageListeners.delete(cb);
|
||||
}
|
||||
, hasListener (cb: MessageListener) {
|
||||
, hasListener(cb: MessageListener) {
|
||||
return onMessageListeners.has(cb);
|
||||
}
|
||||
, hasListeners () {
|
||||
, hasListeners() {
|
||||
return onMessageListeners.size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
, disconnect () {
|
||||
, disconnect() {
|
||||
if (socket) {
|
||||
socket.close();
|
||||
} else {
|
||||
@@ -75,7 +74,7 @@ function connectNative (application: string): Port {
|
||||
}
|
||||
}
|
||||
|
||||
, postMessage (message) {
|
||||
, postMessage(message) {
|
||||
if (socket) {
|
||||
switch (socket.readyState) {
|
||||
case WebSocket.CONNECTING: {
|
||||
@@ -168,7 +167,7 @@ function connectNative (application: string): Port {
|
||||
return portObject;
|
||||
}
|
||||
|
||||
async function sendNativeMessage (
|
||||
async function sendNativeMessage(
|
||||
application: string
|
||||
, message: Message) {
|
||||
|
||||
|
||||
@@ -41,9 +41,8 @@ interface EventMap {
|
||||
"changed": Array<keyof Options>;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:new-parens
|
||||
export default new class extends TypedEventTarget<EventMap> {
|
||||
constructor () {
|
||||
constructor() {
|
||||
super();
|
||||
this.onStorageChanged = this.onStorageChanged.bind(this);
|
||||
browser.storage.onChanged.addListener(this.onStorageChanged);
|
||||
@@ -105,7 +104,7 @@ export default new class extends TypedEventTarget<EventMap> {
|
||||
* Fetches `options` key from storage and returns it as
|
||||
* Options interface type.
|
||||
*/
|
||||
public async getAll (): Promise<Options> {
|
||||
public async getAll(): Promise<Options> {
|
||||
const { options } = await storageArea.get("options");
|
||||
return options;
|
||||
}
|
||||
@@ -114,7 +113,7 @@ export default new class extends TypedEventTarget<EventMap> {
|
||||
* Takes Options object and sets to `options` storage key.
|
||||
* Returns storage promise.
|
||||
*/
|
||||
public async setAll (options: Options): Promise<void> {
|
||||
public async setAll(options: Options): Promise<void> {
|
||||
return storageArea.set({ options });
|
||||
}
|
||||
|
||||
@@ -122,7 +121,7 @@ export default new class extends TypedEventTarget<EventMap> {
|
||||
* Gets specific option from storage and returns it as its
|
||||
* type from Options interface type.
|
||||
*/
|
||||
public async get<T extends keyof Options> (name: T): Promise<Options[T]> {
|
||||
public async get<T extends keyof Options>(name: T): Promise<Options[T]> {
|
||||
const options = await this.getAll();
|
||||
|
||||
if (options.hasOwnProperty(name)) {
|
||||
@@ -136,7 +135,7 @@ export default new class extends TypedEventTarget<EventMap> {
|
||||
* Sets specific option to storage. Returns storage
|
||||
* promise.
|
||||
*/
|
||||
public async set<T extends keyof Options> (
|
||||
public async set<T extends keyof Options>(
|
||||
name: T
|
||||
, value: Options[T]): Promise<void> {
|
||||
|
||||
@@ -151,7 +150,7 @@ export default new class extends TypedEventTarget<EventMap> {
|
||||
* against defaults. Any options in defaults and not in
|
||||
* storage are set. Does not override any existing options.
|
||||
*/
|
||||
public async update (defaults = defaultOptions): Promise<void> {
|
||||
public async update(defaults = defaultOptions): Promise<void> {
|
||||
const newOpts = await this.getAll();
|
||||
|
||||
// Find options not already in storage
|
||||
|
||||
@@ -8,7 +8,7 @@ const PLATFORM_LINUX = "X11; Linux x86_64";
|
||||
const UA_CHROME = "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36";
|
||||
const UA_HYBRID = "Chrome/80.0.3987.87 Gecko/20100101 Firefox/72.0";
|
||||
|
||||
export function getChromeUserAgent (platform: string, hybrid = false) {
|
||||
export function getChromeUserAgent(platform: string, hybrid = false) {
|
||||
let platformComponent: string;
|
||||
if (platform === "mac") {
|
||||
platformComponent = hybrid
|
||||
|
||||
@@ -5,13 +5,11 @@ import logger from "./logger";
|
||||
import { ReceiverSelectorMediaType } from "../background/receiverSelector";
|
||||
|
||||
|
||||
export function getNextEllipsis (ellipsis: string): string {
|
||||
/* tslint:disable:curly */
|
||||
export function getNextEllipsis(ellipsis: string): string {
|
||||
if (ellipsis === "") return ".";
|
||||
if (ellipsis === ".") return "..";
|
||||
if (ellipsis === "..") return "...";
|
||||
if (ellipsis === "...") return "";
|
||||
/* tslint:enable:curly */
|
||||
|
||||
return "";
|
||||
}
|
||||
@@ -19,7 +17,7 @@ export function getNextEllipsis (ellipsis: string): string {
|
||||
/**
|
||||
* Template literal tag function, JSON-encodes substitutions.
|
||||
*/
|
||||
export function stringify (
|
||||
export function stringify(
|
||||
templateStrings: TemplateStringsArray
|
||||
, ...substitutions: any[]) {
|
||||
|
||||
@@ -36,7 +34,7 @@ export function stringify (
|
||||
return formattedString;
|
||||
}
|
||||
|
||||
export function getMediaTypesForPageUrl (
|
||||
export function getMediaTypesForPageUrl(
|
||||
pageUrl: string): ReceiverSelectorMediaType {
|
||||
|
||||
const url = new URL(pageUrl);
|
||||
@@ -90,7 +88,7 @@ export interface WindowCenteredProps {
|
||||
top: number;
|
||||
}
|
||||
|
||||
export function getWindowCenteredProps (
|
||||
export function getWindowCenteredProps(
|
||||
refWin: browser.windows.Window
|
||||
, width: number
|
||||
, height: number): WindowCenteredProps {
|
||||
@@ -111,11 +109,10 @@ export function getWindowCenteredProps (
|
||||
}
|
||||
|
||||
|
||||
// tslint:disable-next-line:max-line-length
|
||||
export const REMOTE_MATCH_PATTERN_REGEX = /^(?:(?:(\*|https?|ftp):\/\/(\*|(?:\*\.(?:[^\/\*:]\.?)+(?:[^\.])|[^\/\*:]*))?)(\/.*)|<all_urls>)$/;
|
||||
|
||||
|
||||
export function loadScript (
|
||||
export function loadScript(
|
||||
scriptUrl: string
|
||||
, doc: Document = document): HTMLScriptElement {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user