feat(windows): use enum to drive installfrm layout

This commit is contained in:
rc-swag 2026-06-25 10:49:35 +10:00
parent 5e26d5dd08
commit 3974f035f9
3 changed files with 79 additions and 36 deletions

View file

@ -1,7 +1,5 @@
{
Keyman is copyright (C) SIL Global. MIT License.
// TODO: #12887 Localise all the labels and captions.
}
unit Keyman.Configuration.UI.UfrmStartInstall;
interface
@ -23,6 +21,15 @@ uses
Vcl.Imaging.pngimage;
type
// The 4 valid installation form scenarios
TInstallCase = (
icNone, // Not a valid case, can be used as check before calling creating form
icRestartRequiredMetered,
icRestartRequiredNotMetered,
icReadyToInstallNotMetered, // Metered warning never needed if ReadyToInstall
icNoInstallMessageMetered
);
TfrmStartInstall = class(TfrmKeymanBase)
cmdInstall: TButton;
cmdLater: TButton;
@ -32,18 +39,15 @@ type
lblMeteredWarning: TLabel;
procedure FormCreate(Sender: TObject);
private
FRestartRequired: Boolean;
FIsMetered: Boolean;
FReadyToInstall: Boolean;
FScenario: TInstallCase;
public
constructor Create(
AOwner: TComponent;
const RestartRequired: Boolean;
const IsMetered: Boolean;
const ReadyToInstall: Boolean = False); reintroduce;
constructor Create(
AOwner: TComponent;
const AScenario: TInstallCase); reintroduce;
end;
implementation
uses
MessageIdentifiers,
MessageIdentifierConsts;
@ -52,14 +56,11 @@ uses
constructor TfrmStartInstall.Create(
AOwner: TComponent;
const RestartRequired: Boolean;
const IsMetered: Boolean;
const ReadyToInstall: Boolean = False);
const AScenario: TInstallCase);
begin
Assert(AScenario <> icNone, 'Invalid install case');
FScenario := AScenario;
inherited Create(AOwner);
FRestartRequired := RestartRequired;
FIsMetered := IsMetered;
FReadyToInstall := ReadyToInstall;
end;
procedure TfrmStartInstall.FormCreate(Sender: TObject);
@ -67,17 +68,39 @@ begin
inherited;
cmdInstall.Caption := MsgFromId(S_Update_Now);
cmdLater.Caption := MsgFromId(S_Later);
if FRestartRequired then
lblUpdateMessage.Caption := MsgFromId(S_Update_Restart_Req)
else
lblUpdateMessage.Caption := MsgFromId(S_Ready_To_Install);
// Show warning if on a metered connection. If FReadyToInstall the update is
// already downloaded, so no use in displaying the warning.
lblMeteredWarning.Visible := FIsMetered and not FReadyToInstall;
shpMeteredWarning.Visible := FIsMetered and not FReadyToInstall;
if FIsMetered then
lblMeteredWarning.Caption := MsgFromId(S_Metered_Warning);
// Default UI configuration state - metered warnings hidden initially
lblUpdateMessage.Visible := True;
lblMeteredWarning.Visible := False;
shpMeteredWarning.Visible := False;
case FScenario of
icRestartRequiredMetered:
begin
lblUpdateMessage.Caption := MsgFromId(S_Update_Restart_Req);
lblMeteredWarning.Caption := MsgFromId(S_Metered_Warning);
lblMeteredWarning.Visible := True;
shpMeteredWarning.Visible := True;
end;
icRestartRequiredNotMetered:
begin
lblUpdateMessage.Caption := MsgFromId(S_Update_Restart_Req);
end;
icReadyToInstallNotMetered:
begin
lblUpdateMessage.Caption := MsgFromId(S_Ready_To_Install);
end;
icNoInstallMessageMetered:
begin
lblUpdateMessage.Visible := False;
lblMeteredWarning.Caption := MsgFromId(S_Metered_Warning);
lblMeteredWarning.Visible := True;
shpMeteredWarning.Visible := True;
end;
end;
end;
end.

View file

@ -819,16 +819,33 @@ var
FResult, InstallNow: Boolean;
frmStartInstallNow: TfrmStartInstall;
IsMetered: Boolean;
EInstallScenario: TInstallCase;
begin
InstallNow := True;
IsMetered := UtilNetworkConnection.IsMetered;
// If a restarted is required (HasKeymanRun == True)
// OR it is a Metered connection warn the user and allow
// them to cancel their request to Install Now.
// Otherwise start installing.
if HasKeymanRun OR IsMetered then
// Otherwise start installing with out pop-up warnings.
EInstallScenario := TInstallCase.icNone;
if HasKeymanRun and not IsMetered then
begin
frmStartInstallNow := TfrmStartInstall.Create(nil, HasKeymanRun, IsMetered);
EInstallScenario := TInstallCase.icRestartRequiredNotMetered;
end
else if HasKeymanRun and IsMetered then
begin
EInstallScenario := TInstallCase.icRestartRequiredMetered;
end
else if (not HasKeymanRun) and IsMetered then
begin
EInstallScenario := TInstallCase.icNoInstallMessageMetered;
end;
// Render dialog if conditions require it
if EInstallScenario <> TInstallCase.icNone then
begin
frmStartInstallNow := TfrmStartInstall.Create(nil, EInstallScenario);
try
if frmStartInstallNow.ShowModal = mrOk then
InstallNow := True
@ -839,18 +856,23 @@ begin
end;
end;
if InstallNow = True then
// Process installation execution execution path
if InstallNow then
begin
ShellPath := TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell);
FResult := TUtilExecute.Shell(0, ShellPath, '', '-an');
if not FResult then
begin
TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR,
'TrmfMain: Shell Execute Update_ApplyNow Failed')
'TrmfMain: Shell Execute Update_ApplyNow Failed');
end
else
ModalResult := mrAbort;
begin
// If a splash screen is currently open when "Install Now" is executed,
// setting mrAbort ensures the splash screen is closed on the
// return of "Keyman Configuration".
ModalResult := mrAbort;
end;
end;
end;

View file

@ -145,7 +145,6 @@ uses
UILanguages,
uninstall,
UpgradeMnemonicLayout,
UtilNetworkConnection,
utilfocusappwnd,
utilkmshell,
Keyman.System.UpdateStateMachine,
@ -670,7 +669,6 @@ function ShouldSendToBUpdateSM(FSilent: Boolean; BUpdateSM: TUpdateStateMachine;
// UI elements from the state machine we have bring some of logic here.
var
frmStartInstall: TfrmStartInstall;
IsMetered: Boolean;
ValidateReadyToInstall: Boolean;
begin
ValidateReadyToInstall := BUpdateSM.ValidateReadyToInstall;
@ -679,8 +677,8 @@ begin
(FMode in [fmStart, fmSplash, fmMain, fmAbout,
fmHelp, fmShowHelp, fmSettings, fmBoot]) then
begin
IsMetered := UtilNetworkConnection.IsMetered;
frmStartInstall := TfrmStartInstall.Create(nil, false, IsMetered, ValidateReadyToInstall);
// We are ready to install Metered warning not needed even if on Metered connection
frmStartInstall := TfrmStartInstall.Create(nil, TInstallCase.icReadyToInstallNotMetered);
try
Result := frmStartInstall.ShowModal = mrOk;
finally