Skip to content

Commit c8c7178

Browse files
committed
feat(mod-ui): convert install button to DropMenu
1 parent 70d3185 commit c8c7178

3 files changed

Lines changed: 90 additions & 40 deletions

File tree

Lines changed: 84 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,97 @@
1-
import { defineComponent, ref } from 'vue';
2-
1+
import { defineComponent, ref, computed } from 'vue';
32
import { globalCapture, modInfo, updateModInfo } from "@/store/refs";
43
import { modUpdateInfo } from "@/store/appUpdate";
54
import api from "@/client/api";
6-
import { latestVersion } from './shouldShowUpdateController';
75
import { useI18n } from 'vue-i18n';
8-
import { Button } from '@munet/ui';
6+
import { Button, DropMenu } from '@munet/ui';
97
import { useAsyncState } from '@vueuse/core';
108
import { updateAquaMaiConfig } from './refs';
9+
1110
export default defineComponent({
1211
setup() {
13-
const showAquaMaiInstallDone = ref(false)
12+
const showDone = ref(false);
1413
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 });
2929
}
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')),
3539
}
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+
);
4996
},
5097
});

MaiChartManager/Front/src/views/Settings/AquaMaiSection.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { defineComponent } from "vue";
22
import { Radio } from "@munet/ui";
33
import { useI18n } from "vue-i18n";
4-
import { selectedChannel } from "@/views/ModManager/shouldShowUpdateController";
4+
import { selectedChannel, isMuModMode } from "@/views/ModManager/shouldShowUpdateController";
55

66
export default defineComponent({
77
setup() {
88
const { t } = useI18n();
99

10-
return () => (
10+
return () => {
11+
if (isMuModMode.value) return null;
12+
return (
1113
<div class="mb-6">
1214
<div class="text-lg font-semibold mb-3 text-[var(--link-color)]">AquaMai</div>
1315
<div class="rounded-xl bg-white/60 p-4 flex flex-col gap-4 border border-gray-200 border-solid">
@@ -23,6 +25,7 @@ export default defineComponent({
2325
</div>
2426
</div>
2527
</div>
26-
);
28+
);
29+
};
2730
},
2831
});
22 KB
Binary file not shown.

0 commit comments

Comments
 (0)