Rename System manufacturer/model to deviceVendor/deviceModel, and version to platformVersion, add platformName/platformLabel

This commit is contained in:
Joshua Granick
2018-01-29 13:01:33 -08:00
parent 15ef07800b
commit 4971f3222c
5 changed files with 287 additions and 182 deletions

View File

@@ -133,14 +133,16 @@ class NativeCFFI {
@:cffi private static function lime_sensor_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
@:cffi private static function lime_system_get_allow_screen_timeout ():Bool;
@:cffi private static function lime_system_set_allow_screen_timeout (value:Bool):Bool;
@:cffi private static function lime_system_get_device_model ():Dynamic;
@:cffi private static function lime_system_get_device_vendor ():Dynamic;
@:cffi private static function lime_system_get_directory (type:Int, company:String, title:String):Dynamic;
@:cffi private static function lime_system_get_display (index:Int):Dynamic;
@:cffi private static function lime_system_get_ios_tablet ():Bool;
@:cffi private static function lime_system_get_manufacturer ():Dynamic;
@:cffi private static function lime_system_get_model ():Dynamic;
@:cffi private static function lime_system_get_num_displays ():Int;
@:cffi private static function lime_system_get_platform_label ():Dynamic;
@:cffi private static function lime_system_get_platform_name ():Dynamic;
@:cffi private static function lime_system_get_platform_version ():Dynamic;
@:cffi private static function lime_system_get_timer ():Float;
@:cffi private static function lime_system_get_version ():Dynamic;
@:cffi private static function lime_system_open_file (path:String):Void;
@:cffi private static function lime_system_open_url (url:String, target:String):Void;
@:cffi private static function lime_text_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;

View File

@@ -57,29 +57,33 @@ class System {
public static var applicationDirectory (get, never):String;
public static var applicationStorageDirectory (get, never):String;
public static var desktopDirectory (get, never):String;
public static var deviceModel (get, never):String;
public static var deviceVendor (get, never):String;
public static var disableCFFI:Bool;
public static var documentsDirectory (get, never):String;
public static var endianness (get, never):Endian;
public static var fontsDirectory (get, never):String;
public static var manufacturer (get, never):String;
public static var model (get, never):String;
public static var numDisplays (get, never):Int;
public static var platformLabel (get, never):String;
public static var platformName (get, never):String;
public static var platformVersion (get, never):String;
public static var userDirectory (get, never):String;
public static var version (get, never):String;
@:noCompletion private static var __applicationConfig:Map<String, Config>;
@:noCompletion private static var __applicationDirectory:String;
@:noCompletion private static var __applicationEntryPoint:Map<String, Function>;
@:noCompletion private static var __applicationStorageDirectory:String;
@:noCompletion private static var __desktopDirectory:String;
@:noCompletion private static var __deviceModel:String;
@:noCompletion private static var __deviceVendor:String;
@:noCompletion private static var __directories = new Map<SystemDirectory, String> ();
@:noCompletion private static var __documentsDirectory:String;
@:noCompletion private static var __endianness:Endian;
@:noCompletion private static var __fontsDirectory:String;
@:noCompletion private static var __manufacturer:String;
@:noCompletion private static var __model:String;
@:noCompletion private static var __platformLabel:String;
@:noCompletion private static var __platformName:String;
@:noCompletion private static var __platformVersion:String;
@:noCompletion private static var __userDirectory:String;
@:noCompletion private static var __version:String;
#if (js && html5)
@@ -605,6 +609,61 @@ class System {
}
private static function get_deviceModel ():String {
if (__deviceModel == null) {
#if (windows || ios)
__deviceModel = NativeCFFI.lime_system_get_device_model ();
#elseif android
var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get ();
var model:String = JNI.createStaticField ("android/os/Build", "MODEL", "Ljava/lang/String;").get ();
if (manufacturer != null && model != null) {
if (StringTools.startsWith (model.toLowerCase (), manufacturer.toLowerCase ())) {
model = StringTools.trim (model.substr (manufacturer.length));
while (StringTools.startsWith (model, "-")) {
model = StringTools.trim (model.substr (1));
}
}
__deviceModel = model;
}
#elseif mac
__deviceModel = __runProcess ("sysctl", [ "-n", "hw.model" ]);
#elseif linux
__deviceModel = __runProcess ("cat", [ "/sys/devices/virtual/dmi/id/sys_vendor" ]);
#end
}
return __deviceModel;
}
private static function get_deviceVendor ():String {
if (__deviceVendor == null) {
#if windows
__deviceVendor = NativeCFFI.lime_system_get_device_vendor ();
#elseif android
var vendor:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get ();
if (vendor != null) {
__deviceVendor = vendor.charAt (0).toUpperCase () + vendor.substr (1);
}
#elseif (ios || mac)
__deviceVendor = "Apple";
#elseif linux
__deviceVendor = __runProcess ("cat", [ "/sys/devices/virtual/dmi/id/product_name" ]);
#end
}
return __deviceVendor;
}
private static function get_desktopDirectory ():String {
if (__desktopDirectory == null) {
@@ -631,6 +690,29 @@ class System {
}
private static function get_endianness ():Endian {
if (__endianness == null) {
#if (ps3 || wiiu || flash)
__endianness = BIG_ENDIAN;
#else
var arrayBuffer = new ArrayBuffer (2);
var uint8Array = new UInt8Array (arrayBuffer);
var uint16array = new UInt16Array (arrayBuffer);
uint8Array[0] = 0xAA;
uint8Array[1] = 0xBB;
if (uint16array[0] == 0xAABB) __endianness = BIG_ENDIAN;
else __endianness = LITTLE_ENDIAN;
#end
}
return __endianness;
}
private static function get_fontsDirectory ():String {
if (__fontsDirectory == null) {
@@ -655,6 +737,76 @@ class System {
}
private static function get_platformLabel ():String {
if (__platformLabel == null) {
#if windows
var label:String = NativeCFFI.lime_system_get_platform_label ();
if (label != null) __platformLabel = StringTools.trim (label);
#elseif linux
__platformLabel = __runProcess ("lsb_release", [ "-ds" ]);
#else
var name = System.platformName;
var version = System.platformVersion;
if (name != null && version != null) __platformLabel = name + " " + version;
#end
}
return __platformLabel;
}
private static function get_platformName ():String {
if (__platformName == null) {
#if windows
__platformName = "Windows";
#elseif android
__platformName = "Android";
#elseif ios
__platformName = "iOS";
#elseif mac
__platformName = "macOS";
#elseif linux
__platformName = __runProcess ("lsb_release", [ "-is" ]);
#end
}
return __platformName;
}
private static function get_platformVersion ():String {
if (__platformVersion == null) {
#if windows
__platformVersion = NativeCFFI.lime_system_get_platform_version ();
#elseif android
var release = JNI.createStaticField ("android/os/Build$VERSION", "RELEASE", "Ljava/lang/String;").get ();
var api = JNI.createStaticField ("android/os/Build$VERSION", "SDK_INT", "I").get ();
if (release != null && api != null) __platformVersion = release + " (API " + api + ")";
#elseif ios
__platformVersion = NativeCFFI.lime_system_get_platform_version ();
#elseif mac
__platformVersion = __runProcess ("sw_vers", [ "-productVersion" ]);
#elseif linux
__platformVersion = __runProcess ("lsb_release", [ "-rs" ]);
#end
}
return __platformVersion;
}
private static function get_userDirectory ():String {
if (__userDirectory == null) {
@@ -668,115 +820,6 @@ class System {
}
private static function get_endianness ():Endian {
if (__endianness == null) {
#if (ps3 || wiiu || flash)
__endianness = BIG_ENDIAN;
#else
var arrayBuffer = new ArrayBuffer (2);
var uint8Array = new UInt8Array (arrayBuffer);
var uint16array = new UInt16Array (arrayBuffer);
uint8Array[0] = 0xAA;
uint8Array[1] = 0xBB;
if (uint16array[0] == 0xAABB) __endianness = BIG_ENDIAN;
else __endianness = LITTLE_ENDIAN;
#end
}
return __endianness;
}
private static function get_manufacturer ():String {
if (__manufacturer == null) {
#if windows
__manufacturer = NativeCFFI.lime_system_get_manufacturer ();
#elseif android
var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get ();
if (manufacturer != null) {
__manufacturer = manufacturer.charAt (0).toUpperCase () + manufacturer.substr (1);
}
#elseif (ios || mac)
__manufacturer = "Apple";
#elseif linux
__manufacturer = __runProcess ("cat", [ "/sys/devices/virtual/dmi/id/product_name" ]);
#end
}
return __manufacturer;
}
private static function get_model ():String {
if (__model == null) {
#if (windows || ios)
__model = NativeCFFI.lime_system_get_model ();
#elseif android
var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get ();
var model:String = JNI.createStaticField ("android/os/Build", "MODEL", "Ljava/lang/String;").get ();
if (manufacturer != null && model != null) {
if (StringTools.startsWith (model.toLowerCase (), manufacturer.toLowerCase ())) {
model = StringTools.trim (model.substr (manufacturer.length));
while (StringTools.startsWith (model, "-")) {
model = StringTools.trim (model.substr (1));
}
}
__model = model;
}
#elseif mac
__model = __runProcess ("sysctl", [ "-n", "hw.model" ]);
#elseif linux
__model = __runProcess ("cat", [ "/sys/devices/virtual/dmi/id/sys_vendor" ]);
#end
}
return __model;
}
private static function get_version ():String {
if (__version == null) {
#if windows
var version:String = NativeCFFI.lime_system_get_version ();
if (version != null) __version = StringTools.trim (version);
#elseif android
var release = JNI.createStaticField ("android/os/Build$VERSION", "RELEASE", "Ljava/lang/String;").get ();
var api = JNI.createStaticField ("android/os/Build$VERSION", "SDK_INT", "I").get ();
if (release != null && api != null) __version = "Android " + release + " (API " + api + ")";
#elseif ios
var name = "iOS";
var version:String = NativeCFFI.lime_system_get_version ();
if (name != null && version != null) __version = name + " " + version;
#elseif mac
//var name = __runProcess ("sw_vers", [ "-productName" ]);
var name = "macOS";
var version = __runProcess ("sw_vers", [ "-productVersion" ]);
if (name != null && version != null) __version = name + " " + version;
#elseif linux
__version = __runProcess ("lsb_release", [ "-ds" ]);
#end
}
return __version;
}
}

View File

@@ -27,20 +27,22 @@ namespace lime {
public:
static bool GetAllowScreenTimeout ();
static std::wstring* GetDeviceModel ();
static std::wstring* GetDeviceVendor ();
static std::wstring* GetDirectory (SystemDirectory type, const char* company, const char* title);
static value GetDisplay (int id);
#ifdef IPHONE
static std::wstring* GetIOSDirectory (SystemDirectory type);
static bool GetIOSTablet ();
#endif
static std::wstring* GetManufacturer ();
static std::wstring* GetModel ();
static std::wstring* GetVersion ();
static int GetNumDisplays ();
static std::wstring* GetPlatformLabel ();
static std::wstring* GetPlatformName ();
static std::wstring* GetPlatformVersion ();
static double GetTimer ();
#ifdef HX_WINDOWS
static int GetWindowsConsoleMode (int handleType);
#endif
static value GetDisplay (int id);
static int GetNumDisplays ();
static double GetTimer ();
static void OpenFile (const char* path);
static void OpenURL (const char* url, const char* target);
static bool SetAllowScreenTimeout (bool allow);

View File

@@ -1444,6 +1444,44 @@ namespace lime {
}
value lime_system_get_device_model () {
std::wstring* model = System::GetDeviceModel ();
if (model) {
value result = alloc_wstring (model->c_str ());
delete model;
return result;
} else {
return alloc_null ();
}
}
value lime_system_get_device_vendor () {
std::wstring* vendor = System::GetDeviceVendor ();
if (vendor) {
value result = alloc_wstring (vendor->c_str ());
delete vendor;
return result;
} else {
return alloc_null ();
}
}
value lime_system_get_directory (int type, HxString company, HxString title) {
std::wstring* path = System::GetDirectory ((SystemDirectory)type, company.c_str (), title.c_str ());
@@ -1481,44 +1519,6 @@ namespace lime {
}
value lime_system_get_manufacturer () {
std::wstring* manufacturer = System::GetManufacturer ();
if (manufacturer) {
value result = alloc_wstring (manufacturer->c_str ());
delete manufacturer;
return result;
} else {
return alloc_null ();
}
}
value lime_system_get_model () {
std::wstring* model = System::GetModel ();
if (model) {
value result = alloc_wstring (model->c_str ());
delete model;
return result;
} else {
return alloc_null ();
}
}
int lime_system_get_num_displays () {
return System::GetNumDisplays ();
@@ -1526,16 +1526,47 @@ namespace lime {
}
double lime_system_get_timer () {
value lime_system_get_platform_label () {
return System::GetTimer ();
std::wstring* label = System::GetPlatformLabel ();
if (label) {
value result = alloc_wstring (label->c_str ());
delete label;
return result;
} else {
return alloc_null ();
}
}
value lime_system_get_version () {
value lime_system_get_platform_name () {
std::wstring* version = System::GetVersion ();
std::wstring* name = System::GetPlatformName ();
if (name) {
value result = alloc_wstring (name->c_str ());
delete name;
return result;
} else {
return alloc_null ();
}
}
value lime_system_get_platform_version () {
std::wstring* version = System::GetPlatformVersion ();
if (version) {
@@ -1552,6 +1583,13 @@ namespace lime {
}
double lime_system_get_timer () {
return System::GetTimer ();
}
int lime_system_get_windows_console_mode (int handleType) {
#ifdef HX_WINDOWS
@@ -2030,14 +2068,16 @@ namespace lime {
DEFINE_PRIME2v (lime_render_event_manager_register);
DEFINE_PRIME2v (lime_sensor_event_manager_register);
DEFINE_PRIME0 (lime_system_get_allow_screen_timeout);
DEFINE_PRIME0 (lime_system_get_device_model);
DEFINE_PRIME0 (lime_system_get_device_vendor);
DEFINE_PRIME3 (lime_system_get_directory);
DEFINE_PRIME1 (lime_system_get_display);
DEFINE_PRIME0 (lime_system_get_ios_tablet);
DEFINE_PRIME0 (lime_system_get_manufacturer);
DEFINE_PRIME0 (lime_system_get_model);
DEFINE_PRIME0 (lime_system_get_num_displays);
DEFINE_PRIME0 (lime_system_get_platform_label);
DEFINE_PRIME0 (lime_system_get_platform_name);
DEFINE_PRIME0 (lime_system_get_platform_version);
DEFINE_PRIME0 (lime_system_get_timer);
DEFINE_PRIME0 (lime_system_get_version);
DEFINE_PRIME1 (lime_system_get_windows_console_mode);
DEFINE_PRIME1v (lime_system_open_file);
DEFINE_PRIME2v (lime_system_open_url);

View File

@@ -108,18 +108,7 @@ namespace lime {
#endif
std::wstring* System::GetManufacturer () {
#ifdef HX_WINDOWS
return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Vendor");
#endif
return NULL;
}
std::wstring* System::GetModel () {
std::wstring* System::GetDeviceModel () {
#ifdef HX_WINDOWS
return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Version");
@@ -130,7 +119,18 @@ namespace lime {
}
std::wstring* System::GetVersion () {
std::wstring* System::GetDeviceVendor () {
#ifdef HX_WINDOWS
return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Vendor");
#endif
return NULL;
}
std::wstring* System::GetPlatformLabel () {
#ifdef HX_WINDOWS
return GetWMIValue (bstr_t ("SELECT * FROM Win32_OperatingSystem"), L"Caption");
@@ -141,6 +141,24 @@ namespace lime {
}
std::wstring* System::GetPlatformName () {
return NULL;
}
std::wstring* System::GetPlatformVersion () {
#ifdef HX_WINDOWS
return GetWMIValue (bstr_t ("SELECT * FROM Win32_OperatingSystem"), L"Version");
#endif
return NULL;
}
#ifdef HX_WINDOWS
int System::GetWindowsConsoleMode (int handleType) {