Skip to content

Add ToggleMouseSonar and AdjustVolume desktop actions#2201

Merged
TalZaccai merged 1 commit intotalzacc/action_json_schemafrom
talzacc/demo-new-actions
Apr 16, 2026
Merged

Add ToggleMouseSonar and AdjustVolume desktop actions#2201
TalZaccai merged 1 commit intotalzacc/action_json_schemafrom
talzacc/demo-new-actions

Conversation

@TalZaccai
Copy link
Copy Markdown
Contributor

@TalZaccai TalZaccai commented Apr 16, 2026

This branch (based on talzacc/action_json_schema) demonstrates how easy it is to add new actions after the architecture refactoring in #2196. Two new actions are added, showcasing the two main patterns described in the README.

ToggleMouseSonar — Option A: Registry Toggle

Enables/disables the Windows "Find my pointer" ring that appears when pressing Ctrl.

Total lines added: 1 (in MouseSettingsHandler.cs)

AddRegistryToggleAction("ToggleMouseSonar", new RegistryToggleConfig(
    @"Control Panel\Mouse", "MouseSonar", "enable",
    OnValue: "1", OffValue: "0", ValueKind: RegistryValueKind.String, DisplayName: "Mouse Sonar"));

No custom handler logic. The AddRegistryToggleAction helper does everything — reads the enable parameter, writes the registry value, returns an ActionResult.

AdjustVolume — Option B: Typed Action with Custom Logic

Adjusts volume relatively ("turn it up a bit") instead of setting an absolute value.

Steps:

  1. Define TS schema type in actionsSchema.ts
  2. Add handler in AudioActionHandler.cs — reads current volume, applies delta, clamps 0–100, saves for restore
export type AdjustVolumeAction = {
    actionName: "AdjustVolume";
    parameters: {
        direction: "up" | "down";
        amount?: number; // default 10
    };
};

The C# AdjustVolumeParams record is automatically generated by the Roslyn source generator from the .pas.json schema — no manual C# type definition needed.

Test Coverage

  • 6 new tests for AdjustVolume (up/down, default amount, clamping, volume save)
  • 2 new tests for ToggleMouseSonar (enable/disable registry writes)

Showcases the two main patterns for adding new actions:

Option A - Registry toggle (ToggleMouseSonar):
  One line in MouseSettingsHandler constructor using AddRegistryToggleAction.
  No custom handler logic needed.

Option B - Typed action with logic (AdjustVolume):
  TS schema type + C# handler with relative volume adjustment,
  clamping, and saved-volume tracking.

Includes unit tests for both actions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TalZaccai TalZaccai changed the title Add ToggleMouseSonar and AdjustVolume actions Add ToggleMouseSonar and AdjustVolume desktop actions Apr 16, 2026
@robgruen
Copy link
Copy Markdown
Collaborator

for the registry toggle action, once you set the value does it immediately take effect or do we need to broadcast some sort of WM_SETTINGCHANGED for it to work first?

@robgruen
Copy link
Copy Markdown
Collaborator

BTW, 😍

@TalZaccai
Copy link
Copy Markdown
Contributor Author

for the registry toggle action, once you set the value does it immediately take effect or do we need to broadcast some sort of WM_SETTINGCHANGED for it to work first?

It does not take affect immediately, but this might be a wider fix than just this specific toggle, I'll look into fixing it in a separate PR.

@robgruen
Copy link
Copy Markdown
Collaborator

robgruen commented Apr 16, 2026 via email

@TalZaccai TalZaccai merged commit b14f115 into talzacc/action_json_schema Apr 16, 2026
1 check passed
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.

2 participants