mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-27 12:26:33 -08:00
Hannah/sentry cleanup (#1862)
Co-authored-by: loucass003 <[email protected]>
This commit is contained in:
1 parent
d1a39dba05
commit
a1e0cd52d2
8 files changed
+73
-53
No files matched your search
+16
-22
@@ -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'),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
+22
-20
@@ -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<void>((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();
|
||||
|
||||
@@ -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);
|
||||
Vendored
+1
@@ -59,6 +59,7 @@ export interface IElectronAPI {
|
||||
ghGet: <T extends GHGet>(options: T) => Promise<GHReturn[T['type']]>;
|
||||
setPresence: (options: DiscordPresence) => void;
|
||||
getInstallDir: () => Promise<string>;
|
||||
isSteam: () => Promise<boolean>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -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<GHReturn[T['type']]>;
|
||||
[IPC_CHANNELS.DISCORD_PRESENCE]: (options: DiscordPresence) => void;
|
||||
[IPC_CHANNELS.IS_STEAM]: () => boolean;
|
||||
}
|
||||
@@ -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 }) {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
+10
-4
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user