-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
115 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts" setup> | ||
defineProps<{ | ||
content?: string | ||
}>(); | ||
</script> | ||
|
||
<template> | ||
<div v-if="content" class="changelog-wrapper" v-html="content" /> | ||
<div v-else class="changelog-wrapper"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<style lang="css" scoped> | ||
.changelog-wrapper:deep() { | ||
h1 { | ||
display: none; | ||
+ h2 { | ||
margin-top: 0; | ||
} | ||
} | ||
h2 { | ||
text-align: center; | ||
&::before { | ||
content: 'v'; | ||
} | ||
} | ||
h3 { | ||
all: unset | ||
} | ||
ul { | ||
margin-top: 4px; | ||
margin-bottom: 4px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,65 @@ | ||
<script lang="ts" setup> | ||
import type { Update } from '@tauri-apps/plugin-updater'; | ||
import { check } from '@tauri-apps/plugin-updater'; | ||
import MarkdownIt from 'markdown-it'; | ||
import { gt, valid } from 'semver'; | ||
const { t } = useI18n({ useScope: 'local' }); | ||
const mdit = new MarkdownIt(); | ||
const loaded = ref(false); | ||
bus.on('login', () => loaded.value = true); | ||
const update = ref<Update | null>(null); | ||
const showUpdateInfoModal = ref(false); | ||
const showDownloadModal = ref(false); | ||
const update = ref<any>(); | ||
const changelog = ref<string>(''); | ||
async function checkUpdate() { | ||
if (!valid(VERSION)) // DEV, Canary, commit id 等作为版本号时不检查更新 | ||
return; | ||
try { | ||
update.value = await check(); | ||
showUpdateInfoModal.value = true; | ||
const res = await $fetch(GITHUB_RELEASE_API_URL); | ||
if (gt(res.tag_name, VERSION)) { | ||
update.value = res; | ||
changelog.value = mdit.render(res.body); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
update.value = null; | ||
} | ||
bus.emit('update-checked', !!update.value); | ||
} | ||
bus.on('check-update', checkUpdate); | ||
const downloadStatus | ||
= ref<'idle' | 'downloading' | 'installing' | 'failed'>('idle'); | ||
const downloadedSize = ref(Number.NaN); | ||
const artifactSize = ref(Number.NaN); | ||
function startUpdate() { | ||
update.value?.downloadAndInstall((progress) => { | ||
if (progress.event === 'Started') { | ||
downloadStatus.value = 'downloading'; | ||
downloadedSize.value = 0; | ||
artifactSize.value = progress.data.contentLength ?? Number.NaN; | ||
} else if (progress.event === 'Progress') { | ||
downloadedSize.value = progress.data.chunkLength; | ||
} else { | ||
downloadStatus.value = 'installing'; | ||
showDownloadModal.value = true; | ||
} | ||
}).catch(() => { | ||
downloadStatus.value = 'failed'; | ||
}); | ||
} | ||
function cancelUpdate() { | ||
update.value?.close(); | ||
downloadStatus.value = 'idle'; | ||
downloadedSize.value = Number.NaN; | ||
artifactSize.value = Number.NaN; | ||
showDownloadModal.value = showUpdateInfoModal.value = false; | ||
function handleGo() { | ||
const to = new URL(WEB_APP_URL); | ||
to.pathname = `/update`; | ||
window.open(to.toString(), '_blank'); | ||
update.value = undefined; | ||
} | ||
</script> | ||
|
||
<template> | ||
<NModal | ||
v-if="loaded && update" | ||
v-model:show="showUpdateInfoModal" | ||
:show="!!update" | ||
preset="dialog" | ||
:title="t('title')" | ||
:title="t('title', [update?.tag_name])" | ||
type="info" | ||
:positive-text="t('start-update')" | ||
:positive-text="t('go')" | ||
:negative-text="t('skip')" | ||
@positive-click="startUpdate" | ||
@negative-click="bus.emit('dismiss-update', update!.version)" | ||
> | ||
<p> | ||
ExCaller v{{ update.currentVersion }} → | ||
<strong> | ||
v{{ update.version }} | ||
</strong> | ||
</p> | ||
<a :href="`${GITHUB_REPO_URL}/blob/main/CHANGELOG.md`" target="_blank"> | ||
{{ t('view-changelog') }} | ||
</a> | ||
</NModal> | ||
|
||
<NModal | ||
v-if="downloadStatus !== 'idle'" | ||
v-model:show="showDownloadModal" | ||
preset="dialog" | ||
:show-icon="false" | ||
:title="t('updating')" | ||
:closable="false" | ||
:negative-text="t('cancel')" | ||
@negative-click="cancelUpdate" | ||
@positive-click="handleGo" | ||
@negative-click="update = undefined" | ||
@close="update = undefined" | ||
@mask-click="update = undefined" | ||
@esc="update = undefined" | ||
> | ||
<NProgress | ||
type="line" | ||
:percentage="Math.floor(downloadedSize / artifactSize * 100)" | ||
processing | ||
/> | ||
<ChangelogWrapper :content="changelog" /> | ||
</NModal> | ||
</template> | ||
<i18n lang="yaml"> | ||
en: | ||
title: New Version Available | ||
start-update: Update Now | ||
title: New Version {0} Available | ||
go: Read More | ||
skip: Skip | ||
view-changelog: View Changelog | ||
updating: Updating | ||
zh-CN: | ||
title: 发现新版本 | ||
start-update: 立即更新 | ||
title: 发现新版本 {0} | ||
go: 查看更新 | ||
skip: 忽略 | ||
view-changelog: 查看更新内容 | ||
updating: 正在更新 | ||
</i18n> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.