Skip to content

Commit

Permalink
autoupdater
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuozhili committed Aug 24, 2020
1 parent 466b3c0 commit 59a70ff
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 6 deletions.
65 changes: 63 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
const { app, BrowserWindow, globalShortcut } = require("electron");
const { app, BrowserWindow, globalShortcut, dialog } = require("electron");
const isDev = require("electron-is-dev");
const { Menu, ipcMain } = require("electron");
const { shell } = require("electron");
const path = require("path");
const { autoUpdater } = require("electron-updater");
let mainWindow;
let settingwindow;
app.on("ready", () => {
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on("error", (error) => {
dialog.showErrorBox(
"Error: ",
error == null ? "unknown" : (error.stack || error).toString()
);
});
autoUpdater.on("checking-for-update", () => {
console.log("Checking for update...");
});
autoUpdater.on("update-available", () => {
dialog.showMessageBox(
{
type: "info",
title: "应用有新的版本",
message: "发现新版本,是否现在更新?",
buttons: ["是", "否"],
},
(buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
}
}
);
});
autoUpdater.on("update-not-available", () => {
dialog.showMessageBox({
title: "没有新版本",
message: "当前已经是最新版本",
});
});

autoUpdater.on("download-progress", (progressObj) => {
let log_message = "Download speed: " + progressObj.bytesPerSecond;
log_message =
log_message + " - Downloaded " + progressObj.percent + "%";
log_message =
log_message +
" (" +
progressObj.transferred +
"/" +
progressObj.total +
")";
console.log(log_message);
});

autoUpdater.on("update-downloaded", () => {
dialog.showMessageBox(
{
title: "安装更新",
message: "更新下载完毕,应用将重启并进行安装",
},
() => {
setImmediate(() => autoUpdater.quitAndInstall());
}
);
});
mainWindow = new BrowserWindow({
width: 1200,
height: 680,
Expand Down Expand Up @@ -202,7 +261,9 @@ const template = [
{
label: "github",
click: () => {
shell.openExternal("https://github.com/yehuozhili");
shell.openExternal(
"https://github.com/yehuozhili/bigbear-mindmap"
);
},
},
],
Expand Down
40 changes: 36 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bigbear-mindmap",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"main": "main.js",
"author": "yehuozhili",
Expand All @@ -20,7 +20,7 @@
"dist": "electron-builder",
"prepack": "npm run build",
"predist": "npm run build",
"release": " GH_TOKEN=$GH_TOKEN electron-builder",
"release": "electron-builder",
"prerelease": "npm run build"
},
"eslintConfig": {
Expand All @@ -41,7 +41,38 @@
"settings/**/*",
"package.json",
"main.js"
]
],
"directories": {
"buildResources": "resources"
},
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": [
"nsis",
"msi"
]
},
"linux": {
"target": [
"deb",
"rpm",
"AppImage"
],
"category": "Development"
}
},
"browserslist": {
"production": [
Expand All @@ -68,6 +99,7 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"bigbear-ui": "^1.0.0",
"@antv/g6": "^3.6.1"
"@antv/g6": "^3.6.1",
"electron-updater": "^4.3.1"
}
}
Binary file added resources/icon.icns
Binary file not shown.
Binary file added resources/icon.ico
Binary file not shown.
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/1024x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59a70ff

Please sign in to comment.