Skip to content

fix(windows): kmshell continues when sm is in waitingrestart and returns to idle#14644

Merged
rc-swag merged 6 commits intomasterfrom
fix/windows/14578/waitingrestart-idle-kmshellcontinue
Sep 10, 2025
Merged

fix(windows): kmshell continues when sm is in waitingrestart and returns to idle#14644
rc-swag merged 6 commits intomasterfrom
fix/windows/14578/waitingrestart-idle-kmshellcontinue

Conversation

@rc-swag
Copy link
Copy Markdown
Contributor

@rc-swag rc-swag commented Aug 29, 2025

When waiting restart on a handlekmshell event and returning to idle kmshell execution should continue
This also refacted the change in #14295, check if automatic updates have been turned off before pompting user. Therefore will have tests for that also.

Fixes: #14578

User Testing

TEST_KMSHELL_CONTINUE_EXECUTION

We need to test that if a handle kmshell event occurs when in the WaitingRestart state, but the cache is now corrupt that when returning to idle, kmshell execution continues.

Install the PR version of Keyman on this PR

  1. If there is no updates available we will maninputlate the state using windows registry Win + R type regedit. Go Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine and change the update state to usWaitingRestart
  2. Open Windows Explorer (Win + E) got to the cache C:\Users\{username}\AppData\Local\Keyman\UpdateCache.. If there is a cache.json file remove it. If there are other files they can stay there.
  3. Go to Keyman Configuration and the Options and uncheck Start with Windows it will make it easier to verify the change.
  4. Restart Windows
  5. Start Keyman ensure that Keyman does start and that update state in the registry returns to idle

We need to verify that changes from #14295 still work

TEST_UPDATE_CANCELED_NO_PROMPT

