Working on fixing a bug with browser
This commit is contained in:
@@ -45,6 +45,7 @@ func _ready():
|
||||
|
||||
if _is_web:
|
||||
print("[UpdateManager] Running on WEB - using memory-only cache")
|
||||
_load_local_manifest_web()
|
||||
else:
|
||||
print("[UpdateManager] Running on DESKTOP - using disk cache")
|
||||
# Ensure cache directory exists (desktop only)
|
||||
@@ -142,13 +143,15 @@ func _check_for_updates():
|
||||
func _download_next():
|
||||
if _download_queue.is_empty():
|
||||
_is_updating = false
|
||||
if _is_web:
|
||||
_save_local_manifest_web()
|
||||
_save_local_manifest()
|
||||
print("[UpdateManager] Update complete! Downloaded %d files" % _files_downloaded)
|
||||
update_completed.emit(_files_downloaded)
|
||||
return
|
||||
|
||||
var item = _download_queue.pop_front()
|
||||
var url = cdn_base_url + item.cdnPath
|
||||
var url = cdn_base_url + item.cdnPath + "?h=" + item.fileHash
|
||||
|
||||
update_progress.emit(_files_downloaded, _files_total, item.filePath)
|
||||
|
||||
@@ -575,3 +578,38 @@ func _save_local_manifest():
|
||||
if file:
|
||||
file.store_string(JSON.stringify(_local_hashes))
|
||||
file.close()
|
||||
|
||||
const WEB_HASHES_KEY: String = "cdn_manifest_hashes_v1"
|
||||
|
||||
func _load_local_manifest_web() -> void:
|
||||
if not _is_web:
|
||||
return
|
||||
|
||||
# JavaScriptBridge is a class in web exports; keep it simple.
|
||||
# eval() returns Variant, so type it explicitly.
|
||||
var raw: Variant = JavaScriptBridge.eval("localStorage.getItem('%s')" % WEB_HASHES_KEY, true)
|
||||
|
||||
if raw == null:
|
||||
return
|
||||
|
||||
var json_str: String = str(raw)
|
||||
if json_str.is_empty():
|
||||
return
|
||||
|
||||
var parsed: Variant = JSON.parse_string(json_str)
|
||||
if parsed is Dictionary:
|
||||
_local_hashes = parsed as Dictionary
|
||||
print("[UpdateManager] (WEB) Loaded local hashes: %d" % _local_hashes.size())
|
||||
|
||||
func _save_local_manifest_web() -> void:
|
||||
if not _is_web:
|
||||
return
|
||||
|
||||
var json_str: String = JSON.stringify(_local_hashes)
|
||||
|
||||
# Safer than trying to nest JSON.stringify() inside an eval string:
|
||||
# we escape backslashes and quotes so the JS string literal is valid.
|
||||
var escaped: String = json_str.replace("\\", "\\\\").replace("'", "\\'")
|
||||
|
||||
var js: String = "localStorage.setItem('%s','%s')" % [WEB_HASHES_KEY, escaped]
|
||||
JavaScriptBridge.eval(js, false)
|
||||
|
||||
Reference in New Issue
Block a user