diff --git a/src/renderer/modules/logger.ts b/src/logger.ts similarity index 99% rename from src/renderer/modules/logger.ts rename to src/logger.ts index 8a0ad0670..fcd12f261 100644 --- a/src/renderer/modules/logger.ts +++ b/src/logger.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - const blurple = "#5865F2"; export type LoggerType = @@ -9,7 +7,8 @@ export type LoggerType = | "Ignition" | "CommonModules" | "Components" - | "Manager"; + | "Manager" + | "Preload"; const repluggedPrefix = (type: LoggerType, name: string): string => `%c[Replugged:${type}:${name}]`; diff --git a/src/main/index.ts b/src/main/index.ts index 8479570e1..48e369e4a 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,10 +1,15 @@ import { dirname, join } from "path"; - import electron from "electron"; import { CONFIG_PATHS } from "src/util.mjs"; -import type { RepluggedWebContents } from "../types"; +import { RepluggedIpcChannels, type RepluggedWebContents } from "../types"; import { getSetting } from "./ipc/settings"; +export const Logger = { + log: console.log, + warn: console.warn, + error: console.error, +}; + const electronPath = require.resolve("electron"); const discordPath = join(dirname(require.main!.filename), "..", "app.orig.asar"); const discordPackage = require(join(discordPath, "package.json")); @@ -60,6 +65,10 @@ class BrowserWindow extends electron.BrowserWindow { super(opts); (this.webContents as RepluggedWebContents).originalPreload = originalPreload; + + Logger.log = (...args) => this.webContents.send(RepluggedIpcChannels.CONSOLE_LOG, ...args); + Logger.warn = (...args) => this.webContents.send(RepluggedIpcChannels.CONSOLE_WARN, ...args); + Logger.error = (...args) => this.webContents.send(RepluggedIpcChannels.CONSOLE_ERROR, ...args); } } diff --git a/src/preload.ts b/src/preload.ts index 0b8397545..5c647b634 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -5,6 +5,8 @@ import { webFrame, } from "electron"; +import { Logger } from "@logger"; + import { RepluggedIpcChannels } from "./types"; // eslint-disable-next-line no-duplicate-imports -- these are only used for types, the other import is for the actual code import type { @@ -17,6 +19,12 @@ import type { RepluggedTheme, } from "./types"; +const MainLogger = new Logger("Preload", "Backend", "#ea5a5a"); + +ipcRenderer.on(RepluggedIpcChannels.CONSOLE_LOG, (_event, ...args) => MainLogger.log(...args)); +ipcRenderer.on(RepluggedIpcChannels.CONSOLE_WARN, (_event, ...args) => MainLogger.warn(...args)); +ipcRenderer.on(RepluggedIpcChannels.CONSOLE_ERROR, (_event, ...args) => MainLogger.error(...args)); + let version = ""; void ipcRenderer.invoke(RepluggedIpcChannels.GET_REPLUGGED_VERSION).then((v) => { version = v; diff --git a/src/renderer/apis/commands.ts b/src/renderer/apis/commands.ts index 38e350349..a473e3e49 100644 --- a/src/renderer/apis/commands.ts +++ b/src/renderer/apis/commands.ts @@ -16,7 +16,7 @@ import { ApplicationCommandOptionType } from "../../types"; import icon from "../assets/logo.png"; import { constants, i18n, messages, users } from "../modules/common"; import type { Store } from "../modules/common/flux"; -import { Logger } from "../modules/logger"; +import { Logger } from "@logger"; import { filters, getByStoreName, waitForModule } from "../modules/webpack"; import { t } from "../modules/i18n"; diff --git a/src/renderer/coremods/contextMenu/index.tsx b/src/renderer/coremods/contextMenu/index.tsx index 156036b73..9e16a77ca 100644 --- a/src/renderer/coremods/contextMenu/index.tsx +++ b/src/renderer/coremods/contextMenu/index.tsx @@ -5,7 +5,7 @@ import type { GetContextItem, RawContextItem, } from "../../../types/coremods/contextMenu"; -import { Logger } from "../../modules/logger"; +import { Logger } from "@logger"; const logger = Logger.api("ContextMenu"); diff --git a/src/renderer/coremods/devCompanion/index.tsx b/src/renderer/coremods/devCompanion/index.tsx index 990b322c5..4f2c58f83 100644 --- a/src/renderer/coremods/devCompanion/index.tsx +++ b/src/renderer/coremods/devCompanion/index.tsx @@ -1,4 +1,4 @@ -import { Logger } from "../../modules/logger"; +import { Logger } from "@logger"; import { getByProps, getBySource, getByValue, getModule } from "src/renderer/modules/webpack"; import { Filter } from "src/types"; import { sourceStrings } from "src/renderer/modules/webpack/patch-load"; diff --git a/src/renderer/coremods/messagePopover/index.tsx b/src/renderer/coremods/messagePopover/index.tsx index 9b36de0df..8286691ce 100644 --- a/src/renderer/coremods/messagePopover/index.tsx +++ b/src/renderer/coremods/messagePopover/index.tsx @@ -1,7 +1,7 @@ import { getBySource, getFunctionBySource } from "@webpack"; import type { Channel, Message } from "discord-types/general"; import type { GetButtonItem, HoverBarButtonProps } from "../../../types/coremods/message"; -import { Logger } from "../../modules/logger"; +import { Logger } from "@logger"; const logger = Logger.api("MessagePopover"); diff --git a/src/renderer/managers/coremods.ts b/src/renderer/managers/coremods.ts index 4d2b1a845..3afb059e3 100644 --- a/src/renderer/managers/coremods.ts +++ b/src/renderer/managers/coremods.ts @@ -10,7 +10,7 @@ import { default as contextMenu } from "../coremods/contextMenu/plaintextPatches import { default as languagePlaintext } from "../coremods/language/plaintextPatches"; import { default as settingsPlaintext } from "../coremods/settings/plaintextPatches"; import { default as badgesPlaintext } from "../coremods/badges/plaintextPatches"; -import { Logger } from "../modules/logger"; +import { Logger } from "@logger"; const logger = Logger.api("Coremods"); diff --git a/src/renderer/managers/ignition.ts b/src/renderer/managers/ignition.ts index cb6721cb7..1db6acce8 100644 --- a/src/renderer/managers/ignition.ts +++ b/src/renderer/managers/ignition.ts @@ -1,4 +1,4 @@ -import { error, log } from "../modules/logger"; +import { error, log } from "@logger"; import { ready as commonReady } from "@common"; import { ready as componentsReady } from "../modules/components"; import * as coremods from "./coremods"; diff --git a/src/renderer/managers/plugins.ts b/src/renderer/managers/plugins.ts index 0797d7cb1..a34d9d1f4 100644 --- a/src/renderer/managers/plugins.ts +++ b/src/renderer/managers/plugins.ts @@ -1,7 +1,7 @@ // btw, pluginID is the directory name, not the RDNN. We really need a better name for this. import { loadStyleSheet } from "../util"; import type { PluginExports, RepluggedPlugin } from "../../types"; -import { Logger } from "../modules/logger"; +import { Logger } from "@logger"; import { patchPlaintext } from "../modules/webpack/plaintext-patch"; import { init } from "../apis/settings"; import type { AddonSettings } from "src/types/addon"; diff --git a/src/renderer/managers/themes.ts b/src/renderer/managers/themes.ts index eea566689..da2b6128a 100644 --- a/src/renderer/managers/themes.ts +++ b/src/renderer/managers/themes.ts @@ -2,7 +2,7 @@ import { loadStyleSheet } from "../util"; import type { RepluggedTheme } from "../../types"; import type { AddonSettings } from "src/types/addon"; import { init } from "../apis/settings"; -import * as logger from "../modules/logger"; +import * as logger from "@logger"; const themeElements = new Map(); diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index 4c4335173..42f0c18e2 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -4,7 +4,7 @@ import { AnyAddonManifest, RepluggedEntity } from "src/types/addon"; import notices from "../apis/notices"; import { init } from "../apis/settings"; import { t } from "../modules/i18n"; -import { Logger } from "../modules/logger"; +import { Logger } from "@logger"; import { waitForProps } from "../modules/webpack"; import * as pluginManager from "./plugins"; import * as themeManager from "./themes"; diff --git a/src/renderer/modules/common/index.ts b/src/renderer/modules/common/index.ts index b89dbd1e9..8fb2bc9c1 100644 --- a/src/renderer/modules/common/index.ts +++ b/src/renderer/modules/common/index.ts @@ -1,4 +1,4 @@ -import { error } from "../logger"; +import { error } from "@logger"; const modulePromises: Array<() => Promise> = []; diff --git a/src/renderer/modules/components/ErrorBoundary.tsx b/src/renderer/modules/components/ErrorBoundary.tsx index d9b37d6d8..b9998b29c 100644 --- a/src/renderer/modules/components/ErrorBoundary.tsx +++ b/src/renderer/modules/components/ErrorBoundary.tsx @@ -2,7 +2,7 @@ import { intl } from "@common/i18n"; import React from "@common/react"; import { plugins } from "@replugged"; import { t } from "../i18n"; -import { Logger } from "../logger"; +import { Logger } from "@logger"; import "./ErrorBoundary.css"; diff --git a/src/renderer/modules/components/index.ts b/src/renderer/modules/components/index.ts index d5244f228..5c3966597 100644 --- a/src/renderer/modules/components/index.ts +++ b/src/renderer/modules/components/index.ts @@ -1,5 +1,5 @@ import type { ModuleExports } from "../../../types"; -import { error } from "../logger"; +import { error } from "@logger"; const modulePromises: Array<() => Promise> = []; diff --git a/src/renderer/modules/webpack/plaintext-patch.ts b/src/renderer/modules/webpack/plaintext-patch.ts index e5bdb361f..988a1825b 100644 --- a/src/renderer/modules/webpack/plaintext-patch.ts +++ b/src/renderer/modules/webpack/plaintext-patch.ts @@ -1,5 +1,5 @@ import type { PlaintextPatch, RawPlaintextPatch, WebpackModule } from "../../../types"; -import { Logger } from "../logger"; +import { Logger } from "@logger"; const logger = Logger.api("plaintext-patch"); /** diff --git a/src/renderer/modules/webpack/util.ts b/src/renderer/modules/webpack/util.ts index bf6b71ce9..fe875f332 100644 --- a/src/renderer/modules/webpack/util.ts +++ b/src/renderer/modules/webpack/util.ts @@ -1,4 +1,4 @@ -import { Logger } from "../logger"; +import { Logger } from "@logger"; const logger = Logger.api("webpack"); diff --git a/src/renderer/replugged.ts b/src/renderer/replugged.ts index 534e0d7ec..19500a7e6 100644 --- a/src/renderer/replugged.ts +++ b/src/renderer/replugged.ts @@ -13,8 +13,8 @@ export { Injector } from "./modules/injector"; * - The "Type" portion of the prefix indicates the type of the message's origin--e.g. an API, a coremod, or a plugin. * - The "Name" portion of the prefix specifies the origin of the message--the name of the API/coremod/plugin. */ -export * as logger from "./modules/logger"; -export { Logger } from "./modules/logger"; +export * as logger from "@logger"; +export { Logger } from "@logger"; export * as webpack from "./modules/webpack"; export * as common from "./modules/common"; diff --git a/src/types/index.ts b/src/types/index.ts index 04f5e4185..ba1777251 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -32,6 +32,9 @@ export enum RepluggedIpcChannels { OPEN_QUICKCSS_FOLDER = "REPLUGGED_OPEN_QUICKCSS_FOLDER", GET_REPLUGGED_VERSION = "REPLUGGED_GET_REPLUGGED_VERSION", DOWNLOAD_REACT_DEVTOOLS = "REPLUGGED_DOWNLOAD_REACT_DEVTOOLS", + CONSOLE_LOG = "REPLUGGED_CONSOLE_LOG", + CONSOLE_WARN = "REPLUGGED_CONSOLE_WARN", + CONSOLE_ERROR = "REPLUGGED_CONSOLE_ERROR", } export interface RepluggedAnnouncement { diff --git a/tsconfig.json b/tsconfig.json index 93f986957..e948e5e74 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -40,7 +40,8 @@ "@common": ["src/renderer/modules/common"], "@common/*": ["src/renderer/modules/common/*"], "@components": ["src/renderer/modules/components"], - "@components/*": ["src/renderer/modules/components/*"] + "@components/*": ["src/renderer/modules/components/*"], + "@logger": ["src/logger.ts"] } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */