Merge pull request #87823 from KoBeWi/ban_adb

Don't invoke adb with no runnable Android preset
This commit is contained in:
Rémi Verschelde 2024-02-17 15:54:49 +01:00
commit e697774f61
No known key found for this signature in database
GPG Key ID: C3336907360768E1
7 changed files with 88 additions and 7 deletions

View File

@ -111,8 +111,13 @@ void EditorExport::save_presets() {
save_timer->start();
}
void EditorExport::emit_presets_runnable_changed() {
emit_signal(_export_presets_runnable_updated);
}
void EditorExport::_bind_methods() {
ADD_SIGNAL(MethodInfo("export_presets_updated"));
ADD_SIGNAL(MethodInfo(_export_presets_updated));
ADD_SIGNAL(MethodInfo(_export_presets_runnable_updated));
}
void EditorExport::add_export_platform(const Ref<EditorExportPlatform> &p_platform) {
@ -136,6 +141,7 @@ void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, in
} else {
export_presets.insert(p_at_pos, p_preset);
}
emit_presets_runnable_changed();
}
int EditorExport::get_export_preset_count() const {
@ -150,6 +156,7 @@ Ref<EditorExportPreset> EditorExport::get_export_preset(int p_idx) {
void EditorExport::remove_export_preset(int p_idx) {
export_presets.remove_at(p_idx);
save_presets();
emit_presets_runnable_changed();
}
void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
@ -382,6 +389,10 @@ bool EditorExport::poll_export_platforms() {
return changed;
}
void EditorExport::connect_presets_runnable_updated(const Callable &p_target) {
connect(_export_presets_runnable_updated, p_target);
}
EditorExport::EditorExport() {
save_timer = memnew(Timer);
add_child(save_timer);
@ -390,6 +401,7 @@ EditorExport::EditorExport() {
save_timer->connect("timeout", callable_mp(this, &EditorExport::_save));
_export_presets_updated = "export_presets_updated";
_export_presets_runnable_updated = "export_presets_runnable_updated";
singleton = this;
set_process(true);

View File

@ -41,7 +41,8 @@ class EditorExport : public Node {
Vector<Ref<EditorExportPreset>> export_presets;
Vector<Ref<EditorExportPlugin>> export_plugins;
StringName _export_presets_updated;
static inline StringName _export_presets_updated;
static inline StringName _export_presets_runnable_updated;
Timer *save_timer = nullptr;
bool block_save = false;
@ -54,6 +55,7 @@ class EditorExport : public Node {
protected:
friend class EditorExportPreset;
void save_presets();
void emit_presets_runnable_changed();
void _notification(int p_what);
static void _bind_methods();
@ -77,6 +79,7 @@ public:
void load_config();
void update_export_presets();
bool poll_export_platforms();
void connect_presets_runnable_updated(const Callable &p_target);
EditorExport();
~EditorExport();

View File

@ -221,6 +221,7 @@ String EditorExportPreset::get_name() const {
void EditorExportPreset::set_runnable(bool p_enable) {
runnable = p_enable;
EditorExport::singleton->emit_presets_runnable_changed();
EditorExport::singleton->save_presets();
}

View File

@ -294,7 +294,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
// Check for devices updates
String adb = get_adb_path();
if (FileAccess::exists(adb)) {
if (ea->has_runnable_preset.is_set() && FileAccess::exists(adb)) {
String devices;
List<String> args;
args.push_back("devices");
@ -426,6 +426,25 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
OS::get_singleton()->execute(adb, args);
}
}
void EditorExportPlatformAndroid::_update_preset_status() {
const int preset_count = EditorExport::get_singleton()->get_export_preset_count();
bool has_runnable = false;
for (int i = 0; i < preset_count; i++) {
const Ref<EditorExportPreset> &preset = EditorExport::get_singleton()->get_export_preset(i);
if (preset->get_platform() == this && preset->is_runnable()) {
has_runnable = true;
break;
}
}
if (has_runnable) {
has_runnable_preset.set();
} else {
has_runnable_preset.clear();
}
}
#endif
String EditorExportPlatformAndroid::get_project_name(const String &p_name) const {
@ -808,6 +827,15 @@ bool EditorExportPlatformAndroid::_uses_vulkan() {
return uses_vulkan;
}
void EditorExportPlatformAndroid::_notification(int p_what) {
#ifndef ANDROID_ENABLED
if (p_what == NOTIFICATION_POSTINITIALIZE) {
ERR_FAIL_NULL(EditorExport::get_singleton());
EditorExport::get_singleton()->connect_presets_runnable_updated(callable_mp(this, &EditorExportPlatformAndroid::_update_preset_status));
}
#endif
}
void EditorExportPlatformAndroid::_get_permissions(const Ref<EditorExportPreset> &p_preset, bool p_give_internet, Vector<String> &r_permissions) {
const char **aperms = android_perms;
while (*aperms) {
@ -3574,6 +3602,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() {
android_plugins_changed.set();
#endif // DISABLE_DEPRECATED
#ifndef ANDROID_ENABLED
_update_preset_status();
check_for_changes_thread.start(_check_for_changes_poll_thread, this);
#endif
}

View File

@ -98,8 +98,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
#ifndef ANDROID_ENABLED
Thread check_for_changes_thread;
SafeFlag quit_request;
SafeFlag has_runnable_preset;
static void _check_for_changes_poll_thread(void *ud);
void _update_preset_status();
#endif
String get_project_name(const String &p_name) const;
@ -187,10 +189,12 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
static bool _uses_vulkan();
protected:
void _notification(int p_what);
public:
typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key);
public:
virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
virtual void get_export_options(List<ExportOption> *r_options) const override;

View File

@ -124,6 +124,14 @@ String EditorExportPlatformIOS::get_export_option_warning(const EditorExportPres
return String();
}
void EditorExportPlatformIOS::_notification(int p_what) {
#ifdef MACOS_ENABLED
if (p_what == NOTIFICATION_POSTINITIALIZE) {
EditorExport::get_singleton()->connect_presets_runnable_updated(callable_mp(this, &EditorExportPlatformIOS::_update_preset_status));
}
#endif
}
bool EditorExportPlatformIOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
return true;
}
@ -2234,7 +2242,7 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
// Enum real devices (via ios_deploy, pre Xcode 15).
String idepl = EDITOR_GET("export/ios/ios_deploy");
if (!idepl.is_empty()) {
if (ea->has_runnable_preset.is_set() && !idepl.is_empty()) {
String devices;
List<String> args;
args.push_back("-c");
@ -2272,7 +2280,7 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
}
// Enum simulators.
if (_check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) {
if (ea->has_runnable_preset.is_set() && _check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) {
{
String devices;
List<String> args;
@ -2310,7 +2318,7 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
}
// Enum simulators.
{
if (ea->has_runnable_preset.is_set()) {
String devices;
List<String> args;
args.push_back("simctl");
@ -2379,6 +2387,25 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
}
}
}
void EditorExportPlatformIOS::_update_preset_status() {
const int preset_count = EditorExport::get_singleton()->get_export_preset_count();
bool has_runnable = false;
for (int i = 0; i < preset_count; i++) {
const Ref<EditorExportPreset> &preset = EditorExport::get_singleton()->get_export_preset(i);
if (preset->get_platform() == this && preset->is_runnable()) {
has_runnable = true;
break;
}
}
if (has_runnable) {
has_runnable_preset.set();
} else {
has_runnable_preset.clear();
}
}
#endif
Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
@ -2643,6 +2670,7 @@ EditorExportPlatformIOS::EditorExportPlatformIOS() {
plugins_changed.set();
devices_changed.set();
#ifdef MACOS_ENABLED
_update_preset_status();
check_for_changes_thread.start(_check_for_changes_poll_thread, this);
#endif
}

View File

@ -81,9 +81,11 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
#ifdef MACOS_ENABLED
Thread check_for_changes_thread;
SafeFlag quit_request;
SafeFlag has_runnable_preset;
static bool _check_xcode_install();
static void _check_for_changes_poll_thread(void *ud);
void _update_preset_status();
#endif
typedef Error (*FileHandler)(String p_file, void *p_userdata);
@ -152,6 +154,8 @@ protected:
virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const override;
virtual String get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const override;
void _notification(int p_what);
public:
virtual String get_name() const override { return "iOS"; }
virtual String get_os_name() const override { return "iOS"; }