2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-17 18:52:06 +00:00

feat: unlink fastfiles via ModMan

This commit is contained in:
Jan Laupetin
2025-10-11 18:56:11 +01:00
parent f53195d4bd
commit d86b70e006
8 changed files with 174 additions and 13 deletions

View File

@@ -1,21 +1,29 @@
<script setup lang="ts">
import { ref } from "vue";
import { computed, ref } from "vue";
import { webviewBinds } from "@/native";
import { useZoneStore } from "@/stores/ZoneStore";
import SpinningLoader from "@/components/SpinningLoader.vue";
const zoneStore = useZoneStore();
const lastPath = ref("");
const loadingFastFile = ref(false);
const unlinkingFastFile = ref(false);
async function onOpenFastfileClick() {
lastPath.value =
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
const performingAction = computed<boolean>(() => loadingFastFile.value || unlinkingFastFile.value);
async function openFastFileSelect() {
return await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] });
}
async function onOpenFastFileClick() {
if (performingAction.value) return;
const fastFilePath = await openFastFileSelect();
if (!fastFilePath) return;
loadingFastFile.value = true;
webviewBinds
.loadFastFile(lastPath.value)
.loadFastFile(fastFilePath)
.catch((e: string) => {
console.error("Failed to load fastfile:", e);
})
@@ -24,6 +32,36 @@ async function onOpenFastfileClick() {
});
}
async function onUnlinkFastFileClick() {
if (performingAction.value) return;
const fastFilePath = await openFastFileSelect();
if (!fastFilePath) return;
try {
unlinkingFastFile.value = true;
let loadedZoneName: string;
try {
loadedZoneName = (await webviewBinds.loadFastFile(fastFilePath)).zoneName;
} catch (e: unknown) {
console.error("Failed to load fastfile:", e as string);
return;
}
try {
await webviewBinds.unlinkZone(loadedZoneName);
} catch (e: unknown) {
console.error("Failed to unlink fastfile:", e as string);
return;
} finally {
webviewBinds.unloadZone(loadedZoneName);
}
} finally {
unlinkingFastFile.value = false;
}
}
function onUnloadClicked(zoneName: string) {
webviewBinds.unloadZone(zoneName).catch((e: string) => {
console.error("Failed to unload zone:", e);
@@ -36,18 +74,23 @@ function onUnloadClicked(zoneName: string) {
<h1>Welcome to ModMan</h1>
<small>Nothing to see here yet, this is mainly for testing</small>
<p>
<button :disabled="loadingFastFile" @click="onOpenFastfileClick">
<div class="actions">
<button :disabled="performingAction" @click="onOpenFastFileClick">
<SpinningLoader v-if="loadingFastFile" class="loading" />
<span>Load fastfile</span>
</button>
</p>
<button :disabled="performingAction" @click="onUnlinkFastFileClick">
<SpinningLoader v-if="unlinkingFastFile" class="loading" />
<span>Unlink fastfile</span>
</button>
</div>
<div>
<h3>Loaded zones:</h3>
<div class="zone-list">
<div v-for="zone in zoneStore.loadedZones" :key="zone" class="zone">
<span>{{ zone }}</span>
<button @click="onUnloadClicked(zone)">Unload</button>
<button :disabled="performingAction" @click="onUnloadClicked(zone)">Unload</button>
</div>
</div>
</div>
@@ -55,6 +98,12 @@ function onUnloadClicked(zoneName: string) {
</template>
<style scoped>
.actions {
display: flex;
justify-content: center;
column-gap: 0.5em;
}
.loading {
margin-right: 0.2em;
}

View File

@@ -0,0 +1,3 @@
export interface UnlinkingBinds {
unlinkZone(zoneName: string): Promise<void>;
}

View File

@@ -8,7 +8,7 @@ export interface ZoneUnloadedDto {
}
export interface ZoneBinds {
loadFastFile(path: string): Promise<void>;
loadFastFile(path: string): Promise<ZoneLoadedDto>;
unloadZone(zoneName: string): Promise<void>;
}

View File

@@ -1,7 +1,8 @@
import type { DialogBinds } from "./DialogBinds";
import type { UnlinkingBinds } from "./UnlinkingBinds";
import type { ZoneBinds, ZoneEventMap } from "./ZoneBinds";
export type NativeMethods = DialogBinds & ZoneBinds;
export type NativeMethods = DialogBinds & UnlinkingBinds & ZoneBinds;
type NativeEventMap = ZoneEventMap;