reset to default skin btn

This commit is contained in:
2026-08-31 01:28:14 +08:00
parent 25eb21755f
commit f82d1041ae
4 changed files with 82 additions and 6 deletions
+3
View File
@@ -38,6 +38,9 @@ async getProfile() : Promise<User> {
async updateProfile(displayName: string, skinData: number[] | null) : Promise<User> {
return await TAURI_INVOKE("update_profile", { displayName, skinData });
},
async resetProfileSkin() : Promise<User> {
return await TAURI_INVOKE("reset_profile_skin");
},
async getPublicKey() : Promise<string> {
return await TAURI_INVOKE("get_public_key");
},
@@ -18,6 +18,7 @@
let skinFile = $state<File | null>(null);
let skinPreviewUrl = $state<string | null>(null);
let skinInput = $state<HTMLInputElement | null>(null);
let pendingSkinReset = $state(false);
let dirty = $state(false);
let busy = $state(false);
let error = $state("");
@@ -45,7 +46,7 @@
}
function updateDirty() {
dirty = hasConfigurationChanges() || skinFile !== null;
dirty = hasConfigurationChanges() || skinFile !== null || pendingSkinReset;
error = "";
}
@@ -58,16 +59,24 @@
function selectSkinFile(file: File | null) {
clearSkinDraft();
pendingSkinReset = false;
skinFile = file;
skinPreviewUrl = file ? URL.createObjectURL(file) : null;
updateDirty();
}
function resetSkin() {
clearSkinDraft();
pendingSkinReset = true;
updateDirty();
}
function reset() {
puppetScale = $sceneConfiguration.puppetScale;
puppetOpacity = $sceneConfiguration.puppetOpacity;
puppetMovementMode = $sceneConfiguration.puppetMovementMode;
clearSkinDraft();
pendingSkinReset = false;
dirty = false;
error = "";
}
@@ -78,7 +87,10 @@
busy = true;
error = "";
try {
if (skinFile) {
if (pendingSkinReset) {
await commands.resetProfileSkin();
pendingSkinReset = false;
} else if (skinFile) {
const currentProfile = await commands.getProfile();
const skinData = Array.from(
new Uint8Array(await skinFile.arrayBuffer()),
@@ -100,7 +112,8 @@
dirty = false;
return true;
} catch (cause) {
dirty = hasConfigurationChanges() || skinFile !== null;
dirty =
hasConfigurationChanges() || skinFile !== null || pendingSkinReset;
error = String(cause);
return false;
} finally {
@@ -141,7 +154,7 @@
<div class="size-full z-10">
<PuppetPreview
userId={$profile.id}
skinHash={$profile.skinHash}
skinHash={pendingSkinReset ? null : $profile.skinHash}
skinSource={skinPreviewUrl}
scale={puppetScale}
opacity={puppetOpacity}
@@ -192,14 +205,22 @@
/>
</div>
</fieldset>
<div>
<div class="grid grid-cols-[minmax(0,1fr)_auto] gap-2">
<button
class="btn w-full"
type="button"
disabled={!$profile || busy}
onclick={() => skinInput?.click()}
>
Choose a custom skin
Choose a skin
</button>
<button
class="btn"
type="button"
disabled={!$profile || busy || (!$profile.skinHash && !skinFile)}
onclick={resetSkin}
>
Reset
</button>
<input
id="skin-file"