Skip to content

Commit f3148d2

Browse files
committed
Firemonkey OSX, IOS & Delphi Linux compatibility
1 parent 24bd7d1 commit f3148d2

7 files changed

+255
-57
lines changed

Quick.Commons.pas

+43-10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
Unit : Quick.Commons
66
Description : Common functions
77
Author : Kike Pérez
8-
Version : 1.5
8+
Version : 1.7
99
Created : 14/07/2017
10-
Modified : 24/01/2019
10+
Modified : 16/02/2019
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -70,6 +70,9 @@ interface
7070
FMX.Helpers.Mac,
7171
Macapi.ObjectiveC,
7272
{$ENDIF}
73+
{$IFDEF POSIX}
74+
Posix.Unistd,
75+
{$ENDIF}
7376
DateUtils;
7477

7578
type
@@ -732,7 +735,11 @@ function GetLoggedUserName : string;
732735
end;
733736
{$ELSE}
734737
begin
738+
{$IFDEF POSIX}
739+
Result := string(getlogin);
740+
{$ELSE}
735741
Result := 'N/A';
742+
{$ENDIF}
736743
//raise ENotImplemented.Create('Not Android GetLoggedUserName implemented!');
737744
end;
738745
{$ENDIF}
@@ -766,22 +773,38 @@ function GetComputerName : string;
766773
Result := pchar(result);
767774
end;
768775
{$ELSE}
769-
{$IF DEFINED(FPC) OR DEFINED(LINUX)}
776+
{$IF DEFINED(FPC) AND DEFINED(LINUX)}
770777
begin
771778
Result := GetEnvironmentVariable('COMPUTERNAME');
772779
end;
773780
{$ELSE} //Android gets model name
774-
begin
775781
{$IFDEF NEXTGEN}
782+
begin
776783
{$IFDEF ANDROID}
777784
Result := JStringToString(TJBuild.JavaClass.MODEL);
778785
{$ELSE} //IOS
779786
Result := GetDeviceModel;
780787
{$ENDIF}
781-
{$ELSE} //OSX
782-
Result := NSStrToStr(TNSHost.Wrap(TNSHost.OCClass.currentHost).localizedName);
788+
end;
789+
{$ELSE}
790+
{$IFDEF DELPHILINUX}
791+
var
792+
puser : PAnsiChar;
793+
begin
794+
//puser := '';
795+
try
796+
if gethostname(puser,_SC_HOST_NAME_MAX) = 0 then Result := string(puser)
797+
else Result := 'N/A';
798+
except
799+
Result := 'N/A';
800+
end;
801+
end;
802+
{$ELSE} //OSX
803+
begin
804+
Result := NSStrToStr(TNSHost.Wrap(TNSHost.OCClass.currentHost).localizedName);
805+
end;
806+
{$ENDIF}
783807
{$ENDIF}
784-
end;
785808
{$ENDIF}
786809
{$ENDIF}
787810

@@ -944,9 +967,13 @@ function GetAppVersionStr: string;
944967
Result := UTF8ToString(BuildStr.UTF8String);
945968

946969
except
947-
Result := 'N/A';
970+
Result := '';
948971
end;
949972
end;
973+
{$ELSE}
974+
begin
975+
Result := '';
976+
end;
950977
{$ENDIF}
951978
{$ENDIF}
952979
{$ENDIF}
@@ -1025,8 +1052,9 @@ function GetAppVersionFullStr: string;
10251052
Result := UTF8ToString(BuildStr.UTF8String);
10261053
end;
10271054
{$ENDIF}
1028-
{$ELSE} //OSX
1029-
var
1055+
{$ELSE}
1056+
{$IFDEF OSX}
1057+
var
10301058
AppKey: Pointer;
10311059
AppBundle: NSBundle;
10321060
BuildStr : NSString;
@@ -1036,6 +1064,11 @@ function GetAppVersionFullStr: string;
10361064
BuildStr := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppKey));
10371065
Result := UTF8ToString(BuildStr.UTF8String);
10381066
end;
1067+
{$ELSE}
1068+
begin
1069+
Result := 'N/A';
1070+
end;
1071+
{$ENDIF}
10391072
{$ENDIF}
10401073
{$ENDIF}
10411074
{$ENDIF}

0 commit comments

Comments
 (0)