Skip to content

Commit 0f0f4e0

Browse files
feat: add size property to mod information and display detailed mod info in Manage component
close #32
1 parent da6c293 commit 0f0f4e0

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

resources/dist.rc

338 Bytes
Binary file not shown.

src/celemod-ui/src/routes/Manage.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,11 @@
194194
color: theme.$fg;
195195
box-shadow: 0 2px 5px #00000040;
196196
}
197+
198+
.modDetails {
199+
padding: 0 6px;
200+
font-size: 8px;
201+
color: rgba(255, 255, 255, 0.4);
202+
margin-top: 6px;
203+
}
197204
}

src/celemod-ui/src/routes/Manage.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface ModInfo {
3737
_deps: BackendDep[]; // raw deps
3838
resolveDependencies: () => DepResolveResult;
3939
file: string;
40+
size: number;
4041
duplicateCount: number;
4142
duplicateFiles: string[];
4243
}
@@ -65,6 +66,7 @@ const modListContext = createContext<{
6566
reloadMods: () => void;
6667
fullTree: boolean;
6768
showUpdate: boolean;
69+
showDetailed: boolean;
6870
alwaysOnMods: string[];
6971
switchAlwaysOn: (name: string, enabled: boolean) => void;
7072
autoDisableNewMods: boolean;
@@ -179,6 +181,7 @@ const ModLocal = ({
179181
version,
180182
optional = false,
181183
file,
184+
size,
182185
duplicateCount,
183186
duplicateFiles,
184187
}: ModInfo & { optional?: boolean }) => {
@@ -341,6 +344,10 @@ const ModLocal = ({
341344
<span
342345
className="modName"
343346
onClick={() => setEditingComment(true)}
347+
onContextMenu={(e) => {
348+
e.preventDefault();
349+
callRemote('open_url', ctx?.modFolder || '');
350+
}}
344351
>{name}</span>
345352
{!editingComment && ctx?.modComments[name] && (
346353
<span className="modComment" onClick={() => {
@@ -361,6 +368,11 @@ const ModLocal = ({
361368
}
362369

363370
<span className="modVersion">{version}</span>
371+
{ctx?.showDetailed && (
372+
<span className="modDetails">
373+
{formatSize(size)} · {file}
374+
</span>
375+
)}
364376
{(!optional || ctx?.fullTree) && expanded && (
365377
<div className={`childTree ${expanded && 'expanded'}`}>
366378
{dependencies.map((v) => (
@@ -413,6 +425,12 @@ const Profile = ({ name, current }: { name: string; current: boolean }) => {
413425
const alphabet =
414426
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- _';
415427

428+
const formatSize = (size: number) => {
429+
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
430+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
431+
return `${(size / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`;
432+
};
433+
416434
let lastApplyReq = -1;
417435

418436
export const Manage = () => {
@@ -440,6 +458,7 @@ export const Manage = () => {
440458
const [checkOptionalDep, setCheckOptionalDep] = useState(false);
441459
const [fullTree, setFullTree] = useState(false);
442460
const [showUpdate, setShowUpdate] = useState(true);
461+
const [showDetailed, setShowDetailed] = useState(false);
443462

444463
const installedModMap = useMemo(() => {
445464
const modMap = new Map<string, ModInfo>();
@@ -453,6 +472,7 @@ export const Manage = () => {
453472
dependencies: [],
454473
dependedBy: [],
455474
file: mod.file,
475+
size: mod.size,
456476
_deps: mod.deps,
457477
resolveDependencies: () => {
458478
let status = 'resolved';
@@ -858,6 +878,7 @@ export const Manage = () => {
858878
},
859879
fullTree,
860880
showUpdate,
881+
showDetailed,
861882
}),
862883
[
863884
currentProfile,
@@ -866,6 +887,7 @@ export const Manage = () => {
866887
modPath,
867888
fullTree,
868889
showUpdate,
890+
showDetailed,
869891
alwaysOnMods,
870892
modComments,
871893
checkOptionalDep
@@ -989,6 +1011,18 @@ export const Manage = () => {
9891011

9901012
{_i18n.t('自动禁用新安装的Mod')}
9911013
</label>
1014+
<label>
1015+
<input
1016+
type="checkbox"
1017+
checked={showDetailed}
1018+
onChange={(e) => {
1019+
// @ts-ignore
1020+
setShowDetailed(e.target.checked);
1021+
}}
1022+
/>
1023+
1024+
{_i18n.t('显示详细信息')}
1025+
</label>
9921026
</div>
9931027
<div
9941028
className="opers"

src/celemod-ui/src/states.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface BackendModInfo {
6969
deps: BackendDep[],
7070
version: string,
7171
file: string,
72+
size: number,
7273
}
7374

7475
export const useInstalledMods = create<{

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct LocalMod {
100100
deps: Vec<ModDependency>,
101101
version: String,
102102
file: String,
103+
size: u64,
103104
}
104105

105106
fn read_to_string_bom(path: &Path) -> anyhow::Result<String> {
@@ -223,12 +224,15 @@ fn get_installed_mods_sync(mods_folder_path: String) -> Vec<LocalMod> {
223224
-1
224225
};
225226

227+
let size = entry.metadata()?.len();
228+
226229
mods.push(LocalMod {
227230
name,
228231
version,
229232
game_banana_id: gbid,
230233
deps,
231234
file: entry.file_name().to_str().unwrap().to_string(),
235+
size,
232236
});
233237
};
234238

0 commit comments

Comments
 (0)