From a1e0cd52d2a8fdce7e1e952f78a0c8e5952f75c8 Mon Sep 17 00:00:00 2001 From: Hannah <57945088+HannahPadd@users.noreply.github.com> Date: Thu, 28 May 2026 09:47:05 +0200 Subject: [PATCH] Hannah/sentry cleanup (#1862) Co-authored-by: loucass003 --- gui/electron.vite.config.ts | 38 +++++++---------- gui/electron/main/index.ts | 42 ++++++++++--------- gui/electron/preload/index.ts | 16 +++++-- gui/electron/preload/interface.d.ts | 1 + gui/electron/shared.ts | 4 +- .../components/providers/ConfigContext.tsx | 7 +++- gui/src/hooks/app.ts | 4 +- gui/src/utils/sentry.ts | 14 +++++-- 8 files changed, 73 insertions(+), 53 deletions(-) diff --git a/gui/electron.vite.config.ts b/gui/electron.vite.config.ts index f9d7b3773..7735ecdd1 100644 --- a/gui/electron.vite.config.ts +++ b/gui/electron.vite.config.ts @@ -1,21 +1,15 @@ -import { defineConfig } from 'electron-vite' -import { resolve } from 'path' -import rendererConfig from './vite.config' // Import your existing React config +import { defineConfig } from 'electron-vite'; +import { resolve } from 'path'; +import rendererConfig from './vite.config'; // Import your existing React config export default defineConfig({ main: { build: { rollupOptions: { input: resolve(__dirname, 'electron/main/index.ts'), - external: [ - 'pino', - 'pino-pretty', - 'pino-roll', - 'commander', - 'open' - ] - } - } + external: ['pino', 'pino-pretty', 'pino-roll', 'commander', 'open'], + }, + }, }, preload: { build: { @@ -23,12 +17,12 @@ export default defineConfig({ input: resolve(__dirname, 'electron/preload/index.ts'), output: { format: 'cjs', // Force CJS for the preload - entryFileNames: 'index.js' // Change back to .js - } - } - } + entryFileNames: 'index.js', // Change back to .js + }, + }, + }, }, - renderer: { + renderer: { ...rendererConfig, root: '.', build: { @@ -40,8 +34,8 @@ export default defineConfig({ transformMixedEsModules: true, }, rollupOptions: { - input: resolve(__dirname, 'index.html') - } - } - } -}) + input: resolve(__dirname, 'index.html'), + }, + }, + }, +}); diff --git a/gui/electron/main/index.ts b/gui/electron/main/index.ts index 799e8ab69..3f1f1dfd7 100644 --- a/gui/electron/main/index.ts +++ b/gui/electron/main/index.ts @@ -156,8 +156,7 @@ handleIpc(IPC_CHANNELS.STORAGE, async (e, { type, method, key, value }) => { handleIpc(IPC_CHANNELS.DISCORD_PRESENCE, async (e, options) => { if (options.enable) { - if (!discordPresence.state.ready) - await discordPresence.connect(); + if (!discordPresence.state.ready) await discordPresence.connect(); discordPresence.updateActivity(options.activity, options.iconText); } else if (discordPresence.state.ready) { discordPresence.destroy(); @@ -193,6 +192,10 @@ handleIpc(IPC_CHANNELS.GET_FOLDER, (e, folder) => { } }); +handleIpc(IPC_CHANNELS.IS_STEAM, () => { + return options.steam; +}); + const defaultWindowState: { width: number; height: number; @@ -208,11 +211,11 @@ const defaultWindowState: { const windowState = await readFile(getWindowStateFile(), { encoding: 'utf-8', }) -.then(data => JSON.parse(data)) -.catch(() => { - logger.error('Failed to load window state, using defaults'); - return defaultWindowState; -}); + .then((data) => JSON.parse(data)) + .catch(() => { + logger.error('Failed to load window state, using defaults'); + return defaultWindowState; + }); const MIN_WIDTH = 393; const MIN_HEIGHT = 667; @@ -245,7 +248,9 @@ function validateWindowState(state: typeof defaultWindowState) { const saveWindowState = async () => { await mkdir(dirname(getWindowStateFile()), { recursive: true }); - await writeFile(getWindowStateFile(), JSON.stringify(windowState), { encoding: 'utf-8' }); + await writeFile(getWindowStateFile(), JSON.stringify(windowState), { + encoding: 'utf-8', + }); }; function createWindow() { @@ -293,10 +298,8 @@ function createWindow() { mainWindow.minimize(); break; case 'toggle-maximize': - if (mainWindow.isMaximized()) - mainWindow.unmaximize(); - else - mainWindow.maximize(); + if (mainWindow.isMaximized()) mainWindow.unmaximize(); + else mainWindow.maximize(); break; } }); @@ -403,7 +406,7 @@ const spawnServer = async () => { 'SlimeVR', `Couldn't find a compatible Java version, please download Java 17 or higher` ); - app.quit() + app.quit(); return; } @@ -425,7 +428,9 @@ const spawnServer = async () => { ? { ...process.env, APPDATA: app.getPath('appData'), - LOCALAPPDATA: process.env['USERPROFILE'] ? path.join(process.env['USERPROFILE'], 'AppData', 'Local') : undefined, + LOCALAPPDATA: process.env['USERPROFILE'] + ? path.join(process.env['USERPROFILE'], 'AppData', 'Local') + : undefined, } : undefined, }); @@ -447,11 +452,11 @@ const spawnServer = async () => { serverProcess.on('error', (err) => { logger.info({ err }, 'Error launching the java server'); if (!isQuitting) app.quit(); - }) + }); serverProcess.on('exit', () => { logger.info('Server process exiting'); - }) + }); const exited = new Promise((resolve) => serverProcess.once('exit', resolve)); @@ -465,8 +470,7 @@ const spawnServer = async () => { const createFolders = async () => { await mkdir(getServerDataFolder(), { recursive: true }); await mkdir(getGuiDataFolder(), { recursive: true }); -} - +}; let isQuitting = false; @@ -477,7 +481,6 @@ app.whenReady().then(async () => { return net.fetch(pathToFileURL(filePath).toString(), { headers: request.headers }); }); - try { await createFolders(); } catch (err) { @@ -490,7 +493,6 @@ app.whenReady().then(async () => { return; } - stores = await initStores(); checkEnvironmentVariables(); const server = await spawnServer(); diff --git a/gui/electron/preload/index.ts b/gui/electron/preload/index.ts index 3eac6c1df..ac50ad251 100644 --- a/gui/electron/preload/index.ts +++ b/gui/electron/preload/index.ts @@ -14,7 +14,8 @@ contextBridge.exposeInMainWorld('electronAPI', { close: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_ACTIONS, 'close'), hide: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_ACTIONS, 'hide'), minimize: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_ACTIONS, 'minimize'), - toggleMaximize: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_ACTIONS, 'toggle-maximize'), + toggleMaximize: () => + ipcRenderer.invoke(IPC_CHANNELS.WINDOW_ACTIONS, 'toggle-maximize'), getStorage: async (type) => { return { get: (key) => @@ -32,10 +33,19 @@ contextBridge.exposeInMainWorld('electronAPI', { setTranslations: () => {}, openDialog: (options) => ipcRenderer.invoke(IPC_CHANNELS.OPEN_DIALOG, options), saveDialog: (options) => ipcRenderer.invoke(IPC_CHANNELS.SAVE_DIALOG, options), - openConfigFolder: async () => ipcRenderer.invoke(IPC_CHANNELS.OPEN_FILE, await ipcRenderer.invoke(IPC_CHANNELS.GET_FOLDER, 'config')), - openLogsFolder: async () => ipcRenderer.invoke(IPC_CHANNELS.OPEN_FILE, await ipcRenderer.invoke(IPC_CHANNELS.GET_FOLDER, 'logs')), + openConfigFolder: async () => + ipcRenderer.invoke( + IPC_CHANNELS.OPEN_FILE, + await ipcRenderer.invoke(IPC_CHANNELS.GET_FOLDER, 'config') + ), + openLogsFolder: async () => + ipcRenderer.invoke( + IPC_CHANNELS.OPEN_FILE, + await ipcRenderer.invoke(IPC_CHANNELS.GET_FOLDER, 'logs') + ), openFile: (path) => ipcRenderer.invoke(IPC_CHANNELS.OPEN_FILE, path), ghGet: (req) => ipcRenderer.invoke(IPC_CHANNELS.GH_FETCH, req), setPresence: (options) => ipcRenderer.invoke(IPC_CHANNELS.DISCORD_PRESENCE, options), getInstallDir: () => ipcRenderer.invoke(IPC_CHANNELS.GET_FOLDER, 'exe'), + isSteam: () => ipcRenderer.invoke(IPC_CHANNELS.IS_STEAM), } satisfies IElectronAPI); diff --git a/gui/electron/preload/interface.d.ts b/gui/electron/preload/interface.d.ts index 76f86d66b..4250b0ca1 100644 --- a/gui/electron/preload/interface.d.ts +++ b/gui/electron/preload/interface.d.ts @@ -59,6 +59,7 @@ export interface IElectronAPI { ghGet: (options: T) => Promise; setPresence: (options: DiscordPresence) => void; getInstallDir: () => Promise; + isSteam: () => Promise; } declare global { diff --git a/gui/electron/shared.ts b/gui/electron/shared.ts index 0472c34a2..ac32c9234 100644 --- a/gui/electron/shared.ts +++ b/gui/electron/shared.ts @@ -19,7 +19,8 @@ export const IPC_CHANNELS = { OPEN_FILE: 'open-file', GET_FOLDER: 'get-folder', GH_FETCH: 'gh-fetch', - DISCORD_PRESENCE: 'discord-presence' + DISCORD_PRESENCE: 'discord-presence', + IS_STEAM: 'is-steam', } as const; export interface IpcInvokeMap { @@ -48,4 +49,5 @@ export interface IpcInvokeMap { options: T ) => Promise; [IPC_CHANNELS.DISCORD_PRESENCE]: (options: DiscordPresence) => void; + [IPC_CHANNELS.IS_STEAM]: () => boolean; } diff --git a/gui/src/components/providers/ConfigContext.tsx b/gui/src/components/providers/ConfigContext.tsx index 88d3eb639..0e0e80879 100644 --- a/gui/src/components/providers/ConfigContext.tsx +++ b/gui/src/components/providers/ConfigContext.tsx @@ -2,11 +2,14 @@ import { ReactNode } from 'react'; import { ConfigContextC, loadConfig, useConfigProvider } from '@/hooks/config'; import { getSentryOrCompute } from '@/utils/sentry'; -const config = await loadConfig(); +const [config, isSteam] = await Promise.all([ + loadConfig(), + window.electronAPI.isSteam(), +]); if (config?.errorTracking !== undefined) { // load sentry ASAP to catch early errors - getSentryOrCompute(config.errorTracking ?? false, config.uuid); + getSentryOrCompute(config.errorTracking ?? false, config.uuid, isSteam); } export function ConfigContextProvider({ children }: { children: ReactNode }) { diff --git a/gui/src/hooks/app.ts b/gui/src/hooks/app.ts index 0623db19b..65003e0e7 100644 --- a/gui/src/hooks/app.ts +++ b/gui/src/hooks/app.ts @@ -16,6 +16,8 @@ import { getSentryOrCompute, updateSentryContext } from '@/utils/sentry'; import { fetchCurrentFirmwareRelease, FirmwareRelease } from './firmware-update'; import { DEFAULT_LOCALE, LangContext } from '@/i18n/config'; +const isSteam = await window.electronAPI.isSteam(); + export interface AppContext { currentFirmwareRelease: FirmwareRelease | null; } @@ -79,7 +81,7 @@ export function useProvideAppContext(): AppContext { if (config.errorTracking !== undefined) { // Alows for sentry to refresh if user change the setting once the gui // is initialized - getSentryOrCompute(config.errorTracking ?? false, config.uuid); + getSentryOrCompute(config.errorTracking ?? false, config.uuid, isSteam); } }, [config]); diff --git a/gui/src/utils/sentry.ts b/gui/src/utils/sentry.ts index 215119434..34c287942 100644 --- a/gui/src/utils/sentry.ts +++ b/gui/src/utils/sentry.ts @@ -9,7 +9,13 @@ import { } from 'react-router-dom'; import { DeviceDataT } from 'solarxr-protocol'; -export function getSentryOrCompute(enabled = false, uuid: string) { +export function getSentryOrCompute(enabled = false, uuid: string, isSteam: boolean) { + // to be considered prod it needs to be a proper version tag, non-dirty + const isProd = import.meta.env.PROD && __GIT_CLEAN__ && __VERSION_TAG__; + + // We disable sentry for non prod environments + if (!isProd) enabled = false; + Sentry.setUser({ id: uuid }); // if sentry is already initialized - SKIP @@ -44,10 +50,10 @@ export function getSentryOrCompute(enabled = false, uuid: string) { }), ], beforeSend: (ev) => (newClient?.getOptions().enabled ? ev : null), - environment: import.meta.env.MODE, + environment: isSteam ? 'steam' : 'production', release: (__VERSION_TAG__ || __COMMIT_HASH__) + (__GIT_CLEAN__ ? '' : '-dirty'), // Tracing - tracesSampleRate: import.meta.env.PROD ? 0.5 : 1.0, // Capture 50% of the transactions + tracesSampleRate: 0.5, // Capture 50% of the transactions // Set profilesSampleRate to 1.0 to profile every transaction. // Since profilesSampleRate is relative to tracesSampleRate, // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate @@ -55,7 +61,7 @@ export function getSentryOrCompute(enabled = false, uuid: string) { // results in 25% of transactions being profiled (0.5*0.5=0.25) profilesSampleRate: 0.2, // Session Replay - replaysSessionSampleRate: import.meta.env.PROD ? 0.1 : 1.0, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production. + replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. normalizeDepth: 8, enabled,