Merge pull request #13168 from keymanapp/feat/windows/13167/add-release-kmutex

refactor(windows): rename `TKeymanMutex.MutexOwned` to `TakeOwnership` and add `ReleaseOwnership`
This commit is contained in:
rc-swag 2025-02-11 15:02:45 +10:00 • committed by GitHub
commit 8d6b331a67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 7 deletions

View file

@ -526,12 +526,16 @@ begin
fmMain, fmAbout:
begin // I2720
FMutex := TKeymanMutex.Create('KeymanConfiguration');
if FMutex.MutexOwned then Main else FocusConfiguration;
if FMutex.TakeOwnership
then Main
else FocusConfiguration;
end;
fmTextEditor:
begin // I2720
FMutex := TKeymanMutex.Create('KeymanTextEditor');
if FMutex.MutexOwned then OpenTextEditor else FocusTextEditor;
if FMutex.TakeOwnership
then OpenTextEditor
else FocusTextEditor;
end;
fmBaseKeyboard: // I4169

View file

@ -220,7 +220,7 @@ begin
begin
FMutex := TKeymanMutex.Create('KeymanSplash');
try
if not FMutex.MutexOwned then
if not FMutex.TakeOwnership then
begin
FocusSplash; // I2562
Exit;

View file

@ -281,7 +281,7 @@ function TKeymanControl.IsConfigurationOpen: WordBool;
begin
with TKeymanMutex.Create('KeymanConfiguration') do
try
Result := MutexOwned;
Result := not TakeOwnership;
finally
Free;
end;
@ -302,7 +302,7 @@ function TKeymanControl.IsTextEditorOpen: WordBool;
begin
with TKeymanMutex.Create('KeymanTextEditor') do
try
Result := MutexOwned;
Result := not TakeOwnership;
finally
Free;
end;

View file

@ -29,7 +29,8 @@ type
public
constructor Create(FName: string);
destructor Destroy; override;
function MutexOwned: Boolean;
function TakeOwnership: Boolean;
function ReleaseOwnership: Boolean;
end;
implementation
@ -52,9 +53,14 @@ begin
inherited Destroy;
end;
function TKeymanMutex.MutexOwned: Boolean;
function TKeymanMutex.TakeOwnership: Boolean;
begin
Result := WaitForSingleObject(hMutex, 0) = WAIT_OBJECT_0;
end;
function TKeymanMutex.ReleaseOwnership: Boolean;
begin
Result := ReleaseMutex(hMutex);
end;
end.