2023-07-31 03:10:09 +08:00
|
|
|
import { useCallback } from "react";
|
2023-07-20 13:45:41 +08:00
|
|
|
import { STOKEY_SETTING } from "../config";
|
|
|
|
|
import storage from "../libs/storage";
|
|
|
|
|
import { useStorages } from "./Storage";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置hook
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export function useSetting() {
|
|
|
|
|
const storages = useStorages();
|
|
|
|
|
return storages?.[STOKEY_SETTING];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新设置
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export function useSettingUpdate() {
|
2023-07-31 03:10:09 +08:00
|
|
|
return useCallback(async (obj) => {
|
|
|
|
|
await storage.putObj(STOKEY_SETTING, { ...obj, updateAt: Date.now() });
|
|
|
|
|
}, []);
|
2023-07-20 13:45:41 +08:00
|
|
|
}
|