mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
feat: enhance updateCurrentTask to include Pomodoro state and session time
This commit is contained in:
parent
924844cae9
commit
7f9fa07559
4 changed files with 62 additions and 30 deletions
6
electron/electronAPI.d.ts
vendored
6
electron/electronAPI.d.ts
vendored
|
|
@ -108,7 +108,11 @@ export interface ElectronAPI {
|
|||
|
||||
backupAppData(appData: AppDataComplete): void;
|
||||
|
||||
updateCurrentTask(task: Task | null);
|
||||
updateCurrentTask(
|
||||
task: Task | null,
|
||||
isPomodoroEnabled: boolean,
|
||||
currentPomodoroSessionTime: number,
|
||||
);
|
||||
|
||||
exec(command: string): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,34 +71,43 @@ function initListeners(): void {
|
|||
}
|
||||
});
|
||||
|
||||
ipcMain.on(IPC.CURRENT_TASK_UPDATED, (ev, currentTask) => {
|
||||
const mainWin = getWin();
|
||||
getSettings(mainWin, (settings: GlobalConfigState) => {
|
||||
const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;
|
||||
ipcMain.on(
|
||||
IPC.CURRENT_TASK_UPDATED,
|
||||
(ev, currentTask, isPomodoroEnabled, currentPomodoroSessionTime) => {
|
||||
const mainWin = getWin();
|
||||
getSettings(mainWin, (settings: GlobalConfigState) => {
|
||||
const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;
|
||||
|
||||
const msg =
|
||||
isTrayShowCurrentTask && currentTask ? createIndicatorStr(currentTask) : '';
|
||||
const msg =
|
||||
isTrayShowCurrentTask && currentTask
|
||||
? createIndicatorMessage(
|
||||
currentTask,
|
||||
isPomodoroEnabled,
|
||||
currentPomodoroSessionTime,
|
||||
)
|
||||
: '';
|
||||
|
||||
if (tray) {
|
||||
// tray handling
|
||||
if (currentTask && currentTask.title) {
|
||||
tray.setTitle(msg);
|
||||
if (!IS_MAC) {
|
||||
// NOTE apparently this has no effect for gnome
|
||||
tray.setToolTip(msg);
|
||||
if (tray) {
|
||||
// tray handling
|
||||
if (currentTask && currentTask.title) {
|
||||
tray.setTitle(msg);
|
||||
if (!IS_MAC) {
|
||||
// NOTE apparently this has no effect for gnome
|
||||
tray.setToolTip(msg);
|
||||
}
|
||||
} else {
|
||||
tray.setTitle('');
|
||||
if (!IS_MAC) {
|
||||
// NOTE apparently this has no effect for gnome
|
||||
tray.setToolTip(msg);
|
||||
}
|
||||
const suf = shouldUseDarkColors ? '-d.png' : '-l.png';
|
||||
setTrayIcon(tray, DIR + `stopped${suf}`);
|
||||
}
|
||||
} else {
|
||||
tray.setTitle('');
|
||||
if (!IS_MAC) {
|
||||
// NOTE apparently this has no effect for gnome
|
||||
tray.setToolTip(msg);
|
||||
}
|
||||
const suf = shouldUseDarkColors ? '-d.png' : '-l.png';
|
||||
setTrayIcon(tray, DIR + `stopped${suf}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => {
|
||||
// const isOnBreak = params.isOnBreak;
|
||||
|
|
@ -111,7 +120,11 @@ function initListeners(): void {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
function createIndicatorStr(task: TaskCopy): string {
|
||||
function createIndicatorMessage(
|
||||
task: TaskCopy,
|
||||
isPomodoroEnabled: boolean,
|
||||
currentPomodoroSessionTime: number,
|
||||
): string {
|
||||
if (task && task.title) {
|
||||
let title = task.title;
|
||||
let timeStr = '';
|
||||
|
|
@ -126,6 +139,10 @@ function createIndicatorStr(task: TaskCopy): string {
|
|||
timeStr = getCountdownMessage(task.timeSpent);
|
||||
}
|
||||
|
||||
if (isPomodoroEnabled) {
|
||||
timeStr = getCountdownMessage(currentPomodoroSessionTime);
|
||||
}
|
||||
|
||||
return `${title} ${timeStr}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ const ea: ElectronAPI = {
|
|||
|
||||
backupAppData: (appData) => _send('BACKUP', appData),
|
||||
|
||||
updateCurrentTask: (task) => _send('CURRENT_TASK_UPDATED', task),
|
||||
updateCurrentTask: (task, isPomodoroEnabled, currentPomodoroSessionTime) =>
|
||||
_send('CURRENT_TASK_UPDATED', task, isPomodoroEnabled, currentPomodoroSessionTime),
|
||||
|
||||
exec: (command: string) => _send('EXEC', command),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { selectCurrentTask } from './task.selectors';
|
|||
import { IS_ELECTRON } from '../../../app.constants';
|
||||
import { GlobalConfigService } from '../../config/global-config.service';
|
||||
import { selectIsFocusOverlayShown } from '../../focus-mode/store/focus-mode.selectors';
|
||||
import { PomodoroService } from '../../pomodoro/pomodoro.service';
|
||||
|
||||
// TODO send message to electron when current task changes here
|
||||
|
||||
|
|
@ -15,15 +16,24 @@ export class TaskElectronEffects {
|
|||
private _actions$ = inject(Actions);
|
||||
private _store$ = inject<Store<any>>(Store);
|
||||
private _configService = inject(GlobalConfigService);
|
||||
private _pomodoroService = inject(PomodoroService);
|
||||
|
||||
taskChangeElectron$: any = createEffect(
|
||||
() =>
|
||||
this._actions$.pipe(
|
||||
ofType(setCurrentTask, unsetCurrentTask, addTimeSpent),
|
||||
withLatestFrom(this._store$.pipe(select(selectCurrentTask))),
|
||||
tap(([action, current]) => {
|
||||
withLatestFrom(
|
||||
this._store$.pipe(select(selectCurrentTask)),
|
||||
this._pomodoroService.isEnabled$,
|
||||
this._pomodoroService.currentSessionTime$,
|
||||
),
|
||||
tap(([action, current, isPomodoroEnabled, currentPomodoroSessionTime]) => {
|
||||
if (IS_ELECTRON) {
|
||||
window.ea.updateCurrentTask(current);
|
||||
window.ea.updateCurrentTask(
|
||||
current,
|
||||
isPomodoroEnabled,
|
||||
currentPomodoroSessionTime,
|
||||
);
|
||||
}
|
||||
}),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue