[macOS] Add option to emit signal when opening files/urls with the app, instead of starting new instance.
This commit is contained in:
parent
88d9325065
commit
da8e9d9747
|
@ -1446,6 +1446,7 @@ ProjectSettings::ProjectSettings() {
|
||||||
GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
|
GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
|
||||||
GLOBAL_DEF("application/config/auto_accept_quit", true);
|
GLOBAL_DEF("application/config/auto_accept_quit", true);
|
||||||
GLOBAL_DEF("application/config/quit_on_go_back", 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:
|
// The default window size is tuned to:
|
||||||
// - Have a 16:9 aspect ratio,
|
// - Have a 16:9 aspect ratio,
|
||||||
|
|
|
@ -45,6 +45,7 @@ void MainLoop::_bind_methods() {
|
||||||
BIND_CONSTANT(NOTIFICATION_TEXT_SERVER_CHANGED);
|
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_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(_initialize);
|
||||||
GDVIRTUAL_BIND(_physics_process, "delta");
|
GDVIRTUAL_BIND(_physics_process, "delta");
|
||||||
|
|
|
@ -90,6 +90,13 @@
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<signals>
|
<signals>
|
||||||
|
<signal name="on_file_open">
|
||||||
|
<param index="0" name="files" type="PackedStringArray" />
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
<signal name="on_request_permissions_result">
|
<signal name="on_request_permissions_result">
|
||||||
<param index="0" name="permission" type="String" />
|
<param index="0" name="permission" type="String" />
|
||||||
<param index="1" name="granted" type="bool" />
|
<param index="1" name="granted" type="bool" />
|
||||||
|
|
|
@ -276,6 +276,10 @@
|
||||||
<member name="application/config/description" type="String" setter="" getter="" default="""">
|
<member name="application/config/description" type="String" setter="" getter="" default="""">
|
||||||
The project's description, displayed as a tooltip in the Project Manager when hovering the project.
|
The project's description, displayed as a tooltip in the Project Manager when hovering the project.
|
||||||
</member>
|
</member>
|
||||||
|
<member name="application/config/emit_on_file_open" type="bool" setter="" getter="" default="false">
|
||||||
|
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.
|
||||||
|
</member>
|
||||||
<member name="application/config/icon" type="String" setter="" getter="" default="""">
|
<member name="application/config/icon" type="String" setter="" getter="" default="""">
|
||||||
Icon used for the project, set when project loads. Exporters will also use this icon as a fallback if necessary.
|
Icon used for the project, set when project loads. Exporters will also use this icon as a fallback if necessary.
|
||||||
</member>
|
</member>
|
||||||
|
|
|
@ -179,8 +179,16 @@
|
||||||
|
|
||||||
if (!args.is_empty()) {
|
if (!args.is_empty()) {
|
||||||
if (os->get_main_loop()) {
|
if (os->get_main_loop()) {
|
||||||
// Application is already running, open a new instance with the URL/files as command line arguments.
|
// 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<String> args_vector;
|
||||||
|
for (List<String>::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);
|
os->create_instance(args);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Application is just started, add to the list of command line arguments and continue.
|
// Application is just started, add to the list of command line arguments and continue.
|
||||||
os->set_cmdline_platform_args(args);
|
os->set_cmdline_platform_args(args);
|
||||||
|
|
Loading…
Reference in New Issue