Skip to content

Commit

Permalink
Update auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
ALiangLiang committed Nov 13, 2016
1 parent a864e35 commit e1987b2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

- [ ] 偵測 SSID 變更,全自動登入。
- [ ] 產品 icon。
- [ ] 自動更新。
- [X] 自動更新。
- [ ] mac 版本支援。
- [ ] 增加測試 scripts。
- [ ] 憑證驗證,防止偽造 WIFI 熱點。
36 changes: 0 additions & 36 deletions app/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,5 @@ module.exports = class Account {
method: 'post',
body: postData,
});
/*
const urlObj = Url.parse(url);
const options = {
hostname: urlObj.host,
port: 80,
path: urlObj.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
return new Promise((resolve, reject) => {
const req = http.request(options, () => {
let str = ''
res.setEncoding('utf8');
res.on('data', function(chunk) {
str += chunk;
});
res.on('end', function() {
console.log(str);
resolve({
body: str,
url: res.url,
});
});
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
reject(e);
});
req.write(postData);
req.end();
});*/
}
}
43 changes: 35 additions & 8 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,51 @@ const
Account = require('./account.js'),
globalValue = require('./globalValue');

let win, visitor;

// if (require('electron-squirrel-startup')) return;
let win, visitor, eventNum;

class EventNum {
constructor(num) {
this._num = num || 0;
}
inc() {
this._num = this._num + 1;
console.log('eventNum: ', this._num);
}
dec() {
this._num = this._num - 1;
console.log('eventNum: ', this._num);
if (this._num <= 0) {
console.log('close');
app.quit();
}
}
}

function initUpdates() {

autoUpdater.on('checking-for-update', () => {
console.log('checking-for-update');
eventNum.inc();
});

autoUpdater.on('update-available', () => {
console.log('update-available');

notify('TANet Roamer 校園網路漫遊器', {
body: '發現新的版本,下載新版本安裝檔中。'
}, openSettingPage);
});

autoUpdater.on('update-not-available', () => {
console.log('update-not-available');
eventNum.dec();
});

autoUpdater.on('update-downloaded', (a, b, c, d, e, quitAndInstall) => {
autoUpdater.on('update-downloaded', (a, b, version, d, e, quitAndInstall) => {
console.log('update-downloaded');
eventNum.inc();
notify('TANet Roamer 校園網路漫遊器', {
body: `安裝檔下載完成,開始安裝新版本 v${version}`
});
quitAndInstall();
});

Expand All @@ -53,6 +77,7 @@ function genUuid() {
}

function openSettingPage() {
eventNum.inc();
visitor.event('main', 'openSettingPage').send();
win = new BrowserWindow({
width: 240,
Expand All @@ -67,7 +92,7 @@ function openSettingPage() {

win.on('closed', () => {
win = null;
app.quit();
eventNum.dec();
});
}

Expand All @@ -88,13 +113,15 @@ function genUA() {

const readyPromise = new Promise((resolve, reject) => {
app.on('ready', () => {
initUpdates()
eventNum = new EventNum();
initUpdates();
resolve();
});
});

Promise.all([genUA(), readyPromise])
.then(() => {
eventNum.inc();
storage.get('user', (err, data) => {
if (!data || !data.id || !data.password || !data.school_place)
return openSettingPage();
Expand All @@ -115,7 +142,7 @@ Promise.all([genUA(), readyPromise])
visitor.event('login', 'failed').send();
const noti = notify((status.isSuccess) ? globalValue.STRING_LOGIN_SUCCESS : globalValue.STRING_LOGIN_FAILED, {
body: status.message
}, openSettingPage /*, app.quit*/ );
}, openSettingPage, eventNum.dec());
});
});
});
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tanetroamer-desktop",
"productName": "TANet-Roamer",
"version": "0.0.2",
"productName": "TANet Roamer 校園網路漫遊器",
"version": "0.0.3",
"description": "一鍵登入校園 WI-FI 的桌面應用程式",
"homepage": "https://github.com/ALiangLiang/tanetroamer-desktop",
"main": "main.js",
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ install:
build_script:
- node --version
- npm --version
- npm run dist
- node release.js
- npm run release

test: off

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"scripts": {
"pack": "build --dir",
"dist": "build",
"release": "build && node release",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
Expand Down

0 comments on commit e1987b2

Please sign in to comment.