From 12f4bcee0acedcfc2551867366e97146fb747b67 Mon Sep 17 00:00:00 2001
From: rc-swag <58423624+rc-swag@users.noreply.github.com>
Date: Fri, 18 Sep 2026 18:07:18 +1000
Subject: [PATCH] fix(windows): add warning when system startup disabled
This is the initial commit to add a check to see if the Windows
System setting for Keyman startup is disabled when the users
as select Keyman to start with Windows.
Fixes: #15785
---
.../windows/delphi/general/RegistryKeys.pas | 7 +++
windows/src/desktop/kmshell/kmshell.dpr | 3 +-
windows/src/desktop/kmshell/kmshell.dproj | 13 ++--
windows/src/desktop/kmshell/main/UfrmMain.dfm | 1 +
windows/src/desktop/kmshell/main/UfrmMain.pas | 38 ++++++++++--
.../kmshell/render/OptionsXMLRenderer.pas | 6 ++
...n.Configuration.System.StartupSettings.pas | 59 +++++++++++++++++++
windows/src/desktop/kmshell/xml/config.css | 14 +++++
.../desktop/kmshell/xml/keyman_options.xsl | 12 +++-
windows/src/desktop/kmshell/xml/strings.xml | 15 +++++
10 files changed, 155 insertions(+), 13 deletions(-)
create mode 100644 windows/src/desktop/kmshell/util/Keyman.Configuration.System.StartupSettings.pas
diff --git a/common/windows/delphi/general/RegistryKeys.pas b/common/windows/delphi/general/RegistryKeys.pas
index 0f627c7329..62dfd4250c 100644
--- a/common/windows/delphi/general/RegistryKeys.pas
+++ b/common/windows/delphi/general/RegistryKeys.pas
@@ -283,6 +283,8 @@ const
SRegValue_WindowsRun_Keyman = 'Keyman';
+ SRegKey_StartupApproved_Run = 'Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run';
+
SRegValue_LanguageCheckDisabledItems = 'language check disabled items'; // CU
{-------------------------------------------------------------------------------
@@ -414,6 +416,11 @@ function BuildKeyboardLanguagesKey_CU(const KeyboardID: string): string;
implementation
+uses
+ System.Win.Registry,
+ Windows,
+ SysUtils;
+
function BuildKeyboardOptionKey_CU(const KeyboardID: string): string;
begin
Result := SRegKey_ActiveKeyboards_CU + '\' + KeyboardID + '\' + SRegSubKey_KeyboardOptions;
diff --git a/windows/src/desktop/kmshell/kmshell.dpr b/windows/src/desktop/kmshell/kmshell.dpr
index e2d28b88d2..eac9017de7 100644
--- a/windows/src/desktop/kmshell/kmshell.dpr
+++ b/windows/src/desktop/kmshell/kmshell.dpr
@@ -183,7 +183,8 @@ uses
Keyman.System.DownloadUpdate in 'main\Keyman.System.DownloadUpdate.pas',
Keyman.System.ExecutionHistory in '..\..\..\..\common\windows\delphi\general\Keyman.System.ExecutionHistory.pas',
Keyman.Configuration.UI.UfrmStartInstall in 'main\Keyman.Configuration.UI.UfrmStartInstall.pas' {frmStartInstall},
- Keyman.Configuration.Util.NetworkConnection in 'util\Keyman.Configuration.Util.NetworkConnection.pas';
+ Keyman.Configuration.Util.NetworkConnection in 'util\Keyman.Configuration.Util.NetworkConnection.pas',
+ Keyman.Configuration.System.StartupSettings in 'util\Keyman.Configuration.System.StartupSettings.pas';
{$R VERSION.RES}
{$R manifest.res}
diff --git a/windows/src/desktop/kmshell/kmshell.dproj b/windows/src/desktop/kmshell/kmshell.dproj
index 371ce4cd49..8680fa5a65 100644
--- a/windows/src/desktop/kmshell/kmshell.dproj
+++ b/windows/src/desktop/kmshell/kmshell.dproj
@@ -358,6 +358,7 @@
+
Cfg_2
@@ -419,12 +420,6 @@
False
-
-
- .\
- true
-
-
kmshell.rsm
@@ -437,6 +432,12 @@
true
+
+
+ .\
+ true
+
+
1
diff --git a/windows/src/desktop/kmshell/main/UfrmMain.dfm b/windows/src/desktop/kmshell/main/UfrmMain.dfm
index 5a7dce719f..8d9d513ea4 100644
--- a/windows/src/desktop/kmshell/main/UfrmMain.dfm
+++ b/windows/src/desktop/kmshell/main/UfrmMain.dfm
@@ -16,6 +16,7 @@ inherited frmMain: TfrmMain
PixelsPerInch = 96
TextHeight = 13
object AppEvents: TApplicationEvents
+ OnActivate = AppEventsActivate
OnMessage = AppEventsMessage
Left = 416
Top = 256
diff --git a/windows/src/desktop/kmshell/main/UfrmMain.pas b/windows/src/desktop/kmshell/main/UfrmMain.pas
index a8fdfe9845..a3810ccbed 100644
--- a/windows/src/desktop/kmshell/main/UfrmMain.pas
+++ b/windows/src/desktop/kmshell/main/UfrmMain.pas
@@ -99,10 +99,12 @@ type
procedure TntFormClose(Sender: TObject; var Action: TCloseAction);
procedure TntFormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
+ procedure AppEventsActivate(Sender: TObject);
private
FPageTag: Integer;
FClosing: Boolean;
+ FRefreshOnActivate: Boolean;
wm_keyman_refresh: Cardinal;
LastRefreshToken: System.IntPtr;
@@ -133,6 +135,7 @@ type
procedure Options_ResetHints;
procedure Options_BaseKeyboard; // I4169
procedure Options_SettingsManager;
+ procedure Options_StartupSettings;
procedure Hotkey_Set(params: TStringList);
procedure Hotkey_Clear(params: TStringList);
@@ -193,6 +196,7 @@ uses
Keyman.Configuration.Util.NetworkConnection,
Keyman.Configuration.System.UmodWebHttpServer,
Keyman.Configuration.System.HttpServer.App.ConfigMain,
+ Keyman.Configuration.System.StartupSettings,
Keyman.Configuration.UI.InstallFile,
Keyman.Configuration.UI.UfrmSettingsManager,
Keyman.Configuration.UI.UfrmStartInstall,
@@ -264,6 +268,15 @@ begin
inherited;
end;
+procedure TfrmMain.AppEventsActivate(Sender: TObject);
+begin
+ if FRefreshOnActivate then
+ begin
+ FRefreshOnActivate := False;
+ DoRefresh;
+ end;
+end;
+
{-------------------------------------------------------------------------------
- Form-level functions -
------------------------------------------------------------------------------}
@@ -343,6 +356,7 @@ begin
else if command = 'options_resethints' then Options_ResetHints
else if command = 'options_basekeyboard' then Options_BaseKeyboard // I4169
else if command = 'options_settingsmanager' then Options_SettingsManager
+ else if command = 'options_startupsettings' then Options_StartupSettings
else if command = 'language_underlyingkeyboard' then Options_BaseKeyboard
@@ -686,17 +700,19 @@ begin
end;
end;
+procedure TfrmMain.Options_StartupSettings;
+begin
+ FRefreshOnActivate := TUtilExecute.Shell(0, 'ms-settings:startupapps', '', '');
+end;
+
procedure TfrmMain.Options_ClickCheck(params: TStringList);
var
option: IKeymanOption;
+ startupDisabled: Boolean;
begin
if GetOptionFromParams(params, option) and option.Enabled then
begin
option.Value := not option.Value;
-
- if (option.ID = 'koDebugging') and option.Value then
- ShowMessage(MsgFromId(SKDebuggingWarning));
-
kmcom.Errors.Clear;
DoApply;
if kmcom.Errors.Count > 0 then
@@ -706,7 +722,19 @@ begin
// be invalid
ShowMessage(kmcom.Errors[0].Description);
DoRefresh;
- end;
+ end
+ else
+ begin
+ if (option.ID = 'koDebugging') and option.Value then
+ ShowMessage(MsgFromId(SKDebuggingWarning));
+ startupDisabled := (option.ID = 'koStartWithWindows') and option.Value and TWindowsStartupSettings.IsWindowsStartupDisabled;
+ DoRefresh;
+ if startupDisabled then
+ if MessageDlg(MsgFromId(S_StartupDisabledWarningOpenSettings),
+ mtWarning, [mbYes, mbNo], 0) = mrYes then
+ Options_StartupSettings;
+ end
+
end
else
ShowMessage(params.Text);
diff --git a/windows/src/desktop/kmshell/render/OptionsXMLRenderer.pas b/windows/src/desktop/kmshell/render/OptionsXMLRenderer.pas
index fb37c9cae1..b0374ca7ff 100644
--- a/windows/src/desktop/kmshell/render/OptionsXMLRenderer.pas
+++ b/windows/src/desktop/kmshell/render/OptionsXMLRenderer.pas
@@ -42,8 +42,10 @@ implementation
uses
custinterfaces,
+ Keyman.Configuration.System.StartupSettings,
kmint,
MessageIdentifiers,
+ RegistryKeys,
utilxml,
Variants;
@@ -70,6 +72,10 @@ var
begin
References := Null; // I2678
Result := kmcom.Options.SerializeXML(0, '', References);
+ if TWindowsStartupSettings.IsWindowsStartupDisabled then
+ Result := Result + 'True'
+ else
+ Result := Result + 'False';
FGroups := TStringList.Create;
try
Result := Result + '';
diff --git a/windows/src/desktop/kmshell/util/Keyman.Configuration.System.StartupSettings.pas b/windows/src/desktop/kmshell/util/Keyman.Configuration.System.StartupSettings.pas
new file mode 100644
index 0000000000..a8c6c119a1
--- /dev/null
+++ b/windows/src/desktop/kmshell/util/Keyman.Configuration.System.StartupSettings.pas
@@ -0,0 +1,59 @@
+(**
+ * Keyman is copyright (C) SIL Global. MIT License.
+ *
+ * Created by Ross Cruickshank on 2026-09-18
+ *
+ *
+ * This unit assists in determining whether Keyman is enabled to start with Windows in the Windows startup settings.
+ *)
+unit Keyman.Configuration.System.StartupSettings;
+
+interface
+
+type
+ TWindowsStartupSettings = class
+ class function IsWindowsStartupDisabled: Boolean; static;
+ end;
+
+implementation
+
+uses
+ RegistryKeys,
+ System.Win.Registry,
+ Windows,
+ SysUtils;
+
+const
+ StartupEnabled: Byte = $02;
+ StartupDisabled: Byte = $03;
+
+
+
+class function TWindowsStartupSettings.IsWindowsStartupDisabled: Boolean;
+var
+ reg: TRegistry;
+ data: array[0..11] of Byte;
+begin
+ Result := False;
+ reg := TRegistry.Create;
+ try
+ try
+ reg.RootKey := HKEY_CURRENT_USER;
+ if not reg.OpenKeyReadOnly('\' + SRegKey_StartupApproved_Run) then
+ Exit;
+ if not reg.ValueExists(SRegValue_WindowsRun_Keyman) then
+ Exit;
+ if reg.GetDataSize(SRegValue_WindowsRun_Keyman) <> SizeOf(data) then
+ Exit;
+ reg.ReadBinaryData(SRegValue_WindowsRun_Keyman, data, SizeOf(data));
+ Result := data[0] = StartUpDisabled;
+ except
+ on E: ERegistryException do
+ Result := False;
+ end;
+ finally
+ reg.Free;
+ end;
+end;
+
+end.
diff --git a/windows/src/desktop/kmshell/xml/config.css b/windows/src/desktop/kmshell/xml/config.css
index 2c00d41adc..cf0316c36f 100644
--- a/windows/src/desktop/kmshell/xml/config.css
+++ b/windows/src/desktop/kmshell/xml/config.css
@@ -736,6 +736,20 @@ table tr
{
display: none;
}
+.options_startup_warning
+{
+ background: #FFF4CE;
+ border: 1px solid #D6B656;
+ color: #4A3B00;
+ margin: 4px 8px 8px 32px;
+ padding: 8px;
+}
+.options_startup_warning input,
+.options_startup_warning button
+{
+ margin-left: 0;
+ margin-top: 6px;
+}
#options_control
{
left: 0;
diff --git a/windows/src/desktop/kmshell/xml/keyman_options.xsl b/windows/src/desktop/kmshell/xml/keyman_options.xsl
index 0d68ca46ca..1d06a83dc9 100644
--- a/windows/src/desktop/kmshell/xml/keyman_options.xsl
+++ b/windows/src/desktop/kmshell/xml/keyman_options.xsl
@@ -16,6 +16,16 @@
+
+
+
+
+
+ keyman:options_startupsettings
+ 1
+
+
+
@@ -105,4 +115,4 @@
-
\ No newline at end of file
+
diff --git a/windows/src/desktop/kmshell/xml/strings.xml b/windows/src/desktop/kmshell/xml/strings.xml
index 7d6f53c85d..285ffd4965 100644
--- a/windows/src/desktop/kmshell/xml/strings.xml
+++ b/windows/src/desktop/kmshell/xml/strings.xml
@@ -404,6 +404,21 @@
Start when Windows starts
+
+
+
+ Windows has disabled Keyman from starting automatically. Enable Keyman in Windows Startup settings.
+
+
+
+
+ Open Windows Startup settings
+
+
+
+
+ Windows has disabled Keyman from starting automatically. Open Windows Startup settings now?
+