You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-19 14:31:59 +00:00
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.
This commit is contained in:
@@ -576,6 +576,29 @@ Vector<String> _OS::get_cmdline_args() {
|
||||
return cmdlinev;
|
||||
}
|
||||
|
||||
void _OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
|
||||
List<String> args_list;
|
||||
for (int i = 0; i < p_restart_arguments.size(); i++) {
|
||||
args_list.push_back(p_restart_arguments[i]);
|
||||
}
|
||||
|
||||
::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();
|
||||
}
|
||||
@@ -1405,6 +1428,10 @@ void _OS::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_name"), &_OS::get_name);
|
||||
ClassDB::bind_method(D_METHOD("get_cmdline_args"), &_OS::get_cmdline_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("get_datetime", "utc"), &_OS::get_datetime, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_date", "utc"), &_OS::get_date, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_time", "utc"), &_OS::get_time, DEFVAL(false));
|
||||
|
||||
Reference in New Issue
Block a user