Skip to content

Commit 76efbaf

Browse files
committed
fix: correct mod enable status display after import
1 parent 4f47dd4 commit 76efbaf

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

frontend/src/pages/ModsPage.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ export const ModsPage: React.FC = () => {
219219
}
220220
};
221221

222+
const refreshModsAndStates = async (name: string) => {
223+
for (let i = 0; i < 4; i++) {
224+
try {
225+
const data = await GetMods(name);
226+
setModsInfo(data || []);
227+
await refreshEnabledStates(name);
228+
} catch {
229+
setModsInfo([]);
230+
}
231+
await new Promise((r) => setTimeout(r, 250));
232+
}
233+
};
234+
222235
useEffect(() => {
223236
const name = readCurrentVersionName();
224237
if (!name) {
@@ -420,11 +433,13 @@ export const ModsPage: React.FC = () => {
420433
}
421434
const data = await GetMods(name);
422435
setModsInfo(data || []);
436+
void refreshEnabledStates(name);
423437
setResultSuccess(succFiles);
424438
setResultFailed(errPairs);
425439
if (succFiles.length > 0 || errPairs.length > 0) {
426440
errOnOpen();
427441
}
442+
await refreshEnabledStates(currentVersionName);
428443
} catch (e: any) {
429444
setErrorMsg(String(e?.message || e || "IMPORT_ERROR"));
430445
} finally {
@@ -555,8 +570,7 @@ export const ModsPage: React.FC = () => {
555570
succFiles.push(f.name);
556571
}
557572
}
558-
const data = await GetMods(currentVersionName);
559-
setModsInfo(data || []);
573+
await refreshModsAndStates(currentVersionName);
560574
setResultSuccess(succFiles);
561575
setResultFailed(errPairs);
562576
if (succFiles.length > 0 || errPairs.length > 0) {
@@ -619,6 +633,8 @@ export const ModsPage: React.FC = () => {
619633
}
620634
const data = await GetMods(name);
621635
setModsInfo(data || []);
636+
await refreshEnabledStates(name);
637+
void refreshEnabledStates(name);
622638
requestAnimationFrame(() => {
623639
try {
624640
if (scrollRef.current) scrollRef.current.scrollTop = pos;
@@ -767,8 +783,7 @@ export const ModsPage: React.FC = () => {
767783
succFiles.push(f.name);
768784
}
769785
}
770-
const data = await GetMods(currentVersionName);
771-
setModsInfo(data || []);
786+
await refreshModsAndStates(currentVersionName);
772787
setResultSuccess(succFiles);
773788
setResultFailed(errPairs);
774789
if (succFiles.length > 0 || errPairs.length > 0) {

internal/icons/icons.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package icons
22

33
import (
4-
"bytes"
5-
"os"
6-
"path/filepath"
4+
"bytes"
5+
"os"
6+
"path/filepath"
77
)
88

9-
10-
119
func writeICOFromPNG(pngData []byte, outPath string) error {
1210
b := &bytes.Buffer{}
1311
b.Write([]byte{0x00, 0x00})
@@ -30,21 +28,21 @@ func writeICOFromPNG(pngData []byte, outPath string) error {
3028
}
3129

3230
func EnsureVersionIcon(versionDir string, _ bool) string {
33-
srcPng := filepath.Join(versionDir, "LargeLogo.png")
34-
icoPath := filepath.Join(versionDir, "LargeLogo.ico")
35-
if fi, err := os.Stat(srcPng); err == nil && !fi.IsDir() {
36-
need := false
37-
if si, e := os.Stat(icoPath); e != nil || si.Size() == 0 || fi.ModTime().After(si.ModTime()) {
38-
need = true
39-
}
40-
if need {
41-
if data, er := os.ReadFile(srcPng); er == nil {
42-
_ = writeICOFromPNG(data, icoPath)
43-
}
44-
}
45-
if _, e := os.Stat(icoPath); e == nil {
46-
return icoPath
47-
}
48-
}
49-
return ""
31+
srcPng := filepath.Join(versionDir, "LargeLogo.png")
32+
icoPath := filepath.Join(versionDir, "LargeLogo.ico")
33+
if fi, err := os.Stat(srcPng); err == nil && !fi.IsDir() {
34+
need := false
35+
if si, e := os.Stat(icoPath); e != nil || si.Size() == 0 || fi.ModTime().After(si.ModTime()) {
36+
need = true
37+
}
38+
if need {
39+
if data, er := os.ReadFile(srcPng); er == nil {
40+
_ = writeICOFromPNG(data, icoPath)
41+
}
42+
}
43+
if _, e := os.Stat(icoPath); e == nil {
44+
return icoPath
45+
}
46+
}
47+
return ""
5048
}

0 commit comments

Comments
 (0)