@@ -5,21 +5,18 @@ import Quickshell
55import Quickshell.Io
66
77// Persistent JSON configuration system
8+ // Loads synchronously at startup via FileView preload
89Singleton {
910 id: root
1011
11- // Configuration ready flag
12- property bool ready: false
13-
14- // Configuration file path - fallback to ~/.config if XDG_CONFIG_HOME is not set
12+ // Configuration file path
1513 readonly property string configDir: {
1614 const xdg = Quickshell .env (" XDG_CONFIG_HOME" )
1715 if (xdg && xdg !== " " ) return xdg + " /hypercube"
1816 const home = Quickshell .env (" HOME" )
1917 return home + " /.config/hypercube"
2018 }
2119 readonly property string configPath: configDir + " /shell.json"
22- readonly property string defaultConfigPath: Qt .resolvedUrl (" ../../defaults/config.json" )
2320
2421 // Default values (used for comparison when saving)
2522 readonly property var defaults: ({
@@ -111,48 +108,31 @@ Singleton {
111108 property int launcherMaxResults: defaults .launcher .maxResults
112109 property bool launcherShowCategories: defaults .launcher .showCategories
113110
114- // Check if config file exists and create if needed
115- Process {
116- id: configDirCheck
117- command: [" sh" , " -c" , " mkdir -p \" $(dirname '" + root .configPath + " ')\" && [ -f '" + root .configPath + " ' ] && echo exists || echo missing" ]
118- running: true
119- onExited: {
120- if (stdout && stdout .trim () === " missing" ) {
121- console .log (" Config: No user config found, using defaults" )
122- root .ready = true
123- } else {
124- // File exists, load it
125- configFile .reload ()
126- }
127- }
128- }
129-
130- // File watcher for config changes
111+ // Load config synchronously at startup
131112 FileView {
132113 id: configFile
133114 path: root .configPath
115+ preload: true
134116 watchChanges: true
135- blockLoading: true
136- preload: false // Don't preload - we check existence first
137117
138- onFileChanged : {
139- reload ( )
118+ onTextChanged : {
119+ root . parseConfig ( text () )
140120 }
121+ }
141122
142- onLoaded: {
143- if (text ()) {
144- root .parseConfig (text ())
145- } else {
146- root .ready = true
147- }
123+ // Parse on component completion (handles preloaded content)
124+ Component .onCompleted : {
125+ const content = configFile .text ()
126+ if (content && content .trim () !== " " ) {
127+ parseConfig (content)
128+ } else {
129+ console .log (" Config: No user config found, using defaults" )
148130 }
149131 }
150132
151133 // Parse configuration from JSON
152134 function parseConfig (content ) {
153135 if (! content || content .trim () === " " ) {
154- console .log (" Config: Empty config, using defaults" )
155- ready = true
156136 return
157137 }
158138
@@ -218,22 +198,17 @@ Singleton {
218198 launcherShowCategories = config .launcher .showCategories ?? launcherShowCategories
219199 }
220200
221- console .log (" Config: Loaded successfully" )
222- ready = true
201+ console .log (" Config: Loaded from" , root .configPath )
223202 } catch (e) {
224- console .error (" Config: Failed to parse config:" , e)
225- ready = true // Use defaults
203+ console .error (" Config: Failed to parse:" , e)
226204 }
227205 }
228206
229207 // Process to write config file
230208 Process {
231209 id: saveProcess
232210 running: false
233-
234- onExited: {
235- console .log (" Config: Saved to" , root .configPath )
236- }
211+ onExited: console .log (" Config: Saved to" , root .configPath )
237212 }
238213
239214 // Helper to add non-default value to config object
@@ -302,31 +277,12 @@ Singleton {
302277 saveProcess .running = true
303278 }
304279
305- // Load configuration
306- function load () {
307- // Config file will be loaded automatically via preload
308- // If already loaded, parse immediately
309- if (configFile .loaded ) {
310- const content = configFile .text ()
311- if (content && content .trim () !== " " ) {
312- parseConfig (content)
313- } else {
314- console .log (" Config: No config file found, using defaults" )
315- ready = true
316- }
317- } else {
318- // Will be parsed when onLoaded fires
319- console .log (" Config: Waiting for config file to load..." )
320- }
321- }
322-
323- // Set a nested value and save
280+ // Set a value and save
324281 function setValue (key , value ) {
325282 const parts = key .split (" ." )
326283 if (parts .length === 1 ) {
327284 root[key] = value
328285 } else {
329- // Handle nested keys like "appearance.darkMode"
330286 root[parts[1 ]] = value
331287 }
332288 save ()
0 commit comments