Skip to content

Commit 0313597

Browse files
committed
refactor(config): use AppConfigKey type
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent 156626b commit 0313597

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/app/AppConfig.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ export async function loadAppConfig() {
126126
}
127127

128128
export function getAppConfig(): AppConfig
129-
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig[T]
129+
export function getAppConfig<T extends AppConfigKey>(key?: T): AppConfig[T]
130130
/**
131131
* Get an application config value
132132
* @param key - The config key to get
133133
* @return - If key is provided, the value of the key. Otherwise, the full config
134134
*/
135-
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig | AppConfig[T] {
135+
export function getAppConfig<T extends AppConfigKey>(key?: T): AppConfig | AppConfig[T] {
136136
if (!initialized) {
137137
throw new Error('The application config is not initialized yet')
138138
}
@@ -152,7 +152,7 @@ export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig | Ap
152152
* @param value - Value to set or undefined to reset to the default value
153153
* @return Promise<AppConfig> - The full settings after the change
154154
*/
155-
export function setAppConfig<K extends keyof AppConfig>(key: K, value?: AppConfig[K]) {
155+
export function setAppConfig<K extends AppConfigKey>(key: K, value?: AppConfig[K]) {
156156
// Ignore if no change
157157
if (appConfig[key] === value) {
158158
return

src/shared/appConfig.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function getAppConfig() {
3535
* @param key - The key of the config value
3636
* @return - The config value
3737
*/
38-
export function getAppConfigValue<K extends keyof AppConfig>(key: K) {
38+
export function getAppConfigValue<K extends AppConfigKey>(key: K) {
3939
if (!appConfig) {
4040
throw new Error('AppConfig is not initialized')
4141
}

src/talk/renderer/Settings/appConfig.store.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const useAppConfig = defineStore('appConfig', () => {
1515
const isRelaunchRequired = ref(false)
1616
const relaunchRequiredConfigs = ['systemTitleBar', 'monochromeTrayIcon'] as const
1717

18-
window.TALK_DESKTOP.onAppConfigChange((event: unknown, { key, value }: { key: keyof AppConfig, value: unknown }) => {
18+
window.TALK_DESKTOP.onAppConfigChange((event: unknown, { key, value }: { key: AppConfigKey, value: unknown }) => {
1919
set(appConfig.value, key, value)
2020
})
2121

@@ -34,7 +34,7 @@ export const useAppConfig = defineStore('appConfig', () => {
3434
* @param key - The key of the config value
3535
* @return - The config
3636
*/
37-
function getAppConfigValue<K extends keyof AppConfig>(key: K) {
37+
function getAppConfigValue<K extends AppConfigKey>(key: K) {
3838
return appConfig.value[key]
3939
}
4040

@@ -43,7 +43,7 @@ export const useAppConfig = defineStore('appConfig', () => {
4343
* @param key - The key of the config value
4444
* @param value - The value to set
4545
*/
46-
function setAppConfigValue<K extends keyof AppConfig>(key: K, value: AppConfig[K]) {
46+
function setAppConfigValue<K extends AppConfigKey>(key: K, value: AppConfig[K]) {
4747
set(appConfig.value, key, value)
4848
window.TALK_DESKTOP.setAppConfig(key, value)
4949
}

src/talk/renderer/Settings/useAppConfigValue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { AppConfig } from '../../../app/AppConfig.ts'
6+
import type { AppConfig, AppConfigKey } from '../../../app/AppConfig.ts'
77
import { computed } from 'vue'
88
import { useAppConfig } from './appConfig.store.ts'
99

@@ -12,7 +12,7 @@ import { useAppConfig } from './appConfig.store.ts'
1212
* @param key - The key of the config value
1313
* @return - A settable config value
1414
*/
15-
export function useAppConfigValue<K extends keyof AppConfig>(key: K) {
15+
export function useAppConfigValue<K extends AppConfigKey>(key: K) {
1616
const { getAppConfigValue, setAppConfigValue } = useAppConfig()
1717

1818
return computed({

0 commit comments

Comments
 (0)