diff --git a/resources/dist.rc b/resources/dist.rc index 2e847f5..d4b1907 100644 Binary files a/resources/dist.rc and b/resources/dist.rc differ diff --git a/src/celemod-ui/src/context/modManage.tsx b/src/celemod-ui/src/context/modManage.tsx index fb2b83b..144475c 100644 --- a/src/celemod-ui/src/context/modManage.tsx +++ b/src/celemod-ui/src/context/modManage.tsx @@ -1,10 +1,11 @@ import _i18n, { useI18N } from 'src/i18n'; import { callRemote } from '../utils'; import { - useInstalledMods, - useGamePath, - useStorage, - initGamePath, + useInstalledMods, + useGamePath, + useStorage, + initGamePath, + useCurrentEverestVersion, } from '../states'; import { useEffect, useMemo } from 'preact/hooks'; import { createPopup } from 'src/components/Popup'; @@ -13,81 +14,87 @@ import { ProgressIndicator } from 'src/components/Progress'; let lastGamePath = ''; export const createModManageContext = () => { - const { setInstalledMods } = useInstalledMods(); + const { setInstalledMods } = useInstalledMods(); - const [gamePath] = useGamePath(); - const { storage, save } = useStorage(); + const [gamePath] = useGamePath(); - useEffect(() => { - if (!gamePath) return; - if (!storage) return; + const { storage, save } = useStorage(); - storage.root ??= {}; - storage.root.lastGamePath = gamePath; - console.log('saving game path', gamePath); - save(); - }, [gamePath, storage]); + useEffect(() => { + if (!gamePath) return; + if (!storage) return; - initGamePath(); + storage.root ??= {}; + storage.root.lastGamePath = gamePath; + console.log('saving game path', gamePath); + save(); + }, [gamePath, storage]); - const ctx = { - reloadMods: () => { - return new Promise((rs, rj) => { - if (!gamePath) { - console.warn('game path not set'); - rj('game path not set'); - return; - } - callRemote('get_installed_mods', gamePath + '/Mods', (data: string) => { - console.log('mod reload finished'); - const da = JSON.parse(data); - rs(da); - setInstalledMods(da); - }); - }); - }, - gamePath, - modsPath: gamePath + '/Mods', - }; + initGamePath(); + + const ctx = { + reloadMods: () => { + return new Promise((rs, rj) => { + if (!gamePath) { + console.warn('game path not set'); + rj('game path not set'); + return; + } + callRemote('get_installed_mods', gamePath + '/Mods', (data: string) => { + console.log('mod reload finished'); + const da = JSON.parse(data); + rs(da); + setInstalledMods(da); + }); + }); + }, + gamePath, + modsPath: gamePath + '/Mods', + }; - // WHY THE FUCK useEffect doesn't trigger here - if (lastGamePath !== gamePath) { - lastGamePath = gamePath; + // WHY THE FUCK useEffect doesn't trigger here + if (lastGamePath !== gamePath) { + lastGamePath = gamePath; - if (gamePath) { - setTimeout(() => { - const popup = createPopup( - () => { - return ( -
- - {_i18n.t('正在加载 Mod 列表,请稍等')} -
- ); - }, - { - cancelable: false, - } - ); - ctx - .reloadMods() - .then(() => popup.hide()) - .catch((e) => { - popup.hide(); - createPopup(() => { - return ( -
-

{_i18n.t('加载 Mod 列表失败')}

-

{_i18n.t('请检查游戏路径是否正确,或网络连接是否正常')}

-

{_i18n.t('部分功能将不可用')}

-

{e}

-
- ); + if (gamePath) { + + callRemote("get_everest_version", gamePath, (ver: string) => { + if (ver && ver.length > 2) { + setTimeout(() => { + const popup = createPopup( + () => { + return ( +
+ + {_i18n.t('正在加载 Mod 列表,请稍等')} +
+ ); + }, + { + cancelable: false, + } + ); + ctx + .reloadMods() + .then(() => popup.hide()) + .catch((e) => { + popup.hide(); + createPopup(() => { + return ( +
+

{_i18n.t('加载 Mod 列表失败')}

+

{_i18n.t('请检查游戏路径是否正确,或网络连接是否正常')}

+

{_i18n.t('部分功能将不可用')}

+

{e}

+
+ ); + }); + }); + }, 10); + } }); - }); - }, 10); + } } - } - return ctx; + return ctx; };