Skip to content

Commit

Permalink
refactor(config): use AppConfigKey type
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Oct 29, 2024
1 parent 156626b commit 0313597
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ export async function loadAppConfig() {
}

export function getAppConfig(): AppConfig
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig[T]
export function getAppConfig<T extends AppConfigKey>(key?: T): AppConfig[T]
/**
* Get an application config value
* @param key - The config key to get
* @return - If key is provided, the value of the key. Otherwise, the full config
*/
export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig | AppConfig[T] {
export function getAppConfig<T extends AppConfigKey>(key?: T): AppConfig | AppConfig[T] {
if (!initialized) {
throw new Error('The application config is not initialized yet')
}
Expand All @@ -152,7 +152,7 @@ export function getAppConfig<T extends keyof AppConfig>(key?: T): AppConfig | Ap
* @param value - Value to set or undefined to reset to the default value
* @return Promise<AppConfig> - The full settings after the change
*/
export function setAppConfig<K extends keyof AppConfig>(key: K, value?: AppConfig[K]) {
export function setAppConfig<K extends AppConfigKey>(key: K, value?: AppConfig[K]) {
// Ignore if no change
if (appConfig[key] === value) {
return
Expand Down
2 changes: 1 addition & 1 deletion src/shared/appConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getAppConfig() {
* @param key - The key of the config value
* @return - The config value
*/
export function getAppConfigValue<K extends keyof AppConfig>(key: K) {
export function getAppConfigValue<K extends AppConfigKey>(key: K) {

Check failure on line 38 in src/shared/appConfig.service.ts

View workflow job for this annotation

GitHub Actions / NPM typecheck

Cannot find name 'AppConfigKey'. Did you mean 'AppConfig'?
if (!appConfig) {
throw new Error('AppConfig is not initialized')
}
Expand Down
6 changes: 3 additions & 3 deletions src/talk/renderer/Settings/appConfig.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useAppConfig = defineStore('appConfig', () => {
const isRelaunchRequired = ref(false)
const relaunchRequiredConfigs = ['systemTitleBar', 'monochromeTrayIcon'] as const

window.TALK_DESKTOP.onAppConfigChange((event: unknown, { key, value }: { key: keyof AppConfig, value: unknown }) => {
window.TALK_DESKTOP.onAppConfigChange((event: unknown, { key, value }: { key: AppConfigKey, value: unknown }) => {

Check failure on line 18 in src/talk/renderer/Settings/appConfig.store.ts

View workflow job for this annotation

GitHub Actions / NPM typecheck

Cannot find name 'AppConfigKey'. Did you mean 'AppConfig'?
set(appConfig.value, key, value)
})

Expand All @@ -34,7 +34,7 @@ export const useAppConfig = defineStore('appConfig', () => {
* @param key - The key of the config value
* @return - The config
*/
function getAppConfigValue<K extends keyof AppConfig>(key: K) {
function getAppConfigValue<K extends AppConfigKey>(key: K) {

Check failure on line 37 in src/talk/renderer/Settings/appConfig.store.ts

View workflow job for this annotation

GitHub Actions / NPM typecheck

Cannot find name 'AppConfigKey'. Did you mean 'AppConfig'?
return appConfig.value[key]
}

Expand All @@ -43,7 +43,7 @@ export const useAppConfig = defineStore('appConfig', () => {
* @param key - The key of the config value
* @param value - The value to set
*/
function setAppConfigValue<K extends keyof AppConfig>(key: K, value: AppConfig[K]) {
function setAppConfigValue<K extends AppConfigKey>(key: K, value: AppConfig[K]) {

Check failure on line 46 in src/talk/renderer/Settings/appConfig.store.ts

View workflow job for this annotation

GitHub Actions / NPM typecheck

Cannot find name 'AppConfigKey'. Did you mean 'AppConfig'?
set(appConfig.value, key, value)
window.TALK_DESKTOP.setAppConfig(key, value)
}
Expand Down
4 changes: 2 additions & 2 deletions src/talk/renderer/Settings/useAppConfigValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { AppConfig } from '../../../app/AppConfig.ts'
import type { AppConfig, AppConfigKey } from '../../../app/AppConfig.ts'
import { computed } from 'vue'
import { useAppConfig } from './appConfig.store.ts'

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

return computed({
Expand Down

0 comments on commit 0313597

Please sign in to comment.