Skip to content

Commit

Permalink
feat(tray): also update for pomodoro #241
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Nov 7, 2020
1 parent e58a657 commit 8734114
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions electron/indicator.ts
Expand Up @@ -7,7 +7,6 @@ import { getWin } from './main-window';
let tray;
let isIndicatorRunning = false;
let DIR: string;
let isTrayShowCurrentTask: boolean;

const isGnomeShellExtensionRunning = false;

Expand Down Expand Up @@ -58,55 +57,54 @@ function initAppListeners(app) {
}

function initListeners() {
ipcMain.on(IPC.SET_PROGRESS_BAR, (ev, {progress}) => {
const suf = nativeTheme.shouldUseDarkColors
? '-d'
: '-l';
if (typeof progress === 'number' && progress > 0 && isFinite(progress)) {
const f = Math.min(Math.round(progress * 15), 15);
const t = DIR + `running-anim${suf}/${f || 0}.png`;
tray.setImage(t);
} else {
const t = DIR + `running${suf}.png`;
tray.setImage(t);
}
});

ipcMain.on(IPC.CURRENT_TASK_UPDATED, (ev, params) => {
const currentTask = params.current;
// const lastActiveTaskTask = params.lastActiveTask;

const mainWin = getWin();
getSettings(mainWin, (settings) => {
isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;
});
const isTrayShowCurrentTask = settings.misc.isTrayShowCurrentTask;

let msg = '';
if (isTrayShowCurrentTask && currentTask) {
msg = createIndicatorStr(currentTask);
}
let msg = '';
if (isTrayShowCurrentTask && currentTask) {
msg = createIndicatorStr(currentTask);
}

if (tray) {
// tray handling
if (currentTask && currentTask.title) {
const suf = nativeTheme.shouldUseDarkColors
? '-d'
: '-l';
tray.setTitle(msg);
if (typeof currentTask.timeEstimate === 'number' && currentTask.timeEstimate > 0) {
const progress = currentTask.timeSpent / currentTask.timeEstimate;
const f = Math.min(Math.round(progress * 15), 15);
const t = DIR + `running-anim${suf}/${f || 0}.png`;
tray.setImage(t);
if (tray) {
// tray handling
if (currentTask && currentTask.title) {
tray.setTitle(msg);
} else {
const t = DIR + `running${suf}.png`;
tray.setImage(t);
tray.setTitle('');
const suf = nativeTheme.shouldUseDarkColors
? '-d.png'
: '-l.png';
tray.setImage(DIR + `stopped${suf}`);
}
} else {
tray.setTitle('');
const suf = nativeTheme.shouldUseDarkColors
? '-d.png'
: '-l.png';
tray.setImage(DIR + `stopped${suf}`);
}
}
});
});

ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => {
// const isOnBreak = params.isOnBreak;
// const currentSessionTime = params.currentSessionTime;
// const currentSessionInitialTime = params.currentSessionInitialTime;

// if (isGnomeShellExtInstalled) {
// dbus.updatePomodoro(isOnBreak, currentSessionTime, currentSessionInitialTime);
// }
});
// ipcMain.on(IPC.POMODORO_UPDATE, (ev, params) => {
// const isOnBreak = params.isOnBreak;
// const currentSessionTime = params.currentSessionTime;
// const currentSessionInitialTime = params.currentSessionInitialTime;
// if (isGnomeShellExtInstalled) {
// dbus.updatePomodoro(isOnBreak, currentSessionTime, currentSessionInitialTime);
// }
// });
}

function createIndicatorStr(task) {
Expand Down

0 comments on commit 8734114

Please sign in to comment.