Install the Keyman for Windows Build associated with this PR.

  1. Start Keyman
  2. Open configuration go to the "Options" tab and ensure "Automatically check for updates and download" is selected.
  3. Go to the "Update" tab
  4. Open the windows registry (Win+R and type regedit) and check the "update state flag" if it is already usWaitingRestart go straight to step 8. Which should be go to Options and uncheck Automatically check for updates and downloads].
  5. Check for now updates
  6. Open the windows registry (Win+R and type regedit) and check the "update state flag" at Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine
  7. It should end up at state usWaitingRestart after going through the other states -> usUpdateAvailable -> usDownloadloading -> usWaitingRestart
  8. Now got to the Options and uncheck Automatically check for updates and downloads.
  9. Exit Configuration and Keyman.
  10. Restart Windows
  11. Once Keyman starts (if it doesn't start, start Keyman)
  12. Open the windows registry (Win+R and type regedit) and check the "update state flag" at Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine
  13. Observe that the update state flag returns to usIdle

TEST_UPDATE_PROMPT

This is a regression to test to ensure the "normal" case still works.

  1. Start Keyman
  2. Go to the Options and check Automatically check for updates and downloads.
  3. Open configuration go to the "Update" tab
  4. Open the windows registry (Win+R and type regedit) and check the "update state flag" if it is already usWaitingRestart go straight to step 8
  5. Check for now updates
  6. Open the windows registry (Win+R and type regedit) and check the "update state flag" at Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine
  7. It should end up at state usWaitingRestart after going through the other states -> usUpdateAvailable -> usDownloadloading -> usWaitingRestart
  8. Exit Configuration and Keyman.
  9. Restart Windows
  10. Once Keyman starts (if it doesn't start, start Keyman), A prompt should appear to notify the user Keyman update will install now with an option to exit.

When waiting restart on a handlekmshell event and returning to idle
kmshell execution should continue
@github-project-automation github-project-automation bot moved this to Todo in Keyman Aug 29, 2025
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Aug 29, 2025
@keymanapp-test-bot
Copy link
Copy Markdown

keymanapp-test-bot bot commented Aug 29, 2025

User Test Results

Test specification and instructions

Test Artifacts

@rc-swag rc-swag self-assigned this Aug 29, 2025
@github-actions github-actions bot added the fix label Aug 29, 2025
@keymanapp-test-bot keymanapp-test-bot bot added this to the A19S10 milestone Aug 29, 2025
@darcywong00 darcywong00 modified the milestones: A19S10, A19S11 Aug 29, 2025
@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels Sep 1, 2025
It became apparent that we need to abort the "waitingtorestart" state
before promting the user if they want to install. Otherwise it is
confusing as to why nothing happens and Keyman just starts.
In doing that it was easier to refactor ReadyToInstall to validate the
cache, and check that automatic updates was still set.
It can now also trigger an abort clearing the cache and returning to
idle. This has slight flow on effect in that the HandleKMShell event
can still be called following in the exectution flow.
@rc-swag rc-swag changed the title fix(windows): continue when waitingrestart return to idle fix(windows): kmshell continues when sm is in waitingrestart and returns to idle Sep 5, 2025
@rc-swag rc-swag marked this pull request as ready for review September 5, 2025 02:11
@dinakaranr dinakaranr self-assigned this Sep 5, 2025
@dinakaranr
Copy link
Copy Markdown

Test Results

I tested this PR in the "Keyman-19.0.111-alpha-test-14644" build on Windows 10. Here I am sharing my observation.

  • TEST_KMSHELL_CONTINUE_EXECUTION (Passed):
  1. Download and Install "Keyman-19.0.111-alpha-test-14644" version of Keyman on this PR
  2. Start the Keyman.
  3. Go to the "Update" tab.
  4. Click the "Check for new updates" button
  5. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  6. Select the "Keyman Engine" and then change the update state to "usWaitingRestart" (Go Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine)
  7. Open the "Appdata" foler by pressing Win + R and then enter "%appdata%"
  8. Go to the C:\Users{username}\AppData\Local\Keyman\UpdateCache.. folder
  9. If there is a cache.json file remove it. If there are other files they can stay there.
  10. Open the "Keyman Configuration" and then navigate to the Options tab.
  11. Uncheck "Start when Windows starts" it will make it easier to verify the change.
  12. Restart Windows
  13. Start Keyman.
  14. Verified that the Keyman does start.
  15. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  16. Select the "Keyman Engine"
  17. Verified that the "update state" changed to "usIdle"
    It works well. Thank you.
  • TEST_UPDATE_CANCELED_NO_PROMPT (Passed):
  1. Download and Install "Keyman-19.0.111-alpha-test-14644" version of Keyman on this PR
  2. Start Keyman
  3. Open the "keyman configuration". Go to the "Options" tab.
  4. Verified the "Automatically check for updates and download" is selected.
  5. Go to "Update" tab
  6. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  7. Select the "Keyman Engine". (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine)
  8. Verified that the "Update state" is "usWaitingRestart" or "usIdle"
  9. It is showing as "usIdle"
  10. Change the "update state" from "usIdle" to "usWaitingRestart"
  11. Go to the "Options" tab.
  12. Uncheck the "Automatically check for updates and downloads" checkbox.
  13. Close the Keyman configuration.
  14. Restart the Windows
  15. Start Keyman (if it doesn't start, start Keyman)
  16. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  17. Select the "Keyman Engine". (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine)
  18. Verified that the update state flag returns to usIdle
    It works well. Thank you.
  • TEST_UPDATE_PROMPT (Passed):
  1. Download and Install "Keyman-19.0.111-alpha-test-14644" version of Keyman on this PR
  2. Start Keyman
  3. Open the "keyman configuration". Go to the "Options" tab.
  4. Checked the "Automatically check for updates and download".
  5. Go to "Update" tab.
  6. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  7. Select the "Keyman Engine". (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine)
  8. Verified that the "Update state" is "usIdle"
  9. Click the "Check for new updates" button.
  10. Open the "Registry Editor" by pressing the Win + R and type the "regedit".
  11. Select the "Keyman Engine". (Computer\HKEY_CURRENT_USER\SOFTWARE\Keyman\Keyman Engine)
  12. Verified that the "Update state" is changing "usUpdateAvailable -> usDownloadloading -> usWaitingRestart"
  13. Close the Keyman configuration.
  14. Restart the Windows
  15. Start Keyman
  16. Verified that the prompt should appear to notify the user Keyman update will install now
  17. Verified that the "Keyman Update" prompt have a "Update now" or "Later" appears
    It works well. Thank you.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label Sep 5, 2025
@dinakaranr dinakaranr removed their assignment Sep 5, 2025
@rc-swag rc-swag requested a review from mcdurdin September 8, 2025 01:16
Comment on lines +573 to +580
// Validate the cache otherwise we could
// prompt the caller for update but then fail.
// Also combined #14295 moved check here from initprog.pas
// The setting for automatic updates may have been set to disable
// after updates were checked and downloaded. The user should
// not be prompted for an update in this case and the update should
// abort.
if not (TUpdateCheckStorage.CheckMetaDataForUpdate and Self.GetAutomaticUpdates) then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm finding this a bit hard to parse. Can you review? If possible, it may be easier to avoid the not test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok that comment didn't help, I think that was cause for confusion? I reworked it and function block comment.
If I remove the not it will make need to be nested which is even harder to parse.

if TUpdateCheckStorage.CheckMetaDataForUpdate and GetAutomaticUpdates then
begin
  if not HasKeymanRun then
    Exit(True);
  Exit(False);
end
else
begin
  RemoveCachedFiles;
  CurrentState(IdleState);
  Exit(False);
end;

Co-authored-by: Marc Durdin <marc@durdin.net>
@rc-swag rc-swag merged commit 2c34a7f into master Sep 10, 2025
8 checks passed
@rc-swag rc-swag deleted the fix/windows/14578/waitingrestart-idle-kmshellcontinue branch September 10, 2025 01:09
@github-project-automation github-project-automation bot moved this from Todo to Done in Keyman Sep 10, 2025
@keyman-server
Copy link
Copy Markdown
Collaborator

Changes in this pull request will be available for download in Keyman version 19.0.116-alpha

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

bug(windows): an event in usWaitingRestart that causes a transition to idle should return kmshell continue

5 participants