mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
fix(profile): apply custom avatar immediately on idle setCustomAvatar / connect
Review feedback on PR #56: 1. setCustomAvatar(buf) now triggers applyIdleAvatar when the bot is idle (currentSong=null OR avatarEnabled=false). Spec said this; original impl only stored the buffer, so a fresh upload from Settings was invisible until next stop event. Track currentSong in BotProfileManager for the idle check. 2. onConnect drops the !avatarEnabled guard — on a fresh connect there's no song playing yet, so the spec matrix wants the custom avatar shown regardless of sync. Previously bots reconnected with a stale TS3 server-side avatar. 3. CustomAvatarRow: defer the initializing=false flip to nextTick so the load-time data-url assignment's queued watcher sees initializing=true and bails. Removes the redundant PUT-on-mount that echoed the just- loaded bytes back to the server. 4. BotInstance avatar load wrapped in try/catch — a corrupt/locked file no longer crashes startup; we log and continue with no custom avatar. Tests rewritten: 10 cases covering the full behavior matrix (idle vs playing × sync on/off × custom set/null × stop/connect). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0f9c7b3c4c
commit
88ff62c829
4 files changed
+130
-27
No files matched your search
@@ -3,12 +3,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { ref, onMounted, watch, nextTick } from 'vue';
|
||||
import axios from 'axios';
|
||||
import AvatarUpload from './AvatarUpload.vue';
|
||||
|
||||
const props = defineProps<{ botId: string }>();
|
||||
const avatarDataUrl = ref<string | null>(null);
|
||||
// Stays true until the watcher queued by the load-time assignment has run,
|
||||
// so the initial null → loaded-data-url transition does not fire a redundant
|
||||
// PUT echoing the just-fetched bytes back to the server.
|
||||
let initializing = true;
|
||||
|
||||
async function loadCurrent() {
|
||||
@@ -22,6 +25,9 @@ async function loadCurrent() {
|
||||
}
|
||||
avatarDataUrl.value = null;
|
||||
} finally {
|
||||
// Wait for the watcher's flush queue to drain (it'll see initializing=true
|
||||
// and bail), then release for real user-driven changes.
|
||||
await nextTick();
|
||||
initializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user