diff --git a/src-electron/electron-main.ts b/src-electron/electron-main.ts index 6fa2aea00..ebd3a9fe8 100644 --- a/src-electron/electron-main.ts +++ b/src-electron/electron-main.ts @@ -17,10 +17,10 @@ const { join } = upath; import { PLATFORM } from './constants'; import { cancelAllDownloads } from './main/downloads'; -import { captureElectronError } from './main/log'; import { initScreenListeners } from './main/screen'; import { initSessionListeners } from './main/session'; import { initUpdater } from './main/updater'; +import { captureElectronError } from './main/utils'; import { closeOtherWindows, sendToWindow } from './main/window/window-base'; import { authorizedClose, diff --git a/src-electron/main/downloads.ts b/src-electron/main/downloads.ts index dff44df3a..2c8678b62 100644 --- a/src-electron/main/downloads.ts +++ b/src-electron/main/downloads.ts @@ -4,8 +4,7 @@ import { ensureDir } from 'fs-extra/esm'; import upath from 'upath'; const { basename } = upath; -import { fetchJson } from './../utils'; -import { captureElectronError } from './log'; +import { captureElectronError, fetchJson } from './utils'; import { sendToWindow } from './window/window-base'; import { mainWindow } from './window/window-main'; diff --git a/src-electron/main/fs.ts b/src-electron/main/fs.ts index 05b495b5a..a86869887 100644 --- a/src-electron/main/fs.ts +++ b/src-electron/main/fs.ts @@ -12,7 +12,7 @@ import { import upath from 'upath'; const { basename, dirname, join, toUnix } = upath; -import { captureElectronError } from './log'; +import { captureElectronError } from './utils'; import { sendToWindow } from './window/window-base'; import { mainWindow } from './window/window-main'; diff --git a/src-electron/main/ipc.ts b/src-electron/main/ipc.ts index 4323f2362..ddac82674 100644 --- a/src-electron/main/ipc.ts +++ b/src-electron/main/ipc.ts @@ -20,7 +20,6 @@ import { } from 'electron'; import { PLATFORM } from '../constants'; -import { getAppVersion, isSelf } from './../utils'; import { downloadFile } from './downloads'; import { openFileDialog, @@ -36,6 +35,7 @@ import { unregisterAllShortcuts, unregisterShortcut, } from './shortcuts'; +import { getAppVersion, isSelf } from './utils'; import { logToWindow } from './window/window-base'; import { mainWindow, toggleAuthorizedClose } from './window/window-main'; import { mediaWindow, moveMediaWindow } from './window/window-media'; diff --git a/src-electron/main/log.ts b/src-electron/main/log.ts deleted file mode 100644 index 13afa3728..000000000 --- a/src-electron/main/log.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { ExclusiveEventHintOrCaptureContext } from 'app/node_modules/@sentry/core/build/types/utils/prepareEvent'; - -import { captureException } from '@sentry/electron/main'; - -import { IS_DEV } from '../constants'; - -/** - * Logs an error to the console or to Sentry - * @param error The error to log - * @param context The context to log with the error - */ -export function captureElectronError( - error: Error | string | unknown, - context?: ExclusiveEventHintOrCaptureContext, -) { - if (error instanceof Error && error.cause) { - captureElectronError(error.cause, context); - } - - if (IS_DEV) { - console.error(error); - console.warn('context', context); - } else { - captureException(error, context); - } -} diff --git a/src-electron/main/screen.ts b/src-electron/main/screen.ts index fd81d4163..2be055145 100644 --- a/src-electron/main/screen.ts +++ b/src-electron/main/screen.ts @@ -2,7 +2,7 @@ import type { Display, ScreenPreferences } from 'src/types'; import { app, type BrowserWindow, screen } from 'electron'; -import { captureElectronError } from './log'; +import { captureElectronError } from './utils'; import { mainWindow } from './window/window-main'; import { mediaWindow, moveMediaWindow } from './window/window-media'; diff --git a/src-electron/main/security.ts b/src-electron/main/security.ts index 69463e695..c2e9b94a0 100644 --- a/src-electron/main/security.ts +++ b/src-electron/main/security.ts @@ -1,6 +1,6 @@ import { app, session, shell } from 'electron'; -import { isSelf, isTrustedDomain } from './../utils'; +import { isSelf, isTrustedDomain } from './utils'; import { logToWindow } from './window/window-base'; import { mainWindow } from './window/window-main'; diff --git a/src-electron/main/session.ts b/src-electron/main/session.ts index 4cef30927..f5a27c0de 100644 --- a/src-electron/main/session.ts +++ b/src-electron/main/session.ts @@ -10,7 +10,7 @@ import { isSelf, isTrustedDomain, isValidUrl, -} from './../utils'; +} from './utils'; export let urlVariables: undefined | UrlVariables; diff --git a/src-electron/main/shortcuts.ts b/src-electron/main/shortcuts.ts index 182ba13dd..e67d6a28b 100644 --- a/src-electron/main/shortcuts.ts +++ b/src-electron/main/shortcuts.ts @@ -2,7 +2,7 @@ import type { SettingsValues } from 'src/types'; import { globalShortcut } from 'electron'; -import { captureElectronError } from './log'; +import { captureElectronError } from './utils'; import { sendToWindow } from './window/window-base'; import { mainWindow } from './window/window-main'; diff --git a/src-electron/main/updater.ts b/src-electron/main/updater.ts index 313f68e8d..3ff59f92d 100644 --- a/src-electron/main/updater.ts +++ b/src-electron/main/updater.ts @@ -6,7 +6,7 @@ const { exists } = fse; import { join } from 'path'; import { PLATFORM } from './../constants'; -import { captureElectronError } from './log'; +import { captureElectronError } from './utils'; export async function initUpdater() { autoUpdater.on('error', (error, message) => { diff --git a/src-electron/utils.ts b/src-electron/main/utils.ts similarity index 86% rename from src-electron/utils.ts rename to src-electron/main/utils.ts index 8540ad160..0f42f2ee8 100644 --- a/src-electron/utils.ts +++ b/src-electron/main/utils.ts @@ -1,9 +1,11 @@ +import type { ExclusiveEventHintOrCaptureContext } from 'app/node_modules/@sentry/core/build/types/utils/prepareEvent'; + +import { captureException } from '@sentry/electron/main'; import { version } from 'app/package.json'; import { app } from 'electron'; -import { IS_DEV, JW_DOMAINS, TRUSTED_DOMAINS } from './constants'; -import { captureElectronError } from './main/log'; -import { urlVariables } from './main/session'; +import { IS_DEV, JW_DOMAINS, TRUSTED_DOMAINS } from '../constants'; +import { urlVariables } from './session'; /** * Gets the current app version @@ -155,6 +157,27 @@ export const fetchJson = async ( return null; }; +/** + * Logs an error to the console or to Sentry + * @param error The error to log + * @param context The context to log with the error + */ +export function captureElectronError( + error: Error | string | unknown, + context?: ExclusiveEventHintOrCaptureContext, +) { + if (error instanceof Error && error.cause) { + captureElectronError(error.cause, context); + } + + if (IS_DEV) { + console.error(error); + console.warn('context', context); + } else { + captureException(error, context); + } +} + /** * Throttles a function to only run once every `delay` milliseconds * @param func The function to throttle diff --git a/src-electron/main/window/window-base.ts b/src-electron/main/window/window-base.ts index 3a42ab565..04ec67873 100644 --- a/src-electron/main/window/window-base.ts +++ b/src-electron/main/window/window-base.ts @@ -9,8 +9,8 @@ import { import { join, resolve } from 'path'; import { fileURLToPath } from 'url'; -import { captureElectronError } from './../log'; import { urlVariables } from './../session'; +import { captureElectronError } from './../utils'; import { StatefulBrowserWindow } from './window-state'; export function closeOtherWindows(source: BrowserWindow) { diff --git a/src-electron/main/window/window-main.ts b/src-electron/main/window/window-main.ts index 92867c559..d84463549 100644 --- a/src-electron/main/window/window-main.ts +++ b/src-electron/main/window/window-main.ts @@ -1,7 +1,7 @@ import type { BrowserWindow } from 'electron'; import { PLATFORM } from 'app/src-electron/constants'; -import { throttle } from 'app/src-electron/utils'; +import { throttle } from 'app/src-electron/main/utils'; import { cancelAllDownloads } from '../downloads'; import { closeOtherWindows, createWindow, sendToWindow } from './window-base'; diff --git a/src-electron/main/window/window-media.ts b/src-electron/main/window/window-media.ts index 4900e2831..e6a5c861d 100644 --- a/src-electron/main/window/window-media.ts +++ b/src-electron/main/window/window-media.ts @@ -5,8 +5,8 @@ import { HD_RESOLUTION, PLATFORM } from 'app/src-electron/constants'; import { join, resolve } from 'path'; import { fileURLToPath } from 'url'; -import { captureElectronError } from './../log'; import { getAllScreens, getWindowScreen, screenPreferences } from './../screen'; +import { captureElectronError } from './../utils'; import { createWindow, sendToWindow } from './window-base'; import { mainWindow } from './window-main'; diff --git a/src-electron/main/window/window-state.ts b/src-electron/main/window/window-state.ts index 238c24bcf..c478cbf71 100644 --- a/src-electron/main/window/window-state.ts +++ b/src-electron/main/window/window-state.ts @@ -8,7 +8,7 @@ import { import { ensureDirSync, readJsonSync, writeJsonSync } from 'fs-extra/esm'; import { dirname, join } from 'path'; -import { captureElectronError } from './../log'; +import { captureElectronError } from './../utils'; interface ExtraOptions { /** The name of file. Defaults to `window-state.json`. */ diff --git a/src-electron/main/window/window-website.ts b/src-electron/main/window/window-website.ts index 0d403103b..e4df67815 100644 --- a/src-electron/main/window/window-website.ts +++ b/src-electron/main/window/window-website.ts @@ -3,7 +3,7 @@ import type { NavigateWebsiteAction } from 'src/types'; import { HD_RESOLUTION, PLATFORM } from 'app/src-electron/constants'; import { type BrowserWindow, systemPreferences, type Video } from 'electron'; -import { captureElectronError } from './../log'; +import { captureElectronError } from './../utils'; import { createWindow, logToWindow, sendToWindow } from './window-base'; import { mainWindow } from './window-main';