mirror of https://gitlab.com/basile.b/dexed.git
Application now compiles on Mac OSX (Yosemite).
Added `internalAppIsRunning` procedure for Darwin. Uses `pgrep` instead of `ps` as MacOSX's ps lacks the `-C` option. Instead we will use `pgrep` to query for the applications pid. If the application is running we will get a positive integer (as a string) in return which is returned as the `Result` after casting to `Int`. Also: my first ever ObjectPascal code ;) Hooray!
This commit is contained in:
parent
ef83e333f6
commit
f35ad0519e
|
@ -6,7 +6,7 @@ interface
|
|||
|
||||
uses
|
||||
|
||||
Classes, SysUtils,
|
||||
Classes, SysUtils, StrUtils,
|
||||
{$IFDEF WINDOWS}
|
||||
Windows, JwaTlHelp32,
|
||||
{$ENDIF}
|
||||
|
@ -911,6 +911,39 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF DARWIN}
|
||||
function internalAppIsRunning(const ExeName: string): integer;
|
||||
var
|
||||
proc: TProcess;
|
||||
lst: TStringList;
|
||||
stripChars: TSysCharSet;
|
||||
var lstText: AnsiString;
|
||||
begin
|
||||
Result := 0;
|
||||
stripChars := ['"'];
|
||||
proc := tprocess.Create(nil);
|
||||
proc.Executable := 'pgrep';
|
||||
proc.Parameters.Add(ExeName);
|
||||
proc.Options := [poUsePipes, poWaitonexit];
|
||||
try
|
||||
proc.Execute;
|
||||
lst := TStringList.Create;
|
||||
try
|
||||
lst.LoadFromStream(proc.Output);
|
||||
lstText := lst.Text;
|
||||
RemoveLeadingChars(lstText, stripChars);
|
||||
Result := StrToInt(lstText);
|
||||
finally
|
||||
lst.Free;
|
||||
end;
|
||||
finally
|
||||
proc.Free;
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
|
||||
function AppIsRunning(const ExeName: string):Boolean;
|
||||
begin
|
||||
Result:= internalAppIsRunning(ExeName) > 0;
|
||||
|
|
Loading…
Reference in New Issue