From df972447d42267f834276161ca23c7d9f8592ed6 Mon Sep 17 00:00:00 2001 From: Kai Tao <69313318+vanzue@users.noreply.github.com> Date: Thu, 9 Oct 2025 14:46:31 +0800 Subject: [PATCH] Mouse Without Borders: A conflict machine Id will make connection fail (#42190) ## Summary of the Pull Request This PR fixes a critical issue in Mouse Without Borders where conflicting machine IDs would cause connection failures. The changes ensure that when machine IDs are generated or updated, the settings are immediately persisted to prevent loss of the new ID and maintain proper synchronization between the property and backing field. Key changes: * Immediate settings persistence when a new machine ID is generated (unless instant saving is paused) * Proper synchronization of the machineId field when the MachineId property is set * Addition of settings saving logic in both getter and setter scenarios ## PR Checklist - [ ] Closes: #42084 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed * Do a release bundle build and install new bundle with this fix on both two machines * Manually change two pc's machine ID to the same value * Make sure they can connect * Verify there is log entrance indicating that there is conflict for machineID * Close MWB, make sure next launch still connect --- .../MouseWithoutBorders/App/Class/Setting.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/modules/MouseWithoutBorders/App/Class/Setting.cs b/src/modules/MouseWithoutBorders/App/Class/Setting.cs index c9d81f2049..623571f6ce 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Setting.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Setting.cs @@ -1055,8 +1055,13 @@ namespace MouseWithoutBorders.Class if (machineId == 0) { - _properties.MachineID.Value = Common.Ran.Next(); - machineId = _properties.MachineID.Value; + var newMachineId = Common.Ran.Next(); + _properties.MachineID.Value = newMachineId; + machineId = newMachineId; + if (!PauseInstantSaving) + { + SaveSettings(); + } } } @@ -1068,6 +1073,11 @@ namespace MouseWithoutBorders.Class lock (_loadingSettingsLock) { _properties.MachineID.Value = value; + machineId = value; + if (!PauseInstantSaving) + { + SaveSettings(); + } } } }