Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Linux and Windows window: links and Copy reach the system (sign-in opened nothing)

shinyobjectz1f1787281640
diff --git a/Cargo.lock b/Cargo.lock
index 1f958407..2985c7e0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14959,6 +14959,7 @@ dependencies = [
"objc2 0.6.5",
"objc2-app-kit 0.3.2",
"objc2-foundation 0.3.2",
+ "raea-io-os",
"raea-runtime-js",
"raw-window-handle",
"serde_json",
diff --git a/engine/page/window/Cargo.toml b/engine/page/window/Cargo.toml
index d96fc7e8..6d661ecf 100644
--- a/engine/page/window/Cargo.toml
+++ b/engine/page/window/Cargo.toml
@@ -8,7 +8,7 @@ description = "raea's desktop window around a page: its chrome (--chrome inset:
[features]
# on screen (raea-page-host's --window): AppKit's calls are made; without it they are recorded and answered
-window = ["bevy/bevy_winit", "dep:objc2", "dep:objc2-app-kit", "dep:objc2-foundation", "dep:raw-window-handle", "dep:block2", "dep:windows"]
+window = ["bevy/bevy_winit", "dep:objc2", "dep:objc2-app-kit", "dep:objc2-foundation", "dep:raw-window-handle", "dep:block2", "dep:windows", "dep:raea-io-os"]
[dependencies]
bevy = { version = "=0.20.0", default-features = false, features = ["std", "bevy_window"] }
@@ -24,6 +24,11 @@ raw-window-handle = { version = "0.6", optional = true }
# completion handlers for notifications
block2 = { version = "0.6", optional = true }
+# native.rs's links and clipboard off the Mac (Linux's and Windows' window): raea-io-os's opener and arboard, which the
+# page host already links for its text fields' paste
+[target.'cfg(not(target_os = "macos"))'.dependencies]
+raea-io-os = { path = "../../../io/os", optional = true }
+
# native.rs dock.badge on Windows: the taskbar button's overlay icon (win.rs)
[target.'cfg(windows)'.dependencies]
windows = { version = "0.62", optional = true, features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_System_Com", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
diff --git a/engine/page/window/src/native.rs b/engine/page/window/src/native.rs
index 2d57868f..3e70a2e3 100644
--- a/engine/page/window/src/native.rs
+++ b/engine/page/window/src/native.rs
@@ -121,8 +121,8 @@ fn run(live: bool, name: &str, a: &Value, answer: Answer) {
match name {
"clipboard.write" => {
let t = text(a, "text");
- if live {
- mac::clipboard_write(&t);
+ if live && let Err(e) = mac::clipboard_write(&t) {
+ return answer.err(e);
}
log(|l| l.clipboard = t);
answer.ok(json!(true))
@@ -133,8 +133,9 @@ fn run(live: bool, name: &str, a: &Value, answer: Answer) {
if !(url.starts_with("https://") || url.starts_with("http://") || url.starts_with("mailto:")) {
return answer.err(format!("app.open: {url:?} isn't an http(s) or mailto link"));
}
- if live {
- mac::open(&url);
+ // a link that didn't open says so, so the page can show it to copy rather than a button that does nothing
+ if live && let Err(e) = mac::open(&url) {
+ return answer.err(e);
}
log(|l| l.opened.push(url));
answer.ok(json!(true))
@@ -242,8 +243,9 @@ mod mac {
}
}
- pub fn clipboard_write(t: &str) {
- write_to(None, t)
+ pub fn clipboard_write(t: &str) -> Result<(), String> {
+ write_to(None, t);
+ Ok(())
}
pub fn clipboard_read() -> String {
@@ -265,14 +267,15 @@ mod mac {
}
}
- pub fn open(url: &str) {
+ pub fn open(url: &str) -> Result<(), String> {
unsafe {
let u: *mut AnyObject = msg_send![class("NSURL").unwrap(), URLWithString: &*NSString::from_str(url)];
if u.is_null() {
- return;
+ return Err(format!("app.open: macOS can't read {url:?} as a link"));
}
let ws: *mut AnyObject = msg_send![class("NSWorkspace").unwrap(), sharedWorkspace];
- let _: Bool = msg_send![ws, openURL: u];
+ let opened: Bool = msg_send![ws, openURL: u];
+ if opened.as_bool() { Ok(()) } else { Err(format!("app.open: macOS didn't open {url}")) }
}
}
@@ -414,27 +417,10 @@ mod mac {
}
}
-/// Without a window (the benches, CI, other platforms): nothing reaches the system; Live is false, so these never run.
+/// Off AppKit: Linux's and Windows' window, through raea-io-os, and no window at all (other.rs).
#[cfg(not(all(target_os = "macos", feature = "window")))]
-mod mac {
- use super::Answer;
- pub fn clipboard_write(_: &str) {}
- pub fn clipboard_read() -> String {
- String::new()
- }
- pub fn open(_: &str) {}
- pub fn badge(_: &str) {}
- pub fn notify(_: &str, _: &str) -> Result<(), String> {
- Err("notifications need raea's window on a Mac".into())
- }
- pub fn ask_permission(a: Answer) {
- a.err("notifications need raea's window on a Mac")
- }
- pub fn listen_for_urls() {}
- pub fn share(paths: &[String], _: f64, _: f64) -> Result<(), String> {
- Err(format!("sharing {} files needs raea's window on a Mac", paths.len()))
- }
-}
+#[path = "other.rs"]
+mod mac;
#[cfg(all(test, target_os = "macos", feature = "window"))]
mod tests {
diff --git a/engine/page/window/src/other.rs b/engine/page/window/src/other.rs
new file mode 100644
index 00000000..fa4c6c33
--- /dev/null
+++ b/engine/page/window/src/other.rs
@@ -0,0 +1,43 @@
+//! Off AppKit. Linux's and Windows' window (feature "window" off the Mac) opens links and uses the clipboard through
+//! raea-io-os, as the page host's text fields already paste: opener (xdg-open, or opener's own copy of it where the
+//! system has none; Windows' shell) and arboard. Until 11-23 these were stubs everywhere but the Mac, so on Linux and
+//! Windows every link the app opened (signing in's among them) and every Copy did nothing and answered that it had.
+//! Without a window (the benches, CI) Live is false and none of these run. Notifications, the share sheet, the Dock
+//! badge and raea:// links are still the Mac's alone (Windows' taskbar overlay is win.rs).
+
+use super::Answer;
+#[cfg(feature = "window")]
+pub fn clipboard_write(t: &str) -> Result<(), String> {
+ raea_io_os::set_clipboard_text(t.to_string())
+}
+#[cfg(feature = "window")]
+pub fn clipboard_read() -> String {
+ raea_io_os::clipboard_text().unwrap_or_default()
+}
+#[cfg(feature = "window")]
+pub fn open(url: &str) -> Result<(), String> {
+ raea_io_os::open_url(url)
+}
+#[cfg(not(feature = "window"))]
+pub fn clipboard_write(_: &str) -> Result<(), String> {
+ Ok(())
+}
+#[cfg(not(feature = "window"))]
+pub fn clipboard_read() -> String {
+ String::new()
+}
+#[cfg(not(feature = "window"))]
+pub fn open(_: &str) -> Result<(), String> {
+ Ok(())
+}
+pub fn badge(_: &str) {}
+pub fn notify(_: &str, _: &str) -> Result<(), String> {
+ Err("notifications need raea's window on a Mac".into())
+}
+pub fn ask_permission(a: Answer) {
+ a.err("notifications need raea's window on a Mac")
+}
+pub fn listen_for_urls() {}
+pub fn share(paths: &[String], _: f64, _: f64) -> Result<(), String> {
+ Err(format!("sharing {} files needs raea's window on a Mac", paths.len()))
+}
diff --git a/io/os/src/lib.rs b/io/os/src/lib.rs
index 45d9e957..aa15deb1 100644
--- a/io/os/src/lib.rs
+++ b/io/os/src/lib.rs
@@ -116,6 +116,12 @@ pub fn call(name: &str, args: Value, done: Done) {
}
}
+/// `url` (http, https or mailto) in the system's handler, recorded when headless: os.open's own, for a caller with no
+/// call to answer. raea's window opens its links through it on Linux and Windows (engine/page/window native.rs app.open).
+pub fn open_url(url: &str) -> Result<(), String> {
+ open(&json!({ "url": url })).map(|_| ())
+}
+
fn open(args: &Value) -> Result<Value, String> {
let url = args["url"].as_str().ok_or("os.open: no url")?;
let scheme = url.split_once(':').map_or("", |(s, _)| s).to_ascii_lowercase();
diff --git a/tools/linux-check.sh b/tools/linux-check.sh
index 077a4efa..12d8c7be 100755
--- a/tools/linux-check.sh
+++ b/tools/linux-check.sh
@@ -1,7 +1,10 @@
#!/bin/bash
-# PT8, the Linux check after landing (docs/ports.feature): `cargo check` of raea-cli, and of raea-render without its
-# default features, for x86_64 Linux on the probe box (Fly Sprite raea-linux in raea's own org, set up by
-# tools/linux-box.sh), so an Apple-only call outside a cfg is caught the day it lands.
+# PT8, the Linux check after landing (docs/ports.feature): `cargo check` of raea-cli, of raea-render without its
+# default features, and of the app's window as the Linux app builds it (raea-page-host --features window, whose bevy
+# brings winit's X11 and Wayland: raea-page-window alone has none, so winit refuses Linux. The window's links and
+# clipboard were Mac-only stubs off the Mac until 11-23, so signing in opened nothing on Linux), for x86_64 Linux on
+# the probe box (Fly Sprite raea-linux in raea's own org, set up by tools/linux-box.sh), so an Apple-only call outside
+# a cfg is caught the day it lands.
#
# tools/linux-check.sh [SHA] # default: origin/main
# tools/linux-check.sh --release VERSION [SHA] [--dry] # RL3: the Linux tarball, built and tried there
@@ -185,7 +188,7 @@ if [ "$2" = release ]; then
echo "linux done $ok"; exit $ok
fi
cd $W && export CARGO_TARGET_DIR=~/linux-check-target
-for args in '-p raea-cli' '-p raea-render --no-default-features'; do
+for args in '-p raea-cli' '-p raea-render --no-default-features' '-p raea-page-host --features window'; do
t0=$(date +%s)
guarded bash -c "cargo check $args -j 7 --message-format short > ~/linux-check.out 2>&1"
code=$?