Skip to content

Commit

Permalink
add auto update trazyn#31
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Sep 18, 2017
1 parent aecb530 commit 2d3f806
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
66 changes: 65 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

import fs from 'fs';
import tmp from 'tmp';
import { app, powerMonitor, BrowserWindow, Tray, Menu, ipcMain, clipboard, shell, nativeImage } from 'electron';
import { app, powerMonitor, BrowserWindow, Tray, Menu, ipcMain, clipboard, shell, nativeImage, dialog } from 'electron';
import windowStateKeeper from 'electron-window-state';
import AutoLaunch from 'auto-launch';
import { autoUpdater } from 'electron-updater';

import pkg from './package.json';

let forceQuit = false;
let downloading = false;
let mainWindow;
let tray;
let settings = {};
Expand Down Expand Up @@ -46,6 +48,13 @@ let mainMenu = [
{
role: 'unhide'
},
{
label: 'Check for updates',
accelerator: 'Cmd+U',
click() {
checkForUpdates();
}
},
{
type: 'separator'
},
Expand Down Expand Up @@ -258,6 +267,22 @@ function getIcon(data) {
});
}

function checkForUpdates() {
if (downloading) {
dialog.showMessageBox({
type: 'info',
buttons: ['OK'],
title: pkg.name,
message: `Downloading...`,
detail: `Please leave the app open, the new version is downloading. You'll receive a new dialog when downloading is finished.`
});

return;
}

autoUpdater.checkForUpdates();
}

function updateTray(unread = 0) {
if (!isOsx) {
// Always show the tray icon on windows
Expand Down Expand Up @@ -322,6 +347,16 @@ function updateTray(unread = 0) {
mainWindow.webContents.send('hide-tray');
}
},
{
type: 'separator'
},
{
label: 'Check for updates',
accelerator: 'Cmd+U',
click() {
checkForUpdates();
}
},
{
label: 'Quit weweChat',
accelerator: 'Command+Q',
Expand Down Expand Up @@ -602,3 +637,32 @@ app.on('activate', e => {
mainWindow.show();
}
});

autoUpdater.on('update-not-available', e => {
dialog.showMessageBox({
type: 'info',
buttons: ['OK'],
title: pkg.name,
message: `${pkg.name} is up to date :)`,
detail: `${pkg.name} ${pkg.version} is currently the newest version available, It looks like you're already rocking the latest version!`
});

console.log('Update not available.');
});

autoUpdater.on('error', err => {
dialog.showMessageBox({
type: 'error',
buttons: ['Cancel update'],
title: pkg.name,
message: `Failed to update ${pkg.name} :(`,
detail: `An error occurred in retrieving update information, Please try again later.`,
});

downloading = false;
console.error(err);
});

autoUpdater.on('update-downloaded', e => {
autoUpdater.quitAndInstall();
});
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wewechat",
"version": "1.1.1",
"version": "1.1.2",
"description": "Unofficial WeChat client built with React, MobX and Electron.",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -64,7 +64,12 @@
},
"directories": {
"output": "../release"
}
},
"publish": [{
"provider": "github",
"owner": "trazyn",
"repo": "weweChat"
}]
},
"dependencies": {
"@exponent/electron-cookies": "^2.0.0",
Expand Down Expand Up @@ -109,11 +114,12 @@
"css-loader": "^0.28.4",
"electron": "^1.6.11",
"electron-builder": "^19.24.1",
"electron-updater": "^2.8.9",
"eslint": "^4.1.1",
"eslint-loader": "^1.9.0",
"eslint-config-standard": "^10.2.1",
"eslint-config-standard-react": "^5.0.0",
"eslint-formatter-pretty": "^1.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.6.1",
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
Expand Down
10 changes: 10 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

if [ -z "$GH_TOKEN" ]; then
echo "You must set the GH_TOKEN environment variable."
echo "See README.md for more details."
exit 1
fi

# This will build, package and upload the app to GitHub.
node_modules/.bin/build --win --mac --linux -p always
2 changes: 0 additions & 2 deletions src/js/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ async function updateMenus(sessions) {
})
);

console.log(conversationsWithIcon);

ipcRenderer.send('menu-update', {
conversations: JSON.stringify(conversationsWithIcon),
contacts: JSON.stringify(contactsWithIcon),
Expand Down

0 comments on commit 2d3f806

Please sign in to comment.