Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: safer types #3993

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- use 'Info' and 'Message Info' consistently #3961
- consolidate 'Profile' wording #3963
- Update local help (2024-06-19)
- refactor: safer types #3993

### Fixed
- Fix crash on "Settings" click when not on main screen (e.g. no account selected): hide the "settings" button
Expand Down
44 changes: 23 additions & 21 deletions src/renderer/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ export interface SettingsStoreState {
accountId: number
selfContact: Type.Contact
settings: {
sentbox_watch: string
mvbox_move: string
e2ee_enabled: string
addr: string
displayname: string
selfstatus: string
mdns_enabled: string
show_emails: string
bcc_self: string
delete_device_after: string
delete_server_after: string
webrtc_instance: string
download_limit: string
only_fetch_mvbox: string
disable_idle: string
media_quality: string
is_chatmail: '0' | '1'
webxdc_realtime_enabled: string
[P in (typeof settingsKeys)[number]]: {
sentbox_watch: string
mvbox_move: string
e2ee_enabled: string
addr: string
displayname: string
selfstatus: string
mdns_enabled: string
show_emails: string
bcc_self: string
delete_device_after: string
delete_server_after: string
webrtc_instance: string
download_limit: string
only_fetch_mvbox: string
disable_idle: string
media_quality: string
is_chatmail: '0' | '1'
webxdc_realtime_enabled: string
}[P]
}
desktopSettings: DesktopSettingsType
rc: RC_Config
}

const settingsKeys: Array<keyof SettingsStoreState['settings']> = [
const settingsKeys = [
'sentbox_watch',
'mvbox_move',
'e2ee_enabled',
Expand All @@ -52,7 +54,7 @@ const settingsKeys: Array<keyof SettingsStoreState['settings']> = [
'media_quality',
'is_chatmail',
'webxdc_realtime_enabled',
]
] as const

class SettingsStore extends Store<SettingsStoreState | null> {
reducer = {
Expand Down Expand Up @@ -123,7 +125,7 @@ class SettingsStore extends Store<SettingsStoreState | null> {
}
const settings = (await BackendRemote.rpc.batchGetConfig(
accountId,
settingsKeys
settingsKeys as unknown as Array<(typeof settingsKeys)[number]>
)) as SettingsStoreState['settings']
const selfContact = await BackendRemote.rpc.getContact(
accountId,
Expand Down
Loading