Skip to content

Commit 7f9fa07

Browse files
panoramix360johannesjo
authored andcommitted
feat: enhance updateCurrentTask to include Pomodoro state and session time
1 parent 924844c commit 7f9fa07

File tree

4 files changed

+64
-32
lines changed

4 files changed

+64
-32
lines changed

Diff for: electron/electronAPI.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ export interface ElectronAPI {
108108

109109
backupAppData(appData: AppDataComplete): void;
110110

111-
updateCurrentTask(task: Task | null);
111+
updateCurrentTask(
112+
task: Task | null,
113+
isPomodoroEnabled: boolean,
114+
currentPomodoroSessionTime: number,
115+
);
112116

113117
exec(command: string): void;
114118
}

Diff for: electron/indicator.ts

+44-27
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,43 @@ function initListeners(): void {
7171
}
7272
});
7373

74-
ipcMain.on(IPC.CURRENT_TASK_UPDATED, (ev, currentTask) => {
75-
const mainWin = getWin();
76-
getSettings(mainWin, (settings: GlobalConfigState) => {
77-
const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;
78-
79-
const msg =
80-
isTrayShowCurrentTask && currentTask ? createIndicatorStr(currentTask) : '';
81-
82-
if (tray) {
83-
// tray handling
84-
if (currentTask && currentTask.title) {
85-
tray.setTitle(msg);
86-
if (!IS_MAC) {
87-
// NOTE apparently this has no effect for gnome
88-
tray.setToolTip(msg);
74+
ipcMain.on(
75+
IPC.CURRENT_TASK_UPDATED,
76+
(ev, currentTask, isPomodoroEnabled, currentPomodoroSessionTime) => {
77+
const mainWin = getWin();
78+
getSettings(mainWin, (settings: GlobalConfigState) => {
79+
const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;
80+
81+
const msg =
82+
isTrayShowCurrentTask && currentTask
83+
? createIndicatorMessage(
84+
currentTask,
85+
isPomodoroEnabled,
86+
currentPomodoroSessionTime,
87+
)
88+
: '';
89+
90+
if (tray) {
91+
// tray handling
92+
if (currentTask && currentTask.title) {
93+
tray.setTitle(msg);
94+
if (!IS_MAC) {
95+
// NOTE apparently this has no effect for gnome
96+
tray.setToolTip(msg);
97+
}
98+
} else {
99+
tray.setTitle('');
100+
if (!IS_MAC) {
101+
// NOTE apparently this has no effect for gnome
102+
tray.setToolTip(msg);
103+
}
104+
const suf = shouldUseDarkColors ? '-d.png' : '-l.png';
105+
setTrayIcon(tray, DIR + `stopped${suf}`);
89106
}
90-
} else {
91-
tray.setTitle('');
92-
if (!IS_MAC) {
93-
// NOTE apparently this has no effect for gnome
94-
tray.setToolTip(msg);
95-
}
96-
const suf = shouldUseDarkColors ? '-d.png' : '-l.png';
97-
setTrayIcon(tray, DIR + `stopped${suf}`);
98107
}
99-
}
100-
});
101-
});
108+
});
109+
},
110+
);
102111

103112
// ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => {
104113
// const isOnBreak = params.isOnBreak;
@@ -111,7 +120,11 @@ function initListeners(): void {
111120
}
112121

113122
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
114-
function createIndicatorStr(task: TaskCopy): string {
123+
function createIndicatorMessage(
124+
task: TaskCopy,
125+
isPomodoroEnabled: boolean,
126+
currentPomodoroSessionTime: number,
127+
): string {
115128
if (task && task.title) {
116129
let title = task.title;
117130
let timeStr = '';
@@ -126,6 +139,10 @@ function createIndicatorStr(task: TaskCopy): string {
126139
timeStr = getCountdownMessage(task.timeSpent);
127140
}
128141

142+
if (isPomodoroEnabled) {
143+
timeStr = getCountdownMessage(currentPomodoroSessionTime);
144+
}
145+
129146
return `${title} ${timeStr}`;
130147
}
131148

Diff for: electron/preload.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ const ea: ElectronAPI = {
8282

8383
backupAppData: (appData) => _send('BACKUP', appData),
8484

85-
updateCurrentTask: (task) => _send('CURRENT_TASK_UPDATED', task),
85+
updateCurrentTask: (task, isPomodoroEnabled, currentPomodoroSessionTime) =>
86+
_send('CURRENT_TASK_UPDATED', task, isPomodoroEnabled, currentPomodoroSessionTime),
8687

8788
exec: (command: string) => _send('EXEC', command),
8889
};

Diff for: src/app/features/tasks/store/task-electron.effects.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { selectCurrentTask } from './task.selectors';
77
import { IS_ELECTRON } from '../../../app.constants';
88
import { GlobalConfigService } from '../../config/global-config.service';
99
import { selectIsFocusOverlayShown } from '../../focus-mode/store/focus-mode.selectors';
10+
import { PomodoroService } from '../../pomodoro/pomodoro.service';
1011

1112
// TODO send message to electron when current task changes here
1213

@@ -15,15 +16,24 @@ export class TaskElectronEffects {
1516
private _actions$ = inject(Actions);
1617
private _store$ = inject<Store<any>>(Store);
1718
private _configService = inject(GlobalConfigService);
19+
private _pomodoroService = inject(PomodoroService);
1820

1921
taskChangeElectron$: any = createEffect(
2022
() =>
2123
this._actions$.pipe(
2224
ofType(setCurrentTask, unsetCurrentTask, addTimeSpent),
23-
withLatestFrom(this._store$.pipe(select(selectCurrentTask))),
24-
tap(([action, current]) => {
25+
withLatestFrom(
26+
this._store$.pipe(select(selectCurrentTask)),
27+
this._pomodoroService.isEnabled$,
28+
this._pomodoroService.currentSessionTime$,
29+
),
30+
tap(([action, current, isPomodoroEnabled, currentPomodoroSessionTime]) => {
2531
if (IS_ELECTRON) {
26-
window.ea.updateCurrentTask(current);
32+
window.ea.updateCurrentTask(
33+
current,
34+
isPomodoroEnabled,
35+
currentPomodoroSessionTime,
36+
);
2737
}
2838
}),
2939
),

0 commit comments

Comments
 (0)