Skip to content

Commit

Permalink
Added auto update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
PatentLobster committed Jun 13, 2020
1 parent d381120 commit 7bfc885
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://itzik.co"
},
"description": "Track your office hours.",
"version": "0.1.3",
"version": "0.1.4",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand All @@ -22,6 +22,7 @@
"axios": "^0.19.2",
"brace": "^0.11.1",
"core-js": "^3.6.5",
"electron-updater": "^4.3.1",
"moment": "^2.26.0",
"nedb": "^1.8.0",
"sass": "^1.26.8",
Expand Down
34 changes: 21 additions & 13 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict';
/* global __static */
import {app, protocol, BrowserWindow, powerMonitor, Tray, Menu, Notification} from 'electron'
import {app, protocol, BrowserWindow, powerMonitor, Tray, Menu, Notification} from 'electron';
import {autoUpdater} from 'electron-updater';

const axios = require('axios');


// App logic
import db from "@/datastore";
import moment from "moment";
import path from "path";

const globalAny = global;
globalAny.db = db;
db.ensureIndex({fieldName: 'date', unique: true}, function (err) {
Expand Down Expand Up @@ -56,13 +59,13 @@ function greet() {
axios.get("https://favqs.com/api/qotd").then((response) => {
const quotes = response.data.quote.body;
const author = response.data.quote.author;
const arr = {'title': author, 'body': quotes, 'icon': path.join(__static,"/icon.png")};
const arr = {'title': author, 'body': quotes, 'icon': path.join(__static, "/icon.png")};
console.log(arr);
return arr;
}).then((arr) => callNotification(arr) );
}).then((arr) => callNotification(arr));
}

function callNotification(notif){
function callNotification(notif) {
new Notification(notif).show();
}

Expand All @@ -81,16 +84,20 @@ let win;
let tray;

const createTray = () => {
tray = new Tray(path.join(__static,"/icon.png"));
tray = new Tray(path.join(__static, "/icon.png"));
const contextMenu = Menu.buildFromTemplate([
{ label: "Open Developer tools", click() {
if( win !== null || win !== undefined) {
{
label: "Open Developer tools", click() {
if (win === null || win !== undefined) {
win.webContents.openDevTools();
}
}},
{ label: 'Exit', click() {
}
},
{
label: 'Exit', click() {
app.quit()
}}
}
}
]);
tray.setToolTip("Vork is running");
tray.setContextMenu(contextMenu);
Expand All @@ -100,7 +107,7 @@ const createTray = () => {
};

const toggleWindow = () => {
if(win === null){
if (win === null) {
createWindow()
} else {
if (win.isVisible()) {
Expand All @@ -124,7 +131,7 @@ const showWindow = () => {
const getWindowPosition = () => {
const windowBounds = win.getBounds();
const trayBounds = tray.getBounds();
const x = Math.round(trayBounds.x - (windowBounds.width / 2.333));
const x = Math.round(trayBounds.x - (windowBounds.width / 2.333));
const y = trayBounds.y - windowBounds.height + 5;
return {x: x, y: y}
};
Expand Down Expand Up @@ -160,7 +167,8 @@ function createWindow() {
} else {
createProtocol('app');
// Load the index.html when not in development
win.loadURL('app://./index.html')
win.loadURL('app://./index.html');
autoUpdater.checkForUpdatesAndNotify();
}

win.on('closed', () => {
Expand Down
1 change: 1 addition & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
externals: ['nedb'],
nodeIntegration: true,
enableRemoteModule: true,
publish: ['github']
}
}
}

0 comments on commit 7bfc885

Please sign in to comment.