Skip to content

Commit ba6c9b0

Browse files
committed
chore: merge
2 parents 9fc16b7 + 184714c commit ba6c9b0

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/main/store/module/preferences.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
import type { PreferencesStore } from '../types'
22
import { homedir, platform } from 'node:os'
3+
import path from 'node:path'
4+
import { app } from 'electron'
35
import Store from 'electron-store'
6+
import fs from 'fs-extra'
47
import { EDITOR_DEFAULTS } from '../constants'
58

69
const isWin = platform() === 'win32'
710

811
const storagePath = isWin ? `${homedir()}\\massCode` : `${homedir()}/massCode`
912
const backupPath = isWin ? `${storagePath}\\backups` : `${storagePath}/backups`
1013

14+
// Detect the correct default engine BEFORE the store constructor merges
15+
// defaults into the preferences file. Without this, existing SQLite users
16+
// who never had a `storage.engine` key would get 'markdown' as default,
17+
// making all their snippets invisible.
18+
function detectDefaultEngine(): 'sqlite' | 'markdown' {
19+
try {
20+
const prefsPath = path.join(
21+
app.getPath('userData'),
22+
'v2',
23+
'preferences.json',
24+
)
25+
26+
if (fs.existsSync(prefsPath)) {
27+
const raw = JSON.parse(fs.readFileSync(prefsPath, 'utf8'))
28+
29+
// User already has an explicit engine setting — respect it
30+
if (raw.storage?.engine) {
31+
return raw.storage.engine
32+
}
33+
34+
// No engine setting — check if SQLite DB exists (existing user)
35+
const userStoragePath = raw.storagePath || storagePath
36+
const dbPath = path.join(userStoragePath, 'massCode.db')
37+
38+
if (fs.existsSync(dbPath)) {
39+
return 'sqlite'
40+
}
41+
}
42+
}
43+
catch {
44+
// If anything goes wrong reading the file, fall through to default
45+
}
46+
47+
return 'markdown'
48+
}
49+
1150
const preferencesStore = new Store<PreferencesStore>({
1251
name: 'preferences',
1352
cwd: 'v2',
@@ -19,7 +58,7 @@ const preferencesStore = new Store<PreferencesStore>({
1958
theme: 'auto',
2059
editor: EDITOR_DEFAULTS,
2160
storage: {
22-
engine: 'markdown',
61+
engine: detectDefaultEngine(),
2362
vaultPath: null,
2463
},
2564
markdown: {

0 commit comments

Comments
 (0)