feat(rules): add default behavior for new app rules#55
Conversation
Adding an app to Per-app rules always seeded the rule as "Lock to", so anyone who mostly wants "Switch to" (or "Ignore") had to re-pick the mode on every app. Add a "New app rules > Default behavior" picker to the App Rules pane that seeds the mode of each newly added rule; the source stays the global default, so only the mode is chosen. The preference lives in `AppState.newAppRuleMode` under its own `UserDefaults` key, deliberately not part of `LockConfiguration`. It has no runtime locking effect — it only templates new rows — and mirrors the per-device `apiEnabled`/`menuBarIconHidden` precedent, so it never travels through config export/import (importing a shared config must not silently change your authoring default). It decodes leniently, falling back to `.locked` to preserve the original behavior. Only the "Add App…" flow honors the preference. The `lockime://set-app-rule` API keeps its own explicit `lock` default, since a programmatic interface must stay deterministic across devices. Closes #54 Signed-off-by: Kevin Cui <bh@bugs.cc>
Summary by CodeRabbit
WalkthroughThis PR adds a persisted Sequence Diagram(s)sequenceDiagram
participant User
participant AppRulesSettingsPane
participant AppState
participant UserDefaults
User->>AppRulesSettingsPane: select default behavior in picker
AppRulesSettingsPane->>AppState: setNewAppRuleMode(mode)
AppState->>UserDefaults: persist rawValue
AppState-->>AppRulesSettingsPane: newAppRuleMode updated
User->>AppRulesSettingsPane: add new app rule via picker sheet
AppRulesSettingsPane->>AppState: read newAppRuleMode
AppRulesSettingsPane->>AppRulesSettingsPane: seed new AppRule with selected mode
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Sources/LockIME/UI/Settings/AppRulesSettingsPane.swift (1)
33-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the shared
AppRuleModelabels. This picker list is duplicated inAppRulesSettingsPaneandAppRuleRow; a shared helper/view would keep both in sync ifAppRuleModechanges.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/LockIME/UI/Settings/AppRulesSettingsPane.swift` around lines 33 - 45, The AppRuleMode picker labels are duplicated between AppRulesSettingsPane and AppRuleRow, so extract the shared label list into a common helper or reusable view and have both places use it. Update the Picker in AppRulesSettingsPane and the corresponding AppRuleMode UI in AppRuleRow to reference the shared source so any future AppRuleMode changes stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Sources/LockIME/UI/Settings/AppRulesSettingsPane.swift`:
- Around line 33-45: The AppRuleMode picker labels are duplicated between
AppRulesSettingsPane and AppRuleRow, so extract the shared label list into a
common helper or reusable view and have both places use it. Update the Picker in
AppRulesSettingsPane and the corresponding AppRuleMode UI in AppRuleRow to
reference the shared source so any future AppRuleMode changes stay in sync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6c3da819-01c8-403e-813c-03d4d9927b03
📒 Files selected for processing (3)
Sources/LockIME/AppState.swiftSources/LockIME/Localizable.xcstringsSources/LockIME/UI/Settings/AppRulesSettingsPane.swift
|
Thank you, I tried version 1.6.2, and it works for me! |
Adding an app to Per-app rules always seeded the new rule as Lock to, so anyone who mostly wants Switch to (or Ignore) had to change the mode on every app they added. This adds a New app rules ▸ Default behavior picker to the App Rules pane that seeds the mode of each newly added rule; the source stays the global default, so only the mode is chosen. Requested in #54.
The preference lives in
AppState.newAppRuleModeunder its ownUserDefaultskey, deliberately not part ofLockConfiguration. It has no runtime locking effect — it only templates new rows — and mirrors the per-deviceapiEnabled/menuBarIconHiddenprecedent, so it never travels through config export/import (importing a shared config must not silently change your authoring default). It decodes leniently, falling back to.lockedto preserve the original behavior.Only the "Add App…" flow honors the preference. The
lockime://set-app-ruleAPI keeps its own explicitlockdefault, since a programmatic interface must stay deterministic across devices; the URL-scheme reference is unchanged.The three new UI strings are translated for every
SupportedLanguage, soLocalizationGuardTestsstays green (build + full test suite pass). One conscious follow-up: the App Rules screenshots in the READMEs (docs/images/settings-app-rules-*) now predate the new section and would need a regen pass — deferred as cosmetic.Closes #54