Skip to content

Commit

Permalink
add auto update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
drecodeam committed Jul 26, 2018
1 parent d1227d2 commit 79232a3
Show file tree
Hide file tree
Showing 12 changed files with 9,158 additions and 83 deletions.
38 changes: 22 additions & 16 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
"directories": {
"output": "app-builds"
},
"files": [
"**/*",
"!*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!.angular-cli.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"files": [
"**/*",
"!*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!.angular-cli.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"publish" : {
"provider": "github",
"releaseType" : "draft",
"vPrefixedTagName": true,
"publishAutoUpdate": true
},
"win": {
"icon": "dist",
"target": [
Expand Down
109 changes: 58 additions & 51 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,80 @@
import { app, BrowserWindow, screen } from 'electron';
import {app, BrowserWindow, screen} from 'electron';
import * as path from 'path';
import * as url from 'url';
import {autoUpdater} from 'electron-updater';


let win, serve;
const args = process.argv.slice(1);
serve = args.some(val => val === '--serve');

function createWindow() {

const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;

// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: 400,
height: 800,
titleBarStyle: 'hidden'
});
// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: 400,
height: 800,
titleBarStyle: 'hidden'
});

if (serve) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)});
win.loadURL('http://localhost:4200');
} else {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
}
if (serve) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)
});
win.loadURL('http://localhost:4200');
} else {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
}

// win.webContents.openDevTools();
// win.webContents.openDevTools();

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}

try {

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// 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();
}
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// 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.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
const log = require("electron-log");
log.transports.file.level = "debug";
autoUpdater.logger = log;
autoUpdater.checkForUpdatesAndNotify();
});

} catch (e) {
// Catch Error
// throw e;
// Catch Error
// throw e;
}
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "Stors",
"version": "0.1.1",
"version": "0.1.2",
"description": "A simple task manager for a day",
"homepage": "https://insert.black",
"repository": "https://github.com/drecodeam/stors",
"browser": {
"child_process": false
},
"author": {
"name": "Drecode Feil",
"email": "[email protected]"
Expand All @@ -24,14 +27,21 @@
"electron:local": "npm run build:prod && electron .",
"electron:linux": "npm run build:prod && npx electron-builder build --linux",
"electron:windows": "npm run build:prod && npx electron-builder build --windows",
"electron:mac": "npm run build:prod && npx electron-builder build --mac ",
"electron:mac": "npm run build:prod && npx electron-builder build --mac --p",
"release:mac": "npm run build:prod && npx electron-builder build --mac --p always",
"test": "ng test",
"e2e": "ng e2e"
},
"dependencies": {
"analytics-node": "^3.3.0",
"auto-launch": "^5.0.5",
"electron-updater": "^2.23.3"
"buffer": "^5.1.0",
"electron-log": "^2.2.16",
"electron-updater": "^3.0.3",
"events": "^3.0.0",
"raven-js": "^3.26.4",
"stream": "0.0.2",
"timers": "^0.1.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.6.3",
Expand All @@ -48,13 +58,14 @@
"@angular/router": "6.0.3",
"@ngx-translate/core": "10.0.1",
"@ngx-translate/http-loader": "3.0.1",
"@types/es6-collections": "^0.5.31",
"@types/jasmine": "2.8.7",
"@types/jasminewd2": "2.0.3",
"@types/node": "8.9.4",
"airtable": "^0.5.6",
"codelyzer": "4.2.1",
"core-js": "2.5.6",
"electron": "2.0.2",
"electron": "^2.0.2",
"electron-builder": "20.14.7",
"electron-reload": "1.2.2",
"jasmine-core": "3.1.0",
Expand Down
7 changes: 5 additions & 2 deletions src/app/components/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="draggable-region"></div>
<div class="container">
<div class="title">Today</div>
<div class="total-time">
<div class="total-time" *ngIf="!!status.showTime">
<span class="hrs">{{totalHrs}}h </span> <span class="mins"> {{totalMins}}m |</span>
<div class="eta">{{eta}}</div>
</div>
<div class="task-list">
<div class="task-list" *ngIf="!status.showEmptyState">
<div class="task-list-item"
*ngFor="let item of data.list"
[id]="item.id"
Expand All @@ -28,6 +28,9 @@
<div class="item-progress-bar" [style.width.%]="item.progress"></div>
</div>
</div>
<div class="empty-state" *ngIf="!!status.showEmptyState">
showing an empty state
</div>
<input type="text" class="add-task" [ngModel]="addTaskInput" (keyup.enter)="addTask(todo.value)" placeholder="+ Add a new task" #todo>
</div>
<div class="help drift-open-chat">👋 Feedback</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/home/home.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $maya-blye : #72BFF9;
color: #666;
caret-color: red;
}

