Replace remaining console calls with logger calls

This commit is contained in:
hensm
2020-01-23 01:14:57 +00:00
parent 7f84b90431
commit f6e09ca687
8 changed files with 46 additions and 27 deletions

View File

@@ -45,7 +45,7 @@ browser.runtime.onInstalled.addListener(async details => {
function initBrowserAction () {
console.info("fx_cast (Debug): init (browser action)");
logger.info("init (browser action)");
/*browser.browserAction.disable();
@@ -86,7 +86,7 @@ function initBrowserAction () {
async function initMenus () {
console.info("fx_cast (Debug): init (menus)");
logger.info("init (menus)");
const URL_PATTERN_HTTP = "http://*/*";
const URL_PATTERN_HTTPS = "https://*/*";
@@ -413,7 +413,7 @@ async function initMenus () {
async function initRequestListener () {
console.info("fx_cast (Debug): init (request listener)");
logger.info("init (request listener)");
type OnBeforeRequestDetails = Parameters<Parameters<
typeof browser.webRequest.onBeforeRequest.addListener>[0]>[0];
@@ -457,7 +457,7 @@ async function initRequestListener () {
function initWhitelist () {
console.info("fx_cast (Debug): init (whitelist)");
logger.info("init (whitelist)");
type OnBeforeSendHeadersDetails = Parameters<Parameters<
typeof browser.webRequest.onBeforeSendHeaders.addListener>[0]>[0];
@@ -536,7 +536,7 @@ function initWhitelist () {
async function initMediaOverlay () {
console.info("fx_cast (Debug): init (media overlay)");
logger.info("init (media overlay)");
let contentScript: browser.contentScripts.RegisteredContentScript;
@@ -553,7 +553,7 @@ async function initMediaOverlay () {
, runAt: "document_start"
});
} catch (err) {
console.error("fx_cast (Debug): Failed to register media overlay");
logger.error("Failed to register media overlay")
}
}
@@ -591,7 +591,7 @@ async function init () {
return;
}
console.info("fx_cast (Debug): init");
logger.info("init");
isInitialized = true;

View File

@@ -2,6 +2,7 @@
import bridge from "../../lib/bridge";
import knownApps from "../../lib/knownApps";
import logger from "../../lib/logger";
import options from "../../lib/options";
import { TypedEventTarget } from "../../lib/typedEvents";
@@ -145,8 +146,7 @@ export default class NativeReceiverSelector
private async onBridgePortMessageError (
message: NativeReceiverSelectorErrorMessage) {
console.error("fx_cast (Debug): Native receiver selector error"
, message.data);
logger.error("Native receiver selector error", message.data);
this.dispatchEvent(new CustomEvent("error"));
}

View File

@@ -90,7 +90,7 @@ async function getSelection (
availableMediaTypes = getMediaTypesForPageUrl(url);
} catch (err) {
console.error("fx_cast (Debug): Failed to locate frame");
logger.error("Failed to locate frame");
reject();
return;
}
@@ -136,25 +136,25 @@ async function getSelection (
}
function onSelected (ev: any) {
console.info("fx_cast (Debug): Selected receiver", ev.detail);
logger.info("Selected receiver", ev.detail);
resolve(ev.detail);
removeListeners();
}
function onCancelled () {
console.info("fx_cast (Debug): Cancelled receiver selection");
logger.info("Cancelled receiver selection");
resolve(null);
removeListeners();
}
function onError () {
console.error("fx_cast (Debug): Failed to select receiver");
logger.error("Failed to select receiver");
reject();
removeListeners();
}
function onStop (ev: any) {
console.info("fx_cast (Debug): Stopped receiver app", ev.detail);
logger.info("Stopped receiver app", ev.detail);
StatusManager.init().then(() => {
StatusManager.stopReceiverApp(ev.detail.receiver);

View File

@@ -69,10 +69,10 @@ async function getInfo (): Promise<BridgeInfo> {
// Print compatibility info to console
if (!isVersionCompatible) {
console.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}.`
, isVersionOlder
logger.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}. ${
isVersionOlder
? "Try updating the native app to the latest version."
: "Try updating the extension to the latest version");
: "Try updating the extension to the latest version"}`);
}
return {

View File

@@ -3,15 +3,30 @@
export class Logger {
constructor (private prefix: string) {}
log (message: string) {
console.log(`${this.prefix} (Log): ${message}`);
log (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Log): ${message}`;
if (data) {
console.log(formattedMessage, data);
} else {
console.log(formattedMessage);
}
}
debug (message: string) {
console.debug(`${this.prefix} (Debug): ${message}`);
info (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Info): ${message}`;
if (data) {
console.info(formattedMessage, data);
} else {
console.info(formattedMessage);
}
}
error (message: string) {
error (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Error): ${message}`;
console.error(formattedMessage);
if (data) {
console.error(formattedMessage, data);
} else {
console.error(formattedMessage);
}
return new Error(formattedMessage);
}
}

View File

@@ -1,5 +1,7 @@
"use strict";
import logger from "./logger";
const WEBSOCKET_DAEMON_URL = "ws://localhost:9556";
@@ -164,7 +166,7 @@ async function sendNativeMessage (
});
ws.addEventListener("error", () => {
console.error("fx_cast (Debug): No bridge application found.");
logger.error("No bridge application found.");
reject();
});
});

View File

@@ -1,5 +1,7 @@
"use strict";
import logger from "../../../lib/logger";
import { bindPropertyDescriptor
, clonePropsDescriptor
, getPropertyDescriptor
@@ -299,7 +301,7 @@ function wrapMediaElement (mediaElement: HTMLMediaElement) {
const shadowRoot = internalShadowRoots.get(wrappedMedia);
if (!shadowRoot) {
console.error("err: Failed to fetch shadow root!");
logger.error("Failed to fetch shadow root!");
return;
}
@@ -329,7 +331,7 @@ function wrapMediaElement (mediaElement: HTMLMediaElement) {
for (const source of mediaElement.getElementsByTagName("source")) {
const internalMedia = shadowRoot.querySelector("audio,video");
if (!internalMedia) {
console.error("err: Failed to fetch internal video element!");
logger.error("Failed to fetch internal video element!");
return;
}

View File

@@ -422,7 +422,7 @@ class OptionsApp extends Component<{}, OptionsAppState> {
});
}
} catch (err) {
console.error("Failed to save options");
logger.error("Failed to save options");
}
}