Skip to content

Commit

Permalink
refactor: cleanup lastCurrentTask and refactor it to one instance of …
Browse files Browse the repository at this point in the history
…lastActiveTask
  • Loading branch information
johannesjo committed Jan 9, 2018
1 parent 914149d commit 053100b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app-src/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
tomorrowsNote: undefined,
theme: undefined,
currentTask: undefined,
lastCurrentTask: undefined,
lastActiveTaskTask: undefined,
currentProject: undefined,
currentSession: {
timeWorkedWithoutBreak: undefined,
Expand Down
2 changes: 1 addition & 1 deletion app-src/scripts/dialogs/was-idle/was-idle-c.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
vm.idleTime = $window.moment.duration(realIdleTime, 'milliseconds').format('hh:mm:ss');

vm.undoneTasks = Tasks.getUndoneToday(true);
vm.selectedTask = $rootScope.r.currentTask || $rootScope.r.lastCurrentTask || undefined;
vm.selectedTask = $rootScope.r.currentTask || $rootScope.r.lastActiveTaskTask || undefined;

vm.trackIdleToTask = () => {
if (vm.selectedTask) {
Expand Down
2 changes: 1 addition & 1 deletion app-src/scripts/main-header/main-header-d.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* @ngInject */
function MainHeaderCtrl(Dialogs, Projects) {
let vm = this;
vm.lastCurrentTask = undefined;
vm.lastActiveTaskTask = undefined;

vm.allProjects = Projects.getList();

Expand Down
41 changes: 22 additions & 19 deletions app-src/scripts/main/global-services/tasks-s.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@

// handlers for dbus events
window.ipcRenderer.on(IPC_EVENT_TASK_MARK_AS_DONE, () => {
const lastActiveTask = this.getLastActiveIfStartable();

if (that.$rootScope.r.currentTask) {
that.markAsDone(that.$rootScope.r.currentTask);
that.$rootScope.$apply();
} else if (that.lastCurrentTask) {
that.markAsDone(that.lastCurrentTask);
} else if (lastActiveTask) {
that.markAsDone(lastActiveTask);
that.$rootScope.$apply();
}
});
window.ipcRenderer.on(IPC_EVENT_TASK_START, () => {
if (!that.$rootScope.r.currentTask && that.lastCurrentTask) {
that.updateCurrent(that.lastCurrentTask);
const lastActiveTask = this.getLastActiveIfStartable();

if (!that.$rootScope.r.currentTask && lastActiveTask) {
that.updateCurrent(lastActiveTask);
that.$rootScope.$apply();
} else {

that.startLastTaskOrOpenDialog();
}
});
window.ipcRenderer.on(IPC_EVENT_TASK_PAUSE, () => {
Expand Down Expand Up @@ -107,20 +111,20 @@
}

getLastCurrent() {
return this.$rootScope.r.lastCurrentTask;
return this.$rootScope.r.lastActiveTaskTask;
}

getLastCurrentIfInTodaysList() {
const lastCurrent = this.$rootScope.r.lastCurrentTask;
if (this.isInTodaysList(lastCurrent)) {
return lastCurrent;
getLastActiveIfStartable() {
const lastActiveTask = this.$rootScope.r.lastActiveTaskTask;
if (this.isInTodaysList(lastActiveTask) && !lastActiveTask.isDone) {
return lastActiveTask;
} else {
return undefined;
}
}

setLastCurrent(task) {
this.$rootScope.r.lastCurrentTask = task;
this.$rootScope.r.lastActiveTaskTask = task;
}

// NOTE: doneBacklogTasks can't be really updated when accessed with this
Expand Down Expand Up @@ -368,7 +372,6 @@
updateCurrent(task, isCallFromTimeTracking) {
const isCurrentTaskChanged = this.TasksUtil.isTaskChanged(task, this.$rootScope.r.currentTask);
const that = this;
this.lastCurrentTask = this.$rootScope.r.currentTask;

function moveInProgress(task) {
if (isCurrentTaskChanged) {
Expand Down Expand Up @@ -420,14 +423,14 @@

// also save a reference to this task
if (task) {
this.$rootScope.r.lastCurrentTask = task;
this.$rootScope.r.lastActiveTaskTask = task;
}
}

if (this.IS_ELECTRON) {
window.ipcRenderer.send(IPC_EVENT_CURRENT_TASK_UPDATED, {
current: task,
lastCurrent: this.lastCurrentTask
lastActiveTask: this.$rootScope.r.lastActiveTaskTask
});
}

Expand Down Expand Up @@ -663,15 +666,15 @@
this.updateCurrent(undefined);
}

selectLastTaskOrOpenDialog() {
startLastTaskOrOpenDialog() {
const defer = this.$q.defer();

if (!this.getCurrent()) {
const lastCurrentTask = this.getLastCurrentIfInTodaysList();
const lastActiveTaskTask = this.getLastActiveIfStartable();

if (lastCurrentTask) {
this.updateCurrent(lastCurrentTask);
defer.resolve(lastCurrentTask);
if (lastActiveTaskTask) {
this.updateCurrent(lastActiveTaskTask);
defer.resolve(lastActiveTaskTask);
} else {
this.Dialogs('TASK_SELECTION')
.then(defer.resolve)
Expand Down
2 changes: 1 addition & 1 deletion app-src/scripts/main/global-services/time-tracking-s.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// update indicator
window.ipcRenderer.send(IPC_EVENT_CURRENT_TASK_UPDATED, {
current: this.$rootScope.r.currentTask,
lastCurrent: this.Tasks.lastCurrentTask
lastActiveTask: this.Tasks.getLastActiveIfStartable()
});

if (!this.isIdle) {
Expand Down
4 changes: 2 additions & 2 deletions app-src/scripts/pomodoro-button/pomodoro-button-s.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

play() {
// select task if none selected
this.Tasks.selectLastTaskOrOpenDialog()
this.Tasks.startLastTaskOrOpenDialog()
.then(() => {
this.start();

Expand Down Expand Up @@ -165,7 +165,7 @@
}
} else {
this.data.currentCycle++;
this.selectTask()
this.Tasks.startLastTaskOrOpenDialog()
.then((task) => {
this.Notifier({
title: 'Pomodoro session #' + this.data.currentCycle + ' started',
Expand Down
29 changes: 18 additions & 11 deletions electron/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,31 @@ function initAppListeners(app) {
function initListeners(isGnomeShellExtInstalled) {
electron.ipcMain.on('CHANGED_CURRENT_TASK', (ev, params) => {
const currentTask = params.current;
const lastCurrentTask = params.lastCurrent;
const lastActiveTaskTask = params.lastActiveTask;

if (currentTask && currentTask.title) {
const msg = createIndicatorStr(currentTask);
let msg;

if (tray) {
tray.setTitle(msg);
}
if (isGnomeShellExtInstalled) {
if (currentTask) {
msg = createIndicatorStr(currentTask);
}

if (isGnomeShellExtInstalled) {
// gnome indicator handling
if (currentTask && currentTask.title) {
dbus.setTask(currentTask.id, msg);
}
} else if (isGnomeShellExtInstalled) {
if (!currentTask && lastCurrentTask && !lastCurrentTask.isDone) {
const msg = createIndicatorStr(lastCurrentTask);
} else if (!currentTask && lastActiveTaskTask && !lastActiveTaskTask.isDone) {
const msg = createIndicatorStr(lastActiveTaskTask);
dbus.setTask('PAUSED', msg);
} else {
dbus.setTask('NONE', 'NONE');
}
} else if (tray) {
// tray handling
if (currentTask && currentTask.title) {
tray.setTitle(msg);
} else {
tray.setTitle('');
}
}
});
}
Expand Down

0 comments on commit 053100b

Please sign in to comment.