Fix web export state for remote debug

This commit is contained in:
Adam Scott 2024-05-20 10:38:54 -04:00
parent 95110ddcb4
commit 1e8e9f4b09
No known key found for this signature in database
GPG key ID: F6BA2A0302E21A77
2 changed files with 89 additions and 35 deletions

View file

@ -589,35 +589,50 @@ bool EditorExportPlatformWeb::poll_export() {
}
}
int prev = menu_options;
menu_options = preset.is_valid();
HTTPServerState prev_server_state = server_state;
server_state = HTTP_SERVER_STATE_OFF;
if (server->is_listening()) {
if (preset.is_null() || menu_options == 0) {
server->stop();
} else {
server_state = HTTP_SERVER_STATE_ON;
menu_options += 1;
RemoteDebugState prev_remote_debug_state = remote_debug_state;
remote_debug_state = REMOTE_DEBUG_STATE_UNAVAILABLE;
if (preset.is_valid()) {
const bool debug = true;
// Throwaway variables to pass to `can_export`.
String err;
bool missing_templates;
if (can_export(preset, err, missing_templates, debug)) {
if (server->is_listening()) {
remote_debug_state = REMOTE_DEBUG_STATE_SERVING;
} else {
remote_debug_state = REMOTE_DEBUG_STATE_AVAILABLE;
}
}
}
return server_state != prev_server_state || menu_options != prev;
if (remote_debug_state != REMOTE_DEBUG_STATE_SERVING && server->is_listening()) {
server->stop();
}
return remote_debug_state != prev_remote_debug_state;
}
Ref<ImageTexture> EditorExportPlatformWeb::get_option_icon(int p_index) const {
Ref<ImageTexture> play_icon = EditorExportPlatform::get_option_icon(p_index);
switch (server_state) {
case HTTP_SERVER_STATE_OFF: {
switch (remote_debug_state) {
case REMOTE_DEBUG_STATE_UNAVAILABLE: {
return nullptr;
} break;
case REMOTE_DEBUG_STATE_AVAILABLE: {
switch (p_index) {
case 0:
case 1:
return play_icon;
default:
ERR_FAIL_V(nullptr);
}
} break;
case HTTP_SERVER_STATE_ON: {
case REMOTE_DEBUG_STATE_SERVING: {
switch (p_index) {
case 0:
return play_icon;
@ -625,18 +640,31 @@ Ref<ImageTexture> EditorExportPlatformWeb::get_option_icon(int p_index) const {
return restart_icon;
case 2:
return stop_icon;
default:
ERR_FAIL_V(nullptr);
}
} break;
}
ERR_FAIL_V_MSG(nullptr, vformat(R"(EditorExportPlatformWeb option icon index "%s" is invalid.)", p_index));
return nullptr;
}
int EditorExportPlatformWeb::get_options_count() const {
if (server_state == HTTP_SERVER_STATE_ON) {
return 3;
switch (remote_debug_state) {
case REMOTE_DEBUG_STATE_UNAVAILABLE: {
return 0;
} break;
case REMOTE_DEBUG_STATE_AVAILABLE: {
return 2;
} break;
case REMOTE_DEBUG_STATE_SERVING: {
return 3;
} break;
}
return 2;
return 0;
}
String EditorExportPlatformWeb::get_option_label(int p_index) const {
@ -645,17 +673,22 @@ String EditorExportPlatformWeb::get_option_label(int p_index) const {
String reexport_project = TTR("Re-export Project");
String stop_http_server = TTR("Stop HTTP Server");
switch (server_state) {
case HTTP_SERVER_STATE_OFF: {
switch (remote_debug_state) {
case REMOTE_DEBUG_STATE_UNAVAILABLE:
return "";
case REMOTE_DEBUG_STATE_AVAILABLE: {
switch (p_index) {
case 0:
return run_in_browser;
case 1:
return start_http_server;
default:
ERR_FAIL_V("");
}
} break;
case HTTP_SERVER_STATE_ON: {
case REMOTE_DEBUG_STATE_SERVING: {
switch (p_index) {
case 0:
return run_in_browser;
@ -663,11 +696,13 @@ String EditorExportPlatformWeb::get_option_label(int p_index) const {
return reexport_project;
case 2:
return stop_http_server;
default:
ERR_FAIL_V("");
}
} break;
}
ERR_FAIL_V_MSG("", vformat(R"(EditorExportPlatformWeb option label index "%s" is invalid.)", p_index));
return "";
}
String EditorExportPlatformWeb::get_option_tooltip(int p_index) const {
@ -676,17 +711,22 @@ String EditorExportPlatformWeb::get_option_tooltip(int p_index) const {
String reexport_project = TTR("Export project again to account for updates.");
String stop_http_server = TTR("Stop the HTTP server.");
switch (server_state) {
case HTTP_SERVER_STATE_OFF: {
switch (remote_debug_state) {
case REMOTE_DEBUG_STATE_UNAVAILABLE:
return "";
case REMOTE_DEBUG_STATE_AVAILABLE: {
switch (p_index) {
case 0:
return run_in_browser;
case 1:
return start_http_server;
default:
ERR_FAIL_V("");
}
} break;
case HTTP_SERVER_STATE_ON: {
case REMOTE_DEBUG_STATE_SERVING: {
switch (p_index) {
case 0:
return run_in_browser;
@ -694,11 +734,13 @@ String EditorExportPlatformWeb::get_option_tooltip(int p_index) const {
return reexport_project;
case 2:
return stop_http_server;
default:
ERR_FAIL_V("");
}
} break;
}
ERR_FAIL_V_MSG("", vformat(R"(EditorExportPlatformWeb option tooltip index "%s" is invalid.)", p_index));
return "";
}
Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
@ -707,8 +749,12 @@ Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int
const String bind_host = EDITOR_GET("export/web/http_host");
const bool use_tls = EDITOR_GET("export/web/use_tls");
switch (server_state) {
case HTTP_SERVER_STATE_OFF: {
switch (remote_debug_state) {
case REMOTE_DEBUG_STATE_UNAVAILABLE: {
return FAILED;
} break;
case REMOTE_DEBUG_STATE_AVAILABLE: {
switch (p_option) {
// Run in Browser.
case 0: {
@ -731,10 +777,14 @@ Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int
}
return _start_server(bind_host, bind_port, use_tls);
} break;
default: {
ERR_FAIL_V_MSG(FAILED, vformat(R"(Invalid option "%s" for the current state.)", p_option));
}
}
} break;
case HTTP_SERVER_STATE_ON: {
case REMOTE_DEBUG_STATE_SERVING: {
switch (p_option) {
// Run in Browser.
case 0: {
@ -754,11 +804,15 @@ Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int
case 2: {
return _stop_server();
} break;
default: {
ERR_FAIL_V_MSG(FAILED, vformat(R"(Invalid option "%s" for the current state.)", p_option));
}
}
} break;
}
ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, vformat(R"(Trying to run EditorExportPlatformWeb, but option "%s" isn't known.)", p_option));
return FAILED;
}
Error EditorExportPlatformWeb::_export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags) {

View file

@ -46,19 +46,19 @@
class EditorExportPlatformWeb : public EditorExportPlatform {
GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);
enum HTTPServerState {
HTTP_SERVER_STATE_OFF,
HTTP_SERVER_STATE_ON,
enum RemoteDebugState {
REMOTE_DEBUG_STATE_UNAVAILABLE,
REMOTE_DEBUG_STATE_AVAILABLE,
REMOTE_DEBUG_STATE_SERVING,
};
Ref<ImageTexture> logo;
Ref<ImageTexture> run_icon;
Ref<ImageTexture> stop_icon;
Ref<ImageTexture> restart_icon;
HTTPServerState server_state = HTTP_SERVER_STATE_OFF;
RemoteDebugState remote_debug_state = REMOTE_DEBUG_STATE_UNAVAILABLE;
Ref<EditorHTTPServer> server;
int menu_options = 0;
String _get_template_name(bool p_extension, bool p_thread_support, bool p_debug) const {
String name = "web";