From 053100b92d2a0490decd7fcb4dc12f7a2977c1e2 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 9 Jan 2018 18:11:43 +0100 Subject: [PATCH] refactor: cleanup lastCurrentTask and refactor it to one instance of lastActiveTask --- app-src/scripts/constants.js | 2 +- .../scripts/dialogs/was-idle/was-idle-c.js | 2 +- app-src/scripts/main-header/main-header-d.js | 2 +- .../scripts/main/global-services/tasks-s.js | 41 ++++++++++--------- .../main/global-services/time-tracking-s.js | 2 +- .../pomodoro-button/pomodoro-button-s.js | 4 +- electron/indicator.js | 29 ++++++++----- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/app-src/scripts/constants.js b/app-src/scripts/constants.js index 456fdae2c0..b8ee7051f6 100644 --- a/app-src/scripts/constants.js +++ b/app-src/scripts/constants.js @@ -60,7 +60,7 @@ tomorrowsNote: undefined, theme: undefined, currentTask: undefined, - lastCurrentTask: undefined, + lastActiveTaskTask: undefined, currentProject: undefined, currentSession: { timeWorkedWithoutBreak: undefined, diff --git a/app-src/scripts/dialogs/was-idle/was-idle-c.js b/app-src/scripts/dialogs/was-idle/was-idle-c.js index 2bb6f978ed..28020e790c 100644 --- a/app-src/scripts/dialogs/was-idle/was-idle-c.js +++ b/app-src/scripts/dialogs/was-idle/was-idle-c.js @@ -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) { diff --git a/app-src/scripts/main-header/main-header-d.js b/app-src/scripts/main-header/main-header-d.js index 94f61c0092..b341ef3fb8 100644 --- a/app-src/scripts/main-header/main-header-d.js +++ b/app-src/scripts/main-header/main-header-d.js @@ -27,7 +27,7 @@ /* @ngInject */ function MainHeaderCtrl(Dialogs, Projects) { let vm = this; - vm.lastCurrentTask = undefined; + vm.lastActiveTaskTask = undefined; vm.allProjects = Projects.getList(); diff --git a/app-src/scripts/main/global-services/tasks-s.js b/app-src/scripts/main/global-services/tasks-s.js index 44005b44b1..38c07c34b9 100644 --- a/app-src/scripts/main/global-services/tasks-s.js +++ b/app-src/scripts/main/global-services/tasks-s.js @@ -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, () => { @@ -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 @@ -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) { @@ -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 }); } @@ -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) diff --git a/app-src/scripts/main/global-services/time-tracking-s.js b/app-src/scripts/main/global-services/time-tracking-s.js index 46dd51bbc2..6b9162d5c4 100644 --- a/app-src/scripts/main/global-services/time-tracking-s.js +++ b/app-src/scripts/main/global-services/time-tracking-s.js @@ -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) { diff --git a/app-src/scripts/pomodoro-button/pomodoro-button-s.js b/app-src/scripts/pomodoro-button/pomodoro-button-s.js index 3048fa17cf..b5ca1a53cd 100644 --- a/app-src/scripts/pomodoro-button/pomodoro-button-s.js +++ b/app-src/scripts/pomodoro-button/pomodoro-button-s.js @@ -101,7 +101,7 @@ play() { // select task if none selected - this.Tasks.selectLastTaskOrOpenDialog() + this.Tasks.startLastTaskOrOpenDialog() .then(() => { this.start(); @@ -165,7 +165,7 @@ } } else { this.data.currentCycle++; - this.selectTask() + this.Tasks.startLastTaskOrOpenDialog() .then((task) => { this.Notifier({ title: 'Pomodoro session #' + this.data.currentCycle + ' started', diff --git a/electron/indicator.js b/electron/indicator.js index 5c8da9ed7e..90ec80b6f4 100644 --- a/electron/indicator.js +++ b/electron/indicator.js @@ -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(''); + } } }); }