Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ventrec committed Feb 19, 2017
2 parents 3b1ab47 + f473c02 commit 97aadd4
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 118 deletions.
10 changes: 5 additions & 5 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ <h2 class="subtitle">
</p>

<div class="box" v-if="orderedTasks.length">
<task v-for="task in orderedTasks" :task-id="task.id" :key="task.id"></task>
<task v-for="task in orderedTasks"
:task-id="task.id"
:key="task.id"
@timerStarted="handleTimerStarted"
@timerStopped="handleTimerStopped"></task>
</div>

<!--<div class="box">-->
<!--<task v-for="task in orderedTasks" :task-id="task.id" :key="task.id"></task>-->
<!--</div>-->
</div>
</div>

Expand Down
30 changes: 28 additions & 2 deletions app/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Vue = require('vue/dist/vue');
const _ = require('lodash');
const moment = require('moment');
const {powerSaveBlocker} = require('electron');

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

computed: {
orderedTasks() {
return _.orderBy(this.tasks, 'id', 'desc');
return _.orderBy(this.tasks, ['completed', 'timer.active'], ['asc', 'desc']);
}
},

Expand Down Expand Up @@ -44,6 +46,7 @@ new Vue({
id: (this.tasks.length + 1),
name: this.taskName,
completed: false,
created_at: moment().format(this.dateFormat),

timer: {
seconds: 0,
Expand All @@ -53,6 +56,29 @@ new Vue({
});

this.taskName = '';
}
},

/**
* Enable power save blocker if it is not already enabled
*/
handleTimerStarted() {
if (this.powerSaveBlockerId === null) {
this.powerSaveBlockerId = powerSaveBlocker.start('prevent-app-suspension');
}
},

handleTimerStopped() {
// Do we have any running tasks?
let activeTasks = this.tasks.filter(function (task) {
return task.timer.active === true;
});

// If we do not have any active tasks, enable power save
if (activeTasks.length === 0) {
powerSaveBlocker.stop(this.powerSaveBlockerId);

this.powerSaveBlockerId = null;
}
},
}
});
8 changes: 1 addition & 7 deletions app/js/components/task/task.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="notification" :class="{ 'is-success' : task.completed }">
<div class="notification" :class="{ 'is-success' : task.completed, 'is-info' : task.timer.active }">
<div class="columns is-mobile is-gapless">
<div class="column is-half">
<span>
Expand All @@ -9,12 +9,6 @@
{{ task.timer.seconds | hours | pad }} :
{{ task.timer.seconds | minutes | pad }} :
{{ task.timer.seconds | seconds | pad }}



<!--<span v-show="task.timer.seconds >= 3600">{{ task.timer.seconds | hours | pad }}h</span>-->
<!--<span v-show="task.timer.seconds >= 60">{{ task.timer.seconds | minutes | pad }}m</span>-->
<!--<span>{{ task.timer.seconds | seconds | pad }}s</span>-->
</div>
<div class="column">
<a @click="startTimer()" v-show="!task.timer.active && !task.completed">
Expand Down
6 changes: 6 additions & 0 deletions app/js/components/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ module.exports = {
this.task.timer.instance = window.setInterval(() => {
this.task.timer.seconds += 1;
}, 1000);

// Tell our parent that we started a timer in order to block power save
this.$emit('timerStarted');
},

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

window.clearInterval(this.task.timer.instance);

// Tell our parent that we stopped a timer in order to check if we can disable power save blocker
this.$emit('timerStopped');
},

completeTask() {
Expand Down
7 changes: 6 additions & 1 deletion app/js/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
title: 'Simple CSV reader',
title: 'Task Timer',

// Used for creating tasks
taskName: '',
Expand All @@ -8,6 +8,11 @@ module.exports = {
path: null
},

dateFormat: 'YYYY-MM-DD HH:mm:ss',

// Id used for the power save blocker feature of electron
powerSaveBlockerId: null,

tasks: [
// {
// id: 1,
Expand Down
4 changes: 1 addition & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ app.on('ready', createWindow);
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
app.quit();
});

app.on('activate', function () {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "task-timer-electron",
"version": "0.1.0",
"productName": "Task Timer",
"version": "0.2.0",
"description": "A simple app that keeps track of the time used on different tasks",
"license": "MIT",
"main": "main.js",
"scripts": {
"start": "electron .",
"package": "node_modules/.bin/electron-packager . Task Timer --out=dist/osx --platform=darwin --arch=x64 --overwrite --icon=clipboard.icns"
"package-mac": "node_modules/.bin/electron-packager . 'Task Timer' --out=dist/osx --platform=darwin --arch=x64 --overwrite --icon=clipboard.icns --prune=true"
},
"author": {
"name": "Runar Jørgensen",
Expand All @@ -18,6 +19,7 @@
"electron": "^1.4.1",
"electron-packager": "^8.2.0",
"lodash": "^4.16.6",
"moment": "^2.17.1",
"vue": "^2.0.3"
}
}
Loading

0 comments on commit 97aadd4

Please sign in to comment.