mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: preserve remembered browser identity on exit
This commit is contained in:
1 parent
96ba467d52
commit
cb3dbe4ca4
3 files changed
+24
-5
No files matched your search
@@ -1054,6 +1054,7 @@ export function useVoiceWebSocket() {
|
|||||||
|
|
||||||
function disconnect(preserveConnection = false): void {
|
function disconnect(preserveConnection = false): void {
|
||||||
connectionSequence++;
|
connectionSequence++;
|
||||||
|
const keepRememberedIdentity = lastConnection?.rememberIdentity === true;
|
||||||
if (!preserveConnection) lastConnection = null;
|
if (!preserveConnection) lastConnection = null;
|
||||||
stopMicrophone();
|
stopMicrophone();
|
||||||
const socket = ws.value;
|
const socket = ws.value;
|
||||||
@@ -1067,7 +1068,7 @@ export function useVoiceWebSocket() {
|
|||||||
state.reconnectFailed = false;
|
state.reconnectFailed = false;
|
||||||
state.tsClientId = 0;
|
state.tsClientId = 0;
|
||||||
state.errorCode = "";
|
state.errorCode = "";
|
||||||
identityMaterial.value = "";
|
if (!keepRememberedIdentity) identityMaterial.value = "";
|
||||||
members.length = 0;
|
members.length = 0;
|
||||||
channels.length = 0;
|
channels.length = 0;
|
||||||
chatMessages.length = 0;
|
chatMessages.length = 0;
|
||||||
|
|||||||
@@ -118,6 +118,18 @@ export async function saveStoredIdentity(privateMaterial: string, label = "此
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function removeStoredIdentity(): Promise<void> {
|
||||||
|
try {
|
||||||
|
await request("identities", "readwrite", (store, resolve, reject) => {
|
||||||
|
const remove = store.delete(CURRENT_IDENTITY_KEY);
|
||||||
|
remove.onsuccess = () => resolve(undefined);
|
||||||
|
remove.onerror = () => reject(remove.error);
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// Identity removal is best effort when browser storage is unavailable.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadLocalPreferences(): Promise<LocalPreferences> {
|
export async function loadLocalPreferences(): Promise<LocalPreferences> {
|
||||||
const defaults: LocalPreferences = { schemaVersion: 1, volumesByUid: {} };
|
const defaults: LocalPreferences = { schemaVersion: 1, volumesByUid: {} };
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
|
|
||||||
<details class="identity-options"><summary>{{ t('identityOptions') }}</summary><label class="remember-identity"><input v-model="rememberIdentity" type="checkbox" /><span><strong>{{ t('rememberIdentity') }}</strong><small>{{ t('rememberIdentityHint') }}</small></span></label></details>
|
<details class="identity-options"><summary>{{ t('identityOptions') }}</summary><label class="remember-identity"><input v-model="rememberIdentity" type="checkbox" /><span><strong>{{ t('rememberIdentity') }}</strong><small>{{ t('rememberIdentityHint') }}</small></span></label></details>
|
||||||
|
|
||||||
<button class="primary-button connect-button" :disabled="!canJoin || serverConfigLoading || voiceState.connecting" type="submit">
|
<button class="primary-button connect-button" :disabled="!canJoin || serverConfigLoading || !identityReady || voiceState.connecting" type="submit">
|
||||||
<span v-if="voiceState.connecting" class="button-spinner"></span>
|
<span v-if="voiceState.connecting" class="button-spinner"></span>
|
||||||
<span>{{ voiceState.connecting ? t('connecting') : t('enterVoice') }}</span>
|
<span>{{ voiceState.connecting ? t('connecting') : t('enterVoice') }}</span>
|
||||||
<Icon v-if="!voiceState.connecting" name="chevron-right" :size="17" />
|
<Icon v-if="!voiceState.connecting" name="chevron-right" :size="17" />
|
||||||
@@ -247,7 +247,7 @@
|
|||||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||||
import Icon from "../components/Icon.vue";
|
import Icon from "../components/Icon.vue";
|
||||||
import { useVoiceWebSocket, type ChannelInfo, type ChannelMember } from "../composables/useVoiceWebSocket.js";
|
import { useVoiceWebSocket, type ChannelInfo, type ChannelMember } from "../composables/useVoiceWebSocket.js";
|
||||||
import { clearLocalData as clearStoredLocalData, isLocalPersistenceAvailable, listFavorites, listRecentServers, loadLocalPreferences, loadStoredIdentity, recordRecentServer, removeFavorite, saveFavorite, saveLocalPreferences, saveStoredIdentity, type FavoriteServer, type RecentServer } from "../services/local-persistence.js";
|
import { clearLocalData as clearStoredLocalData, isLocalPersistenceAvailable, listFavorites, listRecentServers, loadLocalPreferences, loadStoredIdentity, recordRecentServer, removeFavorite, removeStoredIdentity, saveFavorite, saveLocalPreferences, saveStoredIdentity, type FavoriteServer, type RecentServer } from "../services/local-persistence.js";
|
||||||
import { applyTheme, getStoredTheme, nextTheme, saveTheme, type ThemeMode } from "../services/theme.js";
|
import { applyTheme, getStoredTheme, nextTheme, saveTheme, type ThemeMode } from "../services/theme.js";
|
||||||
import { combineTeamSpeakTarget, DEFAULT_TEAM_SPEAK_PORT, isValidTeamSpeakPort, splitTeamSpeakTarget } from "../services/teamspeak-target.js";
|
import { combineTeamSpeakTarget, DEFAULT_TEAM_SPEAK_PORT, isValidTeamSpeakPort, splitTeamSpeakTarget } from "../services/teamspeak-target.js";
|
||||||
|
|
||||||
@@ -338,6 +338,7 @@ const audioSettingsError = ref("");
|
|||||||
const toast = ref("");
|
const toast = ref("");
|
||||||
const chatListEl = ref<HTMLElement | null>(null);
|
const chatListEl = ref<HTMLElement | null>(null);
|
||||||
const localPersistenceAvailable = isLocalPersistenceAvailable();
|
const localPersistenceAvailable = isLocalPersistenceAvailable();
|
||||||
|
const identityReady = ref(!localPersistenceAvailable);
|
||||||
const chatTab = ref<"channel" | "server" | "private" | "events">("channel");
|
const chatTab = ref<"channel" | "server" | "private" | "events">("channel");
|
||||||
const privateClientId = ref(0);
|
const privateClientId = ref(0);
|
||||||
const away = ref(false);
|
const away = ref(false);
|
||||||
@@ -984,7 +985,10 @@ watch(settingsOpen, (open) => {
|
|||||||
});
|
});
|
||||||
watch(rememberIdentity, (remember) => {
|
watch(rememberIdentity, (remember) => {
|
||||||
localStorage.setItem("webspeak:remember-identity", remember ? "1" : "0");
|
localStorage.setItem("webspeak:remember-identity", remember ? "1" : "0");
|
||||||
if (!remember) identityMaterial.value = "";
|
if (!remember) {
|
||||||
|
identityMaterial.value = "";
|
||||||
|
void removeStoredIdentity();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
watch([rememberIdentity, identityMaterial], ([remember, material]) => {
|
watch([rememberIdentity, identityMaterial], ([remember, material]) => {
|
||||||
if (remember && material) void saveStoredIdentity(material);
|
if (remember && material) void saveStoredIdentity(material);
|
||||||
@@ -1029,10 +1033,12 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
void loadStoredIdentity().then((stored) => {
|
void loadStoredIdentity().then((stored) => {
|
||||||
if (stored) {
|
if (stored && localStorage.getItem("webspeak:remember-identity") === "1") {
|
||||||
identityMaterial.value = stored.privateMaterial;
|
identityMaterial.value = stored.privateMaterial;
|
||||||
rememberIdentity.value = true;
|
rememberIdentity.value = true;
|
||||||
}
|
}
|
||||||
|
}).finally(() => {
|
||||||
|
identityReady.value = true;
|
||||||
});
|
});
|
||||||
void listFavorites().then((items) => { favoriteServers.value = items; });
|
void listFavorites().then((items) => { favoriteServers.value = items; });
|
||||||
void listRecentServers().then((items) => { recentServers.value = items; });
|
void listRecentServers().then((items) => { recentServers.value = items; });
|
||||||
|
|||||||
Reference in new issue
Block a user