Change ephemeral settings to only persist in ephemeralConfig
This commit is contained in:
parent
07e2fb7f60
commit
73e8bec42f
18 changed files with 295 additions and 265 deletions
|
@ -14,8 +14,6 @@ import type {
|
|||
import { DEFAULT_CONVERSATION_COLOR } from '../types/Colors';
|
||||
import * as Errors from '../types/errors';
|
||||
import * as Stickers from '../types/Stickers';
|
||||
import type { SystemTraySetting } from '../types/SystemTraySetting';
|
||||
import { parseSystemTraySetting } from '../types/SystemTraySetting';
|
||||
|
||||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import type { AuthorizeArtCreatorDataType } from '../state/ducks/globalModals';
|
||||
|
@ -45,9 +43,15 @@ import { fromWebSafeBase64 } from './webSafeBase64';
|
|||
import { getConversation } from './getConversation';
|
||||
import { instance, PhoneNumberFormat } from './libphonenumberInstance';
|
||||
import { showConfirmationDialog } from './showConfirmationDialog';
|
||||
import type {
|
||||
EphemeralSettings,
|
||||
SettingsValuesType,
|
||||
ThemeType,
|
||||
} from './preload';
|
||||
import type { SystemTraySetting } from '../types/SystemTraySetting';
|
||||
import { drop } from './drop';
|
||||
|
||||
type SentMediaQualityType = 'standard' | 'high';
|
||||
type ThemeType = 'light' | 'dark' | 'system';
|
||||
type NotificationSettingType = 'message' | 'name' | 'count' | 'off';
|
||||
|
||||
export type IPCEventsValuesType = {
|
||||
|
@ -64,17 +68,13 @@ export type IPCEventsValuesType = {
|
|||
hideMenuBar: boolean | undefined;
|
||||
incomingCallNotification: boolean;
|
||||
lastSyncTime: number | undefined;
|
||||
localeOverride: string | null;
|
||||
notificationDrawAttention: boolean;
|
||||
notificationSetting: NotificationSettingType;
|
||||
preferredAudioInputDevice: AudioDevice | undefined;
|
||||
preferredAudioOutputDevice: AudioDevice | undefined;
|
||||
preferredVideoInputDevice: string | undefined;
|
||||
sentMediaQualitySetting: SentMediaQualityType;
|
||||
spellCheck: boolean;
|
||||
systemTraySetting: SystemTraySetting;
|
||||
textFormatting: boolean;
|
||||
themeSetting: ThemeType;
|
||||
universalExpireTimer: DurationInSeconds;
|
||||
zoomFactor: ZoomFactorType;
|
||||
storyViewReceiptsEnabled: boolean;
|
||||
|
@ -144,17 +144,21 @@ export type IPCEventsCallbacksType = {
|
|||
};
|
||||
|
||||
type ValuesWithGetters = Omit<
|
||||
IPCEventsValuesType,
|
||||
SettingsValuesType,
|
||||
// Async
|
||||
| 'zoomFactor'
|
||||
| 'localeOverride'
|
||||
| 'spellCheck'
|
||||
| 'themeSetting'
|
||||
// Optional
|
||||
| 'mediaPermissions'
|
||||
| 'mediaCameraPermissions'
|
||||
| 'autoLaunch'
|
||||
| 'systemTraySetting'
|
||||
>;
|
||||
|
||||
type ValuesWithSetters = Omit<
|
||||
IPCEventsValuesType,
|
||||
SettingsValuesType,
|
||||
| 'blockedCount'
|
||||
| 'defaultConversationColor'
|
||||
| 'linkPreviewSetting'
|
||||
|
@ -166,19 +170,37 @@ type ValuesWithSetters = Omit<
|
|||
// Optional
|
||||
| 'mediaPermissions'
|
||||
| 'mediaCameraPermissions'
|
||||
|
||||
// Only set in the Settings window
|
||||
| 'localeOverride'
|
||||
| 'spellCheck'
|
||||
| 'systemTraySetting'
|
||||
>;
|
||||
|
||||
export type IPCEventGetterType<Key extends keyof IPCEventsValuesType> =
|
||||
export type IPCEventsUpdatersType = {
|
||||
[Key in keyof EphemeralSettings as IPCEventUpdaterType<Key>]?: (
|
||||
value: EphemeralSettings[Key]
|
||||
) => void;
|
||||
};
|
||||
|
||||
export type IPCEventGetterType<Key extends keyof SettingsValuesType> =
|
||||
`get${Capitalize<Key>}`;
|
||||
|
||||
export type IPCEventSetterType<Key extends keyof IPCEventsValuesType> =
|
||||
export type IPCEventSetterType<Key extends keyof SettingsValuesType> =
|
||||
`set${Capitalize<Key>}`;
|
||||
|
||||
export type IPCEventUpdaterType<Key extends keyof SettingsValuesType> =
|
||||
`update${Capitalize<Key>}`;
|
||||
|
||||
export type IPCEventsGettersType = {
|
||||
[Key in keyof ValuesWithGetters as IPCEventGetterType<Key>]: () => ValuesWithGetters[Key];
|
||||
} & {
|
||||
// Async
|
||||
getZoomFactor: () => Promise<ZoomFactorType>;
|
||||
getLocaleOverride: () => Promise<string | null>;
|
||||
getSpellCheck: () => Promise<boolean>;
|
||||
getSystemTraySetting: () => Promise<SystemTraySetting>;
|
||||
getThemeSetting: () => Promise<ThemeType>;
|
||||
// Events
|
||||
onZoomFactorChange: (callback: (zoomFactor: ZoomFactorType) => void) => void;
|
||||
// Optional
|
||||
|
@ -198,6 +220,7 @@ export type IPCEventsSettersType = {
|
|||
|
||||
export type IPCEventsType = IPCEventsGettersType &
|
||||
IPCEventsSettersType &
|
||||
IPCEventsUpdatersType &
|
||||
IPCEventsCallbacksType;
|
||||
|
||||
export function createIPCEvents(
|
||||
|
@ -393,11 +416,14 @@ export function createIPCEvents(
|
|||
window.storage.get('sent-media-quality', 'standard'),
|
||||
setSentMediaQualitySetting: value =>
|
||||
window.storage.put('sent-media-quality', value),
|
||||
getThemeSetting: () => window.storage.get('theme-setting', 'system'),
|
||||
setThemeSetting: value => {
|
||||
const promise = window.storage.put('theme-setting', value);
|
||||
themeChanged();
|
||||
return promise;
|
||||
getThemeSetting: async () => {
|
||||
return getEphemeralSetting('themeSetting') ?? null;
|
||||
},
|
||||
setThemeSetting: async value => {
|
||||
drop(setEphemeralSetting('themeSetting', value));
|
||||
},
|
||||
updateThemeSetting: _theme => {
|
||||
drop(themeChanged());
|
||||
},
|
||||
getHideMenuBar: () => window.storage.get('hide-menu-bar'),
|
||||
setHideMenuBar: value => {
|
||||
|
@ -406,19 +432,9 @@ export function createIPCEvents(
|
|||
window.IPC.setMenuBarVisibility(!value);
|
||||
return promise;
|
||||
},
|
||||
getSystemTraySetting: () =>
|
||||
parseSystemTraySetting(window.storage.get('system-tray-setting')),
|
||||
setSystemTraySetting: value => {
|
||||
const promise = window.storage.put('system-tray-setting', value);
|
||||
window.IPC.updateSystemTraySetting(value);
|
||||
return promise;
|
||||
},
|
||||
|
||||
getLocaleOverride: () => {
|
||||
return window.storage.get('localeOverride') ?? null;
|
||||
},
|
||||
setLocaleOverride: async (locale: string | null) => {
|
||||
await window.storage.put('localeOverride', locale);
|
||||
getSystemTraySetting: () => getEphemeralSetting('systemTraySetting'),
|
||||
getLocaleOverride: async () => {
|
||||
return getEphemeralSetting('localeOverride') ?? null;
|
||||
},
|
||||
getNotificationSetting: () =>
|
||||
window.storage.get('notification-setting', 'message'),
|
||||
|
@ -456,8 +472,9 @@ export function createIPCEvents(
|
|||
setIncomingCallNotification: value =>
|
||||
window.storage.put('incoming-call-notification', value),
|
||||
|
||||
getSpellCheck: () => window.storage.get('spell-check', true),
|
||||
setSpellCheck: value => window.storage.put('spell-check', value),
|
||||
getSpellCheck: () => {
|
||||
return getEphemeralSetting('spellCheck');
|
||||
},
|
||||
getTextFormatting: () => window.storage.get('textFormatting', true),
|
||||
setTextFormatting: value => window.storage.put('textFormatting', value),
|
||||
|
||||
|
@ -709,3 +726,16 @@ function showUnknownSgnlLinkModal(): void {
|
|||
description: window.i18n('icu:unknown-sgnl-link'),
|
||||
});
|
||||
}
|
||||
|
||||
function getEphemeralSetting<Name extends keyof EphemeralSettings>(
|
||||
name: Name
|
||||
): Promise<EphemeralSettings[Name]> {
|
||||
return ipcRenderer.invoke(`settings:get:${name}`);
|
||||
}
|
||||
|
||||
function setEphemeralSetting<Name extends keyof EphemeralSettings>(
|
||||
name: Name,
|
||||
value: EphemeralSettings[Name]
|
||||
): Promise<void> {
|
||||
return ipcRenderer.invoke(`settings:set:${name}`, value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue