fix: use electron store (#2644)
This commit is contained in:
parent
e569681198
commit
9f30194db5
|
|
@ -37,6 +37,7 @@
|
|||
"electron-context-menu": "4.0.4",
|
||||
"electron-log": "5.2.4",
|
||||
"electron-squirrel-startup": "1.0.1",
|
||||
"electron-store": "^10.0.0",
|
||||
"electron-updater": "^6.3.9",
|
||||
"es-toolkit": "1.29.0",
|
||||
"fast-folder-size": "2.3.0",
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ const registerPushNotifications = async () => {
|
|||
debug: true,
|
||||
firebase: JSON.parse(env.VITE_FIREBASE_CONFIG),
|
||||
persistentIds: persistentIds || [],
|
||||
credentials: credentials || null,
|
||||
credentials: credentials || undefined,
|
||||
bundleId: "is.follow",
|
||||
chromeId: "is.follow",
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,39 +1,18 @@
|
|||
import { resolve } from "node:path"
|
||||
import type { Credentials } from "@eneris/push-receiver/dist/types"
|
||||
import Store from "electron-store"
|
||||
|
||||
import { app } from "electron"
|
||||
import { JSONFileSyncPreset } from "lowdb/node"
|
||||
|
||||
let db: {
|
||||
data: Record<string, unknown>
|
||||
write: () => void
|
||||
read: () => void
|
||||
}
|
||||
|
||||
const createOrGetDb = () => {
|
||||
if (!db) {
|
||||
db = JSONFileSyncPreset(resolve(app.getPath("userData"), "db.json"), {}) as typeof db
|
||||
}
|
||||
return db
|
||||
// @keep-sorted
|
||||
type StoreData = {
|
||||
"notifications-credentials"?: Credentials | null
|
||||
"notifications-persistent-ids"?: string[] | null
|
||||
appearance?: "light" | "dark" | "system" | null
|
||||
betterAuthSessionCookie?: string | null
|
||||
cacheSizeLimit?: number | null
|
||||
proxy?: string | null
|
||||
user?: string | null
|
||||
}
|
||||
export const store = new Store<StoreData>({ name: "db" })
|
||||
|
||||
export enum StoreKey {
|
||||
CacheSizeLimit = "cacheSizeLimit",
|
||||
}
|
||||
|
||||
export const store = {
|
||||
get: (key: string) => {
|
||||
const db = createOrGetDb()
|
||||
|
||||
return db.data[key] as any
|
||||
},
|
||||
set: (key: string, value: any) => {
|
||||
const db = createOrGetDb()
|
||||
db.data[key] = value
|
||||
db.write()
|
||||
},
|
||||
delete: (key: string) => {
|
||||
const db = createOrGetDb()
|
||||
delete db.data[key]
|
||||
db.write()
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
export const getBetterAuthSessionCookie = (): string | null => store.get(BetterAuthKey) || null
|
||||
export const cleanBetterAuthSessionCookie = () => store.set(BetterAuthKey, null)
|
||||
|
||||
const UserKey = "user"
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import { tipcClient } from "~/lib/client"
|
|||
const proxyAtom = atom("")
|
||||
|
||||
proxyAtom.onMount = (setAtom) => {
|
||||
tipcClient?.getProxyConfig().then((proxy: string) => {
|
||||
setAtom(proxy)
|
||||
tipcClient?.getProxyConfig().then((proxy) => {
|
||||
setAtom(proxy || "")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -345,6 +345,9 @@ importers:
|
|||
electron-squirrel-startup:
|
||||
specifier: 1.0.1
|
||||
version: 1.0.1
|
||||
electron-store:
|
||||
specifier: ^10.0.0
|
||||
version: 10.0.0
|
||||
electron-updater:
|
||||
specifier: ^6.3.9
|
||||
version: 6.3.9
|
||||
|
|
@ -6545,6 +6548,9 @@ packages:
|
|||
resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==}
|
||||
engines: {node: '>=8.0.0'}
|
||||
|
||||
atomically@2.0.3:
|
||||
resolution: {integrity: sha512-kU6FmrwZ3Lx7/7y3hPS5QnbJfaohcIul5fGqf7ok+4KklIEk9tJ0C2IQPdacSbVUWv6zVHXEBWoWd6NrVMT7Cw==}
|
||||
|
||||
author-regex@1.0.0:
|
||||
resolution: {integrity: sha512-KbWgR8wOYRAPekEmMXrYYdc7BRyhn2Ftk7KWfMUnQ43hFdojWEFRxhhRUm3/OFEdPa1r0KAvTTg9YQK57xTe0g==}
|
||||
engines: {node: '>=0.8'}
|
||||
|
|
@ -7288,6 +7294,10 @@ packages:
|
|||
concat-map@0.0.1:
|
||||
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
|
||||
|
||||
conf@13.1.0:
|
||||
resolution: {integrity: sha512-Bi6v586cy1CoTFViVO4lGTtx780lfF96fUmS1lSX6wpZf6330NvHUu6fReVuDP1de8Mg0nkZb01c8tAQdz1o3w==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
confbox@0.1.8:
|
||||
resolution: {integrity: sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==}
|
||||
|
||||
|
|
@ -7610,6 +7620,10 @@ packages:
|
|||
dayjs@1.11.13:
|
||||
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
|
||||
|
||||
debounce-fn@6.0.0:
|
||||
resolution: {integrity: sha512-rBMW+F2TXryBwB54Q0d8drNEI+TfoS9JpNTAoVpukbWEhjXQq4rySFYLaqXMFXwdv61Zb2OHtj5bviSoimqxRQ==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
debug@2.6.9:
|
||||
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
|
||||
peerDependencies:
|
||||
|
|
@ -7885,6 +7899,10 @@ packages:
|
|||
resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
dot-prop@9.0.0:
|
||||
resolution: {integrity: sha512-1gxPBJpI/pcjQhKgIU91II6Wkay+dLcN3M6rf2uwP8hRur3HtQXjVrdAK3sjC0piaEuxzMwjXChcETiJl47lAQ==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
dotenv-expand@11.0.7:
|
||||
resolution: {integrity: sha512-zIHwmZPRshsCdpMDyVsqGmgyP0yT8GAgXUnkdAoJisxvf33k7yO6OuoKmcTGuXPWSsm8Oh88nZicRLA9Y0rUeA==}
|
||||
engines: {node: '>=12'}
|
||||
|
|
@ -8079,6 +8097,10 @@ packages:
|
|||
electron-squirrel-startup@1.0.1:
|
||||
resolution: {integrity: sha512-sTfFIHGku+7PsHLJ7v0dRcZNkALrV+YEozINTW8X1nM//e5O3L+rfYuvSW00lmGHnYmUjARZulD8F2V8ISI9RA==}
|
||||
|
||||
electron-store@10.0.0:
|
||||
resolution: {integrity: sha512-BU/QZh+5twHBprRdLu3YZX/rIarmZzhTNpJvAvqG1/yN0mNCrsMh0kl7bM4xaUKDNRiHz1r7wP/7Prjh7cleIw==}
|
||||
engines: {node: '>=20'}
|
||||
|
||||
electron-to-chromium@1.5.65:
|
||||
resolution: {integrity: sha512-PWVzBjghx7/wop6n22vS2MLU8tKGd4Q91aCEGhG/TYmW6PP5OcSXcdnxTe1NNt0T66N8D6jxh4kC8UsdzOGaIw==}
|
||||
|
||||
|
|
@ -8184,6 +8206,10 @@ packages:
|
|||
resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
env-paths@3.0.0:
|
||||
resolution: {integrity: sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
|
||||
env-string@1.0.1:
|
||||
resolution: {integrity: sha512-/DhCJDf5DSFK32joQiWRpWrT0h7p3hVQfMKxiBb7Nt8C8IF8BYyPtclDnuGGLOoj16d/8udKeiE7JbkotDmorQ==}
|
||||
|
||||
|
|
@ -10447,6 +10473,9 @@ packages:
|
|||
json-schema-traverse@1.0.0:
|
||||
resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}
|
||||
|
||||
json-schema-typed@8.0.1:
|
||||
resolution: {integrity: sha512-XQmWYj2Sm4kn4WeTYvmpKEbyPsL7nBsb647c7pMe6l02/yx2+Jfc4dT6UZkEXnIUb5LhD55r2HPsJ1milQ4rDg==}
|
||||
|
||||
json-schema@0.4.0:
|
||||
resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==}
|
||||
|
||||
|
|
@ -13894,6 +13923,9 @@ packages:
|
|||
structured-headers@0.4.1:
|
||||
resolution: {integrity: sha512-0MP/Cxx5SzeeZ10p/bZI0S6MpgD+yxAhi1BOQ34jgnMXsCq3j1t6tQnZu+KdlL7dvJTLT3g9xN8tl10TqgFMcg==}
|
||||
|
||||
stubborn-fs@1.2.5:
|
||||
resolution: {integrity: sha512-H2N9c26eXjzL/S/K+i/RHHcFanE74dptvvjM8iwzwbVcWY/zjBbgRqF3K0DY4+OD+uTTASTBvDoxPDaPN02D7g==}
|
||||
|
||||
style-to-object@1.0.8:
|
||||
resolution: {integrity: sha512-xT47I/Eo0rwJmaXC4oilDGDWLohVhR6o/xAQcPQN8q6QBuZVL8qMYL85kLmST5cPjAorwvqIA4qXTRQoYHaL6g==}
|
||||
|
||||
|
|
@ -14439,6 +14471,10 @@ packages:
|
|||
uhyphen@0.2.0:
|
||||
resolution: {integrity: sha512-qz3o9CHXmJJPGBdqzab7qAYuW8kQGKNEuoHFYrBwV6hWIMcpAmxDLXojcHfFr9US1Pe6zUswEIJIbLI610fuqA==}
|
||||
|
||||
uint8array-extras@1.4.0:
|
||||
resolution: {integrity: sha512-ZPtzy0hu4cZjv3z5NW9gfKnNLjoz4y6uv4HlelAjDK7sY/xOkKZv9xK/WQpcsBB3jEybChz9DPC2U/+cusjJVQ==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
unbox-primitive@1.0.2:
|
||||
resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==}
|
||||
|
||||
|
|
@ -14973,6 +15009,9 @@ packages:
|
|||
resolution: {integrity: sha512-f+Gy33Oa5Z14XY9679Zze+7VFhbsQfBFXodnU2x589l4kxGM9L5Y8zETTmcMR5pWOPQyRv4Z0lNax6xCO0NSlA==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
when-exit@2.1.4:
|
||||
resolution: {integrity: sha512-4rnvd3A1t16PWzrBUcSDZqcAmsUIy4minDXT/CZ8F2mVDgd65i4Aalimgz1aQkRGU0iH5eT5+6Rx2TK8o443Pg==}
|
||||
|
||||
which-boxed-primitive@1.1.0:
|
||||
resolution: {integrity: sha512-Ei7Miu/AXe2JJ4iNF5j/UphAgRoma4trE6PtisM09bPygb3egMH3YLW/befsWb1A1AxvNSFidOFTB18XtnIIng==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
|
@ -21863,6 +21902,11 @@ snapshots:
|
|||
|
||||
atomic-sleep@1.0.0: {}
|
||||
|
||||
atomically@2.0.3:
|
||||
dependencies:
|
||||
stubborn-fs: 1.2.5
|
||||
when-exit: 2.1.4
|
||||
|
||||
author-regex@1.0.0: {}
|
||||
|
||||
autoprefixer@10.4.20(postcss@8.4.49):
|
||||
|
|
@ -22809,6 +22853,18 @@ snapshots:
|
|||
|
||||
concat-map@0.0.1: {}
|
||||
|
||||
conf@13.1.0:
|
||||
dependencies:
|
||||
ajv: 8.17.1
|
||||
ajv-formats: 3.0.1(ajv@8.17.1)
|
||||
atomically: 2.0.3
|
||||
debounce-fn: 6.0.0
|
||||
dot-prop: 9.0.0
|
||||
env-paths: 3.0.0
|
||||
json-schema-typed: 8.0.1
|
||||
semver: 7.6.3
|
||||
uint8array-extras: 1.4.0
|
||||
|
||||
confbox@0.1.8: {}
|
||||
|
||||
config-file-ts@0.2.6:
|
||||
|
|
@ -23196,6 +23252,10 @@ snapshots:
|
|||
|
||||
dayjs@1.11.13: {}
|
||||
|
||||
debounce-fn@6.0.0:
|
||||
dependencies:
|
||||
mimic-function: 5.0.1
|
||||
|
||||
debug@2.6.9:
|
||||
dependencies:
|
||||
ms: 2.0.0
|
||||
|
|
@ -23475,6 +23535,10 @@ snapshots:
|
|||
dependencies:
|
||||
is-obj: 2.0.0
|
||||
|
||||
dot-prop@9.0.0:
|
||||
dependencies:
|
||||
type-fest: 4.30.0
|
||||
|
||||
dotenv-expand@11.0.7:
|
||||
dependencies:
|
||||
dotenv: 16.4.7
|
||||
|
|
@ -23721,6 +23785,11 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
electron-store@10.0.0:
|
||||
dependencies:
|
||||
conf: 13.1.0
|
||||
type-fest: 4.30.0
|
||||
|
||||
electron-to-chromium@1.5.65: {}
|
||||
|
||||
electron-updater@6.3.9:
|
||||
|
|
@ -23846,6 +23915,8 @@ snapshots:
|
|||
|
||||
env-paths@2.2.1: {}
|
||||
|
||||
env-paths@3.0.0: {}
|
||||
|
||||
env-string@1.0.1: {}
|
||||
|
||||
envinfo@7.11.0: {}
|
||||
|
|
@ -26801,6 +26872,8 @@ snapshots:
|
|||
|
||||
json-schema-traverse@1.0.0: {}
|
||||
|
||||
json-schema-typed@8.0.1: {}
|
||||
|
||||
json-schema@0.4.0: {}
|
||||
|
||||
json-stable-stringify-without-jsonify@1.0.1: {}
|
||||
|
|
@ -30764,6 +30837,8 @@ snapshots:
|
|||
|
||||
structured-headers@0.4.1: {}
|
||||
|
||||
stubborn-fs@1.2.5: {}
|
||||
|
||||
style-to-object@1.0.8:
|
||||
dependencies:
|
||||
inline-style-parser: 0.2.4
|
||||
|
|
@ -31357,6 +31432,8 @@ snapshots:
|
|||
|
||||
uhyphen@0.2.0: {}
|
||||
|
||||
uint8array-extras@1.4.0: {}
|
||||
|
||||
unbox-primitive@1.0.2:
|
||||
dependencies:
|
||||
call-bind: 1.0.8
|
||||
|
|
@ -31895,6 +31972,8 @@ snapshots:
|
|||
|
||||
wheel-gestures@2.2.48: {}
|
||||
|
||||
when-exit@2.1.4: {}
|
||||
|
||||
which-boxed-primitive@1.1.0:
|
||||
dependencies:
|
||||
is-bigint: 1.1.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue