exe自更新
This commit is contained in:
parent
1b4ce1966f
commit
719cb4bda2
3 changed files with 198 additions and 5 deletions
|
@ -4,6 +4,7 @@ import Launch from '@/pages/Launch.vue'
|
|||
import Update from '@/pages/Update.vue'
|
||||
import Fix from '@/pages/Fix.vue'
|
||||
import { dateZhCN, zhCN } from 'naive-ui'
|
||||
import Settings from '@/pages/Settings.vue'
|
||||
|
||||
const loading = ref(true)
|
||||
const page = ref(null)
|
||||
|
@ -15,6 +16,14 @@ function load_config() {
|
|||
})
|
||||
}
|
||||
|
||||
async function init_version() {
|
||||
version.value = await pywebview.api.get_version()
|
||||
new_version.value = await pywebview.api.get_new_version()
|
||||
if (new_version.value.tag_name > version.value) {
|
||||
update_able.value = true
|
||||
}
|
||||
}
|
||||
|
||||
const log = ref('')
|
||||
provide('log', log)
|
||||
const log_ele = ref(null)
|
||||
|
@ -28,8 +37,12 @@ watch(log, () => {
|
|||
onMounted(() => {
|
||||
if (window.pywebview && pywebview.api) {
|
||||
load_config()
|
||||
init_version()
|
||||
} else {
|
||||
window.addEventListener('pywebviewready', load_config)
|
||||
window.addEventListener('pywebviewready', () => {
|
||||
load_config()
|
||||
init_version()
|
||||
})
|
||||
}
|
||||
window.addEventListener('log', (e) => {
|
||||
log.value += e.detail.log
|
||||
|
@ -46,6 +59,15 @@ provide('running', running)
|
|||
|
||||
const steps = ref([])
|
||||
provide('steps', steps)
|
||||
|
||||
const update_able = ref(false)
|
||||
provide('update_able', update_able)
|
||||
|
||||
const version = ref('')
|
||||
provide('version', version)
|
||||
|
||||
const new_version = ref({})
|
||||
provide('new_version', new_version)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -65,6 +87,15 @@ provide('steps', steps)
|
|||
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
|
||||
<n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane>
|
||||
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
|
||||
<n-tab-pane :disabled="running" name="settings">
|
||||
<template #tab>
|
||||
<n-space :wrap="false">
|
||||
设置
|
||||
<n-tag v-if="update_able" round type="success">新</n-tag>
|
||||
</n-space>
|
||||
</template>
|
||||
<settings />
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
</n-notification-provider>
|
||||
<n-global-style />
|
||||
|
|
88
ui/src/pages/Settings.vue
Normal file
88
ui/src/pages/Settings.vue
Normal file
|
@ -0,0 +1,88 @@
|
|||
<script setup>
|
||||
import { SyncCircle } from '@vicons/ionicons5'
|
||||
|
||||
const notification = useNotification()
|
||||
|
||||
const update_able = inject('update_able')
|
||||
const running = inject('running')
|
||||
const version = inject('version')
|
||||
const new_version = inject('new_version')
|
||||
|
||||
const branch = ref(null)
|
||||
const mirror = ref(null)
|
||||
const check_running = ref(false)
|
||||
const update_self_running = ref(false)
|
||||
|
||||
async function update_self() {
|
||||
running.value = true
|
||||
update_self_running.value = true
|
||||
const response = await pywebview.api.update_self(new_version.value['assets'][0]['browser_download_url'])
|
||||
notification['error']({
|
||||
content: '错误',
|
||||
meta: response,
|
||||
duration: 3000
|
||||
})
|
||||
update_self_running.value = false
|
||||
running.value = false
|
||||
}
|
||||
|
||||
async function open_new_version_html() {
|
||||
window.open(new_version.value['html_url'])
|
||||
}
|
||||
|
||||
async function check_update() {
|
||||
running.value = true
|
||||
check_running.value = true
|
||||
new_version.value = await pywebview.api.get_new_version()
|
||||
if(new_version.value.tag_name > version.value){
|
||||
update_able.value = true
|
||||
notification['info']({
|
||||
content: '提示',
|
||||
meta: "有新版本可更新",
|
||||
duration: 3000
|
||||
})
|
||||
}else{
|
||||
update_able.value = false
|
||||
notification['info']({
|
||||
content: '提示',
|
||||
meta: "当前已是最新版本",
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
check_running.value = false
|
||||
running.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
|
||||
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
|
||||
<n-form-item label="版本">
|
||||
<n-space align="center">
|
||||
{{version}}
|
||||
<n-button type="success" :loading="check_running" :disabled="running" @click="check_update">
|
||||
<template #icon>
|
||||
<n-icon :component="SyncCircle"></n-icon>
|
||||
</template>
|
||||
检查更新
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
<n-alert
|
||||
style="margin: 8px 0"
|
||||
type="success"
|
||||
v-if="update_able"
|
||||
>
|
||||
<template #header>
|
||||
最新版本:{{new_version.name}}
|
||||
<n-button style="float: right" @click="open_new_version_html">了解此版本</n-button>
|
||||
</template>
|
||||
<n-space>
|
||||
<n-button type="success" :loading="update_self_running" :disabled="running" @click="update_self">
|
||||
立即更新
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-alert>
|
||||
</n-form>
|
||||
</n-flex>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue