Add persistent configuration storage#13
Merged
Merged
Conversation
Prompt: I'd like the app to store its settings (selected font size and window size) in the configuration file located at ~/.config/architect. Could we also store the window position? Solution: Implemented a configuration system that persists user preferences across application restarts: - Created config.zig module with Config struct that stores font_size, window_width, window_height, window_x, and window_y - Configuration is saved to ~/.config/architect/config.json in JSON format with proper indentation - On startup, the application loads saved settings or falls back to defaults - Settings are automatically saved when: - Window is resized (SDL_EVENT_WINDOW_RESIZED) - Window is moved (SDL_EVENT_WINDOW_MOVED) - Font size is changed via Cmd+Plus/Minus shortcuts - Added SDL_SetWindowPosition and SDL_EVENT_WINDOW_MOVED to c.zig bindings - Window position is restored on launch if previously saved (skipped if position is 0,0 to allow default centering on first run) The configuration file uses a simple JSON structure and is created automatically in ~/.config/architect/ directory if it doesn't exist.
There was a problem hiding this comment.
Pull request overview
This PR adds persistent configuration storage to Architect, enabling the application to remember user preferences like font size and window dimensions across sessions. The configuration is stored in JSON format at ~/.config/architect/config.json.
Key Changes:
- New
Configmodule with JSON-based persistence for font size and window geometry - Automatic configuration saving on window resize, move, and font size changes
- Configuration restoration on application startup with fallback to defaults
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/config.zig | Implements Config struct with load/save methods for JSON persistence and includes test coverage |
| src/main.zig | Integrates config loading at startup, auto-saves on window/font changes, and restores window position |
| src/c.zig | Adds SDL window positioning function and moved event constant |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes based on Copilot review comments: 1. Fix fs.cwd().writeFile() usage with absolute path - Changed to use fs.createFileAbsolute() instead - The sub_path parameter expects relative paths, not absolute 2. Use sentinel value for window position - Changed default from (0, 0) to (-1, -1) as sentinel - Now correctly handles positions at (0, 0) and negative coordinates - Allows proper multi-monitor support 3. Reduce excessive I/O on window move - Removed auto-save on every SDL_EVENT_WINDOW_MOVED event - Window position is tracked but only saved on resize/font change - Prevents unnecessary file writes during window dragging Updated documentation to reflect these changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements persistent configuration storage for Architect, allowing user preferences to be remembered across application restarts.
Changes
New Configuration Module (
src/config.zig)Configstruct that stores:font_size: Selected font sizewindow_widthandwindow_height: Window dimensionswindow_xandwindow_y: Window positionload()andsave()methods for reading/writing JSON config~/.config/architect/config.jsonUpdated Main Application (
src/main.zig)Updated C Bindings (
src/c.zig)SDL_SetWindowPositionfunctionSDL_EVENT_WINDOW_MOVEDevent constantConfiguration File Format
{ "font_size": 14, "window_width": 1200, "window_height": 900, "window_x": 150, "window_y": 100 }Testing
All tests pass:
zig build test zig buildThe configuration directory is created automatically if it doesn't exist.