summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2021-05-12 03:12:59 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2022-08-01 14:06:13 +0200
commit1b713175b2de9d0aad3554a9add94b5518ee5648 (patch)
tree0327c0d673497f1888a6ff031970e63496571187 /core
parent9ec6de1767292b5cbc1ebdc7b262ef1d9c63df9a (diff)
Expose the "restart on exit" OS functionality
This can be used to restart a project with specific command line arguments applied. This can work in tandem with `OS.get_cmdline_args()` to restart with the same command line arguments as used to originally run the project. Example use cases: - Restart to apply an user setting change that requires a restart to work. - Restart with a Godot command line argument to change the video driver, audio driver, etc.
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp27
-rw-r--r--core/core_bind.h4
2 files changed, 31 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 79c80cf7d1..2cf6e8a025 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -341,6 +341,29 @@ Vector<String> OS::get_cmdline_user_args() {
return cmdlinev;
}
+void OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
+ List<String> args_list;
+ for (const String &restart_argument : p_restart_arguments) {
+ args_list.push_back(restart_argument);
+ }
+
+ ::OS::get_singleton()->set_restart_on_exit(p_restart, args_list);
+}
+
+bool OS::is_restart_on_exit_set() const {
+ return ::OS::get_singleton()->is_restart_on_exit_set();
+}
+
+Vector<String> OS::get_restart_on_exit_arguments() const {
+ List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments();
+ Vector<String> args_vector;
+ for (List<String>::Element *E = args.front(); E; E = E->next()) {
+ args_vector.push_back(E->get());
+ }
+
+ return args_vector;
+}
+
String OS::get_locale() const {
return ::OS::get_singleton()->get_locale();
}
@@ -626,6 +649,10 @@ void OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
+ ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
+ ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
+ ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
+
ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
diff --git a/core/core_bind.h b/core/core_bind.h
index 45b4091ce2..98bf34e07d 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -182,6 +182,10 @@ public:
bool is_process_running(int p_pid) const;
int get_process_id() const;
+ void set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments = Vector<String>());
+ bool is_restart_on_exit_set() const;
+ Vector<String> get_restart_on_exit_arguments() const;
+
bool has_environment(const String &p_var) const;
String get_environment(const String &p_var) const;
bool set_environment(const String &p_var, const String &p_value) const;