From 080d9bcc675e290d508d066bd96a2517e5650ced Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Fri, 29 Nov 2024 13:32:46 +0100 Subject: [PATCH] Loadable: add registerLogUriHandler() to get a log of loaded URIs. --- libs/loadable/loadable.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/loadable/loadable.nim b/libs/loadable/loadable.nim index 0dc8d7e..0bfebf2 100644 --- a/libs/loadable/loadable.nim +++ b/libs/loadable/loadable.nim @@ -239,6 +239,7 @@ func escapeUTF8*(s: string): string = type ProtocolHandler* = proc(uri: string): proc(self: LoadableResource) var custom_protocol_handlers: Table[string, ProtocolHandler] +var log_uri_handler: proc(uri: string) proc registerCustomProtocol*(prefix: string, handler: ProtocolHandler) = ## Registers a handler for a custom protocol. The function will be run for @@ -246,6 +247,9 @@ proc registerCustomProtocol*(prefix: string, handler: ProtocolHandler) = ## will call self.onload() custom_protocol_handlers[prefix] = handler +proc registerLogUriHandler*(handler: proc(uri: string)) = + log_uri_handler = handler + proc loadUri*( uri: string, onload_func: proc(ok: bool, err: string, data: SliceMem[byte]) = nil, @@ -254,7 +258,8 @@ proc loadUri*( use_threads = true, ): Fetch {.discardable.} = - echo "fetching ", uri + if log_uri_handler != nil: + log_uri_handler(uri) for k,v in custom_protocol_handlers: if uri.startswith k: