Skip to content

Commit ab38979

Browse files
committed
feat: moved process specific code to dedicated folder
1 parent ebf0e9e commit ab38979

File tree

4 files changed

+12
-32
lines changed

4 files changed

+12
-32
lines changed

src/common/logger/logger.utils.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import electronLog, { LogMessage } from 'electron-log';
22
import { camelCase, get } from 'lodash';
3-
import { isMainProcess } from '../process/process.utils';
43
import { LogData, LogFunction } from './logger.types';
54

65
export function initializeLogging(logger: electronLog.Logger): void {
7-
// Initialize the logger for any renderer processes. Must do from main.
8-
if (isMainProcess()) {
9-
electronLog.initialize({ preload: true });
10-
}
11-
126
// Add our custom log formatter.
137
logger.hooks.push((message: LogMessage): LogMessage => {
148
const [text, data] = message.data as Parameters<LogFunction>;

src/common/process/process.utils.ts

-17
This file was deleted.

src/main/logger/index.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import * as Sentry from '@sentry/electron/main';
21
import electronLog from 'electron-log/main';
32
import { Logger } from '../../common/logger/logger.types';
43
import { initializeLogging } from '../../common/logger/logger.utils';
54

5+
// This step can only be done from the main process.
6+
// It enables the logger to be usable in the renderer process.
7+
electronLog.initialize({ preload: true });
8+
9+
// Continue with common logger initialization.
610
initializeLogging(electronLog);
711

812
export function createLogger(scope?: string): Logger {
913
return scope ? electronLog.scope(scope) : electronLog;
1014
}
11-
12-
// TOOD move to a sentry init file
13-
Sentry.init({
14-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
15-
// @ts-ignore
16-
dsn: import.meta.env.MAIN_VITE_SENTRY_DSN,
17-
normalizeDepth: 5,
18-
});

src/main/process/process.utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* https://www.electronjs.org/docs/latest/api/process#processtype-readonly
3+
*/
4+
5+
export function isMainProcess(): boolean {
6+
return process.type === 'browser';
7+
}

0 commit comments

Comments
 (0)