diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 37a2608c102..617d77602d5 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1446,6 +1446,7 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("application/run/main_loop_type", "SceneTree"); GLOBAL_DEF("application/config/auto_accept_quit", true); GLOBAL_DEF("application/config/quit_on_go_back", true); + GLOBAL_DEF_BASIC("application/config/emit_on_file_open", false); // The default window size is tuned to: // - Have a 16:9 aspect ratio, diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 5e214901643..ba4f6ee85df 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -45,6 +45,7 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED); ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); + ADD_SIGNAL(MethodInfo("on_file_open", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); GDVIRTUAL_BIND(_initialize); GDVIRTUAL_BIND(_physics_process, "delta"); diff --git a/doc/classes/MainLoop.xml b/doc/classes/MainLoop.xml index 17cc0d78d39..6e605c8b571 100644 --- a/doc/classes/MainLoop.xml +++ b/doc/classes/MainLoop.xml @@ -90,6 +90,13 @@ + + + + Emitted when a user opens file with the application. Signal is emitted only is [member ProjectSettings.application/config/emit_on_file_open] is [code]true[/code] or application is running in the macOS sandbox. + [b]Note:[/b] This signal is implemented only on macOS. + + diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 4f7f3728646..3a6a1cdb011 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -276,6 +276,10 @@ The project's description, displayed as a tooltip in the Project Manager when hovering the project. + + If [code]true[/code], application will emit [signal MainLoop.on_file_open] signal instead of starting new application instance. + [b]Note:[/b] This setting is implemented only on macOS. + Icon used for the project, set when project loads. Exporters will also use this icon as a fallback if necessary. diff --git a/platform/macos/godot_application_delegate.mm b/platform/macos/godot_application_delegate.mm index 02466bab974..9ca3e6460a6 100644 --- a/platform/macos/godot_application_delegate.mm +++ b/platform/macos/godot_application_delegate.mm @@ -179,8 +179,16 @@ if (!args.is_empty()) { if (os->get_main_loop()) { - // Application is already running, open a new instance with the URL/files as command line arguments. - os->create_instance(args); + // Application is already running, open a new instance with the URL/files as command line arguments, or emit signal. + if ((OS::get_singleton()->is_sandboxed() || GLOBAL_GET("application/config/emit_on_file_open").operator bool()) && !Engine::get_singleton()->is_editor_hint()) { + Vector args_vector; + for (List::Element *E = args.front(); E; E = E->next()) { + args_vector.push_back(E->get()); + } + os->get_main_loop()->emit_signal(SNAME("on_file_open"), args_vector); + } else { + os->create_instance(args); + } } else { // Application is just started, add to the list of command line arguments and continue. os->set_cmdline_platform_args(args);