Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): add state machine to control installation including apply now update 💽 #12079

Open
wants to merge 55 commits into
base: epic/windows-updates
Choose a base branch
from

Conversation

rc-swag
Copy link
Contributor

@rc-swag rc-swag commented Aug 2, 2024

Fixes: #10210

Completed and developer tested.

  • UpdateStateMachine.pas added
  • Using the Windows registry to record state use CU so that it is accessible without elevated permissions
  • Updated insthelper postinstall function to set the registry statemachine to postinstall
    • starting to wonder whether "firstrun" should set the registry flag back to idle.
  • Tested using local download

Still outstanding

  • Add error logging.
  • Implement Retry and abort
  • If called in WaitingRestart too many times abort and go back to idle
  • Error log for Unable to set state for Value
  • Update tab table needs to be better currently it is still POC looking
  • The install forms need to have a white background and use localised captions for the labels and buttons
  • I have tested downloading but not downloading and installing at the statemachine is not in the newer build the download finds.

Extra notes:
State Transition matrix
Download updates has to be via a an event (cmd switch) and can’t be run just by kmshell event and checking the state only. This is because we want to launch a new kmshell process to run in the background. If it is Updateavailable and the kmshell.exe is started with a switch such as -c for configuration. At this point if we are on auto updates we would start the download by launching a new process, then returning continue to run configuration in the current process. So that the new process doesn’t again fork for a second time we need a switch or “event” to trigger the download.

background update state machine doesn't even build
…-check' into feat/windows/add-state-machine-o-updates
The event handling needs to be added for all the states
Added an event for install now when the user wants to manual
start the install process straight away.
…/add-apply-now-update

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Aug 2, 2024
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Aug 2, 2024

User Test Results

Test specification and instructions

ERROR: user tests have not yet been defined

Test Artifacts

@keymanapp-test-bot keymanapp-test-bot bot changed the title feat(windows): add state machine to control installation including apply now update feat(windows): add state machine to control installation including apply now update 💽 Aug 2, 2024
@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S7 milestone Aug 2, 2024
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Oct 23, 2024
@darcywong00 darcywong00 modified the milestones: A18S13, A18S14 Oct 26, 2024
There was some dead code from before the RemoteUpdateCheck refactor
was created. This is removed in this commit
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Oct 30, 2024
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 1, 2024
@rc-swag rc-swag requested a review from mcdurdin November 3, 2024 23:14
Comment on lines 45 to 46
* progress bar. This function is similar to DownloadUpdates, but it runs in
* the background.
Copy link
Member

Choose a reason for hiding this comment

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

This is the function comment for DownloadUpdates so I don't understand this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes very confusing. This comment needs updating or removing it is from when this function was the unit TOnlineUpdateCheck.DownloadUpdates and it was actually called something like DownloadBackgroundUpdates. I ended up creating a new unit Keyman.System.DownloadUpdate for greater clarity.

* Result A Boolean value indicating the overall result of the
* download process.
*)
procedure DoDownloadUpdates(SavePath: string; Params: TUpdateCheckResponse; var Result: Boolean);
Copy link
Member

Choose a reason for hiding this comment

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

Why a procedure and not a function?

DownloadBackGroundSavePath := IncludeTrailingPathDelimiter(TKeymanPaths.KeymanUpdateCachePath);
if TUpdateCheckStorage.LoadUpdateCacheData(ucr) then
begin
DoDownloadUpdates(DownloadBackGroundSavePath, ucr, DownloadResult);
Copy link
Member

Choose a reason for hiding this comment

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

I'd just use Result directly as the parameter here (or better, make DoDownloadUpdates into a function:

Result := DoDownloadUpdates(DownloadBackGroundSavePath, ucr);

not Registry.ValueExists(SRegValue_AutomaticUpdates) or
Registry.ReadBool(SRegValue_AutomaticUpdates);
except
on E: Exception do
Copy link
Member

Choose a reason for hiding this comment

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

catch-all ditto

Registry.WriteBool(SRegValue_ApplyNow, Value);
Result := True;
except
on E: Exception do
Copy link
Member

Choose a reason for hiding this comment

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

catch-all ditto

Registry.ValueExists(SRegValue_ApplyNow) and
Registry.ReadBool(SRegValue_ApplyNow);
except
on E: Exception do
Copy link
Member

Choose a reason for hiding this comment

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

catch-all ditto

Comment on lines 562 to 582
{ Make a HTTP request out and see if updates are available for now do
this all in the Idle HandleCheck message. But could be broken into an
seperate state of WaitngCheck RESP }
{ if Response not OK stay in the idle state and return }


// If handle check event force check
// CheckForUpdates := TRemoteUpdateCheck.Create(True);
// try
// Result:= CheckForUpdates.Run;
// finally
// CheckForUpdates.Free;
// end;

{ Response OK and Update is available }
// if Result = wucSuccess then
// begin
// ChangeState(UpdateAvailableState);
// end;

// else staty in idle state
Copy link
Member

Choose a reason for hiding this comment

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

Lots of unfinished code here? Is this going in a follow-up PR?

Comment on lines 825 to 849
// Still can't go if keyman has run
if HasKeymanRun then
begin
Result := kmShellContinue;
// Exit; // Exit is not wokring for some reason.
// this else is only here because the exit is not working.
end
else
begin
// Check downloaded cache if available then
SavedPath := IncludeTrailingPathDelimiter
(TKeymanPaths.KeymanUpdateCachePath);
GetFileNamesInDirectory(SavedPath, Filenames);
if Length(Filenames) = 0 then
begin
// Return to Idle state and check for Updates state
ChangeState(IdleState);
bucStateContext.CurrentState.HandleCheck; // TODO no event here
Result := kmShellExit;
// Exit; // again exit was not working
end
else
begin
// TODO Pop up toast here to ask user if we want to continue
frmStartInstall := TfrmStartInstall.Create(nil);
Copy link
Member

Choose a reason for hiding this comment

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

cleanup needed here?

@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 5, 2024
@rc-swag rc-swag requested a review from mcdurdin November 5, 2024 07:18
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 5, 2024
…/add-apply-now-update

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 6, 2024
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 6, 2024
@github-actions github-actions bot added core/ Keyman Core and removed core/ Keyman Core labels Nov 7, 2024
@darcywong00 darcywong00 modified the milestones: A18S14, A18S15 Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants