mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 19:52:10 +08:00
feat: auto updater demo
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
"files": [
|
||||
"**/*",
|
||||
"!frontend/",
|
||||
"!run/",
|
||||
"!electron/",
|
||||
"!logs/",
|
||||
"!go/",
|
||||
"!python/",
|
||||
@@ -28,7 +28,7 @@
|
||||
"installerHeaderIcon": "build/icons/icon.ico",
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true,
|
||||
"shortcutName": "EE框架"
|
||||
"shortcutName": "ee"
|
||||
},
|
||||
"publish": [
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ const { logger } = require('ee-core/log');
|
||||
const { getConfig } = require('ee-core/config');
|
||||
const { frameworkService } = require('../service/framework');
|
||||
const { sqlitedbService } = require('../service/database/sqlitedb');
|
||||
const { autoUpdater } = require('../service/os/auto_updater');
|
||||
|
||||
/**
|
||||
* framework - demo
|
||||
@@ -241,6 +242,22 @@ class FrameworkController {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有新版本
|
||||
*/
|
||||
checkForUpdater() {
|
||||
autoUpdater.checkUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载新版本
|
||||
*/
|
||||
downloadApp() {
|
||||
autoUpdater.download();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试接口
|
||||
*/
|
||||
|
||||
@@ -11,9 +11,6 @@ const { getMainWindow, setCloseAndQuit } = require('ee-core/electron/window');
|
||||
*/
|
||||
class AutoUpdater {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
@@ -43,7 +40,7 @@ class AutoUpdater {
|
||||
}
|
||||
|
||||
const version = electronApp.getVersion();
|
||||
logger.info('[addon:autoUpdater] current version: ', version);
|
||||
logger.info('[autoUpdater] current version: ', version);
|
||||
|
||||
// 设置下载服务器地址
|
||||
let server = cfg.options.url;
|
||||
@@ -57,7 +54,7 @@ class AutoUpdater {
|
||||
try {
|
||||
autoUpdater.setFeedURL(cfg.options);
|
||||
} catch (error) {
|
||||
logger.error('[addon:autoUpdater] setFeedURL error : ', error);
|
||||
logger.error('[autoUpdater] setFeedURL error : ', error);
|
||||
}
|
||||
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
|
||||
85
frontend/src/views/framework/updater/Index.vue
Normal file
85
frontend/src/views/framework/updater/Index.vue
Normal file
@@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<div id="app-updater">
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
1. 自动更新
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-space>
|
||||
<a-button @click="checkForUpdater()">检查更新</a-button>
|
||||
<a-button @click="download()">下载并安装</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
2. 下载进度
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-progress :percent="percentNumber" status="active" />
|
||||
<a-space>
|
||||
{{ progress }}
|
||||
</a-space>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ipc } from '@/utils/ipcRenderer';
|
||||
import { ipcApiRoute, specialIpcRoute } from '@/api';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
const status = ref(0);
|
||||
const progress = ref('');
|
||||
const percentNumber = ref(0);
|
||||
|
||||
onMounted(() => {
|
||||
init()
|
||||
})
|
||||
|
||||
function init() {
|
||||
ipc.removeAllListeners(specialIpcRoute.appUpdater);
|
||||
ipc.on(specialIpcRoute.appUpdater, (event, result) => {
|
||||
result = JSON.parse(result);
|
||||
status.value = result.status;
|
||||
if (result.status == 3) {
|
||||
progress.value = result.desc;
|
||||
percentNumber.value = result.percentNumber;
|
||||
} else {
|
||||
message.info(result.desc);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function checkForUpdater () {
|
||||
ipc.invoke(ipcApiRoute.framework.checkForUpdater).then(r => {
|
||||
console.log(r);
|
||||
})
|
||||
}
|
||||
|
||||
function download () {
|
||||
if (status.value !== 1) {
|
||||
message.info('没有可用版本');
|
||||
return
|
||||
}
|
||||
ipc.invoke(ipcApiRoute.framework.downloadApp).then(r => {
|
||||
console.log(r);
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
#app-updater {
|
||||
padding: 0px 10px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
.one-block-1 {
|
||||
font-size: 16px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.one-block-2 {
|
||||
padding-top: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user