2023-07-20 13:45:41 +08:00
|
|
|
import { STOKEY_SETTING } from "../config";
|
|
|
|
|
import storage from "../libs/storage";
|
|
|
|
|
import { useStorages } from "./Storage";
|
2023-07-31 15:08:51 +08:00
|
|
|
import { useSync } from "./Sync";
|
2023-08-17 13:27:22 +08:00
|
|
|
import { syncSetting } from "../libs/sync";
|
2023-07-20 13:45:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置hook
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export function useSetting() {
|
|
|
|
|
const storages = useStorages();
|
|
|
|
|
return storages?.[STOKEY_SETTING];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新设置
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export function useSettingUpdate() {
|
2023-07-31 15:08:51 +08:00
|
|
|
const sync = useSync();
|
|
|
|
|
return async (obj) => {
|
|
|
|
|
const updateAt = sync.opt?.settingUpdateAt ? Date.now() : 0;
|
|
|
|
|
await storage.putObj(STOKEY_SETTING, obj);
|
|
|
|
|
await sync.update({ settingUpdateAt: updateAt });
|
2023-08-17 13:27:22 +08:00
|
|
|
syncSetting();
|
2023-07-31 15:08:51 +08:00
|
|
|
};
|
2023-07-20 13:45:41 +08:00
|
|
|
}
|