Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 0e9f1c2

Browse files
authored
fix: 뽀모도로 로그 중복 요청 이슈 수정 (#72, #patch)
* 뽀모도로 로그 중복 요청 이슈 수정 main process에서 뽀모도로 종료 이벤트를 보내면 이벤트 리스너를 통해 기록을 서버에 보냄 그런데 ipcRenderer에 대한 이벤트 리스너 등록만 있고 리스너 해제는 구현하지 않아 중복으로 요청을 보냄 이를 해결하기 위해 이벤트 리스너 해제 로직을 추가함 * guide 안보이던 이슈 수정
1 parent 4a1e88d commit 0e9f1c2

File tree

5 files changed

+58
-17
lines changed

5 files changed

+58
-17
lines changed

src/preload/preload.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ const electronAPI: IElectronAPI = {
2222
startRest: () => ipcRenderer.invoke('start-rest'),
2323
endPomodoro: (reason) => ipcRenderer.invoke('end-pomodoro', reason),
2424

25-
onTickPomodoro: (callback) =>
26-
ipcRenderer.on('tick-pomodoro', (_, cycles, time) => callback(cycles, time)),
27-
onEndPomodoro: (callback) =>
28-
ipcRenderer.on('end-pomodoro', (_, cycles, reason) => callback(cycles, reason)),
29-
onOnceExceedGoalTime: (callback) =>
30-
ipcRenderer.on('once-exceed-goal-time', (_, mode) => callback(mode)),
25+
onTickPomodoro: (callback) => ipcRenderer.on('tick-pomodoro', callback),
26+
offTickPomodoro: (callback) => ipcRenderer.off('tick-pomodoro', callback),
27+
28+
onEndPomodoro: (callback) => ipcRenderer.on('end-pomodoro', callback),
29+
offEndPomodoro: (callback) => ipcRenderer.off('end-pomodoro', callback),
30+
31+
onOnceExceedGoalTime: (callback) => ipcRenderer.on('once-exceed-goal-time', callback),
32+
offOnceExceedGoalTime: (callback) => ipcRenderer.off('once-exceed-goal-time', callback),
3133
};
3234

3335
contextBridge.exposeInMainWorld('electronAPI', electronAPI);

src/renderer/features/category/ui/category-chip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { Icon } from '@/shared/ui';
33
import { cn, getCategoryIconName } from '@/shared/utils';
44

55
type CategoryChipProps = {
6+
id?: string;
67
category: Category;
78
onClick?: () => void;
89
};
910

10-
export const CategoryChip = ({ category, onClick }: CategoryChipProps) => {
11+
export const CategoryChip = ({ id, category, onClick }: CategoryChipProps) => {
1112
return (
1213
<div
14+
id={id}
1315
className={cn(
1416
'subBody-sb flex min-w-[80px] select-none gap-sm rounded-xs bg-background-secondary p-md text-text-tertiary',
1517
onClick && 'cursor-pointer',

src/renderer/features/pomodoro/hooks/use-pomodoro-by-main.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { useEffect, useRef, useState } from 'react';
22

3-
import { PomodoroCycle, PomodoroEndReason, PomodoroManagerConfig, PomodoroTime } from 'shared/type';
3+
import {
4+
EndPomodoroCallback,
5+
OnceExceedGoalTimeCallback,
6+
PomodoroCycle,
7+
PomodoroEndReason,
8+
PomodoroManagerConfig,
9+
PomodoroTime,
10+
TickPomodoroCallback,
11+
} from 'shared/type';
412

513
export type UsePomodoroParams = Omit<PomodoroManagerConfig, 'onTickPomodoro'>;
614

@@ -19,16 +27,20 @@ export const usePomodoroByMain = (params: UsePomodoroParams) => {
1927
callbacksRef.current = callbacks;
2028

2129
useEffect(() => {
22-
window.electronAPI.onTickPomodoro((cycles, time) => {
30+
const tickPomodoroCallback: TickPomodoroCallback = (_, cycles, time) => {
2331
setPomodoroCycles(cycles);
2432
setPomodoroTime(time);
25-
});
26-
window.electronAPI.onEndPomodoro((cycles, reason) => {
33+
};
34+
const endPomodoroCallback: EndPomodoroCallback = (_, cycles, reason) => {
2735
callbacksRef.current.onEndPomodoro(cycles, reason);
28-
});
29-
window.electronAPI.onOnceExceedGoalTime((mode) => {
36+
};
37+
const onceExceedGoalTimeCallback: OnceExceedGoalTimeCallback = (_, mode) => {
3038
callbacksRef.current.onceExceedGoalTime?.(mode);
31-
});
39+
};
40+
41+
window.electronAPI.onTickPomodoro(tickPomodoroCallback);
42+
window.electronAPI.onEndPomodoro(endPomodoroCallback);
43+
window.electronAPI.onOnceExceedGoalTime(onceExceedGoalTimeCallback);
3244

3345
window.electronAPI.setupPomodoro({
3446
focusTime,
@@ -37,6 +49,12 @@ export const usePomodoroByMain = (params: UsePomodoroParams) => {
3749
restTime,
3850
restExceedMaxTime,
3951
});
52+
53+
return () => {
54+
window.electronAPI.offTickPomodoro(tickPomodoroCallback);
55+
window.electronAPI.offEndPomodoro(endPomodoroCallback);
56+
window.electronAPI.offOnceExceedGoalTime(onceExceedGoalTimeCallback);
57+
};
4058
}, [focusTime, focusExceedMaxTime, restWaitExceedMaxTime, restTime, restExceedMaxTime]);
4159

4260
const startFocus = () => {

src/renderer/widgets/pomodoro/ui/home-screen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const HomeScreen = ({
108108
<div className="header-4 text-text-tertiary">{user?.cat?.name}</div>
109109
<div className="flex flex-col items-center gap-md p-lg">
110110
<CategoryChip
111+
id="categoryButton"
111112
category={currentCategory}
112113
onClick={() => {
113114
changeCategoryDrawerProps.onOpen();

src/shared/type/electron.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import {
66
PomodoroTime,
77
} from './pomodoro';
88

9+
export type TickPomodoroCallback = (
10+
event: Electron.IpcRendererEvent,
11+
cycles: PomodoroCycle[],
12+
time: PomodoroTime,
13+
) => void;
14+
export type EndPomodoroCallback = (
15+
event: Electron.IpcRendererEvent,
16+
cycles: PomodoroCycle[],
17+
reason: PomodoroEndReason,
18+
) => void;
19+
export type OnceExceedGoalTimeCallback = (
20+
event: Electron.IpcRendererEvent,
21+
mode: PomodoroMode,
22+
) => void;
23+
924
// @see: https://www.electronjs.org/docs/latest/tutorial/context-isolation#usage-with-typescript
1025
export interface IElectronAPI {
1126
showWindow: () => void;
@@ -24,7 +39,10 @@ export interface IElectronAPI {
2439
startRest: () => Promise<void>;
2540
endPomodoro: (reason: PomodoroEndReason) => Promise<void>;
2641

27-
onTickPomodoro: (callback: (cycles: PomodoroCycle[], time: PomodoroTime) => void) => void;
28-
onEndPomodoro: (callback: (cycles: PomodoroCycle[], reason: PomodoroEndReason) => void) => void;
29-
onOnceExceedGoalTime: (callback: (mode: PomodoroMode) => void) => void;
42+
onTickPomodoro: (callback: TickPomodoroCallback) => void;
43+
offTickPomodoro: (callback: TickPomodoroCallback) => void;
44+
onEndPomodoro: (callback: EndPomodoroCallback) => void;
45+
offEndPomodoro: (callback: EndPomodoroCallback) => void;
46+
onOnceExceedGoalTime: (callback: OnceExceedGoalTimeCallback) => void;
47+
offOnceExceedGoalTime: (callback: OnceExceedGoalTimeCallback) => void;
3048
}

0 commit comments

Comments
 (0)