Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Commit 7a2c875

Browse files
authored
Merge pull request #16 from eNkru/feature/auto-update
Add the auto-updater to the application
2 parents e6b2c46 + c1a36ee commit 7a2c875

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"pack": "electron-builder --dir",
99
"dist:linux": "electron-builder --linux deb tar.xz",
1010
"dist:macOS": "electron-builder --mac",
11-
"postinstall": "electron-builder install-app-deps"
11+
"postinstall": "electron-builder install-app-deps",
12+
"publish": "build -p always"
1213
},
1314
"repository": "https://github.com/eNkru/electron-xiami",
1415
"keywords": [
@@ -29,14 +30,16 @@
2930
"electron-dl": "^1.10.0",
3031
"electron-json-storage": "^4.0.2",
3132
"electron-settings": "^3.1.1",
33+
"electron-updater": "^2.20.1",
3234
"fs-extra": "^5.0.0",
3335
"hh-mm-ss": "^1.2.0",
3436
"lyrics.js": "^0.3.5"
3537
},
3638
"build": {
3739
"appId": "nz.co.enkru.${name}",
3840
"linux": {
39-
"category": "Audio"
41+
"category": "Audio",
42+
"target": ["AppImage", "deb", "pacman", "tar.xz"]
4043
}
4144
}
4245
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { autoUpdater } = require('electron-updater');
2+
const { dialog } = require('electron');
3+
const settings = require('electron-settings');
4+
5+
class UpdateController {
6+
7+
constructor() {
8+
autoUpdater.autoDownload = false;
9+
10+
const language = settings.get('language', 'en');
11+
const Locale = language === 'en' ? require('../locale/locale_en') : require('../locale/locale_sc');
12+
13+
autoUpdater.on('update-available', (info) => {
14+
dialog.showMessageBox({
15+
type: "info",
16+
buttons: [Locale.UPDATE_CANCEL_BUTTON, Locale.UPDATE_OK_BUTTON],
17+
defaultId: 1,
18+
cancelId: 0,
19+
title: Locale.UPDATE_TITLE,
20+
message: Locale.UPDATE_MESSAGE,
21+
detail: `${info.releaseNotes}`
22+
}, response => {
23+
if (response) {
24+
autoUpdater.downloadUpdate();
25+
}
26+
});
27+
});
28+
}
29+
30+
checkUpdate() {
31+
autoUpdater.checkForUpdates()
32+
}
33+
}
34+
35+
module.exports = UpdateController;

src/locale/locale_en.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
class Locale {
1+
class Locale {}
22

3-
}
3+
Locale.UPDATE_CANCEL_BUTTON = 'Later';
4+
Locale.UPDATE_OK_BUTTON = 'Upgrade';
5+
Locale.UPDATE_TITLE = 'Version Upgrade';
6+
Locale.UPDATE_MESSAGE = 'Upgrade Information';
47

58
Locale.TRAY_TOOLTIP = 'Xiami Player';
69
Locale.TRAY_SHOW_MAIN = 'Show Player';

src/locale/locale_sc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
class Locale {}
22

3+
Locale.UPDATE_CANCEL_BUTTON = '稍后再说';
4+
Locale.UPDATE_OK_BUTTON = '马上更新';
5+
Locale.UPDATE_TITLE = '版本更新';
6+
Locale.UPDATE_MESSAGE = '更新内容';
7+
38
Locale.TRAY_TOOLTIP = '虾米播放器';
49
Locale.TRAY_SHOW_MAIN = '显示播放器';
510
Locale.TRAY_PLAY_PAUSE = '播放 | 暂停';

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const PlayerController = require('./controller/player-controller');
44
const SettingsController = require('./controller/settings-controller');
55
const AppTray = require('./controller/app-tray-controller');
66
const LyricsController = require('./controller/lyrics-controller');
7+
const UpdateController = require('./controller/update-controller');
78

89
class ElectronXiami {
910

@@ -42,6 +43,9 @@ class ElectronXiami {
4243
this.createSettings();
4344
this.createPlayer(this.lyricsController);
4445
this.createTray(this.settingsController, this.lyricsController, this.playerController);
46+
47+
// check update
48+
new UpdateController().checkUpdate();
4549
});
4650

4751
// Quit when all windows are closed.

0 commit comments

Comments
 (0)