-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
5 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Option } from '@swan-io/boxed' | ||
import { Store } from 'tauri-plugin-store-api' | ||
|
||
import { makeAsyncGetWithDefault } from './tools' | ||
|
||
export const settings = new Store('.settings.dat') | ||
|
||
export const getSettings = makeAsyncGetWithDefault(settings) | ||
// eslint-disable-next-line etc/no-misused-generics | ||
export const getSettings = async <T>(key: string) => Option.fromNullable(await settings.get<T>(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +0,0 @@ | ||
import { type AsyncGetProtocol } from '@/types' | ||
|
||
export const makeAsyncGetWithDefault = (self: AsyncGetProtocol) => { | ||
return async <T>( | ||
key: string, | ||
defaultValue: T, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
validator: (value: any) => value is T = (value): value is T => true | ||
) => { | ||
const value = await self.get(key) | ||
if (value !== null && validator(value)) { | ||
return value | ||
} | ||
return defaultValue | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
export type AsyncGetProtocol = { | ||
get: (key: string) => Promise<unknown> | ||
} | ||