Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: offline support with service worker caching #141

Merged
merged 37 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
15132ba
feat(server): Serve widgets through server
veryard Oct 30, 2024
08343fb
wip: Linux?
veryard Nov 1, 2024
fd1f089
remove setting of user agent
lars-berger Dec 6, 2024
f7432ae
attach token via header in service worker
lars-berger Dec 6, 2024
36e7419
go to init route first then redirect to target
lars-berger Dec 6, 2024
29aed6c
change to use "asset id" for identifying incoming requests
lars-berger Dec 6, 2024
6fb869b
move server-related functions to new `asset_server` mod
lars-berger Dec 6, 2024
c90e495
move initialization script to its own file
lars-berger Dec 6, 2024
6073d2a
feat: add normalize css in initialization script
lars-berger Dec 6, 2024
3c6fe0b
add empty favicon in initialization script
lars-berger Dec 7, 2024
77ea1ce
remove `cache_assets` from config
lars-berger Dec 7, 2024
aa58b93
change localhost port to `6124`
lars-berger Dec 7, 2024
67c5745
parse with params when creating webview url
lars-berger Dec 7, 2024
7d21a74
share cache id for widgets in the same top-level dir
lars-berger Dec 7, 2024
3c620c9
simplify retrieval of widget assets from rocket route
lars-berger Dec 7, 2024
f10668b
simplify `NotFound` errors by returning an `Option`
lars-berger Dec 7, 2024
3d173db
allow service worker to be served from subroute
lars-berger Dec 7, 2024
ad72515
handle opaque responses in sw
lars-berger Dec 8, 2024
a6e2262
prevent directory traversal when serving assets
lars-berger Dec 8, 2024
91e269a
add config options and create form component
lars-berger Dec 8, 2024
9e2d05f
wip custom field for cache duration
lars-berger Dec 8, 2024
8e3a008
working cache duration field
lars-berger Dec 8, 2024
d484cea
form styling
lars-berger Dec 8, 2024
dbbece6
add state route for the sw to fetch from
lars-berger Dec 9, 2024
7d3b109
bump @glzr/components
lars-berger Dec 9, 2024
e18c986
wip passing config to sw
lars-berger Dec 9, 2024
1ffa1c7
successfully set config from initialization script
lars-berger Dec 9, 2024
eda8728
update widget config schema
lars-berger Dec 9, 2024
4776009
wip implementation of cache duration + rules
lars-berger Dec 9, 2024
b9f4f82
store metadata in separate cache
lars-berger Dec 9, 2024
688a54b
fix cache duration
lars-berger Dec 9, 2024
8b016f3
clear sw cache from system tray
lars-berger Dec 9, 2024
0523027
inline script for clearing sw cache
lars-berger Dec 9, 2024
f0badde
share token for widgets in the same directory
lars-berger Dec 10, 2024
fe26e6b
implement `PathExt` for `Path`
lars-berger Dec 10, 2024
9e7202b
move `create_init_url` to `asset_server` mod
lars-berger Dec 10, 2024
c15d322
move out asset server token map to `asset_server` mod
lars-berger Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parse with params when creating webview url
  • Loading branch information
lars-berger committed Dec 7, 2024
commit 67c57459c686443ca88f17e73c016a3cdc7f9a57
3 changes: 2 additions & 1 deletion packages/desktop/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc};

use rocket::{
fs::NamedFile,
http::{ContentType, Cookie, CookieJar, Status},
http::{ContentType, Cookie, CookieJar, SameSite, Status},
request::{FromRequest, Outcome},
response::Redirect,
tokio::task,
Expand Down Expand Up @@ -38,6 +38,7 @@ pub fn init(
cookies.add(
Cookie::build(("ZEBAR_ASSET_ID", asset_id))
.http_only(true)
.same_site(SameSite::Strict)
.path("/"),
);

Expand Down
21 changes: 11 additions & 10 deletions packages/desktop/src/widget_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use anyhow::Context;
use serde::Serialize;
use tauri::{
path::BaseDirectory, AppHandle, Manager, PhysicalPosition, PhysicalSize,
WebviewUrl, WebviewWindowBuilder, WindowEvent,
Url, WebviewUrl, WebviewWindowBuilder, WindowEvent,
};
use tokio::{
sync::{broadcast, Mutex},
Expand Down Expand Up @@ -265,15 +265,16 @@ impl WidgetFactory {
.and_then(|file_name| file_name.to_str())
.context("Not a valid HTML file path.")?;

let webview_url = WebviewUrl::App(
format!(
// todo: url encode this using Tauri's Url struct.
// todo: use asset_id instead of widget_id.
"http://127.0.0.1:6124/__zebar/init?asset_id={}&redirect=/{}",
widget_id, html_filename
)
.into(),
);
let url = Url::parse_with_params(
"http://127.0.0.1:6124/__zebar/init",
&[
("asset_id", widget_id.to_string()),
("redirect", html_filename.to_string()),
],
)?;

// todo: use asset_id instead of widget_id.
let webview_url = WebviewUrl::External(url);

let mut state = WidgetState {
id: widget_id.clone(),
Expand Down