.task-list {
position: relative;
overflow: hidden;
Expand Down Expand Up @@ -183,6 +184,7 @@ $maya-blye : #72BFF9;
}
}
}

.add-task {
background: transparent;
padding: 1rem;
Expand Down Expand Up @@ -211,12 +213,14 @@ $maya-blye : #72BFF9;
background: $mirage;
}
}

.clear-tasks {
color: white;
text-align: center;
margin-top: 2rem
;
}

.onboarding {
overflow: hidden;
background: $magenta;
Expand Down
25 changes: 22 additions & 3 deletions src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ElectronService } from '../../providers/electron.service';


@Component({
selector: 'app-home',
templateUrl: './home.component.html',
Expand All @@ -12,7 +13,6 @@ export class HomeComponent implements OnInit {
private electronService: ElectronService
) {}


filePath = this.electronService.remote.app.getPath('appData') + '/list.json';
data;
fs = this.electronService.fs;
Expand All @@ -25,6 +25,11 @@ export class HomeComponent implements OnInit {
totalHrs;
totalMins;
eta: any;
status = {
showOnboarding: false,
showTime: false,
showEmptyState: false
};
hideOnboarding = false;
showOnboarding = false;

Expand Down Expand Up @@ -121,9 +126,18 @@ export class HomeComponent implements OnInit {
* Sync data onto the file
*/
updateData() {
if ( this.data.list.length <= 0 ) {
this.status.showEmptyState = true;
} else {
this.status.showEmptyState = false;
}
this.fs.writeFileSync(this.filePath, JSON.stringify(this.data));
}

/**
*
* @param date
*/
formatAMPM(date) {
let hours = date.getHours();
let minutes = date.getMinutes();
Expand All @@ -141,13 +155,13 @@ export class HomeComponent implements OnInit {
markItemComplete( task ) {
task.isTicked = true;
this.totalTime = this.totalTime - ( task.time - task.elapsed );
this.currentTaskID = 0;
this.currentTaskID = 0;
this.updateEta();
this.updateData();
}

/**
* Mark the item as complete
* Mark the item as complsete
* @param task
*/
deleteItem( task ) {
Expand All @@ -168,6 +182,11 @@ export class HomeComponent implements OnInit {
*/
updateEta() {
const time = this.totalTime;
if ( this.totalTime > 0 ) {
this.status.showTime = true;
} else {
this.status.showTime = false;
}
this.totalHrs = Math.floor( this.totalTime/60 );
this.totalMins = this.totalTime % 60;
const date = new Date( new Date().getTime() + time * 60000 );
Expand Down
4 changes: 2 additions & 2 deletions src/environments/environment.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const AppConfig = {
production: false,
environment: 'DEV'
production: false,
environment: 'DEV'
};
4 changes: 2 additions & 2 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const AppConfig = {
production: true,
environment: 'PROD'
production: true,
environment: 'PROD'
};
4 changes: 2 additions & 2 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const AppConfig = {
production: false,
environment: 'LOCAL'
production: false,
environment: 'LOCAL'
};
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { AppConfig } from './environments/environment';


if (AppConfig.production) {
enableProdMode();
}
Expand Down
Loading

0 comments on commit 79232a3

Please sign in to comment.