refactor: organize desktop vs. mobile into separate folders
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { ipcMain, type IpcMainInvokeEvent } from "electron";
|
||||
import { reportError } from "@/lib/errors";
|
||||
|
||||
type InvokeHandler = (
|
||||
event: IpcMainInvokeEvent,
|
||||
...args: unknown[]
|
||||
) => Promise<unknown> | unknown;
|
||||
|
||||
/**
|
||||
* Wraps `ipcMain.handle` so handler failures log with full stack in main and
|
||||
* re-throw a sanitized message to the renderer.
|
||||
*/
|
||||
export function safeHandle(channel: string, handler: InvokeHandler): void {
|
||||
ipcMain.handle(channel, async (event, ...args) => {
|
||||
try {
|
||||
return await handler(event, ...(args as unknown[]));
|
||||
} catch (err) {
|
||||
reportError(err, { scope: `ipc.${channel}` });
|
||||
const message = err instanceof Error ? err.message : "IPC error";
|
||||
throw new Error(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { app } from "electron";
|
||||
import * as Sentry from "@sentry/electron/main";
|
||||
import { appConfig, appEnv } from "@/config/env";
|
||||
import { installErrorSinks } from "@/lib/errors";
|
||||
|
||||
/**
|
||||
* Initialise Sentry for the main process. Captures uncaught exceptions from
|
||||
* the Node side and the crash reporter. Safe to call before `app.whenReady`.
|
||||
*/
|
||||
export function initSentryMain(): void {
|
||||
if (!appConfig.sentryDsn) return;
|
||||
|
||||
Sentry.init({
|
||||
dsn: appConfig.sentryDsn,
|
||||
environment: appEnv,
|
||||
tracesSampleRate: 0,
|
||||
release: app.getVersion(),
|
||||
});
|
||||
|
||||
installErrorSinks({
|
||||
capture: (err, context) =>
|
||||
Sentry.captureException(err, { extra: context }),
|
||||
breadcrumb: (err, context) =>
|
||||
Sentry.addBreadcrumb({
|
||||
category: "error",
|
||||
level: "error",
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
data: context,
|
||||
}),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user