Skip to content

Commit 79232a3

Browse files
committed
add auto update feature
1 parent d1227d2 commit 79232a3

12 files changed

+9158
-83
lines changed

electron-builder.json

+22-16
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
"directories": {
44
"output": "app-builds"
55
},
6-
"files": [
7-
"**/*",
8-
"!*.ts",
9-
"!*.code-workspace",
10-
"!LICENSE.md",
11-
"!package.json",
12-
"!package-lock.json",
13-
"!src/",
14-
"!e2e/",
15-
"!hooks/",
16-
"!.angular-cli.json",
17-
"!_config.yml",
18-
"!karma.conf.js",
19-
"!tsconfig.json",
20-
"!tslint.json"
21-
],
6+
"files": [
7+
"**/*",
8+
"!*.ts",
9+
"!*.code-workspace",
10+
"!LICENSE.md",
11+
"!package.json",
12+
"!package-lock.json",
13+
"!src/",
14+
"!e2e/",
15+
"!hooks/",
16+
"!.angular-cli.json",
17+
"!_config.yml",
18+
"!karma.conf.js",
19+
"!tsconfig.json",
20+
"!tslint.json"
21+
],
22+
"publish" : {
23+
"provider": "github",
24+
"releaseType" : "draft",
25+
"vPrefixedTagName": true,
26+
"publishAutoUpdate": true
27+
},
2228
"win": {
2329
"icon": "dist",
2430
"target": [

main.ts

+58-51
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,80 @@
1-
import { app, BrowserWindow, screen } from 'electron';
1+
import {app, BrowserWindow, screen} from 'electron';
22
import * as path from 'path';
33
import * as url from 'url';
4+
import {autoUpdater} from 'electron-updater';
5+
46

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

911
function createWindow() {
1012

11-
const electronScreen = screen;
12-
const size = electronScreen.getPrimaryDisplay().workAreaSize;
13+
const electronScreen = screen;
14+
const size = electronScreen.getPrimaryDisplay().workAreaSize;
1315

14-
// Create the browser window.
15-
win = new BrowserWindow({
16-
x: 0,
17-
y: 0,
18-
width: 400,
19-
height: 800,
20-
titleBarStyle: 'hidden'
21-
});
16+
// Create the browser window.
17+
win = new BrowserWindow({
18+
x: 0,
19+
y: 0,
20+
width: 400,
21+
height: 800,
22+
titleBarStyle: 'hidden'
23+
});
2224

23-
if (serve) {
24-
require('electron-reload')(__dirname, {
25-
electron: require(`${__dirname}/node_modules/electron`)});
26-
win.loadURL('http://localhost:4200');
27-
} else {
28-
win.loadURL(url.format({
29-
pathname: path.join(__dirname, 'dist/index.html'),
30-
protocol: 'file:',
31-
slashes: true
32-
}));
33-
}
25+
if (serve) {
26+
require('electron-reload')(__dirname, {
27+
electron: require(`${__dirname}/node_modules/electron`)
28+
});
29+
win.loadURL('http://localhost:4200');
30+
} else {
31+
win.loadURL(url.format({
32+
pathname: path.join(__dirname, 'dist/index.html'),
33+
protocol: 'file:',
34+
slashes: true
35+
}));
36+
}
3437

35-
// win.webContents.openDevTools();
38+
// win.webContents.openDevTools();
3639

37-
// Emitted when the window is closed.
38-
win.on('closed', () => {
39-
// Dereference the window object, usually you would store window
40-
// in an array if your app supports multi windows, this is the time
41-
// when you should delete the corresponding element.
42-
win = null;
43-
});
40+
// Emitted when the window is closed.
41+
win.on('closed', () => {
42+
// Dereference the window object, usually you would store window
43+
// in an array if your app supports multi windows, this is the time
44+
// when you should delete the corresponding element.
45+
win = null;
46+
});
4447
}
4548

4649
try {
4750

48-
// This method will be called when Electron has finished
49-
// initialization and is ready to create browser windows.
50-
// Some APIs can only be used after this event occurs.
51-
app.on('ready', createWindow);
51+
// This method will be called when Electron has finished
52+
// initialization and is ready to create browser windows.
53+
// Some APIs can only be used after this event occurs.
54+
app.on('ready', createWindow);
5255

53-
// Quit when all windows are closed.
54-
app.on('window-all-closed', () => {
55-
// On OS X it is common for applications and their menu bar
56-
// to stay active until the user quits explicitly with Cmd + Q
57-
if (process.platform !== 'darwin') {
58-
app.quit();
59-
}
60-
});
56+
// Quit when all windows are closed.
57+
app.on('window-all-closed', () => {
58+
// On OS X it is common for applications and their menu bar
59+
// to stay active until the user quits explicitly with Cmd + Q
60+
if (process.platform !== 'darwin') {
61+
app.quit();
62+
}
63+
});
6164

62-
app.on('activate', () => {
63-
// On OS X it's common to re-create a window in the app when the
64-
// dock icon is clicked and there are no other windows open.
65-
if (win === null) {
66-
createWindow();
67-
}
68-
});
65+
app.on('activate', () => {
66+
// On OS X it's common to re-create a window in the app when the
67+
// dock icon is clicked and there are no other windows open.
68+
if (win === null) {
69+
createWindow();
70+
}
71+
const log = require("electron-log");
72+
log.transports.file.level = "debug";
73+
autoUpdater.logger = log;
74+
autoUpdater.checkForUpdatesAndNotify();
75+
});
6976

7077
} catch (e) {
71-
// Catch Error
72-
// throw e;
78+
// Catch Error
79+
// throw e;
7380
}

package.json

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"name": "Stors",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A simple task manager for a day",
55
"homepage": "https://insert.black",
66
"repository": "https://github.com/drecodeam/stors",
7+
"browser": {
8+
"child_process": false
9+
},
710
"author": {
811
"name": "Drecode Feil",
912
"email": "[email protected]"
@@ -24,14 +27,21 @@
2427
"electron:local": "npm run build:prod && electron .",
2528
"electron:linux": "npm run build:prod && npx electron-builder build --linux",
2629
"electron:windows": "npm run build:prod && npx electron-builder build --windows",
27-
"electron:mac": "npm run build:prod && npx electron-builder build --mac ",
30+
"electron:mac": "npm run build:prod && npx electron-builder build --mac --p",
31+
"release:mac": "npm run build:prod && npx electron-builder build --mac --p always",
2832
"test": "ng test",
2933
"e2e": "ng e2e"
3034
},
3135
"dependencies": {
3236
"analytics-node": "^3.3.0",
3337
"auto-launch": "^5.0.5",
34-
"electron-updater": "^2.23.3"
38+
"buffer": "^5.1.0",
39+
"electron-log": "^2.2.16",
40+
"electron-updater": "^3.0.3",
41+
"events": "^3.0.0",
42+
"raven-js": "^3.26.4",
43+
"stream": "0.0.2",
44+
"timers": "^0.1.1"
3545
},
3646
"devDependencies": {
3747
"@angular-devkit/build-angular": "0.6.3",
@@ -48,13 +58,14 @@
4858
"@angular/router": "6.0.3",
4959
"@ngx-translate/core": "10.0.1",
5060
"@ngx-translate/http-loader": "3.0.1",
61+
"@types/es6-collections": "^0.5.31",
5162
"@types/jasmine": "2.8.7",
5263
"@types/jasminewd2": "2.0.3",
5364
"@types/node": "8.9.4",
5465
"airtable": "^0.5.6",
5566
"codelyzer": "4.2.1",
5667
"core-js": "2.5.6",
57-
"electron": "2.0.2",
68+
"electron": "^2.0.2",
5869
"electron-builder": "20.14.7",
5970
"electron-reload": "1.2.2",
6071
"jasmine-core": "3.1.0",

src/app/components/home/home.component.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div class="draggable-region"></div>
22
<div class="container">
33
<div class="title">Today</div>
4-
<div class="total-time">
4+
<div class="total-time" *ngIf="!!status.showTime">
55
<span class="hrs">{{totalHrs}}h </span> <span class="mins"> {{totalMins}}m |</span>
66
<div class="eta">{{eta}}</div>
77
</div>
8-
<div class="task-list">
8+
<div class="task-list" *ngIf="!status.showEmptyState">
99
<div class="task-list-item"
1010
*ngFor="let item of data.list"
1111
[id]="item.id"
@@ -28,6 +28,9 @@
2828
<div class="item-progress-bar" [style.width.%]="item.progress"></div>
2929
</div>
3030
</div>
31+
<div class="empty-state" *ngIf="!!status.showEmptyState">
32+
showing an empty state
33+
</div>
3134
<input type="text" class="add-task" [ngModel]="addTaskInput" (keyup.enter)="addTask(todo.value)" placeholder="+ Add a new task" #todo>
3235
</div>
3336
<div class="help drift-open-chat">👋 Feedback</div>

src/app/components/home/home.component.scss

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ $maya-blye : #72BFF9;
6464
color: #666;
6565
caret-color: red;
6666
}
67+
6768
.task-list {
6869
position: relative;
6970
overflow: hidden;
@@ -183,6 +184,7 @@ $maya-blye : #72BFF9;
183184
}
184185
}
185186
}
187+
186188
.add-task {
187189
background: transparent;
188190
padding: 1rem;
@@ -211,12 +213,14 @@ $maya-blye : #72BFF9;
211213
background: $mirage;
212214
}
213215
}
216+
214217
.clear-tasks {
215218
color: white;
216219
text-align: center;
217220
margin-top: 2rem
218221
;
219222
}
223+
220224
.onboarding {
221225
overflow: hidden;
222226
background: $magenta;

src/app/components/home/home.component.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { ElectronService } from '../../providers/electron.service';
33

4+
45
@Component({
56
selector: 'app-home',
67
templateUrl: './home.component.html',
@@ -12,7 +13,6 @@ export class HomeComponent implements OnInit {
1213
private electronService: ElectronService
1314
) {}
1415

15-
1616
filePath = this.electronService.remote.app.getPath('appData') + '/list.json';
1717
data;
1818
fs = this.electronService.fs;
@@ -25,6 +25,11 @@ export class HomeComponent implements OnInit {
2525
totalHrs;
2626
totalMins;
2727
eta: any;
28+
status = {
29+
showOnboarding: false,
30+
showTime: false,
31+
showEmptyState: false
32+
};
2833
hideOnboarding = false;
2934
showOnboarding = false;
3035

@@ -121,9 +126,18 @@ export class HomeComponent implements OnInit {
121126
* Sync data onto the file
122127
*/
123128
updateData() {
129+
if ( this.data.list.length <= 0 ) {
130+
this.status.showEmptyState = true;
131+
} else {
132+
this.status.showEmptyState = false;
133+
}
124134
this.fs.writeFileSync(this.filePath, JSON.stringify(this.data));
125135
}
126136

137+
/**
138+
*
139+
* @param date
140+
*/
127141
formatAMPM(date) {
128142
let hours = date.getHours();
129143
let minutes = date.getMinutes();
@@ -141,13 +155,13 @@ export class HomeComponent implements OnInit {
141155
markItemComplete( task ) {
142156
task.isTicked = true;
143157
this.totalTime = this.totalTime - ( task.time - task.elapsed );
144-
this.currentTaskID = 0;
158+
this.currentTaskID = 0;
145159
this.updateEta();
146160
this.updateData();
147161
}
148162

149163
/**
150-
* Mark the item as complete
164+
* Mark the item as complsete
151165
* @param task
152166
*/
153167
deleteItem( task ) {
@@ -168,6 +182,11 @@ export class HomeComponent implements OnInit {
168182
*/
169183
updateEta() {
170184
const time = this.totalTime;
185+
if ( this.totalTime > 0 ) {
186+
this.status.showTime = true;
187+
} else {
188+
this.status.showTime = false;
189+
}
171190
this.totalHrs = Math.floor( this.totalTime/60 );
172191
this.totalMins = this.totalTime % 60;
173192
const date = new Date( new Date().getTime() + time * 60000 );

src/environments/environment.dev.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
// The list of which env maps to which file can be found in `.angular-cli.json`.
55

66
export const AppConfig = {
7-
production: false,
8-
environment: 'DEV'
7+
production: false,
8+
environment: 'DEV'
99
};

src/environments/environment.prod.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const AppConfig = {
2-
production: true,
3-
environment: 'PROD'
2+
production: true,
3+
environment: 'PROD'
44
};

src/environments/environment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const AppConfig = {
2-
production: false,
3-
environment: 'LOCAL'
2+
production: false,
3+
environment: 'LOCAL'
44
};

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { enableProdMode } from '@angular/core';
22
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3-
43
import { AppModule } from './app/app.module';
54
import { AppConfig } from './environments/environment';
65

6+
77
if (AppConfig.production) {
88
enableProdMode();
99
}

0 commit comments

Comments
 (0)