1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-18 14:21:41 +00:00

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
2 changed files with 89 additions and 35 deletions

View File

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

View File

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