This commit is contained in:
zhanggy committed 2025-11-05 14:46:49 +08:00
1 parent fc250c54ed
commit 5eec516459
62 files changed
+3912 -3376

No files matched your search

+97 -93
View File
@@ -1,3 +1,88 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { useAppStore } from '@/renderer/store/app';
const { t } = useI18n();
const appStore = useAppStore();
// 从store获取状态
const updateStatus = computed(() => appStore.updateStatus);
const downloadProgress = computed(() => appStore.downloadProgress);
// 对话框显示状态
const dialogVisible = computed({
get: () => {
return appStore.updateDialogVisible
|| updateStatus.value.status === 'available'
|| updateStatus.value.status === 'downloading'
|| updateStatus.value.status === 'downloaded'
|| (updateStatus.value.status === 'error' && !!updateStatus.value.error);
},
set: (value: boolean) => {
if (value) {
appStore.showUpdateDialog();
} else {
appStore.hideUpdateDialog();
}
},
});
const latestVersion = computed(() => {
// 这里应该从API获取最新版本号,暂时使用固定值
return `v${(updateStatus.value.currentVersion || '1.0.0').replace(/^v?/, '').split('.').map((n, i) =>
i === 2 ? (Number.parseInt(n) + 1).toString() : n,
).join('.')}`;
});
const isDownloading = computed(() => updateStatus.value.status === 'downloading');
const isDownloadComplete = computed(() => downloadProgress.value >= 100);
// 方法
const downloadUpdate = async () => {
await appStore.startUpdateDownload();
};
const skipUpdate = () => {
appStore.setUpdateStatus('not-available', updateStatus.value.currentVersion);
dialogVisible.value = false;
};
const cancelDownload = () => {
// 取消下载逻辑
appStore.setUpdateStatus('not-available', updateStatus.value.currentVersion);
dialogVisible.value = false;
};
const laterInstall = () => {
dialogVisible.value = false;
};
const installUpdate = () => {
// 安装更新,这需要触发quitAndInstall
window.mainApi.invoke('msgInstallUpdate');
dialogVisible.value = false;
};
const closeDialog = () => {
appStore.setUpdateStatus('idle');
dialogVisible.value = false;
};
// 监听更新下载进度
onMounted(() => {
// 监听主进程发来的更新相关事件
window.mainApi.on('update-download-progress', (_, progress) => {
appStore.setDownloadProgress(progress.percent);
});
});
onUnmounted(() => {
// 移除事件监听器
window.mainApi.off('update-download-progress', () => {});
});
</script>
<template>
<v-dialog
v-model="dialogVisible"
@@ -12,10 +97,12 @@
<v-card-text>
<div>{{ t('update.currentVersion') }}: {{ updateStatus.currentVersion }}</div>
<div>{{ t('update.latestVersion') }}: {{ latestVersion }}</div>
<div class="mt-3">{{ t('update.updateDescription') }}</div>
<div class="mt-3">
{{ t('update.updateDescription') }}
</div>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-spacer />
<v-btn
color="primary"
variant="text"
@@ -26,8 +113,8 @@
<v-btn
color="primary"
variant="flat"
@click="downloadUpdate"
:loading="isDownloading"
@click="downloadUpdate"
>
{{ t('update.downloadUpdate') }}
</v-btn>
@@ -47,15 +134,17 @@
>
<strong>{{ Math.round(downloadProgress) }}%</strong>
</v-progress-linear>
<div class="mt-3">{{ t('update.downloadProgressText') }}</div>
<div class="mt-3">
{{ t('update.downloadProgressText') }}
</div>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-spacer />
<v-btn
color="primary"
variant="text"
@click="cancelDownload"
:disabled="isDownloadComplete"
@click="cancelDownload"
>
{{ t('common.cancel') }}
</v-btn>
@@ -70,7 +159,7 @@
{{ t('update.updateReadyToInstall') }}
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-spacer />
<v-btn
color="primary"
variant="text"
@@ -96,7 +185,7 @@
{{ updateStatus.error }}
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-spacer />
<v-btn
color="primary"
variant="flat"
@@ -108,88 +197,3 @@
</v-card>
</v-dialog>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted } from 'vue'
import { useAppStore, UpdateStatus } from '@/renderer/store/app'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const appStore = useAppStore()
// 从store获取状态
const updateStatus = computed(() => appStore.updateStatus)
const downloadProgress = computed(() => appStore.downloadProgress)
// 对话框显示状态
const dialogVisible = computed({
get: () => {
return appStore.updateDialogVisible ||
updateStatus.value.status === 'available' ||
updateStatus.value.status === 'downloading' ||
updateStatus.value.status === 'downloaded' ||
(updateStatus.value.status === 'error' && !!updateStatus.value.error)
},
set: (value: boolean) => {
if (value) {
appStore.showUpdateDialog()
} else {
appStore.hideUpdateDialog()
}
}
})
const latestVersion = computed(() => {
// 这里应该从API获取最新版本号,暂时使用固定值
return 'v' + (updateStatus.value.currentVersion || '1.0.0').replace(/^v?/, '').split('.').map((n, i) =>
i === 2 ? (parseInt(n) + 1).toString() : n
).join('.')
})
const isDownloading = computed(() => updateStatus.value.status === 'downloading')
const isDownloadComplete = computed(() => downloadProgress.value >= 100)
// 方法
const downloadUpdate = async () => {
await appStore.startUpdateDownload()
}
const skipUpdate = () => {
appStore.setUpdateStatus('not-available', updateStatus.value.currentVersion)
dialogVisible.value = false
}
const cancelDownload = () => {
// 取消下载逻辑
appStore.setUpdateStatus('not-available', updateStatus.value.currentVersion)
dialogVisible.value = false
}
const laterInstall = () => {
dialogVisible.value = false
}
const installUpdate = () => {
// 安装更新,这需要触发quitAndInstall
window.mainApi.invoke('msgInstallUpdate')
dialogVisible.value = false
}
const closeDialog = () => {
appStore.setUpdateStatus('idle')
dialogVisible.value = false
}
// 监听更新下载进度
onMounted(() => {
// 监听主进程发来的更新相关事件
window.mainApi.on('update-download-progress', (_, progress) => {
appStore.setDownloadProgress(progress.percent)
})
})
onUnmounted(() => {
// 移除事件监听器
window.mainApi.off('update-download-progress', () => {})
})
</script>