Skip to content

Fix config hot reload after directory recreation - #1209

Merged
lujjjh merged 1 commit into
mainfrom
fix-1205-config-hot-reload
May 25, 2026
Merged

lujjjh merged 1 commit into
mainfrom
fix-1205-config-hot-reload

Conversation

@lujjjh

@lujjjh lujjjh commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the configuration-specific DispatchSource watchers with a generic FSEvents-backed FileWatcher.
  • Watch stable parent roots so deleting and recreating the configuration directory still triggers reloads.
  • Keep configuration saves disabled outside the app runtime so unit tests do not write to the user config file.

Testing

  • swiftformat --lint LinearMouse/Utilities/FileWatcher.swift LinearMouse/State/ConfigurationState.swift LinearMouse/Utilities/ProcessEnvironment.swift LinearMouseUnitTests/Utilities/FileWatcherTests.swift LinearMouseUnitTests/Utilities/ProcessEnvironmentTests.swift
  • swiftlint lint --quiet LinearMouse/Utilities/FileWatcher.swift LinearMouse/State/ConfigurationState.swift LinearMouse/Utilities/ProcessEnvironment.swift LinearMouseUnitTests/Utilities/FileWatcherTests.swift LinearMouseUnitTests/Utilities/ProcessEnvironmentTests.swift
  • xcodebuild test -project LinearMouse.xcodeproj -scheme LinearMouse -destination 'platform=macOS' -only-testing:LinearMouseUnitTests/ProcessEnvironmentTests -only-testing:LinearMouseUnitTests/FileWatcherTests

Closes #1205

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes configuration hot-reload so that deleting and recreating the configuration directory still triggers reloads, and it prevents configuration writes when running under unit tests (and other non-app runtime contexts).

Changes:

  • Introduces a generic FileWatcher backed by FSEvents to watch stable parent roots (survives directory recreation).
  • Replaces DispatchSourceFileSystemObject-based config watchers in ConfigurationState with the new FileWatcher.
  • Improves runtime detection via ProcessEnvironment and gates configuration saving when not running as the app; adds unit tests for both.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
LinearMouse/Utilities/FileWatcher.swift Adds an FSEvents-based watcher that can keep detecting changes even if the watched directory is deleted/recreated.
LinearMouse/State/ConfigurationState.swift Switches config hot reload to FileWatcher and prevents saves outside app runtime (tests/previews).
LinearMouse/Utilities/ProcessEnvironment.swift Expands test-environment detection and adds isRunningApp for gating side effects.
LinearMouseUnitTests/Utilities/FileWatcherTests.swift Adds coverage to ensure events are reported after a watched directory is recreated.
LinearMouseUnitTests/Utilities/ProcessEnvironmentTests.swift Adds coverage verifying the unit test host is detected as running tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lujjjh
lujjjh merged commit 9f4d73b into main May 25, 2026
2 checks passed
@lujjjh
lujjjh deleted the fix-1205-config-hot-reload branch May 25, 2026 15:05
@lujjjh lujjjh added the bug Something isn't working label May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config file watching stops if config directory is removed and recreated

2 participants