Loadable: add registerLogUriHandler() to get a log of loaded URIs.
This commit is contained in:
parent
6212b816f0
commit
080d9bcc67
1 changed files with 6 additions and 1 deletions
|
@ -239,6 +239,7 @@ func escapeUTF8*(s: string): string =
|
||||||
|
|
||||||
type ProtocolHandler* = proc(uri: string): proc(self: LoadableResource)
|
type ProtocolHandler* = proc(uri: string): proc(self: LoadableResource)
|
||||||
var custom_protocol_handlers: Table[string, ProtocolHandler]
|
var custom_protocol_handlers: Table[string, ProtocolHandler]
|
||||||
|
var log_uri_handler: proc(uri: string)
|
||||||
|
|
||||||
proc registerCustomProtocol*(prefix: string, handler: ProtocolHandler) =
|
proc registerCustomProtocol*(prefix: string, handler: ProtocolHandler) =
|
||||||
## Registers a handler for a custom protocol. The function will be run for
|
## 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()
|
## will call self.onload()
|
||||||
custom_protocol_handlers[prefix] = handler
|
custom_protocol_handlers[prefix] = handler
|
||||||
|
|
||||||
|
proc registerLogUriHandler*(handler: proc(uri: string)) =
|
||||||
|
log_uri_handler = handler
|
||||||
|
|
||||||
proc loadUri*(
|
proc loadUri*(
|
||||||
uri: string,
|
uri: string,
|
||||||
onload_func: proc(ok: bool, err: string, data: SliceMem[byte]) = nil,
|
onload_func: proc(ok: bool, err: string, data: SliceMem[byte]) = nil,
|
||||||
|
@ -254,7 +258,8 @@ proc loadUri*(
|
||||||
use_threads = true,
|
use_threads = true,
|
||||||
): Fetch {.discardable.} =
|
): Fetch {.discardable.} =
|
||||||
|
|
||||||
echo "fetching ", uri
|
if log_uri_handler != nil:
|
||||||
|
log_uri_handler(uri)
|
||||||
|
|
||||||
for k,v in custom_protocol_handlers:
|
for k,v in custom_protocol_handlers:
|
||||||
if uri.startswith k:
|
if uri.startswith k:
|
||||||
|
|
Loading…
Reference in a new issue