2023-10-28 23:56:34 +00:00
|
|
|
package funkin.util;
|
|
|
|
|
2023-11-07 09:04:22 +00:00
|
|
|
/**
|
|
|
|
* Utility functions related to specific platforms.
|
|
|
|
*/
|
2023-10-28 23:56:34 +00:00
|
|
|
class PlatformUtil
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns true if the current platform is MacOS.
|
|
|
|
*
|
|
|
|
* NOTE: Only use this for choosing modifier keys for shortcut hints.
|
|
|
|
* @return Whether the current platform is MacOS, or HTML5 running on MacOS.
|
|
|
|
*/
|
|
|
|
public static function isMacOS():Bool
|
|
|
|
{
|
|
|
|
#if mac
|
|
|
|
return true;
|
|
|
|
#elseif html5
|
2024-03-17 02:20:22 +00:00
|
|
|
return js.Browser.window.navigator.platform.startsWith('Mac')
|
|
|
|
|| js.Browser.window.navigator.platform.startsWith('iPad')
|
|
|
|
|| js.Browser.window.navigator.platform.startsWith('iPhone');
|
2023-10-28 23:56:34 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#end
|
|
|
|
}
|
2023-11-20 16:26:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detects and returns the current host platform.
|
|
|
|
* Always returns `HTML5` on web, regardless of the computer running that browser.
|
2024-03-17 02:20:22 +00:00
|
|
|
* @return The host platform, or `null` if the platform could not be detected.
|
2023-11-20 16:26:58 +00:00
|
|
|
*/
|
|
|
|
public static function detectHostPlatform():Null<HostPlatform>
|
|
|
|
{
|
|
|
|
#if html5
|
|
|
|
return HTML5;
|
|
|
|
#else
|
|
|
|
switch (Sys.systemName())
|
|
|
|
{
|
|
|
|
case ~/window/i.match(_) => true:
|
|
|
|
return WINDOWS;
|
|
|
|
case ~/linux/i.match(_) => true:
|
|
|
|
return LINUX;
|
|
|
|
case ~/mac/i.match(_) => true:
|
|
|
|
return MAC;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a host platform.
|
|
|
|
*/
|
|
|
|
enum HostPlatform
|
|
|
|
{
|
|
|
|
WINDOWS;
|
|
|
|
LINUX;
|
|
|
|
MAC;
|
|
|
|
HTML5;
|
2023-10-28 23:56:34 +00:00
|
|
|
}
|