Отключить мультиаккаунтность и уточнить статусы профиля

This commit is contained in:
AidarKC
2026-11-27 13:22:15 +03:00
parent ae430e84c7
commit 91a8bb9c3c
40 changed files with 312 additions and 383 deletions
+18 -3
View File
@@ -218,6 +218,9 @@ function persistProfileStoreRaw(items) {
}
}
// MULTI-PROFILE MODE: temporarily disabled. Preserve dormant implementation.
export const MULTI_PROFILE_ENABLED = false;
function getActiveProfileLoginRaw() {
try {
return normalizeProfileLogin(localStorage.getItem(ACTIVE_PROFILE_STORAGE_KEY));
@@ -297,7 +300,7 @@ function loadStoredSession() {
const profiles = loadProfileStoreRaw();
if (profiles.length) {
const activeLogin = getActiveProfileLoginRaw();
const active = profiles.find((item) => normalizeProfileLogin(item.login) === activeLogin) || profiles[0];
const active = profiles.find((item) => normalizeProfileLogin(item.login) === activeLogin) || (MULTI_PROFILE_ENABLED ? profiles[0] : null);
if (active) {
setActiveProfileLoginRaw(active.login);
return {
@@ -358,7 +361,7 @@ function loadStoredEntrySettings() {
const profiles = loadProfileStoreRaw();
if (profiles.length) {
const activeLogin = getActiveProfileLoginRaw();
const active = profiles.find((item) => normalizeProfileLogin(item.login) === activeLogin) || profiles[0];
const active = profiles.find((item) => normalizeProfileLogin(item.login) === activeLogin) || (MULTI_PROFILE_ENABLED ? profiles[0] : null);
if (active?.entrySettings && typeof active.entrySettings === 'object') {
return active.entrySettings;
}
@@ -1282,6 +1285,10 @@ export async function terminateCurrentSession({ infoMessage = '', closeServerSes
await tryCloseCurrentSessionOnServer();
}
if (!MULTI_PROFILE_ENABLED) {
persistProfileStoreRaw(loadProfileStoreRaw().filter(item => normalizeProfileLogin(item.login) !== normalizeProfileLogin(signedOutLogin)));
setActiveProfileLoginRaw('');
}
clearStoredSession();
resetStateForSignedOut();
await clearStoredMessages(signedOutLogin).catch(() => {});
@@ -1318,6 +1325,7 @@ export function getSavedProfiles() {
}
export async function switchToSavedProfile(login) {
if (!MULTI_PROFILE_ENABLED) throw new Error('Multi-profile mode is disabled');
const targetLogin = normalizeProfileLogin(login);
const target = loadProfileStoreRaw().find((item) => normalizeProfileLogin(item.login) === targetLogin);
if (!target) throw new Error('Профиль не найден на этом устройстве');
@@ -1412,6 +1420,11 @@ async function closeSavedProfileSessionBestEffort(profile) {
}
export async function closeSavedProfile(login) {
if (!MULTI_PROFILE_ENABLED) {
if (!login || normalizeProfileLogin(login) !== normalizeProfileLogin(state.session.login)) return { closed: false, nextProfile: null };
await terminateCurrentSession({ closeServerSession: true, notifySessionReset: false });
return { closed: true, nextProfile: null };
}
const normalized = normalizeProfileLogin(login);
const items = loadProfileStoreRaw();
const index = items.findIndex((item) => normalizeProfileLogin(item.login) === normalized);
@@ -1441,6 +1454,7 @@ export async function closeSavedProfile(login) {
}
export async function closeAllSavedProfiles() {
if (!MULTI_PROFILE_ENABLED) throw new Error('Multi-profile mode is disabled');
const items = loadProfileStoreRaw();
for (const item of items) {
await clearStoredMessages(item.login).catch(() => {});
@@ -1462,10 +1476,11 @@ export async function closeAllSavedProfiles() {
}
export function isAddingProfileLogin() {
return state.session.isAuthorized && String(state.authReturnHash || '').trim() === '/profiles';
return MULTI_PROFILE_ENABLED && state.session.isAuthorized && String(state.authReturnHash || '').trim() === '/profiles';
}
export async function prepareAddProfileLogin() {
if (!MULTI_PROFILE_ENABLED) throw new Error('Multi-profile mode is disabled');
state.loginDraft.login = '';
state.loginDraft.password = '';
clearAuthMessages();