Merge pull request #720 from hydralauncher/ci/sentry

ci: adding sentry
This commit is contained in:
Chubby Granny Chaser 2024-06-28 20:55:42 +01:00 committed by GitHub
commit b61fd1e61a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1253 additions and 17 deletions

View file

@ -1,4 +1,5 @@
import jwt from "jsonwebtoken";
import * as Sentry from "@sentry/electron/main";
import { userAuthRepository } from "@main/repository";
import { registerEvent } from "../register-event";
@ -8,6 +9,9 @@ const getSessionHash = async (_event: Electron.IpcMainInvokeEvent) => {
if (!auth) return null;
const payload = jwt.decode(auth.accessToken) as jwt.JwtPayload;
Sentry.setContext("sessionId", payload.sessionId);
return payload.sessionId;
};

View file

@ -1,4 +1,5 @@
import { registerEvent } from "../register-event";
import * as Sentry from "@sentry/electron/main";
import { HydraApi, TorrentDownloader, gamesPlaytime } from "@main/services";
import { dataSource } from "@main/data-source";
import { DownloadQueue, Game, UserAuth } from "@main/entity";
@ -19,6 +20,9 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
gamesPlaytime.clear();
});
/* Removes user from Sentry */
Sentry.setUser(null);
/* Disconnects libtorrent */
TorrentDownloader.kill();

View file

@ -1,4 +1,5 @@
import { registerEvent } from "../register-event";
import * as Sentry from "@sentry/electron/main";
import { HydraApi } from "@main/services";
import { UserProfile } from "@types";
import { userAuthRepository } from "@main/repository";
@ -21,6 +22,8 @@ const getMe = async (
["id"]
);
Sentry.setUser({ id: me.id, username: me.username });
return me;
})
.catch((err) => {

View file

@ -1,4 +1,5 @@
import { app, BrowserWindow, net, protocol } from "electron";
import { init } from "@sentry/electron/main";
import updater from "electron-updater";
import i18n from "i18next";
import path from "node:path";
@ -22,6 +23,12 @@ autoUpdater.logger = logger;
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) app.quit();
if (import.meta.env.MAIN_VITE_SENTRY_DSN) {
init({
dsn: import.meta.env.MAIN_VITE_SENTRY_DSN,
});
}
app.commandLine.appendSwitch("--no-sandbox");
i18n.init({

View file

@ -3,6 +3,7 @@
interface ImportMetaEnv {
readonly MAIN_VITE_STEAMGRIDDB_API_KEY: string;
readonly MAIN_VITE_API_URL: string;
readonly MAIN_VITE_SENTRY_DSN: string;
}
interface ImportMeta {

View file

@ -6,6 +6,8 @@ import { Provider } from "react-redux";
import LanguageDetector from "i18next-browser-languagedetector";
import { HashRouter, Route, Routes } from "react-router-dom";
import * as Sentry from "@sentry/electron/renderer";
import "@fontsource/fira-mono/400.css";
import "@fontsource/fira-mono/500.css";
import "@fontsource/fira-mono/700.css";
@ -29,6 +31,8 @@ import { store } from "./store";
import * as resources from "@locales";
import { User } from "./pages/user/user";
Sentry.init({});
i18n
.use(LanguageDetector)
.use(initReactI18next)

View file

@ -1,6 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />
interface ImportMeta {
readonly env: ImportMetaEnv;
}

View file

@ -272,6 +272,7 @@ export interface UserDetails {
export interface UserProfile {
id: string;
displayName: string;
username: string;
profileImageUrl: string | null;
totalPlayTimeInSeconds: number;
libraryGames: UserGame[];