Files
discord-decomp/modules/client_themes/native/CustomThemeMobileStore.tsx
T
2026-11-01 12:12:55 +02:00

195 lines
7.4 KiB
TypeScript

// Metro module 1346 (f1347).
import SelectivelySyncedUserSettingsStore from "../../user_settings/SelectivelySyncedUserSettingsStore";
import ThemeStore from "../../user_settings/ThemeStore";
import UnsyncedUserSettingsStore from "../../user_settings/UnsyncedUserSettingsStore";
import UserSettingsProtoStore from "../../user_settings/UserSettingsProtoStore";
import { PROTO_THEME_MAP_MOBILE } from "../../user_settings/ThemeConstants";
import { UserSettingsTypes } from "../../user_settings/UserSettingsConstants";
import { isPerModeThemingActive } from "../../user_settings/isPerModeThemingActive";
import { Theme } from "../../../_bundle/Module1306";
import { isMobileVisualRefreshEnabled } from "../../themes/experiments/MobileVisualRefreshExperiment";
import Module589 from "../../../_bundle/Module589";
import Dispatcher from "../../../Dispatcher";
let theme, customUserThemeSettings, previewCustomTheme2, handleSelectivelySyncedUserSettingsUpdate, isSyncedModeThemesEnabled;
const reset = function reset() {
theme = void 0;
customUserThemeSettings = void 0;
previewCustomTheme2 = void 0;
};
const handleSyncedModeChange = function handleSyncedModeChange() {
return isPerModeThemingActive(isSyncedModeThemesEnabled);
};
const handleSameAsDeviceThemeToggle = function handleSameAsDeviceThemeToggle() {
return isMobileVisualRefreshEnabled("CustomThemeMobileStore");
};
const loadFromProtoSettings = function loadFromProtoSettings() {
if (SelectivelySyncedUserSettingsStore.shouldSync("appearance")) {
const appearance = UserSettingsProtoStore.settings.appearance;
if (appearance != null) {
let theme2 = appearance.theme;
if (theme2 == null) {
theme2 = Theme.UNSET;
}
theme = PROTO_THEME_MAP_MOBILE[theme2];
customUserThemeSettings = appearance.clientThemeSettings?.customUserThemeSettings;
}
}
};
handleSelectivelySyncedUserSettingsUpdate = function handleSelectivelySyncedUserSettingsUpdate() {
if (SelectivelySyncedUserSettingsStore.shouldSync("appearance")) {
const appearance = UserSettingsProtoStore.settings.appearance;
if (appearance != null) {
let theme2 = appearance.theme;
if (theme2 == null) {
theme2 = Theme.UNSET;
}
theme = PROTO_THEME_MAP_MOBILE[theme2];
customUserThemeSettings = appearance.clientThemeSettings?.customUserThemeSettings;
}
}
};
isSyncedModeThemesEnabled = function isSyncedModeThemesEnabled() {
return isMobileVisualRefreshEnabled("CustomThemeMobileStore");
};
class CustomThemeMobileStore extends Module589.PersistedStore {
static displayName = "CustomThemeMobileStore";
static persistKey = "CustomThemeMobileStore";
initialize(a0) {
if (a0 != null) {
theme = a0.theme;
customUserThemeSettings = a0.customTheme;
}
this.waitFor(SelectivelySyncedUserSettingsStore, ThemeStore, UnsyncedUserSettingsStore, UserSettingsProtoStore);
this.syncWith([SelectivelySyncedUserSettingsStore], handleSelectivelySyncedUserSettingsUpdate);
}
getState() {
return theme != null && customUserThemeSettings != null && customUserThemeSettings.colors.length > 0 ? {
theme,
customTheme: customUserThemeSettings
} : {
theme: void 0,
customTheme: void 0
};
}
getCustomTheme() {
let r16;
const isPerModeThemingActive2 = isPerModeThemingActive(isSyncedModeThemesEnabled);
const r13 = {
baseTheme: null,
customTheme: null
};
if (isPerModeThemingActive2) {
r13.baseTheme = ThemeStore.theme;
r13.customTheme = ThemeStore.getSyncedClientTheme(ThemeStore.systemTheme)?.customUserThemeSettings;
r16 = r13;
} else {
r13.baseTheme = theme;
r13.customTheme = customUserThemeSettings;
r16 = r13;
}
const { baseTheme, customTheme } = r16;
return baseTheme != null && customTheme != null && customTheme.colors.length > 0 ? r16.customTheme : void 0;
}
getBaseTheme() {
let r16;
const isPerModeThemingActive2 = isPerModeThemingActive(isSyncedModeThemesEnabled);
const r13 = {
baseTheme: null,
customTheme: null
};
if (isPerModeThemingActive2) {
r13.baseTheme = ThemeStore.theme;
r13.customTheme = ThemeStore.getSyncedClientTheme(ThemeStore.systemTheme)?.customUserThemeSettings;
r16 = r13;
} else {
r13.baseTheme = theme;
r13.customTheme = customUserThemeSettings;
r16 = r13;
}
const { baseTheme, customTheme } = r16;
return baseTheme != null && customTheme != null && customTheme.colors.length > 0 ? r16.baseTheme : void 0;
}
getPreviewTheme() {
return previewCustomTheme2;
}
getCustomThemeDisplaySettings() {
let r17;
if (previewCustomTheme2 !== void 0) {
return previewCustomTheme2;
}
const isPerModeThemingActive2 = isPerModeThemingActive(isSyncedModeThemesEnabled);
const r14 = {
baseTheme: null,
customTheme: null
};
if (isPerModeThemingActive2) {
r14.baseTheme = ThemeStore.theme;
r14.customTheme = ThemeStore.getSyncedClientTheme(ThemeStore.systemTheme)?.customUserThemeSettings;
r17 = r14;
} else {
r14.baseTheme = theme;
r14.customTheme = customUserThemeSettings;
r17 = r14;
}
const { baseTheme, customTheme } = r17;
return baseTheme != null && customTheme != null && customTheme.colors.length > 0 ? {
baseTheme: r17.baseTheme,
customTheme: r17.customTheme
} : void 0;
}
hasCustomTheme() {
let r15;
const isPerModeThemingActive2 = isPerModeThemingActive(isSyncedModeThemesEnabled);
const r12 = {
baseTheme: null,
customTheme: null
};
if (isPerModeThemingActive2) {
r12.baseTheme = ThemeStore.theme;
r12.customTheme = ThemeStore.getSyncedClientTheme(ThemeStore.systemTheme)?.customUserThemeSettings;
r15 = r12;
} else {
r12.baseTheme = theme;
r12.customTheme = customUserThemeSettings;
r15 = r12;
}
const { baseTheme, customTheme } = r15;
return baseTheme != null && customTheme != null && customTheme.colors.length > 0;
}
}
const customThemeMobileStore = new CustomThemeMobileStore(Dispatcher, {
UPDATE_CUSTOM_THEME: function handleUpdateCustomTheme({ customTheme, theme: theme2 }) {
customUserThemeSettings = customTheme;
theme = theme2;
},
SYSTEM_THEME_CHANGE: handleSyncedModeChange,
UPDATE_SYNCED_CLIENT_THEME: handleSyncedModeChange,
UPDATE_THEME_PREFERENCES: handleSyncedModeChange,
SET_SAME_AS_DEVICE_THEME_ENABLED: handleSameAsDeviceThemeToggle,
CLEAR_SYNCED_CLIENT_THEMES: handleSameAsDeviceThemeToggle,
PREVIEW_CUSTOM_THEME: function previewCustomTheme(a0) {
previewCustomTheme2 = a0.previewCustomTheme;
},
CLEAR_PREVIEW_CUSTOM_THEME: function clearPreviewTheme() {
previewCustomTheme2 = void 0;
},
RESET_CUSTOM_THEME: reset,
CACHE_LOADED: loadFromProtoSettings,
POST_CONNECTION_OPEN: loadFromProtoSettings,
USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate({ settings }) {
if (SelectivelySyncedUserSettingsStore.shouldSync("appearance")) {
const r12 = settings.type === UserSettingsTypes.PRELOADED_USER_SETTINGS ? settings.proto?.appearance : null;
if (r12 != null) {
let theme2 = r12.theme;
if (theme2 == null) {
theme2 = Theme.UNSET;
}
theme = PROTO_THEME_MAP_MOBILE[theme2];
customUserThemeSettings = r12.clientThemeSettings?.customUserThemeSettings;
}
}
},
LOGOUT: reset
});
export default customThemeMobileStore;