chore: better type safe for electron store

This commit is contained in:
Stephen Zhou 2025-01-22 22:38:44 +08:00
parent 9f30194db5
commit 0d124ffd6b
No known key found for this signature in database
6 changed files with 14 additions and 11 deletions

View File

@ -5,7 +5,6 @@ import { env } from "@follow/shared/env"
import { imageRefererMatches, selfRefererMatches } from "@follow/shared/image"
import { parse } from "cookie-es"
import { app, BrowserWindow, session } from "electron"
import type { Cookie } from "electron/main"
import squirrelStartup from "electron-squirrel-startup"
import { DEVICE_ID } from "./constants/system"
@ -77,7 +76,7 @@ function bootstrap() {
mainWindow = createMainWindow()
// restore cookies
const cookies = store.get("cookies") as Cookie[]
const cookies = store.get("cookies")
if (cookies) {
Promise.all(
cookies.map((cookie) => {

View File

@ -25,7 +25,7 @@ export const setProxyConfig = (inputProxy: string) => {
}
export const getProxyConfig = () => {
const proxyConfig = store.get("proxy") as string | undefined
const proxyConfig = store.get("proxy")
if (!proxyConfig) {
return
}

View File

@ -1,4 +1,5 @@
import type { Credentials } from "@eneris/push-receiver/dist/types"
import type { Cookie } from "electron"
import Store from "electron-store"
// @keep-sorted
@ -8,8 +9,16 @@ type StoreData = {
appearance?: "light" | "dark" | "system" | null
betterAuthSessionCookie?: string | null
cacheSizeLimit?: number | null
cookies?: Cookie[] | null
minimizeToTray?: boolean | null
proxy?: string | null
user?: string | null
windowState?: {
height: number
width: number
x: number
y: number
} | null
}
export const store = new Store<StoreData>({ name: "db" })

View File

@ -54,7 +54,7 @@ const destroyAppTray = () => {
const DEFAULT_MINIMIZE_TO_TRAY = isMacOS ? false : true
export const getTrayConfig = (): boolean => store.get("minimizeToTray") ?? DEFAULT_MINIMIZE_TO_TRAY
export const getTrayConfig = () => store.get("minimizeToTray") ?? DEFAULT_MINIMIZE_TO_TRAY
export const setTrayConfig = (input: boolean) => {
store.set("minimizeToTray", input)

View File

@ -8,7 +8,7 @@ import { store } from "./store"
const BetterAuthKey = "betterAuthSessionCookie"
export const setBetterAuthSessionCookie = (cookie: string) => store.set(BetterAuthKey, cookie)
export const getBetterAuthSessionCookie = (): string | null => store.get(BetterAuthKey) || null
export const getBetterAuthSessionCookie = () => store.get(BetterAuthKey)
export const cleanBetterAuthSessionCookie = () => store.set(BetterAuthKey, null)
const UserKey = "user"

View File

@ -222,12 +222,7 @@ export function createWindow(
}
export const windowStateStoreKey = "windowState"
export const createMainWindow = () => {
const windowState = store.get(windowStateStoreKey) as {
height: number
width: number
x: number
y: number
} | null
const windowState = store.get(windowStateStoreKey)
const primaryDisplay = screen.getPrimaryDisplay()
const { workArea } = primaryDisplay