|
|
@@ -1,5 +1,5 @@
|
|
|
-//! GTK/WebKit shell for a URL. Webapps can detect this host with `html[data-webruntime]` (CSS),
|
|
|
-//! `window.webruntime.version`, or `navigator.userAgent` (application details append `webruntime`
|
|
|
+//! GTK/WebKit shell for a URL. Webapps can detect this host with `html[data-appiphany]` (CSS),
|
|
|
+//! `window.appiphany.version`, or `navigator.userAgent` (application details append `appiphany`
|
|
|
//! and the crate version). See the `HOST_MARKER_ATTR` constant below.
|
|
|
|
|
|
mod desktop_install;
|
|
|
@@ -26,31 +26,31 @@ use webkit6::{
|
|
|
};
|
|
|
|
|
|
/// JavaScript `window.webkit.messageHandlers.<name>` must match this identifier.
|
|
|
-const WINDOW_DRAG_MESSAGE_HANDLER: &str = "webruntimeWindowDrag";
|
|
|
+const WINDOW_DRAG_MESSAGE_HANDLER: &str = "appiphanyWindowDrag";
|
|
|
|
|
|
-/// Mark draggable chrome in your HTML, e.g. `<div data-webruntime-window-drag>…</div>`.
|
|
|
-const WINDOW_DRAG_ATTR: &str = "data-webruntime-window-drag";
|
|
|
+/// Mark draggable chrome in your HTML, e.g. `<div data-appiphany-window-drag>…</div>`.
|
|
|
+const WINDOW_DRAG_ATTR: &str = "data-appiphany-window-drag";
|
|
|
|
|
|
/// Host detection for embedded webapps (set on `<html>` at document start).
|
|
|
///
|
|
|
-/// **Stable API:** Pages can target webruntime with CSS, e.g. `html[data-webruntime] { … }`,
|
|
|
-/// read `document.documentElement.hasAttribute("data-webruntime")`, or use
|
|
|
-/// `window.webruntime.version`. The User-Agent also includes application details
|
|
|
-/// (`set_user_agent_with_application_details("webruntime", version)`), so
|
|
|
-/// `navigator.userAgent` contains a webruntime token for JS or server-side checks.
|
|
|
-const HOST_MARKER_ATTR: &str = "data-webruntime";
|
|
|
+/// **Stable API:** Pages can target appiphany with CSS, e.g. `html[data-appiphany] { … }`,
|
|
|
+/// read `document.documentElement.hasAttribute("data-appiphany")`, or use
|
|
|
+/// `window.appiphany.version`. The User-Agent also includes application details
|
|
|
+/// (`set_user_agent_with_application_details("appiphany", version)`), so
|
|
|
+/// `navigator.userAgent` contains an appiphany token for JS or server-side checks.
|
|
|
+const HOST_MARKER_ATTR: &str = "data-appiphany";
|
|
|
|
|
|
/// Lazily created shared profile; one store for every origin (WebKit partitions internally).
|
|
|
-const APP_NETWORK_SESSION_KEY: &str = "webruntime-network-session";
|
|
|
+const APP_NETWORK_SESSION_KEY: &str = "appiphany-network-session";
|
|
|
|
|
|
-/// Injected at document start: sets `html[data-webruntime]`, `window.webruntime`, and the
|
|
|
-/// window-drag bridge (mousedown inside `[data-webruntime-window-drag]` …).
|
|
|
-fn webruntime_document_start_script_source() -> String {
|
|
|
+/// Injected at document start: sets `html[data-appiphany]`, `window.appiphany`, and the
|
|
|
+/// window-drag bridge (mousedown inside `[data-appiphany-window-drag]` …).
|
|
|
+fn appiphany_document_start_script_source() -> String {
|
|
|
format!(
|
|
|
r#"(function () {{
|
|
|
try {{
|
|
|
document.documentElement.setAttribute("{host_attr}", "");
|
|
|
- window.webruntime = {{ version: "{version}" }};
|
|
|
+ window.appiphany = {{ version: "{version}" }};
|
|
|
}} catch (_) {{}}
|
|
|
const attr = "{attr}";
|
|
|
const interactive = "A,BUTTON,INPUT,TEXTAREA,SELECT,LABEL,SUMMARY,DETAILS,AUDIO,VIDEO";
|
|
|
@@ -81,7 +81,7 @@ fn webruntime_document_start_script_source() -> String {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-/// Called when embedded JS reports a press on `[data-webruntime-window-drag]`.
|
|
|
+/// Called when embedded JS reports a press on `[data-appiphany-window-drag]`.
|
|
|
fn begin_move_from_pointer_on_window(window: &ApplicationWindow) {
|
|
|
let Some(display) = gdk::Display::default() else {
|
|
|
return;
|
|
|
@@ -115,14 +115,14 @@ fn begin_move_from_pointer_on_window(window: &ApplicationWindow) {
|
|
|
}
|
|
|
|
|
|
/// WebView with injected bridge + script handler; call after `window` exists so moves target it.
|
|
|
-fn build_webruntime_webview(window: &ApplicationWindow, network_session: &NetworkSession) -> WebView {
|
|
|
+fn build_appiphany_webview(window: &ApplicationWindow, network_session: &NetworkSession) -> WebView {
|
|
|
let ucm = UserContentManager::new();
|
|
|
if !ucm.register_script_message_handler(WINDOW_DRAG_MESSAGE_HANDLER, None) {
|
|
|
- eprintln!("webruntime: failed to register `{WINDOW_DRAG_MESSAGE_HANDLER}` message handler");
|
|
|
+ eprintln!("appiphany: failed to register `{WINDOW_DRAG_MESSAGE_HANDLER}` message handler");
|
|
|
}
|
|
|
|
|
|
let script = UserScript::new(
|
|
|
- &webruntime_document_start_script_source(),
|
|
|
+ &appiphany_document_start_script_source(),
|
|
|
UserContentInjectedFrames::AllFrames,
|
|
|
UserScriptInjectionTime::Start,
|
|
|
&[],
|
|
|
@@ -142,7 +142,7 @@ fn build_webruntime_webview(window: &ApplicationWindow, network_session: &Networ
|
|
|
|
|
|
if let Some(settings) = WebViewExt::settings(&webview) {
|
|
|
settings.set_user_agent_with_application_details(
|
|
|
- Some("webruntime"),
|
|
|
+ Some("appiphany"),
|
|
|
Some(env!("CARGO_PKG_VERSION")),
|
|
|
);
|
|
|
}
|
|
|
@@ -195,12 +195,12 @@ fn build_persistent_network_session() -> NetworkSession {
|
|
|
Ok((data_dir, cache_dir)) => match (data_dir.to_str(), cache_dir.to_str()) {
|
|
|
(Some(data), Some(cache)) => NetworkSession::new(Some(data), Some(cache)),
|
|
|
_ => {
|
|
|
- eprintln!("webruntime: non-UTF8 storage path, using ephemeral session");
|
|
|
+ eprintln!("appiphany: non-UTF8 storage path, using ephemeral session");
|
|
|
NetworkSession::new_ephemeral()
|
|
|
}
|
|
|
},
|
|
|
Err(e) => {
|
|
|
- eprintln!("webruntime: could not create storage dirs ({e}), using ephemeral session");
|
|
|
+ eprintln!("appiphany: could not create storage dirs ({e}), using ephemeral session");
|
|
|
NetworkSession::new_ephemeral()
|
|
|
}
|
|
|
};
|
|
|
@@ -241,7 +241,7 @@ fn load_uri_into_overlay_webview(win: &ApplicationWindow, url: &str) {
|
|
|
return;
|
|
|
};
|
|
|
let session = network_session_for_app(&app);
|
|
|
- let webview = build_webruntime_webview(win, &session);
|
|
|
+ let webview = build_appiphany_webview(win, &session);
|
|
|
webview.set_hexpand(true);
|
|
|
webview.set_vexpand(true);
|
|
|
overlay.set_child(Some(&webview));
|
|
|
@@ -264,7 +264,7 @@ fn normalize_url(arg: &str) -> Result<String, &'static str> {
|
|
|
}
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
-#[command(name = "webruntime", version, about = "Minimal WebKit wrapper around a URL")]
|
|
|
+#[command(name = "appiphany", version, about = "Minimal WebKit wrapper around a URL")]
|
|
|
struct Args {
|
|
|
#[command(subcommand)]
|
|
|
cmd: Option<Cmd>,
|
|
|
@@ -294,11 +294,11 @@ enum Cmd {
|
|
|
|
|
|
fn persistent_profile_paths() -> Result<(PathBuf, PathBuf), std::io::Error> {
|
|
|
let data_dir: PathBuf = glib::user_data_dir()
|
|
|
- .join("webruntime")
|
|
|
+ .join("appiphany")
|
|
|
.join("profile")
|
|
|
.join("data");
|
|
|
let cache_dir: PathBuf = glib::user_cache_dir()
|
|
|
- .join("webruntime")
|
|
|
+ .join("appiphany")
|
|
|
.join("profile")
|
|
|
.join("cache");
|
|
|
std::fs::create_dir_all(&data_dir)?;
|
|
|
@@ -314,11 +314,11 @@ fn main() -> glib::ExitCode {
|
|
|
|
|
|
match (&parsed.cmd, &parsed.url) {
|
|
|
(Some(_), Some(_)) => {
|
|
|
- eprintln!("webruntime: cannot pass a URL together with a subcommand");
|
|
|
+ eprintln!("appiphany: cannot pass a URL together with a subcommand");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
(None, None) => {
|
|
|
- eprintln!("webruntime: expected <URL> or a subcommand (see --help)");
|
|
|
+ eprintln!("appiphany: expected <URL> or a subcommand (see --help)");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
_ => {}
|
|
|
@@ -336,24 +336,24 @@ fn main() -> glib::ExitCode {
|
|
|
return match result {
|
|
|
Ok(()) => glib::ExitCode::SUCCESS,
|
|
|
Err(msg) => {
|
|
|
- eprintln!("webruntime: {msg}");
|
|
|
+ eprintln!("appiphany: {msg}");
|
|
|
glib::ExitCode::from(1)
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
if let Err(msg) = normalize_url(parsed.url.as_ref().expect("validated")) {
|
|
|
- eprintln!("webruntime: {msg}");
|
|
|
+ eprintln!("appiphany: {msg}");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
|
|
|
if let Err(e) = adw::init() {
|
|
|
- eprintln!("webruntime: failed to initialize libadwaita: {e}");
|
|
|
+ eprintln!("appiphany: failed to initialize libadwaita: {e}");
|
|
|
return glib::ExitCode::from(1);
|
|
|
}
|
|
|
|
|
|
let app = Application::builder()
|
|
|
- .application_id("dev.webruntime.app")
|
|
|
+ .application_id("dev.appiphany.app")
|
|
|
.flags(ApplicationFlags::HANDLES_COMMAND_LINE)
|
|
|
.build();
|
|
|
|
|
|
@@ -366,20 +366,20 @@ fn main() -> glib::ExitCode {
|
|
|
{
|
|
|
Ok(a) => a,
|
|
|
Err(_) => {
|
|
|
- eprintln!("webruntime: arguments must be valid UTF-8");
|
|
|
+ eprintln!("appiphany: arguments must be valid UTF-8");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if args.len() != 2 {
|
|
|
- eprintln!("Usage: webruntime <url>");
|
|
|
+ eprintln!("Usage: appiphany <url>");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
|
|
|
let url = match normalize_url(&args[1]) {
|
|
|
Ok(u) => u,
|
|
|
Err(msg) => {
|
|
|
- eprintln!("webruntime: {msg}");
|
|
|
+ eprintln!("appiphany: {msg}");
|
|
|
return glib::ExitCode::from(2);
|
|
|
}
|
|
|
};
|
|
|
@@ -394,13 +394,13 @@ fn main() -> glib::ExitCode {
|
|
|
|
|
|
let window = ApplicationWindow::builder()
|
|
|
.application(app)
|
|
|
- .title("Webruntime")
|
|
|
+ .title("Appiphany")
|
|
|
.default_width(1024)
|
|
|
.default_height(768)
|
|
|
.build();
|
|
|
|
|
|
let network_session = network_session_for_app(app);
|
|
|
- let webview = build_webruntime_webview(&window, &network_session);
|
|
|
+ let webview = build_appiphany_webview(&window, &network_session);
|
|
|
let shell = build_overlay_with_webview(&webview);
|
|
|
window.set_content(Some(&shell));
|
|
|
webview.load_uri(&url);
|