├── vue ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── router.js │ ├── App.vue │ ├── main.js │ ├── assets │ │ ├── sqlite │ │ │ └── sqlite_util.js │ │ └── js │ │ │ └── update.js │ └── components │ │ └── HelloWorld.vue └── package.json ├── electron-main ├── icons │ ├── icon.icns │ ├── icon.ico │ └── 256x256.png ├── hotKey.js ├── tray.js ├── update.js ├── package.json └── main.js ├── .gitignore └── README.md /vue/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoyucode/electron-vue-guoyu/HEAD/vue/public/favicon.ico -------------------------------------------------------------------------------- /electron-main/icons/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoyucode/electron-vue-guoyu/HEAD/electron-main/icons/icon.icns -------------------------------------------------------------------------------- /electron-main/icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoyucode/electron-vue-guoyu/HEAD/electron-main/icons/icon.ico -------------------------------------------------------------------------------- /electron-main/icons/256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guoyucode/electron-vue-guoyu/HEAD/electron-main/icons/256x256.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | /build/ 23 | electron-main/dist/ 24 | -------------------------------------------------------------------------------- /vue/src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import index from './components/HelloWorld' 4 | 5 | Vue.use(Router) 6 | 7 | export default new Router({ 8 | routes: [ 9 | { 10 | path: '/', 11 | name: '首页', 12 | component: index 13 | }, 14 | { 15 | path: '*', 16 | redirect: '/' 17 | } 18 | ] 19 | }) 20 | -------------------------------------------------------------------------------- /vue/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 23 | -------------------------------------------------------------------------------- /vue/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | electron-vue 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /vue/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App' 3 | import router from './router' 4 | import vView from 'vue-view-lazy' 5 | import {update} from "./assets/js/update" 6 | //import store from './store' 7 | //import configData from "./page/js/config_data" 8 | 9 | Vue.use(vView) 10 | 11 | //饿了么UI 12 | import ElementUI from 'element-ui' 13 | import 'element-ui/lib/theme-chalk/index.css' 14 | Vue.use(ElementUI) 15 | 16 | //if (!process.env.IS_WEB) Vue.use(require('vue-electron')) 17 | Vue.config.productionTip = false 18 | Vue.prototype.$electron = window.require("electron") 19 | 20 | /** 21 | * 事件总线 22 | * @type {Vue | CombinedVueInstance>} 23 | */ 24 | window.$EventBus = Vue.prototype.$EventBus = new Vue() //事件总线 25 | 26 | window.staticPath = require('path').join(""); 27 | 28 | /* eslint-disable no-new */ 29 | new Vue({ 30 | router, 31 | render: h => h(App), 32 | //store, 33 | //template: '', 34 | mounted() { 35 | update(this); 36 | }, 37 | }).$mount('#app') 38 | -------------------------------------------------------------------------------- /vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-vue", 3 | "author": { 4 | "name": "guoyu", 5 | "email": "guoyumail@qq.com" 6 | }, 7 | "version": "0.0.1", 8 | "private": true, 9 | "main": "./electron-main/main.js", 10 | "scripts": { 11 | "dev-vue": "cross-env NODE_ENV=development vue-cli-service serve", 12 | "build-vue": "vue-cli-service build" 13 | }, 14 | "dependencies": { 15 | "axios": "0.19.0", 16 | "echarts": "4.3.0", 17 | "element-ui": "2.12.0", 18 | "qs": "6.8.0", 19 | "vue": "2.6.10", 20 | "vue-router": "3.1.3", 21 | "vue-view-lazy": "0.0.6" 22 | }, 23 | "devDependencies": { 24 | "@vue/cli-service": "3.11.0", 25 | "vue-template-compiler": "2.6.10", 26 | "cross-env": "6.0.0" 27 | }, 28 | "vue": { 29 | "publicPath": "./", 30 | "outputDir": "../electron-main/dist", 31 | "assetsDir": "", 32 | "lintOnSave": false, 33 | "runtimeCompiler": true, 34 | "productionSourceMap": false, 35 | "parallel": true 36 | }, 37 | "postcss": { 38 | "plugins": { 39 | "autoprefixer": {} 40 | } 41 | }, 42 | "browserslist": [ 43 | "> 1%", 44 | "last 2 versions" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /vue/src/assets/sqlite/sqlite_util.js: -------------------------------------------------------------------------------- 1 | 2 | /// Import SqliteDB. 3 | var SqliteDB = require('../../../electron-main/sqlite.js'); 4 | var file = "db2.db"; 5 | var sqliteDB = new SqliteDB(file); 6 | 7 | /// create table. 8 | var createTileTableSql = "create table if not exists test_tiles(level INTEGER, column INTEGER, row INTEGER, content BLOB);"; 9 | var createLabelTableSql = "create table if not exists test_labels(level INTEGER, longitude REAL, latitude REAL, content BLOB);"; 10 | sqliteDB.createTable(createTileTableSql); 11 | sqliteDB.createTable(createLabelTableSql); 12 | 13 | /// insert data. 14 | var tileData = [[1, 10, 10], [1, 11, 11], [1, 10, 9], [1, 11, 9]]; 15 | var insertTileSql = "insert into test_tiles(level, column, row) values(?, ?, ?)"; 16 | sqliteDB.insertData(insertTileSql, tileData); 17 | 18 | /// query data. 19 | var querySql = 'select * from test_tiles where level = 1 and column >= 10 and column <= 11 and row >= 10 and row <=11'; 20 | sqliteDB.queryData(querySql, dataDeal); 21 | 22 | /// update data. 23 | var updateSql = 'update test_tiles set level = 2 where level = 1 and column = 10 and row = 10'; 24 | sqliteDB.executeSql(updateSql); 25 | 26 | /// query data after update. 27 | querySql = "select * from test_tiles where level = 2"; 28 | sqliteDB.queryData(querySql, dataDeal); 29 | 30 | //close db 31 | sqliteDB.close(); 32 | 33 | function dataDeal(objects){ 34 | for(var i = 0; i < objects.length; ++i){ 35 | console.log(objects[i]); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /electron-main/hotKey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 快捷键设置 3 | * */ 4 | let { ipcMain, globalShortcut } = require('electron') 5 | 6 | let mainWindow = null; 7 | 8 | /** 9 | * 快捷键 10 | * @param mainWindow_input 11 | */ 12 | module.exports = mainWindow_input => { 13 | mainWindow = mainWindow_input 14 | //设置刷新快捷键 15 | //监听通知发送过来的消息 16 | ipcMain.on("setHotKey", (e, v) => { 17 | setHotKeyFun2(v) 18 | }) 19 | } 20 | 21 | 22 | const state = {} 23 | const setHotKeyFun2 = function (hotKey) { 24 | 25 | if (!globalShortcut || !hotKey) return; 26 | if (state.hotKey_val && state.hotKey_val == hotKey) return; 27 | 28 | //如果之前注册成功了快捷键,那么解除该快捷键 29 | if (state.hotKey_val && state.hotKey_val != "无") globalShortcut.unregister(state.hotKey_val) 30 | if (!hotKey || hotKey == "无") return 31 | 32 | //console.log("快捷键注册", hotKey) 33 | let bool = globalShortcut.register(hotKey, () => { 34 | mainWindow.send("refresh-shortcut", hotKey) 35 | if(state.callback){ 36 | state.callback() 37 | } 38 | }) 39 | 40 | if (bool) { 41 | let msg = "设置快捷键成功: " + hotKey 42 | if(state.hotKey_val) mainWindow.send("show-success-message", msg) 43 | state.hotKey_val = hotKey + ""; 44 | } else { 45 | let msg = "设置刷新快捷键: " + hotKey + " 失败, 请检查是否有软件快捷键冲突, 或者到设置中重新设置一个不同的快捷键." 46 | mainWindow.send("alert-message", msg) 47 | console.error(msg) 48 | //state.hotKey = state.hotKey_val || "无" 49 | } 50 | state.hotKey_val = hotKey + "" 51 | } 52 | -------------------------------------------------------------------------------- /electron-main/tray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * tray 显示托盘 3 | * */ 4 | let {app, Menu, Tray, dialog, ipcMain} = require('electron') 5 | let {autoUpdater} = require('electron-updater') 6 | const path = require('path'); 7 | 8 | /** 9 | * 显示托盘 10 | */ 11 | const showTray = () => { 12 | //非windows系统不显示托盘 13 | let os = process.platform; 14 | if (os.indexOf("win32") == -1) return; 15 | 16 | let showWindow = () => ipcMain.emit("showWindows"); 17 | let exit = () => app.quit(); 18 | 19 | let isDev = process.env.NODE_ENV && process.env.NODE_ENV == 'development' 20 | let trayIcon = isDev ? './public/img/amex.ico' : path.resolve("./") + "/resources/app.asar/dist/img/amex.ico" 21 | 22 | let tray = new Tray(trayIcon) 23 | const contextMenu = Menu.buildFromTemplate([ 24 | {label: '打开主界面2', type: 'normal', checked: true, click: showWindow}, 25 | {label: '检查更新', type: 'normal', checked: true, click: checkForUpdates}, 26 | {label: '退出', type: 'normal', checked: true, click: exit}, 27 | ]) 28 | tray.setToolTip('单击打开主界面,或者右击选择退出') 29 | tray.setContextMenu(contextMenu) 30 | tray.on("click", function (event, bounds) { 31 | showWindow() 32 | }) 33 | } 34 | 35 | const checkForUpdates = () => { 36 | autoUpdater.once('update-not-available', res => { 37 | dialog.showMessageBox({ 38 | type: 'info', 39 | title: '检查更新提示', 40 | defaultId: 0, 41 | noLink: true, 42 | message: `没有检测到新版本!`, 43 | buttons: ['我知道了'] 44 | }, (index) => { 45 | }) 46 | }) 47 | autoUpdater.checkForUpdates() 48 | } 49 | 50 | module.exports = { 51 | showTray: showTray, 52 | checkForUpdates: checkForUpdates, 53 | } 54 | -------------------------------------------------------------------------------- /vue/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 40 | 41 | 42 | 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Out of the box electron-vue (开箱即用项目) 2 | 3 | 功能说明 4 | 1. The front end is developed using vue.js; 5 | + 前端使用vue.js开发 6 | 2. Packaging integration framework using electron 7 | + 包装集成框架使用electron 8 | 3. Support packaged as windows exe installation file, support mac packaged as dmg installation file 9 | + 支持打包为 windows exe 安装文件, 支持 mac 打包为 dmg 安装文件 10 | 4. Support automatic update, use electron-updater dependency, auto update is not supported on mac, need to click the link to manually download and install when prompted to have new version 11 | + 支持自动更新,使用electron-updater依赖, mac上不支持自动更新,需要在提示有新版时点击链接手动下载安装 12 | 5. Display tray function (windows) 13 | + 显示托盘功能(windows) 14 | 15 | ## Sqlite3 version, need to compile the node file executed by sqlite3. (sqlite3 版本, 需要编译sqlite3执行的node文件) 16 | 1. Switch branches to: sqlite3 17 | + 切换分支到: sqlite3 18 | 1. Need to install python 2.7 and add to path 19 | + 需要安装python2.7,并加入到path 20 | 2. Need to install vs2015, Can be a community version 21 | + 需要安装vs2015,可以是社区版 22 | 3. After executing npm install, you need to execute: npm run rebuild 23 | + 执行完npm install 后还需要执行: npm run rebuild 24 | 4. The syntactic code for sqlite3 is the two files: electron-main/sqlite/sqlite.js, electron-main/sqlite/sqlite_util.js 25 | + sqlite3 的相文代码是这两个文件 26 | 5. The generated db2.db database file is in the project installation directory 27 | + 生成的 db2.db 数据库文件在项目安装目录 28 | 29 | ## Project use precautions (项目使用注意事项) 30 | 1. Use the latest version of electron, use the latest version of vue 31 | + 使用最新版本的electron,使用最新版本的vue 32 | 2. Out of the box, as the name suggests: Download it and use it directly 33 | + 开箱即用,顾名思义:下载并直接使用 34 | 3. If you have any questions, please go to github to ask issues: https://github.com/guoyucode/electron-vue-guoyu/issues 35 | + 如果您有任何疑问,请访问 github 提问 36 | 37 | ## Project setup (项目安装) 38 | ``` 39 | npm install 40 | ``` 41 | 42 | 1. Vue supports compilation and hot update for development 43 | + vue支持编译和热更新以进行开发 44 | 2. Run the first one first, then execute the second one after success. 45 | + 先运行第一条,成功后再执行第二条 (这两条命令也就是先编译vue,再开启electron访问vue编译后的代码) 46 | ``` 47 | npm run dev-vue 48 | npm run dev-electron 49 | ``` 50 | 51 | ### Compiles and minifies for production(编译生产版本) 52 | ``` 53 | npm run build-electron 54 | ``` 55 | 56 | ### Customize configuration 57 | See [Configuration Reference](https://cli.vuejs.org/config/). 58 | -------------------------------------------------------------------------------- /electron-main/update.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 更新使用 3 | */ 4 | 5 | 6 | let { ipcMain } = require('electron') 7 | let { autoUpdater } = require('electron-updater') 8 | 9 | const packageInfo = require('./package.json'); 10 | 11 | // 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写 12 | module.exports = mainWindow => { 13 | 14 | autoUpdater.autoDownload = false 15 | // 通过main进程发送事件给renderer进程,提示更新信息 16 | function sendUpdateMessage(text) { 17 | mainWindow.webContents.send('update-message', text) 18 | } 19 | 20 | let message = { 21 | error: '检查更新出错', 22 | checking: '正在检查更新……', 23 | updateAva: '检测到新版本,正在下载……', 24 | updateNotAva: '现在使用的就是最新版本,不用更新', 25 | }; 26 | 27 | //通用服务器的下载方式 28 | //const uploadUrl = packageInfo.build.publish[0].url; // 下载地址,不加后面的**.exe 29 | 30 | //github的下载包方式 31 | //let publish = packageInfo.build.publish[0]; 32 | //autoUpdater.setFeedURL(publish); 33 | 34 | autoUpdater.on('update-not-available', function (info) { 35 | sendUpdateMessage(message.updateNotAva) 36 | }); 37 | autoUpdater.on('checking-for-update', function () { 38 | sendUpdateMessage(message.checking) 39 | }); 40 | 41 | 42 | autoUpdater.on('error', function (e, msg) { 43 | mainWindow.webContents.send('update-message_error', msg) 44 | }); 45 | autoUpdater.on('update-available', function (info) { 46 | mainWindow.webContents.send('update-message_update-available', info) 47 | }); 48 | 49 | 50 | // 更新下载进度事件 51 | autoUpdater.on('download-progress', function (progressObj) { 52 | mainWindow.webContents.send('downloadProgress', progressObj) 53 | //mainWindow.setProgressBar(progress.percent / 100); 54 | }) 55 | 56 | autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) { 57 | mainWindow.webContents.send('isUpdateNow') 58 | }); 59 | 60 | //下载完成,开始更新 61 | ipcMain.on('isUpdateNow', () => { 62 | autoUpdater.quitAndInstall(); 63 | }); 64 | 65 | //执行下载更新 66 | ipcMain.on("downloadUpdate",()=>{ 67 | autoUpdater.downloadUpdate() 68 | }) 69 | 70 | //执行自动更新检查 71 | ipcMain.on("checkForUpdate",()=>{ 72 | autoUpdater.checkForUpdates(); 73 | }) 74 | } 75 | 76 | /*{ 77 | "provider": "generic", 78 | "url": "https://guoyu.link/StockInfoWatch-download/" 79 | }*/ 80 | 81 | -------------------------------------------------------------------------------- /electron-main/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-vue", 3 | "author": { 4 | "name": "guoyu", 5 | "email": "guoyumail@qq.com" 6 | }, 7 | "version": "0.0.1", 8 | "private": true, 9 | "main": "./main.js", 10 | "scripts": { 11 | "electron-dev": "cross-env NODE_ENV=development electron main.js ", 12 | "postinstall": "electron-builder install-app-deps", 13 | "rebuild": "electron-rebuild -f -w sqlite3", 14 | "electron-builder": "electron-builder" 15 | }, 16 | "dependencies": { 17 | "electron-debug": "3.0.1", 18 | "electron-updater": "4.1.2" 19 | }, 20 | "devDependencies": { 21 | "electron": "9.1.0", 22 | "electron-builder": "21.2.0", 23 | "electron-rebuild": "1.8.6", 24 | "cross-env": "6.0.0" 25 | }, 26 | "vue": { 27 | "publicPath": "./", 28 | "outputDir": "dist", 29 | "assetsDir": "", 30 | "lintOnSave": false, 31 | "runtimeCompiler": true, 32 | "productionSourceMap": false, 33 | "parallel": true 34 | }, 35 | "build": { 36 | "asar": true, 37 | "npmRebuild": false, 38 | "productName": "electron-vue", 39 | "appId": "electron-vue-appid", 40 | "directories": { 41 | "output": "../build" 42 | }, 43 | "publish": [ 44 | { 45 | "provider": "github", 46 | "url": "https://github.com", 47 | "owner": "you github name", 48 | "repo": "your repo", 49 | "private": false 50 | } 51 | ], 52 | "files": [ 53 | "./dist/**", 54 | "./icons/**", 55 | "./*.js" 56 | ], 57 | "dmg": { 58 | "contents": [ 59 | { 60 | "x": 410, 61 | "y": 150, 62 | "type": "link", 63 | "path": "/Applications" 64 | }, 65 | { 66 | "x": 130, 67 | "y": 150, 68 | "type": "file" 69 | } 70 | ] 71 | }, 72 | "mac": { 73 | "target": [ 74 | "dmg" 75 | ], 76 | "icon": "public/icons/icon.icns" 77 | }, 78 | "win": { 79 | "target": [ 80 | "nsis" 81 | ], 82 | "icon": "public/icons/icon.ico" 83 | }, 84 | "nsis": { 85 | "oneClick": false, 86 | "allowToChangeInstallationDirectory": true, 87 | "perMachine": true 88 | }, 89 | "linux": { 90 | "icon": "public/icons/icons" 91 | } 92 | }, 93 | "postcss": { 94 | "plugins": { 95 | "autoprefixer": {} 96 | } 97 | }, 98 | "browserslist": [ 99 | "> 1%", 100 | "last 2 versions" 101 | ] 102 | } 103 | -------------------------------------------------------------------------------- /electron-main/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 主进程打开electron调用该文件 3 | * */ 4 | 5 | let { app, BrowserWindow, ipcMain, globalShortcut } = require('electron') 6 | const path = require("path"); 7 | let updateHandle = require("./update") 8 | let {showTray, checkForUpdates} = require("./tray") 9 | let setHotKeyFun = require("./hotKey") 10 | 11 | //let v = require("./sqlite/sqlite_util") 12 | 13 | let isDev = process.env.NODE_ENV && process.env.NODE_ENV == 'development' 14 | let env_openChromeDevTools = !!process.env.openChromeDevTools; 15 | let isOpenDevTools = (env_openChromeDevTools || isDev) 16 | 17 | 18 | global.__main = require('path').join(__dirname, "./").replace(/\\/g, '\\\\'); 19 | 20 | /** 21 | * 托盘变量定义 22 | * @type {string} 23 | */ 24 | const trayIcon = __main + "/icons/icon.ico"; 25 | 26 | if(isOpenDevTools){ 27 | app.on('ready', () => { 28 | if(isOpenDevTools){ 29 | require('electron-debug')({showDevTools: true})//打开开发工具 30 | } 31 | }) 32 | } 33 | 34 | 35 | let mainWindow 36 | const loadUrl = "http://127.0.0.1:8080" 37 | 38 | function createWindow () { 39 | /** 40 | * Initial window options 41 | */ 42 | mainWindow = new BrowserWindow({ 43 | webPreferences: { 44 | devTools: isOpenDevTools, //Whether to enable DevTools. 45 | nodeIntegration: true,//是否完整的支持 node 46 | webSecurity: false, //设置为false则可以跨域 47 | }, 48 | height: 563, 49 | useContentSize: true, 50 | width: 1000 51 | }) 52 | 53 | mainWindow.once('ready-to-show', () => { 54 | mainWindow.show() 55 | }) 56 | 57 | mainWindow.on('closed', () => { 58 | mainWindow = null 59 | }) 60 | 61 | //最小化是隐藏 62 | mainWindow.on('minimize', () => { 63 | mainWindow.hide() 64 | }) 65 | 66 | //非开发环境隐藏工具栏 67 | if (!isOpenDevTools){ 68 | mainWindow.setMenu(null) 69 | } 70 | 71 | if(isDev) mainWindow.loadURL(loadUrl) 72 | else mainWindow.loadFile(`${__main}/dist/index.html`) 73 | 74 | //自动更新方法 75 | updateHandle(mainWindow) 76 | 77 | //快捷键 78 | setHotKeyFun(mainWindow); 79 | 80 | 81 | } 82 | 83 | app.on('ready', createWindow) 84 | 85 | app.on('window-all-closed', () => { 86 | if (process.platform !== 'darwin') { 87 | app.quit() 88 | } 89 | }) 90 | 91 | 92 | app.on('activate', () => { 93 | if (mainWindow === null) { 94 | createWindow() 95 | } 96 | }) 97 | 98 | //监听通知发送过来的消息 99 | ipcMain.on("showWindows", () => { 100 | mainWindow.show() 101 | }) 102 | 103 | 104 | 105 | //托盘设置---------------------------------------------------- 106 | function openWindow(menuItem, browserWindow, event) { 107 | mainWindow.show() 108 | } 109 | function exit(menuItem, browserWindow, event) { 110 | app.quit() 111 | } 112 | const { Menu, Tray} = require("electron") 113 | let tray = null 114 | app.on('ready', () => { 115 | 116 | //非windows系统不显示托盘 117 | let os = process.platform; 118 | if(os.indexOf("win32") == -1) return; 119 | 120 | tray = new Tray(trayIcon) 121 | const contextMenu = Menu.buildFromTemplate([ 122 | { label: '打开主界面', type: 'normal', checked: true, click: openWindow}, 123 | { label: '检查更新', type: 'normal', checked: true, click: checkForUpdates}, 124 | { label: '退出', type: 'normal', checked: true , click: exit}, 125 | ]) 126 | tray.setToolTip('单击打开主界面,或者右击选择退出') 127 | tray.setContextMenu(contextMenu) 128 | tray.on("click", function (event, bounds) { 129 | openWindow() 130 | }) 131 | }) 132 | //托盘设置---------------------------------------------------- 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /vue/src/assets/js/update.js: -------------------------------------------------------------------------------- 1 | const packageInfo = require('../../../package.json'); 2 | 3 | /** 4 | * 升级方法 5 | * @param _this 6 | */ 7 | export const update = function(_this){ 8 | 9 | _this.$electron.ipcRenderer.on("update-message", function(e, msg) { 10 | console.log("更新消息", e, msg); 11 | _this.tips = msg; 12 | //alert(text) 13 | }); 14 | 15 | _this.$electron.ipcRenderer.on("downloadProgress", function(e, msg) { 16 | console.log("更新消息-下载进度", e, msg); 17 | //alert("下载进度: "+ progressObj.percent / 100); 18 | //_this.downloadPercent = progressObj.percent || 0; 19 | }); 20 | 21 | _this.$electron.ipcRenderer.on("update-message_error", function(e, msg) { 22 | console.log("更新消息-发生错误", e, msg); 23 | let html = `

