-
-
Notifications
You must be signed in to change notification settings - Fork 144
fix(windows): set basekeyboard as current user not the admin user on an elevated process #16162
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
Open
rc-swag
wants to merge
27
commits into
master
Choose a base branch
from
fix/windows/15152/basekeyboard-user-not-admin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
65335ec
fix(windows): initial commit
rc-swag 92643e3
fix(windows): handle basekeyboard change non-admin user
rc-swag 2f4c428
fix(windows): restore UpdateBaseLayout interface
rc-swag 27970c6
fix(windows): refresh UI after basekbd change
rc-swag 9108af2
chore(windows): Merge branch 'master' into fix/windows/15152/basekeyb…
rc-swag 62dd0de
fix(windows): add compile for base keyoard to api
rc-swag 82fb400
fix(windows): pass basekeyboardid to installation api
rc-swag 155b8e1
fix(windows): strtoint for command line basekeyboardid
rc-swag 0c68b1e
fix(windows): typos and return type in interface declaration
rc-swag 3c1b47e
fix(windows): Free the correct object
rc-swag 8e77a57
fix(windows): CompileForBaseKeyboard doesn't return
rc-swag 314dea4
fix(windows): move non ui function from ufrmbasekeyboard
rc-swag c316094
chore(windows): Revert "fix(windows): typos and return type in interf…
rc-swag 5e89946
chore(windows): Revert "fix(windows): strtoint for command line basek…
rc-swag 4892366
chore(windows): Revert "fix(windows): pass basekeyboardid to installa…
rc-swag b9743d2
fix(windows): fix indentation
rc-swag d67c491
fix(windows): rename Setting System
rc-swag 0409cda
fix(windows): add comments for new functions
rc-swag 163806b
fix(windows): git revert error fix
rc-swag 63d12b6
fix(windows): remove UpdateBaseLayout deadcode
rc-swag f80986d
fix(windows): apply batched suggestions from code review
rc-swag babd43a
fix(windows): refactor ConfigureBaseKeyboard
rc-swag b6f475a
fix(windows): add basekeyboard filename functions
rc-swag eec0b12
fix(windows): rename argument that was misleading
rc-swag c940cae
fix(windows): fix date in title block
rc-swag 587d74d
fix(windows): apply batched suggestions from code review
rc-swag bb20b89
fix(windows): rename filename builder functions
rc-swag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
windows/src/desktop/kmshell/main/Keyman.Configuration.System.BaseKeyboard.pas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| (* | ||
| * Keyman is copyright (C) SIL Global. MIT License. | ||
| * | ||
| * Created by Ross Cruickshank on 2026-09-12 | ||
| * | ||
| * | ||
| * This unit assists in setting the base keyboard configuration, | ||
| * including compiling the installed keyboard layouts against | ||
| * the selected base keyboard. | ||
| *) | ||
| unit Keyman.Configuration.System.BaseKeyboard; | ||
|
mcdurdin marked this conversation as resolved.
|
||
|
|
||
| interface | ||
|
|
||
| uses | ||
| Winapi.Windows, | ||
| System.SysUtils, | ||
| keymanapi_TLB; | ||
|
|
||
| (** | ||
| * Returns true if the keyboard files need to be compiled for the specified KLID. | ||
| * @param BaseKeyboardID KLID of the base keyboard to compile. | ||
| * @returns True If the keyboard files need to be compiled. | ||
| *) | ||
| function BaseKeyboardNeedsMCompile(BaseKeyboardID: Integer): Boolean; | ||
|
|
||
| (** | ||
| * Sets the base keyboard KLID for the current user and compiles the keyboard | ||
| * layout files if necessary. In the case the compiled keyboard files are | ||
| *not present, it will require elevation. | ||
| * @param WindowHandle Window handle to own the elevation prompt. | ||
| * @param BaseKeyboardID KLID of the base keyboard KLID to set. | ||
| * @returns True when the base keyboard setting has been applied. | ||
| *) | ||
| function SetBaseKeyboard(WindowHandle: THandle; BaseKeyboardID: Integer): Boolean; | ||
|
|
||
| (** | ||
| * Compiles the installed keyboard layouts for the specified KLID. | ||
| * Must run elevated. | ||
| * | ||
| * @param BaseKeyboardID KLID of the base keyboard to compile. | ||
| * @returns True when the compilation is successful. | ||
| *) | ||
| function MCompileBaseKeyboard(BaseKeyboardID: Integer): Boolean; | ||
|
|
||
| implementation | ||
|
|
||
| uses | ||
| kmint, | ||
| utilkmshell, | ||
| utilfiletypes; | ||
|
|
||
| function BaseKeyboardNeedsMCompile(BaseKeyboardID: Integer): Boolean; | ||
| var | ||
| I: Integer; | ||
| Keyboard: IKeymanKeyboardInstalled; | ||
| KeyboardFileName: string; | ||
| BaseKeyboardIDHex: string; | ||
| begin | ||
| BaseKeyboardIDHex := IntToHex(BaseKeyboardID, 8); | ||
| for I := 0 to kmcom.Keyboards.Count - 1 do | ||
| begin | ||
| Keyboard := kmcom.Keyboards.Items[I]; | ||
| KeyboardFileName := Keyboard.Filename; | ||
| if FileExists(KeyboardFileName) and | ||
| (not FileExists(BuildKeyboardFilenameWithBaseKeyboardID(KeyboardFileName, BaseKeyboardIDHex)) or | ||
| not FileExists(BuildKeyboardFilenameWithBaseKeyboardIDAndDeadkey(KeyboardFileName, BaseKeyboardIDHex))) then | ||
| Exit(True); | ||
| end; | ||
| Result := False; | ||
| end; | ||
|
|
||
| function SetBaseKeyboard(WindowHandle: THandle; BaseKeyboardID: Integer): Boolean; | ||
| begin | ||
| Result := True; | ||
| if BaseKeyboardNeedsMCompile(BaseKeyboardID) then | ||
| begin | ||
| if not kmcom.SystemInfo.IsAdministrator then | ||
| begin | ||
| Result := WaitForElevatedConfiguration(WindowHandle, '-mcompilekbds ' + IntToHex(BaseKeyboardID, 8)) = 0; | ||
| end | ||
| else | ||
| Result := MCompileBaseKeyboard(BaseKeyboardID); | ||
| end; | ||
| if not Result then | ||
| Exit; | ||
| kmcom.Options['koBaseLayout'].Value := BaseKeyboardID; | ||
| kmcom.Options.Apply; | ||
| end; | ||
|
|
||
| function MCompileBaseKeyboard(BaseKeyboardID: Integer): Boolean; | ||
| var | ||
| i: Integer; | ||
| kbd: IKeymanKeyboardInstalled; | ||
| begin | ||
| Result := False; | ||
| // can be called from command line so test for admin | ||
| if not kmcom.SystemInfo.IsAdministrator then | ||
| Exit; | ||
| for i := 0 to kmcom.Keyboards.Count - 1 do | ||
| begin | ||
| kbd := kmcom.Keyboards[i]; | ||
| (kbd as IKeymanKeyboardInstalled2).MCompileForBaseKeyboard(BaseKeyboardID); | ||
| end; | ||
| Result := True; | ||
| end; | ||
|
|
||
| end. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,7 @@ implementation | |
| Hints, | ||
| HotkeyUtils, | ||
| initprog, | ||
| Keyman.Configuration.System.BaseKeyboard, | ||
| Keyman.Configuration.System.TIPMaintenance, | ||
| Keyman.Configuration.UI.UfrmDiagnosticTests, | ||
| KeymanOptionNames, | ||
|
|
@@ -198,6 +199,7 @@ implementation | |
| Keyman.Configuration.UI.UfrmStartInstall, | ||
| RegistryKeys, | ||
| SupportXMLRenderer, | ||
| UfrmBaseKeyboard, | ||
| UfrmChangeHotkey, | ||
| UfrmHTML, | ||
| UfrmInstallKeyboardFromWeb, | ||
|
|
@@ -661,9 +663,14 @@ procedure TfrmMain.cefBeforeBrowseSync(Sender: TObject; const Url: string; | |
| ------------------------------------------------------------------------------} | ||
|
|
||
| procedure TfrmMain.Options_BaseKeyboard; // I4169 | ||
| var | ||
| BaseKeyboardID: Integer; | ||
| begin | ||
| WaitForElevatedConfiguration(Handle, '-basekeyboard'); | ||
| // Refresh will be triggered by elevated process | ||
| if ConfigureAndSetBaseKeyboard(Handle) then | ||
| begin | ||
| DoRefresh; | ||
| end; | ||
|
Comment on lines
+666
to
+672
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This then can also use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| end; | ||
|
|
||
| procedure TfrmMain.Options_SettingsManager; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a number of suggestions to these functions. Can you move the whole lot to utilfiletypes.pas, rather than utilstr.pas?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
six for one half-a-dozen for the other. It isn't really filetype identifier but I guess it is making a new filename of the same type. It is also really str manipulation function. I will move it.