Add scenario switcher for v4.1 - #1058
Open
vibhor1102 wants to merge 5 commits into
Open
Conversation
vibhor1102
marked this pull request as ready for review
August 18, 2026 14:04
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.
📝 Description
Important
Target release: v4.1. This feature is not intended for v4.0.0.
This PR implements the manual Smart-scenario switching flow discussed and agreed upon in Discussion #921.
It allows a running Smart AutoClicker service to load another Smart scenario without stopping the service, closing the overlay, or requesting screen-capture permission again. The existing media-projection session is kept alive, while the actual scenario change is restricted to the paused/recording state so actions cannot continue running during the transition.
The implementation follows the compromise established in the discussion:
✨ User-facing changes
Switch from the service notification
The expanded Smart-scenario notification now includes a Switch action using the Material Symbols
swap_horizicon.If detection is active when the action is tapped, the service first pauses detection and waits for the processor to reach its stable recording state. It then opens the scenario picker as an overlay, keeping the automated app in the foreground and preserving the current capture session.
Repeated notification taps cannot open multiple pickers while that pause is settling.
Optional floating-toolbar entry
Settings now contains a Show scenario switcher toggle, described as: “Shows the scenario switcher in the floating toolbar for quick swaps.”
When enabled, the toolbar button:
swap_horizasset at the requested weight;The notification entry remains available regardless of this preference.
Compact scenario picker
The picker follows the home page’s card-based visual language while deliberately removing home-page functionality that is not useful during a quick switch:
The picker stays in the
smart-configfeature rather than directly importing the home-page adapter from the application module. Direct reuse would reverse the existing module dependency and create a cycle, while the home adapter also carries expansion, statistics, event previews, and scenario-management actions that this flow intentionally does not need. The smaller feature-local component instead reuses the relevant theme, card, typography, icon, and sorting conventions.🛡️ Switching and service-state safety
Scenario changes are coordinated by a dedicated
SmartScenarioSwitcherrather than being performed directly by the dialog.The switching path:
If the service stops, restarts, loses projection, changes processing state, or the selected scenario is deleted during the operation, the stale transition is rejected and the current service session is not overwritten. Persistence and UI-synchronization failures are reported without treating an uncommitted switch as successful.
The dialog maps these outcomes to specific localized messages and offers a retry when the selected scenario is still available.
The home page and scenario picker now use the same generic sorting helper for name, most-recently-used, and most-used ordering. Stable name and database-ID tie-breakers prevent equal values from making the list jump unpredictably.
A scenario selected through the switcher counts as a use, just like a scenario started normally. Database migration 23 → 24 makes the usage relationship truly one-to-one:
This is required so quick switches remain accurately represented by the existing home-page sorting preferences.
🌍 Localization
All 17 user-facing strings introduced by the feature are translated for the ten locale sets currently shipped by the project:
The translations follow existing project terminology where equivalent wording was already present.
🚫 Deliberate non-goals
✅ How to test
Notification flow
Floating-toolbar flow
Picker and failure states
🔍 Validation
Build and unit-test evidence: https://github.com/vibhor1102/Smart-AutoClicker/actions/runs/32142234934
❓ FAQ
Why is this targeted at v4.1 instead of v4.0.0?
The notification-first flow plus optional floating-toolbar entry is the compromise approved in Discussion #921 for the v4.1 scope. This PR intentionally identifies that target rather than presenting the feature as a late addition to v4.0.0.
Why is the notification action available by default, but the toolbar button optional?
The notification provides scenario switching without permanently adding complexity to the app’s most frequently used overlay. Users who need faster repeated access can opt into the fifth toolbar action.
Why must detection be paused before the scenario is changed?
Switching the processor’s scenario while events and actions are actively running would make the transition ambiguous and unsafe. The notification action pauses first; the toolbar action appears only in the stable paused state.
Does switching request screen-capture permission again?
No. A valid switch keeps the existing media projection alive. If that projection has already been lost, the switch is rejected and the user is told to restart recording instead of silently creating a broken session.
Why not reuse the complete home-page scenario adapter?
The home page belongs to the application module, which already depends on the feature module containing this overlay. Depending on it in the opposite direction would create a module cycle. Its adapter also owns expansion, previews, statistics, and management actions that are deliberately excluded here. The picker therefore uses a compact feature-local card component while sharing the applicable presentation and sorting conventions.
Why are there no sorting controls in the picker?
The picker is meant to be a quick action, not another scenario-management screen. It automatically follows the user’s saved home-page ordering, so adding another set of controls would be redundant and could make the two lists disagree.
Why does this PR include a database migration?
Both normal starts and quick switches update usage statistics. The old non-unique index allowed concurrent updates to create more than one usage row for a scenario. Migration 24 merges any existing duplicates and enforces the intended one-row-per-scenario relationship.
What happens if the service changes while the picker is open?
The switch coordinator checks the service session, processor state, projection, current scenario, and selected database record both before and after suspending work. A stale picker cannot install a scenario into a newly started or torn-down service session.
Does this implement automated scenario chaining?
No. Every switch in this PR is initiated manually by the user. Automated transitions remain a separate feature and design discussion.