Skip to content

Commit d1225ca

Browse files
refactor: 자동 생성된 preload 타입 개선
1 parent 96bdbc4 commit d1225ca

19 files changed

+404
-218
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"electron-log": "^5.3.4",
2626
"electron-store": "^8",
2727
"electron-updater": "^6.6.2",
28+
"es-toolkit": "^1.36.0",
2829
"i18next": "^25.0.1",
2930
"jsonc-parser": "^3.3.1",
30-
"lodash": "^4.17.21",
3131
"path-to-regexp": "^8.2.0",
3232
"reflect-metadata": "^0.2.2",
3333
"rxjs": "^7.8.2",
@@ -37,7 +37,6 @@
3737
"@swc/core": "^1.11.22",
3838
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
3939
"@types/auto-launch": "^5.0.5",
40-
"@types/lodash": "^4.17.16",
4140
"@types/node": "^22.15.2",
4241
"@types/react": "^19.1.2",
4342
"@types/react-dom": "^19.1.2",
@@ -59,6 +58,7 @@
5958
"react-i18next": "^15.5.1",
6059
"react-router-dom": "^7.5.2",
6160
"swr": "^2.3.3",
61+
"type-fest": "^4.40.1",
6262
"typescript": "^5.8.3",
6363
"vite": "^6.3.3"
6464
}

pnpm-lock.yaml

Lines changed: 28 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/modules/config/config.controller.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ import { Injectable } from '@nestjs/common'
22

33
import { ConfigService } from '@main/modules/config/config.service'
44
import type { ConfigStoreValues } from '@main/modules/config/config.store'
5-
import { IPCHandle } from '@main/modules/electron/decorators/ipc-handle.decorator'
5+
import { IPCHandler } from '@main/modules/electron/decorators/ipc-handler.decorator'
66

77
@Injectable()
88
export class ConfigController {
99
constructor(private readonly configService: ConfigService) {}
1010

11-
@IPCHandle()
11+
/**
12+
* 설정 값을 가져옵니다.
13+
*/
14+
@IPCHandler()
1215
public getConfig() {
1316
return this.configService.getAll()
1417
}
1518

16-
@IPCHandle()
19+
/**
20+
* 설정 값을 저장합니다.
21+
*/
22+
@IPCHandler()
1723
public setConfig(config: ConfigStoreValues) {
1824
return this.configService.setAll(config)
1925
}

src/main/modules/developer/developer.controller.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
import { Injectable } from '@nestjs/common'
22

33
import { DeveloperService } from '@main/modules/developer/developer.service'
4-
import { IPCHandle } from '@main/modules/electron/decorators/ipc-handle.decorator'
4+
import { IPCHandler } from '@main/modules/electron/decorators/ipc-handler.decorator'
55

66
@Injectable()
77
export class DeveloperController {
88
constructor(private readonly developerService: DeveloperService) {}
99

10-
@IPCHandle()
10+
/**
11+
* 테스트 용도로 사용합니다.
12+
*/
13+
@IPCHandler()
1114
public ping() {
1215
console.log('pong')
1316
return 'pong'
1417
}
1518

16-
@IPCHandle()
19+
/**
20+
* 저장소 경로를 가져옵니다.
21+
*/
22+
@IPCHandler()
1723
public getStorePath() {
1824
return this.developerService.getStorePath()
1925
}
2026

21-
@IPCHandle()
27+
/**
28+
* 로그를 가져옵니다.
29+
*/
30+
@IPCHandler()
2231
public getLogs() {
2332
return this.developerService.getLogs()
2433
}
2534

26-
@IPCHandle()
35+
/**
36+
* 로그 지우기
37+
*/
38+
@IPCHandler()
2739
public clearLogs() {
2840
return this.developerService.clearLogs()
2941
}

src/main/modules/electron/decorators/deep-link-handle.decorator.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface DeepLinkHandlerMetadata {
2+
path: string
3+
handler: (params: object) => void
4+
target: any
5+
}
6+
7+
export const DeepLinkHandlerMap = new Map<string, DeepLinkHandlerMetadata>()
8+
9+
export function DeepLinkHandler(path: string) {
10+
return function (target: any, _, descriptor: PropertyDescriptor) {
11+
DeepLinkHandlerMap.set(path, { path, handler: descriptor.value, target: target.constructor })
12+
}
13+
}

src/main/modules/electron/decorators/ipc-handle.decorator.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export interface IPCHandlerOptions {
2+
channel?: string
3+
type?: IPCHandlerType
4+
}
5+
6+
export interface IPCHandlerMetadata {
7+
channel: string
8+
type: IPCHandlerType
9+
handler: (...args: any[]) => any
10+
target: any
11+
}
12+
13+
export type IPCHandlerType = 'handle' | 'handleOnce' | 'on' | 'once'
14+
15+
export const IPCHandlerMap = new Map<string, IPCHandlerMetadata>()
16+
17+
/**
18+
* Renderer > Main 방향의 IPC 데코레이터
19+
*
20+
* @description 렌더러에서 메인 프로세스에 있는 함수를 호출해야할 때 사용합니다.
21+
* 메인 프로세스에서 메소드에 데코레이터를 붙이면 렌더러에서 해당 메소드를 호출할 수 있습니다.
22+
*/
23+
export function IPCHandler(options: IPCHandlerOptions = {}) {
24+
return function (target: any, key: string, descriptor: PropertyDescriptor) {
25+
const { channel = key, type = 'handle' } = options
26+
27+
IPCHandlerMap.set(channel, {
28+
channel,
29+
type,
30+
handler: descriptor.value,
31+
target: target.constructor,
32+
})
33+
}
34+
}

0 commit comments

Comments
 (0)