UNPKG

backsplash-app

Version:
109 lines (101 loc) 2.96 kB
import { store } from "./store"; import { lastWallpaperState, schedulerState, expandedCategoriesState, activeStylesState, customStyleState, currentWallpaperModeState, WallpaperData, SchedulerState, } from "./atoms"; import { STORE_MESSAGES } from "@/ipc/channels/messages"; type StoreType = { get: (key: string) => Promise<any>; set: (key: string, value: any) => Promise<void>; clear: (key: string) => Promise<void>; }; // Effect for last wallpaper state export const lastWallpaperEffect = { key: STORE_MESSAGES.OPERATIONS.LAST_WALLPAPER, atom: lastWallpaperState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return value || null; }, write: async (key: string, value: WallpaperData | null, store: StoreType) => { await store.set(key, value); }, }; // Effect for scheduler state export const schedulerEffect = { key: STORE_MESSAGES.OPERATIONS.SCHEDULER_ACTIVE, atom: schedulerState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return ( value || { isActive: false, intervalMinutes: null, nextChangeCountdown: "", } ); }, write: async (key: string, value: SchedulerState, store: StoreType) => { await store.set(key, value); }, }; // Effect for expanded categories export const expandedCategoriesEffect = { key: STORE_MESSAGES.OPERATIONS.EXPANDED_CATEGORIES, atom: expandedCategoriesState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return value || []; }, write: async (key: string, value: string[], store: StoreType) => { await store.set(key, value); }, }; // Effect for active styles export const activeStylesEffect = { key: STORE_MESSAGES.OPERATIONS.ACTIVE_STYLES, atom: activeStylesState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return value || []; }, write: async (key: string, value: string[], store: StoreType) => { await store.set(key, value); }, }; // Effect for custom style export const customStyleEffect = { key: STORE_MESSAGES.OPERATIONS.CUSTOM_STYLE, atom: customStyleState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return value || ""; }, write: async (key: string, value: string, store: StoreType) => { await store.set(key, value); }, }; // Effect for current wallpaper mode export const currentWallpaperModeEffect = { key: STORE_MESSAGES.OPERATIONS.CURRENT_MODE, atom: currentWallpaperModeState, store: store, read: async (key: string, store: StoreType) => { const value = await store.get(key); return value || "RandomStyleSelection"; }, write: async (key: string, value: string, store: StoreType) => { await store.set(key, value); }, };