Skip to content

Commit ff7c915

Browse files
refactor: reorganize app and preferences store keys (#706)
1 parent c758ae0 commit ff7c915

30 files changed

Lines changed: 939 additions & 165 deletions

File tree

src/main/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function initApi() {
1818
const { node } = await importEsm('@elysiajs/node')
1919

2020
const app = new Elysia({ adapter: node() })
21-
const port = store.preferences.get('apiPort')
21+
const port = store.preferences.get('api.port')
2222

2323
app
2424
.use(cors({ origin: '*' }))

src/main/db/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let currentDbPath: string | null = null
1313

1414
export function useDB(customDbPath?: string) {
1515
const dbPath
16-
= customDbPath || `${store.preferences.get('storagePath')}/${DB_NAME}`
16+
= customDbPath || `${store.preferences.get('storage.rootPath')}/${DB_NAME}`
1717

1818
if (db && currentDbPath === dbPath)
1919
return db

src/main/i18n/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Backend from 'i18next-fs-backend'
55
import { store } from '../store'
66
import { language } from './language'
77

8-
const storedLng = store.preferences.get('language')
8+
const storedLng = store.preferences.get('localization.locale')
99

1010
const lng
1111
= storedLng && Object.keys(language).includes(storedLng) ? storedLng : 'en_US'

src/main/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else {
4141
}
4242

4343
function createWindow() {
44-
const bounds = store.app.get('bounds')
44+
const bounds = store.app.get('window.bounds')
4545

4646
mainWindow = new BrowserWindow({
4747
width: 1200,
@@ -79,7 +79,7 @@ function createWindow() {
7979
})
8080

8181
mainWindow.on('close', (event) => {
82-
store.app.set('bounds', mainWindow.getBounds())
82+
store.app.set('window.bounds', mainWindow.getBounds())
8383

8484
if (process.platform === 'darwin' && !isQuitting) {
8585
event.preventDefault()
@@ -104,7 +104,7 @@ else {
104104
const vaultPath
105105
= (store.preferences.get('storage.vaultPath') as string | null)
106106
|| path.join(
107-
store.preferences.get('storagePath') as string,
107+
store.preferences.get('storage.rootPath') as string,
108108
'markdown-vault',
109109
)
110110
ensureFlatSpacesLayout(vaultPath)
@@ -137,7 +137,7 @@ else {
137137
})
138138

139139
try {
140-
const storagePath = store.preferences.get('storagePath')
140+
const storagePath = store.preferences.get('storage.rootPath')
141141
const dbPath = `${storagePath}/massCode.db`
142142

143143
if (isSqliteFile(dbPath)) {

src/main/ipc/handlers/fs.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const ASSETS_DIR = 'assets'
1111

1212
export function registerFsHandlers() {
1313
ipcMain.handle('fs:assets', (event, { buffer, fileName }) => {
14-
const storagePath = store.preferences.get('storagePath')
14+
const storagePath = store.preferences.get('storage.rootPath')
1515

1616
return new Promise((resolve, reject) => {
1717
try {
@@ -35,7 +35,10 @@ export function registerFsHandlers() {
3535
ipcMain.handle('fs:notes-asset', (event, { buffer, ext }) => {
3636
const vaultPath
3737
= (store.preferences.get('storage.vaultPath') as string | null)
38-
|| join(store.preferences.get('storagePath') as string, 'markdown-vault')
38+
|| join(
39+
store.preferences.get('storage.rootPath') as string,
40+
'markdown-vault',
41+
)
3942

4043
return new Promise((resolve, reject) => {
4144
try {

src/main/ipc/handlers/prettier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import prettier from 'prettier'
44
import { store } from '../../store'
55

66
export async function format(source: string, parser: string) {
7-
const editor = store.preferences.get('editor')
7+
const editor = store.preferences.get('editor.code')
88

99
return prettier.format(source, {
1010
parser,

src/main/ipc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function registerIPC() {
3131
})
3232

3333
ipcMain.handle('db:migrate-to-markdown', async (_, sqliteDbPath?: string) => {
34-
const storagePath = store.preferences.get('storagePath') as string
34+
const storagePath = store.preferences.get('storage.rootPath') as string
3535
const dbPath
3636
= typeof sqliteDbPath === 'string' && sqliteDbPath.trim()
3737
? sqliteDbPath

src/main/preload.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import type {
2-
AppStore,
3-
MathNotebookStore,
4-
PreferencesStore,
5-
} from './store/types'
61
import type { EventCallback } from './types'
72
import type { Channel } from './types/ipc'
83
import { contextBridge, ipcRenderer } from 'electron'
@@ -26,27 +21,20 @@ contextBridge.exposeInMainWorld('electron', {
2621
},
2722
store: {
2823
app: {
29-
get: (name: keyof AppStore) => store.app.get(name),
30-
set: <T extends keyof AppStore>(name: T, value: AppStore[T]) =>
31-
store.app.set(name, value),
32-
delete: (name: keyof AppStore) => store.app.delete(name),
24+
get: <T = unknown>(name: string) => store.app.get(name) as T,
25+
set: (name: string, value: unknown) => store.app.set(name, value),
26+
delete: (name: string) => store.app.delete(name),
3327
},
3428
preferences: {
35-
get: (name: keyof PreferencesStore) => store.preferences.get(name),
36-
set: <T extends keyof PreferencesStore>(
37-
name: T,
38-
value: PreferencesStore[T],
39-
) => store.preferences.set(name, value),
40-
delete: (name: keyof PreferencesStore) => store.preferences.delete(name),
29+
get: <T = unknown>(name: string) => store.preferences.get(name) as T,
30+
set: (name: string, value: unknown) => store.preferences.set(name, value),
31+
delete: (name: string) => store.preferences.delete(name),
4132
},
4233
mathNotebook: {
43-
get: (name: keyof MathNotebookStore) => store.mathNotebook.get(name),
44-
set: <T extends keyof MathNotebookStore>(
45-
name: T,
46-
value: MathNotebookStore[T],
47-
) => store.mathNotebook.set(name, value),
48-
delete: (name: keyof MathNotebookStore) =>
49-
store.mathNotebook.delete(name),
34+
get: <T = unknown>(name: string) => store.mathNotebook.get(name) as T,
35+
set: (name: string, value: unknown) =>
36+
store.mathNotebook.set(name, value),
37+
delete: (name: string) => store.mathNotebook.delete(name),
5038
},
5139
},
5240
i18n: {

src/main/storage/providers/markdown/runtime/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function getVaultPath(): string {
3030
return configuredVaultPath
3131
}
3232

33-
const storagePath = store.preferences.get('storagePath') as string
33+
const storagePath = store.preferences.get('storage.rootPath') as string
3434
return path.join(storagePath, 'markdown-vault')
3535
}
3636

0 commit comments

Comments
 (0)