Browse Source

Can save tasks in a database

master
Dashie der otter 6 months ago
parent
commit
ff8fafbe2b
Signed by: dashie <rhaamo@leloop.org> GPG Key ID: C2D57B325840B755
4 changed files with 600 additions and 42 deletions
  1. +2
    -0
      package.json
  2. +26
    -1
      src/background.js
  3. +9
    -5
      vue.config.js
  4. +563
    -36
      yarn.lock

+ 2
- 0
package.json View File

@@ -16,9 +16,11 @@
"bootstrap-vue": "^2.15.0",
"core-js": "^3.6.5",
"fork-awesome": "^1.1.7",
"knex": "^0.21.2",
"moment": "^2.27.0",
"sass": "^1.26.10",
"sass-loader": "^9.0.2",
"sqlite3": "^5.0.0",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"


+ 26
- 1
src/background.js View File

@@ -93,6 +93,26 @@ if (isDevelopment) {
}
}

/* Database handling */
const databasePath = path.join(app.getPath('userData'), 'tasks.sqlite');
let knex = require('knex')({
client: 'sqlite3',
connection: {
filename: databasePath,
},
useNullAsDefault: true
})

/* tasks table */
knex.schema.createTableIfNotExists('tasks', function (table) {
table.increments('id')
table.timestamp('started')
table.timestamp('ended')
table.integer('duration') // seconds
table.text('title') // what the task was
})
.then()

/* MAIN APP CODE */

let timerState = {
@@ -118,7 +138,12 @@ ipcMain.on('toggleTimer', (e, taskText ) => {

function insertTaskAndNotify (start, end, text) {
console.log("Task:", text, start, end);
// TODO: insert in BDD
knex.insert({
started: start,
ended: end,
duration: Math.floor((end - start) / 1000),
title: text
}).into('tasks').then()
win.webContents.send("taskAdded", start, end, text);
}



+ 9
- 5
vue.config.js View File

@@ -1,7 +1,11 @@
module.exports = {
pluginOptions: {
electronBuilder: {
preload: 'src/preload.js',
}
pluginOptions: {
electronBuilder: {
preload: 'src/preload.js',
builderOptions: {
extraResources: ['src/migrations/']
},
externals: ['knex', 'sqlite3']
}
}
}
}

+ 563
- 36
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save