mirror of
https://git.vladimir.cc/vladimir/ewsdr.git
synced 2026-08-25 19:45:09 +00:00
Бандл под LaunchServices не может передать argv, поэтому GL-режим включался через bash-обёртку в CFBundleExecutable. Теперь тот же переключатель читается из окружения, что позволяет задать его в Info.plist через LSEnvironment и обойтись без обёртки. Разбор аргументов командной строки не изменён. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
1.9 KiB
ObjectPascal
72 lines
1.9 KiB
ObjectPascal
unit PlatformUtils;
|
|
|
|
{
|
|
PlatformUtils.pas - small helpers for desktop/runtime platform checks.
|
|
}
|
|
|
|
{$IFDEF FPC}
|
|
{$MODE Delphi}
|
|
{$ENDIF}
|
|
|
|
interface
|
|
|
|
function HasOpenGLSpectrumSwitch: Boolean;
|
|
function CurrentScreenDPI: Integer;
|
|
// Возвращает каталог для хранения конфигурации (с завершающим разделителем).
|
|
// macOS: ~/Library/Application Support/ewsdr/
|
|
// Linux: ~/.config/ewsdr/
|
|
// Windows: %APPDATA%\ewsdr\
|
|
function GetAppCfgDir: string;
|
|
|
|
implementation
|
|
|
|
uses
|
|
SysUtils {$IFNDEF HEADLESS}, Forms{$ENDIF};
|
|
|
|
function HasOpenGLSpectrumSwitch: Boolean;
|
|
var
|
|
I: Integer;
|
|
S: string;
|
|
begin
|
|
Result := False;
|
|
for I := 1 to ParamCount do
|
|
begin
|
|
S := LowerCase(ParamStr(I));
|
|
if (S = '--opengl') or (S = '-opengl') or (S = '/opengl') then
|
|
Exit(True);
|
|
end;
|
|
// Бандл под LaunchServices не может передать argv, поэтому тот же
|
|
// переключатель читается из окружения (Info.plist -> LSEnvironment).
|
|
S := LowerCase(Trim(GetEnvironmentVariable('EWSDR_OPENGL')));
|
|
if (S = '1') or (S = 'true') or (S = 'yes') or (S = 'on') then
|
|
Exit(True);
|
|
end;
|
|
|
|
function CurrentScreenDPI: Integer;
|
|
begin
|
|
{$IFNDEF HEADLESS}
|
|
Result := Screen.PixelsPerInch;
|
|
if Result <= 0 then Result := 96;
|
|
{$ELSE}
|
|
Result := 96; // headless-демон без LCL: экрана нет, дефолт DPI
|
|
{$ENDIF}
|
|
end;
|
|
|
|
function GetAppCfgDir: string;
|
|
begin
|
|
{$IFDEF WINDOWS}
|
|
Result := GetEnvironmentVariable('APPDATA');
|
|
if Result = '' then
|
|
Result := GetEnvironmentVariable('LOCALAPPDATA');
|
|
if Result = '' then
|
|
Result := ExtractFilePath(ParamStr(0));
|
|
Result := IncludeTrailingPathDelimiter(Result) + 'ewsdr' + PathDelim;
|
|
{$ELSE}
|
|
Result := IncludeTrailingPathDelimiter(GetAppConfigDir(False));
|
|
{$ENDIF}
|
|
if not DirectoryExists(Result) then
|
|
ForceDirectories(Result);
|
|
end;
|
|
|
|
end.
|