Skip to content

Commit 97aadd4

Browse files
committed
Merge branch 'release/0.2.0'
2 parents 3b1ab47 + f473c02 commit 97aadd4

File tree

8 files changed

+209
-118
lines changed

8 files changed

+209
-118
lines changed

app/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ <h2 class="subtitle">
5252
</p>
5353

5454
<div class="box" v-if="orderedTasks.length">
55-
<task v-for="task in orderedTasks" :task-id="task.id" :key="task.id"></task>
55+
<task v-for="task in orderedTasks"
56+
:task-id="task.id"
57+
:key="task.id"
58+
@timerStarted="handleTimerStarted"
59+
@timerStopped="handleTimerStopped"></task>
5660
</div>
57-
58-
<!--<div class="box">-->
59-
<!--<task v-for="task in orderedTasks" :task-id="task.id" :key="task.id"></task>-->
60-
<!--</div>-->
6161
</div>
6262
</div>
6363

app/js/app.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Vue = require('vue/dist/vue');
22
const _ = require('lodash');
3+
const moment = require('moment');
4+
const {powerSaveBlocker} = require('electron');
35

46
Vue.filter('pad', require('./filters/pad'));
57
Vue.filter('seconds', require('./filters/seconds'));
@@ -15,7 +17,7 @@ new Vue({
1517

1618
computed: {
1719
orderedTasks() {
18-
return _.orderBy(this.tasks, 'id', 'desc');
20+
return _.orderBy(this.tasks, ['completed', 'timer.active'], ['asc', 'desc']);
1921
}
2022
},
2123

@@ -44,6 +46,7 @@ new Vue({
4446
id: (this.tasks.length + 1),
4547
name: this.taskName,
4648
completed: false,
49+
created_at: moment().format(this.dateFormat),
4750

4851
timer: {
4952
seconds: 0,
@@ -53,6 +56,29 @@ new Vue({
5356
});
5457

5558
this.taskName = '';
56-
}
59+
},
60+
61+
/**
62+
* Enable power save blocker if it is not already enabled
63+
*/
64+
handleTimerStarted() {
65+
if (this.powerSaveBlockerId === null) {
66+
this.powerSaveBlockerId = powerSaveBlocker.start('prevent-app-suspension');
67+
}
68+
},
69+
70+
handleTimerStopped() {
71+
// Do we have any running tasks?
72+
let activeTasks = this.tasks.filter(function (task) {
73+
return task.timer.active === true;
74+
});
75+
76+
// If we do not have any active tasks, enable power save
77+
if (activeTasks.length === 0) {
78+
powerSaveBlocker.stop(this.powerSaveBlockerId);
79+
80+
this.powerSaveBlockerId = null;
81+
}
82+
},
5783
}
5884
});

app/js/components/task/task.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="notification" :class="{ 'is-success' : task.completed }">
1+
<div class="notification" :class="{ 'is-success' : task.completed, 'is-info' : task.timer.active }">
22
<div class="columns is-mobile is-gapless">
33
<div class="column is-half">
44
<span>
@@ -9,12 +9,6 @@
99
{{ task.timer.seconds | hours | pad }} :
1010
{{ task.timer.seconds | minutes | pad }} :
1111
{{ task.timer.seconds | seconds | pad }}
12-
13-
14-
15-
<!--<span v-show="task.timer.seconds >= 3600">{{ task.timer.seconds | hours | pad }}h</span>-->
16-
<!--<span v-show="task.timer.seconds >= 60">{{ task.timer.seconds | minutes | pad }}m</span>-->
17-
<!--<span>{{ task.timer.seconds | seconds | pad }}s</span>-->
1812
</div>
1913
<div class="column">
2014
<a @click="startTimer()" v-show="!task.timer.active && !task.completed">

app/js/components/task/task.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ module.exports = {
4747
this.task.timer.instance = window.setInterval(() => {
4848
this.task.timer.seconds += 1;
4949
}, 1000);
50+
51+
// Tell our parent that we started a timer in order to block power save
52+
this.$emit('timerStarted');
5053
},
5154

5255
stopTimer() {
5356
this.task.timer.active = false;
5457

5558
window.clearInterval(this.task.timer.instance);
59+
60+
// Tell our parent that we stopped a timer in order to check if we can disable power save blocker
61+
this.$emit('timerStopped');
5662
},
5763

5864
completeTask() {

app/js/store.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
title: 'Simple CSV reader',
2+
title: 'Task Timer',
33

44
// Used for creating tasks
55
taskName: '',
@@ -8,6 +8,11 @@ module.exports = {
88
path: null
99
},
1010

11+
dateFormat: 'YYYY-MM-DD HH:mm:ss',
12+
13+
// Id used for the power save blocker feature of electron
14+
powerSaveBlockerId: null,
15+
1116
tasks: [
1217
// {
1318
// id: 1,

main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ app.on('ready', createWindow);
1717
app.on('window-all-closed', function () {
1818
// On OS X it is common for applications and their menu bar
1919
// to stay active until the user quits explicitly with Cmd + Q
20-
if (process.platform !== 'darwin') {
21-
app.quit();
22-
}
20+
app.quit();
2321
});
2422

2523
app.on('activate', function () {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "task-timer-electron",
3-
"version": "0.1.0",
3+
"productName": "Task Timer",
4+
"version": "0.2.0",
45
"description": "A simple app that keeps track of the time used on different tasks",
56
"license": "MIT",
67
"main": "main.js",
78
"scripts": {
89
"start": "electron .",
9-
"package": "node_modules/.bin/electron-packager . Task Timer --out=dist/osx --platform=darwin --arch=x64 --overwrite --icon=clipboard.icns"
10+
"package-mac": "node_modules/.bin/electron-packager . 'Task Timer' --out=dist/osx --platform=darwin --arch=x64 --overwrite --icon=clipboard.icns --prune=true"
1011
},
1112
"author": {
1213
"name": "Runar Jørgensen",
@@ -18,6 +19,7 @@
1819
"electron": "^1.4.1",
1920
"electron-packager": "^8.2.0",
2021
"lodash": "^4.16.6",
22+
"moment": "^2.17.1",
2123
"vue": "^2.0.3"
2224
}
2325
}

0 commit comments

Comments
 (0)