image-cache: use custom URI scheme for transparent cache-miss re-download
Instead of rewriting img src to file:// URIs, rewrite to a custom feedthemonkey-img:/// scheme. A WebKit URI scheme handler is registered on the WebView's WebContext that: - Serves the image directly from the cache directory if present. - On a cache miss (e.g. after the user deletes ~/.cache), spawns a reqwest download in the tokio runtime, then resumes on the GLib main loop via glib::spawn_future_local and serves the freshly downloaded bytes — all transparent to the WebView. This means deleting the cache directory never results in permanently broken images; they are silently re-fetched on first access.
This commit is contained in:
parent
8e21c80a33
commit
00700c3211
2 changed files with 133 additions and 17 deletions
|
|
@ -245,6 +245,9 @@ pub mod imp {
|
|||
|
||||
fn setup_webview(&self) {
|
||||
let wv = &*self.web_view;
|
||||
if let Some(ctx) = wv.web_context() {
|
||||
crate::image_cache::register_scheme(&ctx);
|
||||
}
|
||||
|
||||
// Load content.html from GResource, inlining the CSS so WebKit
|
||||
// doesn't need to fetch it over a custom scheme.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue