TSLint compliance

This commit is contained in:
hensm
2020-02-15 06:06:57 +00:00
parent 809a591bbd
commit 14999a4f57
19 changed files with 219 additions and 77 deletions

View File

@@ -56,7 +56,7 @@ export default new class StatusManager
}
}
public * getReceivers() {
public *getReceivers () {
for (const [, receiver ] of this.receivers) {
if (receiver.status && receiver.status.application
&& receiver.status.volume) {

View File

@@ -45,23 +45,9 @@ browser.runtime.onInstalled.addListener(async details => {
});
function initBrowserAction () {
async function initBrowserAction () {
logger.info("init (browser action)");
/*browser.browserAction.disable();
function onServiceChange () {
if (StatusManager.getReceivers().length) {
browser.browserAction.enable();
} else {
browser.browserAction.disable();
}
}
StatusManager.addEventListener("serviceUp", onServiceChange);
StatusManager.addEventListener("serviceDown", onServiceChange);*/
/**
* When the browser action is clicked, open a receiver
* selector and load a sender for the response. The
@@ -463,7 +449,7 @@ async function initRequestListener () {
}
function initWhitelist () {
async function initWhitelist () {
logger.info("init (whitelist)");
type OnBeforeSendHeadersDetails = Parameters<Parameters<
@@ -476,9 +462,6 @@ function initWhitelist () {
* to reflect this on whitelisted sites.
*/
async function onBeforeSendHeaders (details: OnBeforeSendHeadersDetails) {
const { os } = await browser.runtime.getPlatformInfo();
const chromeUserAgent = getChromeUserAgent(os);
if (!details.requestHeaders) {
throw logger.error("OnBeforeSendHeaders handler details missing requestHeaders.");
}
@@ -487,6 +470,8 @@ function initWhitelist () {
header => header.name === "Host");
for (const header of details.requestHeaders) {
const { os } = await browser.runtime.getPlatformInfo();
if (header.name.toLowerCase() === "user-agent") {
/**
* New YouTube breaks without the default user agent string,
@@ -497,7 +482,7 @@ function initWhitelist () {
break;
}
header.value = chromeUserAgent;
header.value = getChromeUserAgent(os);
break;
}
}
@@ -526,7 +511,7 @@ function initWhitelist () {
}
// Register on first run
registerUserAgentWhitelist();
await registerUserAgentWhitelist();
// Re-register when options change
options.addEventListener("changed", ev => {
@@ -559,7 +544,7 @@ async function initMediaOverlay () {
, runAt: "document_start"
});
} catch (err) {
logger.error("Failed to register media overlay")
logger.error("Failed to register media overlay");
}
}
@@ -577,7 +562,7 @@ async function initMediaOverlay () {
await unregisterMediaOverlayContentScript();
await registerMediaOverlayContentScript();
}
})
});
}
@@ -601,16 +586,13 @@ async function init () {
isInitialized = true;
await StatusManager.init();
await ShimManager.init();
await initMenus();
await initRequestListener();
await initWhitelist();
await initMediaOverlay();
await StatusManager.init();
await ShimManager.init();
await initBrowserAction();

View File

@@ -104,8 +104,8 @@ export default class NativeReceiverSelector
, i18n_extensionName: _("extensionName")
, i18n_castButtonTitle: _("popupCastButtonTitle")
, i18n_stopButtonTitle: _("popupStopButtonTitle")
, i18n_mediaTypeApp:
knownApps[requestedAppId]?.name ?? _("popupMediaTypeApp")
, i18n_mediaTypeApp: knownApps[requestedAppId]?.name
?? _("popupMediaTypeApp")
, i18n_mediaTypeTab: _("popupMediaTypeTab")
, i18n_mediaTypeScreen: _("popupMediaTypeScreen")
, i18n_mediaTypeFile: _("popupMediaTypeFile")

View File

@@ -35,7 +35,7 @@ export default async function loadSender (opts: LoadSenderOptions) {
const shim = ShimManager.getShim(opts.tabId, opts.frameId);
if (!shim) {
throw logger.error(`Shim not found at tabId ${
opts.tabId} / frameId ${opts.frameId}`)
opts.tabId} / frameId ${opts.frameId}`);
}
shim.contentPort.postMessage({

View File

@@ -3,15 +3,17 @@
export class Logger {
constructor (private prefix: string) {}
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
console.log(formattedMessage, data);
} else {
// tslint:disable-next-line:no-console
console.log(formattedMessage);
}
}
info (message: string, data?: any) {
public info (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Info): ${message}`;
if (data) {
console.info(formattedMessage, data);
@@ -19,7 +21,7 @@ export class Logger {
console.info(formattedMessage);
}
}
error (message: string, data?: any) {
public error (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Error): ${message}`;
if (data) {
console.error(formattedMessage, data);

View File

@@ -107,7 +107,7 @@ export default new class extends TypedEventTarget<EventMap> {
* Returns storage promise.
*/
public async setAll (options: Options): Promise<void> {
return storageArea.set({ options })
return storageArea.set({ options });
}
/**

View File

@@ -16,7 +16,7 @@ export class TypedStorageArea<Schema extends { [key: string]: any }> {
/**
* Retrieves one or more items from the storage area.
*
* @param keys -
* @param keys -
* A string, array of strings or partial schema object
* (with default values) indicating which keys to retrieve
* from storage.
@@ -24,7 +24,7 @@ export class TypedStorageArea<Schema extends { [key: string]: any }> {
public async get<SchemaKey extends keyof Schema
, SchemaPartial extends Partial<Schema>> (
keys?: SchemaKey
| Array<SchemaKey>
| SchemaKey[]
| SchemaPartial
| null | undefined)
: Promise<Pick<Schema, Extract<
@@ -37,12 +37,12 @@ export class TypedStorageArea<Schema extends { [key: string]: any }> {
* Gets the amount of storage space — in bytes — used by one
* or more items in the storage area.
*
* @param keys -
* @param keys -
* A string or array of strings indicating the keys of
* which to get the storage space.
*/
public async getBytesInUse<SchemaKey extends keyof Schema> (
keys?: Schema | Array<SchemaKey>): Promise<number> {
keys?: Schema | SchemaKey[]): Promise<number> {
return await this.storageArea.getBytesInUse(keys);
}
@@ -61,12 +61,12 @@ export class TypedStorageArea<Schema extends { [key: string]: any }> {
/**
* Removes one or more items from the storage area.
*
* @param keys -
* @param keys -
* A string or array of strings indicating which keys to
* remove from storage.
*/
public async remove<SchemaKey extends keyof Schema> (
keys: SchemaKey | Array<SchemaKey>): Promise<void> {
keys: SchemaKey | SchemaKey[]): Promise<void> {
await this.storageArea.remove(keys);
}

View File

@@ -6,9 +6,9 @@ const PLATFORM_WIN = "Windows NT 10.0; Win64; x64";
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"
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

View File

@@ -91,8 +91,9 @@ function getSession (opts: InitOptions): Promise<cast.Session> {
}
}
// TODO: Handle this
function sessionListener () {}
function sessionListener () {
// TODO: Handle this
}
function onRequestSessionSuccess (session: cast.Session) {
resolve(session);
@@ -136,7 +137,7 @@ function getMedia (opts: InitOptions): Promise<cast.media.Media> {
= await startMediaServer(mediaTitle, port);
const baseUrl = new URL(`http://${host}:${port}/`);
mediaUrl = new URL(mediaPath, baseUrl)
mediaUrl = new URL(mediaPath, baseUrl);
subtitleUrls = subtitlePaths.map(
path => new URL(path, baseUrl));
@@ -395,6 +396,7 @@ export async function init (opts: InitOptions) {
});
if (await options.get("mediaStopOnUnload")) {
// tslint:disable-next-line: no-empty
currentSession.stop(() => {}, () => {});
}
});

View File

@@ -43,7 +43,7 @@ export function bindPropertyDescriptor (
* element and collect them into a property descriptor map.
*/
export function clonePropsDescriptor<T> (
target: T, props: Array<any/*keyof typeof T*/>)
target: T, props: any[])
: PropertyDescriptorMap {
return props.reduce<PropertyDescriptorMap>((descriptorMap, prop) => {

View File

@@ -51,6 +51,7 @@ function deepQuerySelector (selector: string): Element | null {
, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (!shadowRoot) {
@@ -78,6 +79,7 @@ function deepQuerySelectorAll (selector: string): Node[] {
const nodes: Node[] = [];
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (shadowRoot) {
@@ -361,7 +363,7 @@ document.addEventListener("DOMContentLoaded", () => {
const mediaElements = document.querySelectorAll(mediaSelector);
const deepMediaElements = deepQuerySelectorAll(mediaSelector);
for (const mediaElement of [...Array.from(mediaElements), ...deepMediaElements]) {
for (const mediaElement of [...mediaElements, ...deepMediaElements]) {
wrapMediaElement(mediaElement as HTMLMediaElement);
}
});

View File

@@ -35,7 +35,7 @@ function sendAppMessage (subject: string, data: any) {
session.sendMessage(FX_CAST_RECEIVER_APP_NAMESPACE, {
subject
, data
}, () => {}, () => {});
});
}
@@ -45,7 +45,6 @@ window.addEventListener("beforeunload", () => {
async function onRequestSessionSuccess (newSession: cast.Session) {
cast.logMessage("onRequestSessionSuccess");
session = newSession;

View File

@@ -295,8 +295,8 @@ export default class Session {
}
public leave (
successCallback: SuccessCallback
, errorCallback: ErrorCallback): void {
successCallback?: SuccessCallback
, errorCallback?: ErrorCallback): void {
const id = uuid();
@@ -314,8 +314,8 @@ export default class Session {
public loadMedia (
loadRequest: LoadRequest
, successCallback: LoadSuccessCallback
, errorCallback: ErrorCallback): void {
, successCallback?: LoadSuccessCallback
, errorCallback?: ErrorCallback): void {
this._sendMediaMessage({
type: "LOAD"
@@ -372,8 +372,8 @@ export default class Session {
public queueLoad (
_queueLoadRequest: QueueLoadRequest
, _successCallback: LoadSuccessCallback
, _errorCallback: ErrorCallback): void {
, _successCallback?: LoadSuccessCallback
, _errorCallback?: ErrorCallback): void {
logger.info("STUB :: Session#queueLoad");
}
@@ -399,8 +399,8 @@ export default class Session {
public sendMessage (
namespace: string
, message: {} | string
, successCallback: SuccessCallback
, errorCallback: ErrorCallback): void {
, successCallback?: SuccessCallback
, errorCallback?: ErrorCallback): void {
const messageId = uuid();
@@ -422,8 +422,8 @@ export default class Session {
public setReceiverMuted (
muted: boolean
, successCallback: SuccessCallback
, errorCallback: ErrorCallback) {
, successCallback?: SuccessCallback
, errorCallback?: ErrorCallback) {
const volumeId = uuid();
@@ -441,8 +441,8 @@ export default class Session {
public setReceiverVolumeLevel (
newLevel: number
, successCallback: SuccessCallback
, errorCallback: ErrorCallback): void {
, successCallback?: SuccessCallback
, errorCallback?: ErrorCallback): void {
const volumeId = uuid();
@@ -459,8 +459,8 @@ export default class Session {
}
public stop (
successCallback: SuccessCallback
, errorCallback: ErrorCallback): void {
successCallback?: SuccessCallback
, errorCallback?: ErrorCallback): void {
const stopId = uuid();
@@ -478,9 +478,6 @@ export default class Session {
private _sendMediaMessage (message: string | {}) {
this.sendMessage(
"urn:x-cast:com.google.cast.media"
, message
, () => {}, () => {});
this.sendMessage("urn:x-cast:com.google.cast.media", message);
}
}

View File

@@ -178,8 +178,8 @@ export function requestSession (
export function _requestSession (
_receiver: Receiver
, successCallback: RequestSessionSuccessCallback
, errorCallback: ErrorCallback): void {
, successCallback?: RequestSessionSuccessCallback
, errorCallback?: ErrorCallback): void {
logger.info("cast._requestSession");
@@ -243,7 +243,7 @@ export function _requestSession (
const lastSession = sessionList[sessionList.length - 1];
if (lastSession.status !== SessionStatus.STOPPED) {
lastSession.stop(createSession, () => {});
lastSession.stop(createSession);
}
} else {
createSession();
@@ -368,7 +368,7 @@ onMessage(async message => {
const lastSession = sessionList[sessionList.length - 1];
if (lastSession.status !== SessionStatus.STOPPED) {
lastSession.stop(createSession, () => {});
lastSession.stop(createSession);
}
} else {
createSession();
@@ -417,8 +417,7 @@ onMessage(async message => {
_requestSession(receiver
, session => {
apiConfig.sessionListener(session);
}
, () => {});
});
break;
}

View File

@@ -390,7 +390,7 @@ class OptionsApp extends Component<{}, OptionsAppState> {
{ _("optionsUserAgentWhitelistContent") }
</div>
<div className="option__control">
{ this.state.options?.userAgentWhitelist &&
{ this.state.options?.userAgentWhitelist &&
<EditableList data={ this.state.options.userAgentWhitelist }
onChange={ this.handleWhitelistChange }
itemPattern={ REMOTE_MATCH_PATTERN_REGEX }

View File

@@ -277,7 +277,7 @@ class ReceiverEntry extends Component<ReceiverEntryProps, ReceiverEntryState> {
showAlternateAction: ev.type === "keydown"
});
}
}
};
window.addEventListener("keydown", handleActionKeyEvents);
window.addEventListener("keyup", handleActionKeyEvents);