"Version X is available" in the top bar is now a button that opens an Update popup: - Update and restart gets the download link from the server (the redirect is not followed, as the Gitea link needs no token), downloads the new game next to the running one with a progress bar, checks it (complete, and an MZ or ELF file), swaps it in and restarts. The quiz is saved first and continues. On Windows the running .exe is renamed to .old, put back if the swap fails, and deleted at the next start. - Download in browser opens the .exe, the Linux package, or the release page on other platforms. - From the editor, an unwritable folder or another platform, only the browser download is offered, with the reason. The message now fits between the tabs and the buttons in every theme; in Nord and Christmas it ran into Sync. The macOS export preset is removed, and the unused download_client_* functions are replaced by fetch_client_download_url. Closes #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
1.9 KiB
GDScript
55 lines
1.9 KiB
GDScript
class_name HttpTransport
|
|
extends RefCounted
|
|
## Sends HTTP requests for [code]MusicServerClient[/code] using [HTTPRequest] nodes.
|
|
##
|
|
## Tests subclass this to answer requests without a network connection.
|
|
|
|
## Seconds before a request is given up and reported as failed. This covers the whole
|
|
## download, so it is generous enough for long songs on a slow connection.
|
|
|
|
var timeout_seconds: float = 120.0
|
|
var _owner: Node
|
|
|
|
|
|
func _init(owner: Node) -> void:
|
|
_owner = owner
|
|
|
|
|
|
## Requests [param url] and calls [param on_complete] with
|
|
## [code](response_code: int, body: PackedByteArray, headers: PackedStringArray)[/code],
|
|
## the headers as [code]"Name: value"[/code] lines. Connection errors and timeouts are
|
|
## reported with response code 0 and no headers. [param headers], which name the
|
|
## [param body]'s type, are sent as-is. Without [param follow_redirects] a redirect is
|
|
## answered as it is, with its [code]Location[/code] header.
|
|
func request(
|
|
url: String,
|
|
method: int,
|
|
on_complete: Callable,
|
|
headers: PackedStringArray = PackedStringArray(),
|
|
body: PackedByteArray = PackedByteArray(),
|
|
follow_redirects: bool = true,
|
|
) -> void:
|
|
var http_request: HTTPRequest = HTTPRequest.new()
|
|
http_request.timeout = timeout_seconds
|
|
if !follow_redirects:
|
|
http_request.max_redirects = 0
|
|
_owner.add_child(http_request)
|
|
http_request.request_completed.connect(
|
|
func(
|
|
result: int,
|
|
response_code: int,
|
|
response_headers: PackedStringArray,
|
|
response_body: PackedByteArray,
|
|
) -> void:
|
|
http_request.queue_free()
|
|
if result != HTTPRequest.RESULT_SUCCESS:
|
|
on_complete.call(0, response_body, PackedStringArray())
|
|
return
|
|
on_complete.call(response_code, response_body, response_headers)
|
|
)
|
|
var error: int = http_request.request_raw(url, headers, method, body)
|
|
if error != OK:
|
|
http_request.queue_free()
|
|
push_error("Could not send request to %s (error %d)" % [url, error])
|
|
on_complete.call(0, PackedByteArray(), PackedStringArray())
|