Skip to content

Commit

Permalink
Merge pull request #92163 from adamscott/fix-new-web-export-bug
Browse files Browse the repository at this point in the history
Fix web export state for Remote Debug
  • Loading branch information
akien-mga committed Jun 26, 2024
2 parents ba3bb44 + 1e8e9f4 commit df78d0d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 35 deletions.
114 changes: 84 additions & 30 deletions platform/web/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,54 +589,82 @@ 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;
case 1:
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 {
Expand All @@ -645,29 +673,36 @@ 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;
case 1:
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 {
Expand All @@ -676,29 +711,36 @@ 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;
case 1:
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) {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions platform/web/export/export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit df78d0d

Please sign in to comment.