Fix web redirects and loader rendering

This commit is contained in:
hz
2026-07-20 16:29:24 -05:00
parent 121e80b2ea
commit d142da2f78
9 changed files with 56 additions and 33 deletions
+1 -23
View File
@@ -5,7 +5,6 @@ const DEFAULT_URL := "https://s3q.ranaze.com/api/donations"
const REQUEST_TIMEOUT_SECONDS := 30.0
const POLL_INTERVAL_SECONDS := 3.0
const POLL_LIMIT := 200
const CHECKOUT_STORAGE_KEY := "ranaze_donation_checkout_url"
signal checkout_started(donation_id: String, checkout_url: String)
signal donation_status_changed(status: String, donation: Dictionary)
@@ -47,7 +46,6 @@ func begin_checkout(amount_cents: int) -> void:
if not AuthState.can_send_authenticated_request():
donation_failed.emit("Log in before making a contribution.")
return
_prepare_browser_window()
checkout_pending = true
request_token = AuthState.access_token
var headers := PackedStringArray([
@@ -59,7 +57,6 @@ func begin_checkout(amount_cents: int) -> void:
JSON.stringify({"amountCents": amount_cents}))
if error != OK:
checkout_pending = false
_close_browser_window()
donation_failed.emit("The secure checkout request could not be started.")
@@ -83,18 +80,15 @@ func _on_checkout_completed(result: int, response_code: int, _headers: PackedStr
if response_code == 401:
AuthState.handle_unauthorized(request_token)
if result != HTTPRequest.RESULT_SUCCESS or response_code < 200 or response_code >= 300:
_close_browser_window()
donation_failed.emit(_failure_message("Checkout could not be started.", result, response_code, body))
return
var parsed: Variant = JSON.parse_string(body.get_string_from_utf8())
if typeof(parsed) != TYPE_DICTIONARY:
_close_browser_window()
donation_failed.emit("The donation service returned an invalid response.")
return
var donation_id := str(parsed.get("donationId", ""))
var checkout_url := str(parsed.get("checkoutUrl", ""))
if donation_id.is_empty() or not checkout_url.begins_with("https://"):
_close_browser_window()
donation_failed.emit("The donation service returned an invalid checkout link.")
return
active_donation_id = donation_id
@@ -137,29 +131,13 @@ func _on_status_completed(result: int, response_code: int, _headers: PackedStrin
stop_polling()
func _prepare_browser_window() -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
"window.localStorage.removeItem('%s'); var ranazeDonationBridge = new URL('/external-redirect.html?key=%s&provider=Stripe', window.location.origin).href; window.medmindDonationWindow = window.open(ranazeDonationBridge, 'medmind_donation_checkout');" % [CHECKOUT_STORAGE_KEY, CHECKOUT_STORAGE_KEY],
true)
func _open_checkout_url(url: String) -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
"var ranazeDonationUrl = %s; window.localStorage.setItem('%s', ranazeDonationUrl); if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { try { window.medmindDonationWindow.location.replace(ranazeDonationUrl); } catch (_) {} window.medmindDonationWindow.focus(); } else { var ranazeDonationPopup = window.open(ranazeDonationUrl, 'medmind_donation_checkout'); if (ranazeDonationPopup) { window.medmindDonationWindow = ranazeDonationPopup; ranazeDonationPopup.focus(); } else { window.location.assign(ranazeDonationUrl); } }" % [JSON.stringify(url), CHECKOUT_STORAGE_KEY],
true)
JavaScriptBridge.eval("window.location.assign(%s);" % JSON.stringify(url), true)
else:
OS.shell_open(url)
func _close_browser_window() -> void:
if OS.has_feature("web"):
JavaScriptBridge.eval(
"window.localStorage.removeItem('%s'); if (window.medmindDonationWindow && !window.medmindDonationWindow.closed) { window.medmindDonationWindow.close(); } window.medmindDonationWindow = null;" % CHECKOUT_STORAGE_KEY,
true)
func _failure_message(prefix: String, result: int, response_code: int, body: PackedByteArray) -> String:
if result != HTTPRequest.RESULT_SUCCESS and response_code == 0:
return "%s Check your connection and try again." % prefix
+1 -1
View File
@@ -651,7 +651,7 @@ func _on_reset_confirmed(result: int, code: int, _headers: PackedStringArray, bo
func _start_steam() -> void:
if OS.has_feature("web"):
var popup_result: Variant = JavaScriptBridge.eval(
"window.localStorage.removeItem('%s'); var ranazeSteamBridge = new URL('/external-redirect.html?key=%s&provider=Steam', window.location.origin).href; window.ranazeSteamWindow = window.open(ranazeSteamBridge, 'ranaze_steam'); window.ranazeSteamWindow !== null;" % [STEAM_AUTH_STORAGE_KEY, STEAM_AUTH_STORAGE_KEY],
"window.localStorage.removeItem('%s'); var ranazeSteamBridge = new URL('/external-redirect.html?key=%s&provider=Steam', window.location.origin).href; window.ranazeSteamWindow = window.open(ranazeSteamBridge, 'ranaze_steam', 'popup=yes,width=560,height=720,resizable=yes,scrollbars=yes'); if (window.ranazeSteamWindow) { window.ranazeSteamWindow.blur(); window.focus(); } window.ranazeSteamWindow !== null;" % [STEAM_AUTH_STORAGE_KEY, STEAM_AUTH_STORAGE_KEY],
true
)
steam_popup_opened = bool(popup_result)