Skip to content

Commit 392a6d5

Browse files
committed
fix some small things
1 parent 9b22f0c commit 392a6d5

11 files changed

Lines changed: 105 additions & 101 deletions

File tree

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ pub fn run() {
8989
// utils.rs
9090
utils::show_main_window,
9191
utils::get_dir_size,
92-
utils::get_engine_mods_size,
9392
// engines.rs
9493
engines::get_engine_contexts,
9594
engines::add_engine_context,
@@ -107,4 +106,4 @@ pub fn run() {
107106
.plugin(tauri_plugin_opener::init())
108107
.run(tauri::generate_context!())
109108
.expect("Error while running tauri application");
110-
}
109+
}

src-tauri/src/utils.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn show_main_window(window: tauri::Window) {
66
}
77

88
#[tauri::command]
9-
fn get_dir_size(folder_path: String) -> u64 {
9+
pub fn get_dir_size(folder_path: String) -> u64 {
1010
fn walk(path: &std::path::Path) -> u64 {
1111
match std::fs::read_dir(path) {
1212
Err(e) => {
@@ -27,36 +27,10 @@ fn get_dir_size(folder_path: String) -> u64 {
2727
}
2828
}
2929
let path = std::path::Path::new(&folder_path);
30-
log::info!("get_dir_size called with: {:?} (exists: {})", folder_path, path.exists());
31-
walk(path)
32-
}
33-
34-
#[tauri::command]
35-
fn get_engine_mods_size(engine_folder_path: String) -> u64 {
36-
fn walk(path: &std::path::Path) -> u64 {
37-
match std::fs::read_dir(path) {
38-
Err(e) => {
39-
log::warn!("get_engine_mods_size: cannot read {:?}: {}", path, e);
40-
0
41-
}
42-
Ok(entries) => entries
43-
.filter_map(|e| e.ok())
44-
.map(|e| {
45-
let p = e.path();
46-
if p.is_dir() {
47-
walk(&p)
48-
} else {
49-
e.metadata().map(|m| m.len()).unwrap_or(0)
50-
}
51-
})
52-
.sum(),
53-
}
54-
}
55-
let mods_path = std::path::Path::new(&engine_folder_path).join("mods");
5630
log::info!(
57-
"get_engine_mods_size: scanning {:?} (exists: {})",
58-
mods_path,
59-
mods_path.exists()
31+
"get_dir_size called with: {:?} (exists: {})",
32+
folder_path,
33+
path.exists()
6034
);
61-
walk(&mods_path)
35+
walk(path)
6236
}
Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
<script setup lang="ts">
22
import { invoke } from '@tauri-apps/api/core';
3+
import { join } from '@tauri-apps/api/path';
34
import { computed, onMounted, ref, watch } from 'vue';
45
5-
interface ListDisplayInfo {
6-
canonInfo: CanonInfo;
7-
instance?: Instance;
8-
children?: ListDisplayInfo[];
9-
}
6+
import type { ListDisplayInfo } from '@core/instances';
7+
import { formatSize } from '@core/utils';
108
119
const props = defineProps<{
1210
instanceData: ListDisplayInfo;
1311
}>();
1412
1513
const totalBytes = ref<number | null>(null);
14+
const modsTotalBytes = ref<number | null>(null);
1615
const isLoading = ref(true);
1716
const hasError = ref(false);
1817
19-
function formatSize(bytes: number): string {
20-
if (bytes < 1024) return `${bytes} B`;
21-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
22-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
23-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
24-
}
25-
2618
const totalFileSize = computed(() => {
2719
if (isLoading.value) return '...';
2820
if (hasError.value || totalBytes.value === null) return 'N/A';
2921
return formatSize(totalBytes.value);
3022
});
3123
24+
const modsFileSize = computed(() => {
25+
if (isLoading.value) return '...';
26+
if (hasError.value || modsTotalBytes.value === null) return 'N/A';
27+
return formatSize(modsTotalBytes.value);
28+
});
29+
3230
const modsCount = computed(() => {
3331
if (props.instanceData.canonInfo.kind === 'engine') {
3432
return props.instanceData.canonInfo.softcode_list.length;
@@ -42,24 +40,25 @@ async function computeSize() {
4240
hasError.value = false;
4341
4442
try {
45-
if (props.instanceData.canonInfo.kind === 'engine') {
46-
// scan the engines mods/ folder directly on the rust side.
47-
// ts includes ALL mods regardless of whether they have valid modpack.ini,
48-
// so the count is always accurate even when some mods fail to parse.
43+
totalBytes.value = await invoke<number>('get_dir_size', {
44+
folderPath: props.instanceData.canonInfo.folder_path,
45+
});
4946
50-
// in summary: bypass everything and just get the folder size
51-
const size = await invoke<number>('get_engine_mods_size', {
52-
engineFolderPath: props.instanceData.canonInfo.folder_path,
53-
});
54-
totalBytes.value = size;
55-
} else {
56-
const size = await invoke<number>('get_dir_size', {
57-
folderPath: props.instanceData.canonInfo.folder_path,
47+
// If it's an engine that has mods, check the size of the mods folder as well
48+
if (
49+
props.instanceData.canonInfo.kind === 'engine' &&
50+
modsCount.value &&
51+
modsCount.value > 0
52+
) {
53+
modsTotalBytes.value = await invoke<number>('get_dir_size', {
54+
folderPath: await join(
55+
props.instanceData.canonInfo.folder_path,
56+
'mods',
57+
), // FIXME: mods folder could possibly be named differently (looking at you, Nightmarevision). Should account for that
5858
});
59-
totalBytes.value = size;
6059
}
6160
} catch (e) {
62-
console.error('[ModFriend] Failed to compute size:', e);
61+
console.error('Failed to compute size:', e);
6362
hasError.value = true;
6463
} finally {
6564
isLoading.value = false;
@@ -74,14 +73,19 @@ onMounted(computeSize);
7473
<div id="widget" class="ml-6 mr-6 text-wrap">
7574
<!-- Engine view -->
7675
<template v-if="instanceData.canonInfo.kind === 'engine'">
77-
<div class="infobar-item">
76+
<div class="infobar-item" v-if="modsCount">
7877
<span class="key">Mods Count</span>
7978
<span class="value">{{ modsCount }}</span>
8079
</div>
80+
<div class="infobar-item" v-if="modsCount && modsTotalBytes !== null">
81+
<span class="key">Mods Size</span>
82+
<span class="value">{{ modsFileSize }}</span>
83+
</div>
8184
<div class="infobar-item">
8285
<span class="key">Total Size</span>
8386
<span class="value">{{ totalFileSize }}</span>
8487
</div>
88+
8589
<div class="infobar-item">
8690
<span class="key">Engine Type</span>
8791
<span class="value">{{ instanceData.canonInfo.engine_kind }}</span>
@@ -96,7 +100,9 @@ onMounted(computeSize);
96100
</div>
97101
<div class="infobar-item">
98102
<span class="key">Version</span>
99-
<span class="value">{{ instanceData.canonInfo.canonical_version || 'N/A' }}</span>
103+
<span class="value">{{
104+
instanceData.canonInfo.canonical_version || 'N/A'
105+
}}</span>
100106
</div>
101107
<div class="infobar-item">
102108
<span class="key">Mod Kind</span>
@@ -107,15 +113,15 @@ onMounted(computeSize);
107113
</template>
108114

109115
<style scoped lang="css">
110-
@reference "maincss";
116+
@reference "maincss";
111117
112-
.infobar-item {
113-
@apply flex flex-col gap-0.5 text-xs h-full;
114-
> .key {
115-
@apply text-modfriend-300 uppercase;
116-
}
117-
> .value {
118-
@apply text-modfriend-100;
119-
}
118+
.infobar-item {
119+
@apply flex flex-col gap-0.5 text-xs h-full;
120+
> .key {
121+
@apply text-modfriend-300 uppercase;
122+
}
123+
> .value {
124+
@apply text-modfriend-100;
120125
}
126+
}
121127
</style>

src/components/WidgetRawData.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<script setup lang="ts">
2-
//i dont fucking know
2+
import { ListDisplayInfo } from '@core/instances';
33
44
const props = defineProps<{
5-
instanceData: Category;
5+
instanceData: ListDisplayInfo;
66
}>();
77
</script>
88

99
<template>
10-
<div id="widget" class="ml-6 mr-6 text-wrap">
11-
<pre class="text-xs">{{ props.instanceData }}</pre>
12-
</div>
10+
<div id="widget" class="ml-6 mr-6 text-wrap">
11+
<pre class="text-xs">{{ props.instanceData }}</pre>
12+
</div>
1313
</template>
1414

1515
<style scoped lang="css">
16-
@reference "maincss";
17-
</style>
16+
@reference "maincss";
17+
</style>

src/core/engines.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import type { BasicCanonInfo } from '@core/instances';
2+
13
interface EngineContext {
24
folder_path: string;
35
exe_path: string;
46
engine_kind: number;
57
}
68

7-
interface EngineCanonInfo extends EngineContext, BasicCanonInfo {
9+
export interface EngineCanonInfo extends EngineContext, BasicCanonInfo {
810
supports_softcode: boolean;
911
softcode_list: string[];
1012
}

src/core/instances.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1+
import type { EngineCanonInfo } from '@core/engines';
2+
import type { ModCanonInfo } from '@core/mods';
13

2-
interface BasicCanonInfo {
4+
export interface BasicCanonInfo {
35
canonical_display_name: string;
46
canonical_author: string;
57
}
68

7-
type CanonInfo =
8-
| ({ kind: "mod" } & ModCanonInfo)
9-
| ({ kind: "engine" } & EngineCanonInfo);
9+
export type CanonInfo =
10+
| ({ kind: 'mod' } & ModCanonInfo)
11+
| ({ kind: 'engine' } & EngineCanonInfo);
1012

11-
interface InstanceInfo {
13+
export interface InstanceInfo {
1214
display_name?: string;
1315
version?: string;
1416
author?: string;
1517
description?: string;
1618
}
1719

18-
interface Instance {
20+
export interface Instance {
1921
folder_path: string;
2022
edited_info?: InstanceInfo;
2123
children?: string[];
2224
}
25+
26+
export interface ListDisplayInfo {
27+
canonInfo: CanonInfo;
28+
instance?: Instance;
29+
children?: ListDisplayInfo[];
30+
}

src/core/mods.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import type { BasicCanonInfo } from '@core/instances';
2+
13
interface ModContext {
24
folder_path: string;
35
mod_kind: number;
46
mod_name: string;
57
// data: any; // Not needed for the library view, can be very large
68
}
79

8-
interface ModCanonInfo extends ModContext, BasicCanonInfo {
9-
canonical_description: String;
10-
canonical_version: String;
11-
12-
canonical_color: String; // In hex format
13-
14-
canonical_icon?: String;
15-
canonical_banner?: String;
10+
export interface ModCanonInfo extends ModContext, BasicCanonInfo {
11+
canonical_description: string;
12+
canonical_version: string;
13+
canonical_color: string; // In hex format
14+
canonical_icon?: string;
15+
canonical_banner?: string;
1616
}

src/core/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function formatSize(bytes: number): string {
2+
if (bytes < 1024) return `${bytes} B`;
3+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
4+
if (bytes < 1024 * 1024 * 1024)
5+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
6+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
7+
}

src/main.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@
124124
}
125125
#widget {
126126
/* TODO: stylize this properly */
127-
background: darkgray;
128-
border: thick solid black;
127+
border: 1px solid black;
129128
}
130129
}
131130

0 commit comments

Comments
 (0)