🔧 persist font size across sessions
This commit is contained in:
@@ -5,6 +5,8 @@ import { readFileSync, writeFileSync, mkdirSync } from 'fs'
|
|||||||
export interface GlobalConfig {
|
export interface GlobalConfig {
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
projectPath?: string
|
projectPath?: string
|
||||||
|
fontSize?: number
|
||||||
|
theme?: 'dark' | 'light'
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONFIG_DIR = join(homedir(), '.hohoff')
|
const CONFIG_DIR = join(homedir(), '.hohoff')
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default function App(): JSX.Element {
|
|||||||
const {
|
const {
|
||||||
setFileTree, activeFilePath, isDirty, markSaved, activeFileContent, theme, toggleTheme,
|
setFileTree, activeFilePath, isDirty, markSaved, activeFileContent, theme, toggleTheme,
|
||||||
loadSession, revisionPanelOpen, toggleRevisionPanel, fontSize, setFontSize,
|
loadSession, revisionPanelOpen, toggleRevisionPanel, fontSize, setFontSize,
|
||||||
openProjectSearch, clearActiveFile
|
openProjectSearch, clearActiveFile, initPrefs
|
||||||
} = useEditorStore()
|
} = useEditorStore()
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(
|
const [sidebarOpen, setSidebarOpen] = useState(
|
||||||
() => localStorage.getItem('sidebarOpen') !== 'false'
|
() => localStorage.getItem('sidebarOpen') !== 'false'
|
||||||
@@ -32,10 +32,10 @@ export default function App(): JSX.Element {
|
|||||||
window.api.listFiles().then(setFileTree)
|
window.api.listFiles().then(setFileTree)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load file tree, apply persisted theme, restore session, and detect first run
|
// Load file tree, restore prefs + session, and detect first run
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.api.listFiles().then(setFileTree)
|
window.api.listFiles().then(setFileTree)
|
||||||
document.documentElement.classList.toggle('light', theme === 'light')
|
initPrefs()
|
||||||
loadSession()
|
loadSession()
|
||||||
window.api.readConfig().then((cfg) => {
|
window.api.readConfig().then((cfg) => {
|
||||||
if (!cfg.apiKey || !cfg.projectPath) {
|
if (!cfg.apiKey || !cfg.projectPath) {
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ interface EditorState {
|
|||||||
// Theme
|
// Theme
|
||||||
theme: 'dark' | 'light'
|
theme: 'dark' | 'light'
|
||||||
toggleTheme: () => void
|
toggleTheme: () => void
|
||||||
|
initPrefs: () => Promise<void>
|
||||||
|
|
||||||
// Revision panel
|
// Revision panel
|
||||||
revisionPanelOpen: boolean
|
revisionPanelOpen: boolean
|
||||||
@@ -604,22 +605,29 @@ export const useEditorStore = create<EditorState>((set, get) => ({
|
|||||||
revisions: [],
|
revisions: [],
|
||||||
setRevisions: (revisions) => set({ revisions }),
|
setRevisions: (revisions) => set({ revisions }),
|
||||||
|
|
||||||
fontSize: Number(localStorage.getItem('editorFontSize')) || 15,
|
fontSize: 15,
|
||||||
setFontSize: (size) => {
|
setFontSize: (size) => {
|
||||||
const clamped = Math.max(11, Math.min(24, size))
|
const clamped = Math.max(11, Math.min(24, size))
|
||||||
localStorage.setItem('editorFontSize', String(clamped))
|
window.api.writeConfig({ fontSize: clamped })
|
||||||
set({ fontSize: clamped })
|
set({ fontSize: clamped })
|
||||||
},
|
},
|
||||||
|
|
||||||
theme: (localStorage.getItem('editorTheme') as 'dark' | 'light') || 'dark',
|
theme: 'dark',
|
||||||
toggleTheme: () => {
|
toggleTheme: () => {
|
||||||
set((s) => {
|
set((s) => {
|
||||||
const next = s.theme === 'dark' ? 'light' : 'dark'
|
const next = s.theme === 'dark' ? 'light' : 'dark'
|
||||||
localStorage.setItem('editorTheme', next)
|
window.api.writeConfig({ theme: next })
|
||||||
document.documentElement.classList.toggle('light', next === 'light')
|
document.documentElement.classList.toggle('light', next === 'light')
|
||||||
return { theme: next }
|
return { theme: next }
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
initPrefs: async () => {
|
||||||
|
const cfg = await window.api.readConfig()
|
||||||
|
const fontSize = Math.max(11, Math.min(24, cfg.fontSize ?? 15))
|
||||||
|
const theme = cfg.theme ?? 'dark'
|
||||||
|
document.documentElement.classList.toggle('light', theme === 'light')
|
||||||
|
set({ fontSize, theme })
|
||||||
|
},
|
||||||
|
|
||||||
projectSearchOpen: false,
|
projectSearchOpen: false,
|
||||||
openProjectSearch: () => set({ projectSearchOpen: true }),
|
openProjectSearch: () => set({ projectSearchOpen: true }),
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user