2022-03-27 02:18:26 +00:00
|
|
|
package funkin.util;
|
|
|
|
|
2023-01-02 22:40:53 +00:00
|
|
|
import flixel.util.FlxSignal.FlxTypedSignal;
|
|
|
|
|
2023-11-24 00:48:28 +00:00
|
|
|
using StringTools;
|
|
|
|
|
2023-11-07 09:04:22 +00:00
|
|
|
/**
|
|
|
|
* Utilities for operating on the current window, such as changing the title.
|
|
|
|
*/
|
2023-03-02 01:27:29 +00:00
|
|
|
#if (cpp && windows)
|
2023-01-23 00:55:30 +00:00
|
|
|
@:cppFileCode('
|
|
|
|
#include <iostream>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
')
|
|
|
|
#end
|
2022-03-27 02:18:26 +00:00
|
|
|
class WindowUtil
|
|
|
|
{
|
2023-06-25 16:36:21 +00:00
|
|
|
/**
|
|
|
|
* Runs platform-specific code to open a URL in a web browser.
|
|
|
|
* @param targetUrl The URL to open.
|
|
|
|
*/
|
2023-11-23 00:17:35 +00:00
|
|
|
public static function openURL(targetUrl:String):Void
|
2023-01-23 00:55:30 +00:00
|
|
|
{
|
|
|
|
#if CAN_OPEN_LINKS
|
|
|
|
#if linux
|
2024-05-13 20:16:49 +00:00
|
|
|
Sys.command('/usr/bin/xdg-open $targetUrl &');
|
2023-01-23 00:55:30 +00:00
|
|
|
#else
|
2023-06-25 16:36:21 +00:00
|
|
|
// This should work on Windows and HTML5.
|
2023-01-23 00:55:30 +00:00
|
|
|
FlxG.openURL(targetUrl);
|
|
|
|
#end
|
|
|
|
#else
|
2023-06-25 16:36:21 +00:00
|
|
|
throw 'Cannot open URLs on this platform.';
|
2023-01-23 00:55:30 +00:00
|
|
|
#end
|
|
|
|
}
|
2023-01-02 22:40:53 +00:00
|
|
|
|
2023-11-23 00:17:35 +00:00
|
|
|
/**
|
|
|
|
* Runs platform-specific code to open a path in the file explorer.
|
|
|
|
* @param targetPath The path to open.
|
|
|
|
*/
|
|
|
|
public static function openFolder(targetPath:String):Void
|
|
|
|
{
|
|
|
|
#if CAN_OPEN_LINKS
|
|
|
|
#if windows
|
2024-03-17 02:20:22 +00:00
|
|
|
Sys.command('explorer', [targetPath.replace('/', '\\')]);
|
2023-11-23 00:17:35 +00:00
|
|
|
#elseif mac
|
|
|
|
Sys.command('open', [targetPath]);
|
|
|
|
#elseif linux
|
|
|
|
Sys.command('open', [targetPath]);
|
|
|
|
#end
|
|
|
|
#else
|
|
|
|
throw 'Cannot open URLs on this platform.';
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-11-24 00:54:34 +00:00
|
|
|
/**
|
|
|
|
* Runs platform-specific code to open a file explorer and select a specific file.
|
|
|
|
* @param targetPath The path of the file to select.
|
|
|
|
*/
|
|
|
|
public static function openSelectFile(targetPath:String):Void
|
|
|
|
{
|
|
|
|
#if CAN_OPEN_LINKS
|
|
|
|
#if windows
|
2024-03-17 02:20:22 +00:00
|
|
|
Sys.command('explorer', ['/select,' + targetPath.replace('/', '\\')]);
|
2023-11-24 00:54:34 +00:00
|
|
|
#elseif mac
|
2024-03-17 02:20:22 +00:00
|
|
|
Sys.command('open', ['-R', targetPath]);
|
2023-11-24 00:54:34 +00:00
|
|
|
#elseif linux
|
|
|
|
// TODO: unsure of the linux equivalent to opening a folder and then "selecting" a file.
|
|
|
|
Sys.command('open', [targetPath]);
|
|
|
|
#end
|
|
|
|
#else
|
|
|
|
throw 'Cannot open URLs on this platform.';
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
/**
|
|
|
|
* Dispatched when the game window is closed.
|
|
|
|
*/
|
|
|
|
public static final windowExit:FlxTypedSignal<Int->Void> = new FlxTypedSignal<Int->Void>();
|
2023-01-02 22:40:53 +00:00
|
|
|
|
2023-06-25 16:36:21 +00:00
|
|
|
/**
|
|
|
|
* Wires up FlxSignals that happen based on window activity.
|
|
|
|
* For example, we can run a callback when the window is closed.
|
|
|
|
*/
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function initWindowEvents():Void
|
2023-01-23 00:55:30 +00:00
|
|
|
{
|
|
|
|
// onUpdate is called every frame just before rendering.
|
2023-01-02 22:40:53 +00:00
|
|
|
|
2023-01-23 00:55:30 +00:00
|
|
|
// onExit is called when the game window is closed.
|
2023-03-02 01:27:29 +00:00
|
|
|
openfl.Lib.current.stage.application.onExit.add(function(exitCode:Int) {
|
2023-01-23 00:55:30 +00:00
|
|
|
windowExit.dispatch(exitCode);
|
|
|
|
});
|
2024-04-30 04:40:42 +00:00
|
|
|
|
2024-09-23 20:09:34 +00:00
|
|
|
#if FEATURE_DEBUG_TRACY
|
|
|
|
// Apply a marker to indicate frame end for the Tracy profiler.
|
|
|
|
// Do this only if Tracy is configured to prevent lag.
|
|
|
|
openfl.Lib.current.stage.addEventListener(openfl.events.Event.EXIT_FRAME, (e:openfl.events.Event) -> {
|
|
|
|
cpp.vm.tracy.TracyProfiler.frameMark();
|
|
|
|
});
|
|
|
|
#end
|
|
|
|
|
2024-04-30 04:40:42 +00:00
|
|
|
openfl.Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_DOWN, (e:openfl.events.KeyboardEvent) -> {
|
2024-06-09 06:22:03 +00:00
|
|
|
for (key in PlayerSettings.player1.controls.getKeysForAction(WINDOW_FULLSCREEN))
|
2024-04-30 04:40:42 +00:00
|
|
|
{
|
|
|
|
if (e.keyCode == key)
|
|
|
|
{
|
|
|
|
openfl.Lib.application.window.fullscreen = !openfl.Lib.application.window.fullscreen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-01-23 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turns off that annoying "Report to Microsoft" dialog that pops up when the game crashes.
|
|
|
|
*/
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function disableCrashHandler():Void
|
2023-01-23 00:55:30 +00:00
|
|
|
{
|
2023-03-02 01:27:29 +00:00
|
|
|
#if (cpp && windows)
|
2023-01-23 00:55:30 +00:00
|
|
|
untyped __cpp__('SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);');
|
|
|
|
#else
|
|
|
|
// Do nothing.
|
|
|
|
#end
|
|
|
|
}
|
2023-06-22 05:41:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the title of the application window.
|
|
|
|
* @param value The title to use.
|
|
|
|
*/
|
|
|
|
public static function setWindowTitle(value:String):Void
|
|
|
|
{
|
|
|
|
lime.app.Application.current.window.title = value;
|
|
|
|
}
|
2022-03-27 02:18:26 +00:00
|
|
|
}
|