Skip to content

Commit

Permalink
feat: 删除应用内更新功能
Browse files Browse the repository at this point in the history
改为通过 GitHub API 检测更新,用户选择更新时跳转第三方下载页面。
  • Loading branch information
typed-sigterm committed Oct 2, 2024
1 parent 7b2c43d commit c3681af
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 458 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
contents: write
runs-on: ${{ matrix.platform }}
needs: sync-latest-branch
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}

strategy:
fail-fast: false
Expand Down Expand Up @@ -118,5 +116,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ steps.get-release.outputs.result }}
updaterJsonKeepUniversal: true
args: --target ${{matrix.target}}
1 change: 0 additions & 1 deletion 3rd-party-licenses.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
| [`@tauri-apps/plugin-dialog`,<br>`tauri-plugin-dialog`](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/dialog) | [MIT License](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/dialog/LICENSE_MIT) ||
| [`@tauri-apps/plugin-fs`,<br>`tauri-plugin-fs`](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/fs) | [MIT License](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/fs/LICENSE_MIT) ||
| [`@tauri-apps/plugin-shell`,<br>`tauri-plugin-shell`](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell) | [MIT License](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/LICENSE_MIT) ||
| [`@tauri-apps/plugin-updater`,<br>`tauri-plugin-updater`](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/updater) | [MIT License](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/updater/LICENSE_MIT) ||
| [`@typed-sigterm/eslint-config`](https://github.com/typed-sigterm/eslint-config) | [MIT License](https://github.com/unocss/unocss/blob/main/LICENSE) ||
| [`@unocss/nuxt`](https://unocss.dev/) | [MIT License](https://github.com/unocss/unocss/blob/main/LICENSE) ||
| [`@vueuse/nuxt`](https://github.com/vueuse/vueuse) | [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE) ||
Expand Down
6 changes: 3 additions & 3 deletions app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const locale = computed(() => {
// 动画和事件
promiseTimeout(1500).then(() => loading.value = false);
promiseTimeout(1850).then(() => {
promiseTimeout(1850).then(async () => {
bus.emit('login');
bus.emit('check-update');
show.value = true;
triggerWelcomeGuide();
await triggerWelcomeGuide();
bus.emit('check-update');
});
</script>

Expand Down
38 changes: 38 additions & 0 deletions app/components/changelog-wrapper.vue
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>
32 changes: 4 additions & 28 deletions app/components/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { t } = useI18n({ useScope: 'local' });
</script>

<template>
<NAlert v-if="__CANARY__" type="info">
<NAlert v-if="__CANARY__" type="info" class="mb-4">
<I18nT keypath="canary-tip">
<a
:href="`${GITHUB_REPO_URL}/blob/main/CHANGELOG.md`"
Expand All @@ -18,35 +18,11 @@ const { t } = useI18n({ useScope: 'local' });
{{ t('build-time') }}
<NTime :time="useRuntimeConfig().public.buildTime" />
</NAlert>
<ChangelogMd />
<ChangelogWrapper>
<ChangelogMd />
</ChangelogWrapper>
</template>

<style lang="postcss" scoped>
: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>

<i18n lang="yaml">
en:
canary-tip: For the latest changes in the canary version, please visit {0}.
Expand Down
8 changes: 6 additions & 2 deletions app/components/settings/footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ function checkUpdate() {
return;
checkingUpdate.value = true;
const handleUpdateChecked = () => {
checkingUpdate.value = false;
const handleUpdateChecked = (available: boolean) => {
bus.off('update-checked', handleUpdateChecked);
checkingUpdate.value = false;
if (!available)
ui.message.success(t('no-update'));
};
bus.on('update-checked', handleUpdateChecked);
bus.emit('check-update');
Expand Down Expand Up @@ -143,6 +145,7 @@ en:
changelog: Changelog
changelog-title: ExCaller Changelog
check-update: Check Update
no-update: Already up to date
feedback:
title: Send Feedback
desc:
Expand All @@ -169,6 +172,7 @@ zh-CN:
changelog: 更新记录
changelog-title: ExCaller 更新记录
check-update: 检查更新
no-update: 已是最新版本
feedback:
title: 提交反馈
desc: 如果您在使用 ExCaller 时有任何问题或建议,欢迎反馈给我们。
Expand Down
108 changes: 30 additions & 78 deletions app/components/updater.vue
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)) {

Check failure on line 16 in app/components/updater.vue

View workflow job for this annotation

GitHub Actions / 类型检查

'res' is of type 'unknown'.
update.value = res;
changelog.value = mdit.render(res.body);

Check failure on line 18 in app/components/updater.vue

View workflow job for this annotation

GitHub Actions / 类型检查

'res' is of type 'unknown'.
}
} 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>
2 changes: 2 additions & 0 deletions app/utils/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { version } from '~~/package.json';
import { reactive } from 'vue';

export const GITHUB_REPO_URL = 'https://github.com/typed-sigterm/ex-caller';
export const GITHUB_RELEASE_API_URL = 'https://api.github.com/repos/typed-sigterm/ex-caller/releases/latest';
export const WEB_APP_URL = 'https://ex-caller.by-ts.top';

/** 是否正式生产环境 */
export const __GA__ = import.meta.env.PROD && !import.meta.env.EXC_CANARY;
Expand Down
5 changes: 0 additions & 5 deletions app/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ export const bus = mitt<{
* @param 是否有新版本
*/
'update-checked': boolean
/**
* 忽略更新
* @param 忽略的版本号
*/
'dismiss-update': string
}>();
28 changes: 16 additions & 12 deletions app/utils/guide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,26 @@ const getElement = (id: string) => document.querySelector(`[data-guide-id="${id}
* 若教程未完成,开始教程,完成教程后标记为已完成。
* @param name 教程名称
* @param options driver 配置
* @returns 一个 `Promise`,教程完成后 resolve
*/
function drive(name: keyof Guide, options: Config) {
if (!shouldStartGuide(name))
return;
const driver = createDriver({
...options,
onDestroyed(...args) {
markGuideAsStarted(name);
options.onDeselected?.(...args);
},
return Promise.resolve();
return new Promise<void>((resolve) => {
const driver = createDriver({
...options,
onDestroyed(...args) {
markGuideAsDone(name);
resolve();
options.onDeselected?.call(this, ...args);
},
});
driver.drive();
});
driver.drive();
}

export function triggerWelcomeGuide() {
drive('welcome', {
return drive('welcome', {
steps: [{
popover: getGuidePopover('welcome.0'),
}, {
Expand All @@ -69,7 +73,7 @@ export function triggerWelcomeGuide() {
}

export function triggerStopRollingGuide() {
drive('stopRolling', {
return drive('stopRolling', {
steps: [{
element: getElement('result-board'),
popover: getGuidePopover('stopRolling.0'),
Expand All @@ -78,7 +82,7 @@ export function triggerStopRollingGuide() {
}

export function triggerNamelistGuide() {
drive('namelist', {
return drive('namelist', {
steps: [{
element: getElement('namelist-drawer'),
popover: getGuidePopover('namelist.0'),
Expand All @@ -93,7 +97,7 @@ export function triggerNamelistGuide() {
}

export function triggerPlanGuide() {
drive('plan', {
return drive('plan', {
steps: [{
element: getElement('plan-drawer'),
popover: getGuidePopover('plan.0'),
Expand Down
2 changes: 1 addition & 1 deletion app/utils/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function shouldStartGuide(key: keyof Guide) {
return !useGuideStore()[key];
}
/** 标记教程为已完成。 */
export function markGuideAsStarted(key: keyof Guide) {
export function markGuideAsDone(key: keyof Guide) {
useGuideStore().$patch({ [key]: true });
}

Expand Down
Loading

0 comments on commit c3681af

Please sign in to comment.