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