Skip to content

feat(rules): add default behavior for new app rules#55

Merged
BlackHole1 merged 1 commit into
mainfrom
feat/new-app-rule-default-mode
Jul 5, 2026
Merged

feat(rules): add default behavior for new app rules#55
BlackHole1 merged 1 commit into
mainfrom
feat/new-app-rule-default-mode

Conversation

@BlackHole1

Copy link
Copy Markdown
Member

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.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; the URL-scheme reference is unchanged.

The three new UI strings are translated for every SupportedLanguage, so LocalizationGuardTests stays 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

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>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added a new setting to choose the default behavior for newly created app rules.
    • Added a picker in Settings to set how new app rules start: locked, switched, ignored, or use default.
    • New app rules now inherit the selected default behavior when created.
  • Localization

    • Added translated text for the new app rules settings and help copy.

Walkthrough

This PR adds a persisted newAppRuleMode setting to AppState, loaded from and saved to UserDefaults with a .locked default. AppRulesSettingsPane gains a "New app rules" section with a "Default behavior" picker bound to this setting, and the app-picker sheet now seeds newly added AppRule instances using the selected mode instead of always defaulting to .locked. Corresponding localized strings were added for the new UI text across supported languages.

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
Loading

Possibly related PRs

  • oomol-lab/LockIME#22: Both PRs modify mode handling in AppRulesSettingsPane.swift around the .switched option, with this PR seeding newly added rules using a selectable default mode.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required feat(scope): subject format and accurately describes the new default behavior for app rules.
Description check ✅ Passed The description clearly matches the change and references the same new default behavior for app rules.
Linked Issues check ✅ Passed The PR implements #54 by adding a global default for new app rules and using it when seeding new rules.
Out of Scope Changes check ✅ Passed The changes stay within the requested feature scope: state, UI, and localization for the new app-rule default.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/new-app-rule-default-mode

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Sources/LockIME/UI/Settings/AppRulesSettingsPane.swift (1)

33-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the shared AppRuleMode labels. This picker list is duplicated in AppRulesSettingsPane and AppRuleRow; a shared helper/view would keep both in sync if AppRuleMode changes.

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 65d2391 and 89505bb.

📒 Files selected for processing (3)
  • Sources/LockIME/AppState.swift
  • Sources/LockIME/Localizable.xcstrings
  • Sources/LockIME/UI/Settings/AppRulesSettingsPane.swift

@BlackHole1 BlackHole1 merged commit a1730b1 into main Jul 5, 2026
3 checks passed
@BlackHole1 BlackHole1 deleted the feat/new-app-rule-default-mode branch July 5, 2026 12:17
@singularitti

Copy link
Copy Markdown

Thank you, I tried version 1.6.2, and it works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add a global default behavior for new App Rules

2 participants