Skip to content

Commit 0d124ff

Browse files
committed
chore: better type safe for electron store
1 parent 9f30194 commit 0d124ff

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

apps/main/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { env } from "@follow/shared/env"
55
import { imageRefererMatches, selfRefererMatches } from "@follow/shared/image"
66
import { parse } from "cookie-es"
77
import { app, BrowserWindow, session } from "electron"
8-
import type { Cookie } from "electron/main"
98
import squirrelStartup from "electron-squirrel-startup"
109

1110
import { DEVICE_ID } from "./constants/system"
@@ -77,7 +76,7 @@ function bootstrap() {
7776
mainWindow = createMainWindow()
7877

7978
// restore cookies
80-
const cookies = store.get("cookies") as Cookie[]
79+
const cookies = store.get("cookies")
8180
if (cookies) {
8281
Promise.all(
8382
cookies.map((cookie) => {

apps/main/src/lib/proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const setProxyConfig = (inputProxy: string) => {
2525
}
2626

2727
export const getProxyConfig = () => {
28-
const proxyConfig = store.get("proxy") as string | undefined
28+
const proxyConfig = store.get("proxy")
2929
if (!proxyConfig) {
3030
return
3131
}

apps/main/src/lib/store.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Credentials } from "@eneris/push-receiver/dist/types"
2+
import type { Cookie } from "electron"
23
import Store from "electron-store"
34

45
// @keep-sorted
@@ -8,8 +9,16 @@ type StoreData = {
89
appearance?: "light" | "dark" | "system" | null
910
betterAuthSessionCookie?: string | null
1011
cacheSizeLimit?: number | null
12+
cookies?: Cookie[] | null
13+
minimizeToTray?: boolean | null
1114
proxy?: string | null
1215
user?: string | null
16+
windowState?: {
17+
height: number
18+
width: number
19+
x: number
20+
y: number
21+
} | null
1322
}
1423
export const store = new Store<StoreData>({ name: "db" })
1524

apps/main/src/lib/tray.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const destroyAppTray = () => {
5454

5555
const DEFAULT_MINIMIZE_TO_TRAY = isMacOS ? false : true
5656

57-
export const getTrayConfig = (): boolean => store.get("minimizeToTray") ?? DEFAULT_MINIMIZE_TO_TRAY
57+
export const getTrayConfig = () => store.get("minimizeToTray") ?? DEFAULT_MINIMIZE_TO_TRAY
5858

5959
export const setTrayConfig = (input: boolean) => {
6060
store.set("minimizeToTray", input)

apps/main/src/lib/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { store } from "./store"
88

99
const BetterAuthKey = "betterAuthSessionCookie"
1010
export const setBetterAuthSessionCookie = (cookie: string) => store.set(BetterAuthKey, cookie)
11-
export const getBetterAuthSessionCookie = (): string | null => store.get(BetterAuthKey) || null
11+
export const getBetterAuthSessionCookie = () => store.get(BetterAuthKey)
1212
export const cleanBetterAuthSessionCookie = () => store.set(BetterAuthKey, null)
1313

1414
const UserKey = "user"

apps/main/src/window.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,7 @@ export function createWindow(
222222
}
223223
export const windowStateStoreKey = "windowState"
224224
export const createMainWindow = () => {
225-
const windowState = store.get(windowStateStoreKey) as {
226-
height: number
227-
width: number
228-
x: number
229-
y: number
230-
} | null
225+
const windowState = store.get(windowStateStoreKey)
231226
const primaryDisplay = screen.getPrimaryDisplay()
232227
const { workArea } = primaryDisplay
233228

0 commit comments

Comments
 (0)