检查新版本出错, 是否重新检测?

` 24 | + `

错误信息: ${msg}

`; 25 | _this.$confirm(html, '升级提示', { 26 | confirmButtonText: '确定', 27 | cancelButtonText: '取消', 28 | center: true, 29 | type: 'error', 30 | closeOnClickModal: false, 31 | dangerouslyUseHTMLString: true, 32 | }).then(function () { 33 | _this.$electron.ipcRenderer.send("checkForUpdate") 34 | }); 35 | }); 36 | 37 | _this.$electron.ipcRenderer.on("isUpdateNow", function(e, msg) { 38 | console.log("更新消息-下载到新版本", e, msg); 39 | 40 | _this.$alert('已经成功为您下载新版本,将在您重启应用后自动安装!', '升级成功提示', { 41 | confirmButtonText: '我知道了', 42 | }); 43 | 44 | /*_this.$confirm(`已经为您成功下载到新版本,是否现在开始安装,或者在您重启应用后,应用自动安装?`, '升级提示', { 45 | confirmButtonText: '现在安装', 46 | cancelButtonText: '我知道了', 47 | center: true, 48 | type: 'success' 49 | }).then(function () { 50 | _this.$electron.ipcRenderer.send("isUpdateNow"); 51 | });*/ 52 | }); 53 | 54 | _this.$electron.ipcRenderer.on("update-message_update-available", function(e, msg) { 55 | console.log("更新消息-检测到新版本", e, msg); 56 | 57 | //非windows版本自已去手动下载 58 | let os = process.platform; 59 | if(os.indexOf("win32") == -1){ 60 | 61 | let publish = packageInfo.build.publish[0]; 62 | let fullPath = `${publish.url}/${publish.owner}/${publish.repo}/releases/download/v${msg.version}/${msg.path}` 63 | 64 | //let fullPath = msg["full-path"]; 65 | let html = `检测到新版本: ${msg.version}` 66 | if(!fullPath) { 67 | html += " 但更新链接不完整,请联系开发者进行维护" 68 | _this.$alert(html, '升级提示', { 69 | dangerouslyUseHTMLString: true 70 | }); 71 | return; 72 | } 73 | html += `
请点击或者复制下列链接去下载并安装程序 ${fullPath}` 74 | _this.$alert(html, '升级提示', { 75 | dangerouslyUseHTMLString: true 76 | }); 77 | return 78 | } 79 | 80 | _this.$confirm(`检测到新版本: ${msg.version} 是否现在开始下载?`, '升级提示', { 81 | closeOnClickModal: false, 82 | confirmButtonText: '确定', 83 | cancelButtonText: '取消', 84 | center: true, 85 | type: 'warning' 86 | }).then(function () { 87 | _this.$electron.ipcRenderer.send("downloadUpdate"); 88 | }); 89 | }); 90 | 91 | checkForUpdate(_this) 92 | } 93 | 94 | let isDev = process.env.NODE_ENV == 'development' 95 | let checkForUpdate = function (_this) { 96 | if(isDev) { 97 | console.warn("开发环境不检测更新") 98 | return; 99 | } 100 | function check() { 101 | _this.$electron.ipcRenderer.send("checkForUpdate"); 102 | } 103 | setTimeout(check, 60*1000) 104 | //setInterval(check, 1000*60*60*6) 105 | } 106 | --------------------------------------------------------------------------------