|
1 | | -import { defineComponent, ref } from 'vue'; |
2 | | - |
| 1 | +import { defineComponent, ref, computed } from 'vue'; |
3 | 2 | import { globalCapture, modInfo, updateModInfo } from "@/store/refs"; |
4 | 3 | import { modUpdateInfo } from "@/store/appUpdate"; |
5 | 4 | import api from "@/client/api"; |
6 | | -import { latestVersion } from './shouldShowUpdateController'; |
7 | 5 | import { useI18n } from 'vue-i18n'; |
8 | | -import { Button } from '@munet/ui'; |
| 6 | +import { Button, DropMenu } from '@munet/ui'; |
9 | 7 | import { useAsyncState } from '@vueuse/core'; |
10 | 8 | import { updateAquaMaiConfig } from './refs'; |
| 9 | + |
11 | 10 | export default defineComponent({ |
12 | 11 | setup() { |
13 | | - const showAquaMaiInstallDone = ref(false) |
| 12 | + const showDone = ref(false); |
14 | 13 | const { t } = useI18n(); |
15 | | - const { isLoading: installingAquaMai, execute: installAquaMai } = useAsyncState(async () => { |
16 | | - const type = latestVersion.value.type; |
17 | | - console.log(type) |
18 | | - // 但是你根本看不到这个加载图标,因为太快了 |
19 | | - if (type === 'builtin') { |
20 | | - await api.InstallAquaMai() |
21 | | - } else { |
22 | | - const version = modUpdateInfo.value?.find(it => it.type === type); |
23 | | - if (!version) { |
24 | | - throw new Error(t('mod.versionNotFound')); |
25 | | - } |
26 | | - const urls = [version.url!]; |
27 | | - if (version.url2) { |
28 | | - urls.push(version.url2); |
| 14 | + const installType = ref<'builtin' | 'slow' | 'ci' | 'mumod'>('slow'); |
| 15 | + |
| 16 | + const { isLoading: installing, execute: doInstallAsync } = useAsyncState( |
| 17 | + async () => { |
| 18 | + const type = installType.value; |
| 19 | + if (type === 'mumod') { |
| 20 | + await api.InstallMuMod(); |
| 21 | + } else if (type === 'builtin') { |
| 22 | + await api.InstallAquaMai(); |
| 23 | + } else { |
| 24 | + const version = modUpdateInfo.value?.find(it => it.type === type); |
| 25 | + if (!version) throw new Error(t('mod.versionNotFound')); |
| 26 | + const urls = [version.url!]; |
| 27 | + if (version.url2) urls.push(version.url2); |
| 28 | + await api.InstallAquaMaiOnline({ type, urls, sign: version.sign }); |
29 | 29 | } |
30 | | - await api.InstallAquaMaiOnline({ |
31 | | - type, |
32 | | - urls, |
33 | | - sign: version.sign, |
34 | | - }); |
| 30 | + await updateModInfo(); |
| 31 | + await updateAquaMaiConfig(); |
| 32 | + showDone.value = true; |
| 33 | + setTimeout(() => (showDone.value = false), 3000); |
| 34 | + }, |
| 35 | + undefined, |
| 36 | + { |
| 37 | + immediate: false, |
| 38 | + onError: (e: any) => globalCapture(e, t('mod.installFailed')), |
35 | 39 | } |
36 | | - await updateModInfo() |
37 | | - await updateAquaMaiConfig() |
38 | | - showAquaMaiInstallDone.value = true |
39 | | - setTimeout(() => showAquaMaiInstallDone.value = false, 3000); |
40 | | - }, undefined, { |
41 | | - immediate: false, |
42 | | - onError: (e: any) => globalCapture(e, t('mod.installFailed')), |
43 | | - }) |
44 | | - |
45 | | - return () => |
46 | | - <Button ing={installingAquaMai.value} onClick={() => installAquaMai()}> |
47 | | - {showAquaMaiInstallDone.value ? <span class="i-material-symbols-done" /> : modInfo.value?.aquaMaiInstalled ? t('mod.reinstallUpdate') : t('mod.install')} |
48 | | - </Button> |
| 40 | + ); |
| 41 | + |
| 42 | + const doInstall = (type: 'builtin' | 'slow' | 'ci' | 'mumod') => { |
| 43 | + installType.value = type; |
| 44 | + doInstallAsync(0); |
| 45 | + }; |
| 46 | + |
| 47 | + const formatVersionDesc = (type: string) => { |
| 48 | + const entry = modUpdateInfo.value?.find(it => it.type === type); |
| 49 | + if (!entry?.version) return ''; |
| 50 | + const date = entry.createdAt ? new Date(entry.createdAt).toLocaleDateString() : ''; |
| 51 | + return date ? `v${entry.version} · ${date}` : `v${entry.version}`; |
| 52 | + }; |
| 53 | + |
| 54 | + const installChannel = (type: 'slow' | 'ci') => { |
| 55 | + const hasOnlineVersion = modUpdateInfo.value?.find(it => it.type === type && it.url); |
| 56 | + if (hasOnlineVersion) { |
| 57 | + doInstall(type); |
| 58 | + } else { |
| 59 | + doInstall('builtin'); |
| 60 | + } |
| 61 | + }; |
| 62 | + |
| 63 | + const options = computed(() => [ |
| 64 | + { |
| 65 | + label: t('mod.stableChannel'), |
| 66 | + desc: formatVersionDesc('slow'), |
| 67 | + action: () => installChannel('slow'), |
| 68 | + }, |
| 69 | + { |
| 70 | + label: t('mod.fastChannel'), |
| 71 | + desc: formatVersionDesc('ci'), |
| 72 | + action: () => installChannel('ci'), |
| 73 | + }, |
| 74 | + { |
| 75 | + label: 'MuMod', |
| 76 | + desc: t('mod.mumodDesc'), |
| 77 | + action: () => doInstall('mumod'), |
| 78 | + }, |
| 79 | + ]); |
| 80 | + |
| 81 | + return () => ( |
| 82 | + <DropMenu options={options.value} align="right"> |
| 83 | + {{ |
| 84 | + trigger: (onClick: any) => ( |
| 85 | + <Button ing={installing.value} onClick={onClick}> |
| 86 | + {showDone.value |
| 87 | + ? <span class="i-material-symbols-done" /> |
| 88 | + : modInfo.value?.aquaMaiInstalled || modInfo.value?.muModInstalled |
| 89 | + ? t('mod.reinstallUpdate') |
| 90 | + : t('mod.install')} |
| 91 | + </Button> |
| 92 | + ), |
| 93 | + }} |
| 94 | + </DropMenu> |
| 95 | + ); |
49 | 96 | }, |
50 | 97 | }); |
0 commit comments