Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Six apps on one engine: each app a window of its own

Yashwanth Kamireddiaa53bf180f40
diff --git a/.uiverify/app-window.mjs b/.uiverify/app-window.mjs
new file mode 100644
index 0000000..1383eaf
--- /dev/null
+++ b/.uiverify/app-window.mjs
@@ -0,0 +1,28 @@
+// A window opened as one app (`?app=…`, from its launcher entry or the tray) is that app
+// alone: its own screen, and no list of the others, no account card, no library search.
+// Without it, the window is the whole library as before.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+for (const [app, marker] of [["notes", ".note-rows"], ["reminders", ".rx-list"], ["calendar", ".cx-side, .cx-month, .cx-grid"]]) {
+ const ctx = await b.newContext({ viewport: { width: 1040, height: 700 } });
+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, notesFixture: true, calendarFixture: true, remindersFixture: true });
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+ await page.goto(`http://localhost:4173/?app=${app}`, { waitUntil: "networkidle" });
+ await page.waitForTimeout(800);
+ ok((await page.locator(`main.content[data-screen="${app}"]`).count()) === 1 && (await page.locator(marker).count()) > 0, `${app}: the window is that app`);
+ ok(!(await page.locator("nav.sidebar").isVisible()) && !(await page.getByRole("combobox", { name: "Search everything" }).isVisible()),
+ `${app}: with no list of the other apps, and no library search`);
+ await ctx.close();
+}
+const ctx = await b.newContext({ viewport: { width: 1040, height: 700 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+const page = await ctx.newPage();
+await page.goto("http://localhost:4173/", { waitUntil: "networkidle" });
+await page.waitForTimeout(600);
+ok(await page.locator("nav.sidebar").isVisible(), "without ?app, the window is the whole library, its app list there");
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/Cargo.lock b/Cargo.lock
index 55ff1cf..c01f3c4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3630,9 +3630,12 @@ dependencies = [
"base64 0.22.1",
"fuser",
"futures-util",
+ "gdk",
+ "glib 0.18.5",
"gstreamer",
"gstreamer-app",
"gstreamer-video",
+ "gtk",
"image",
"jiff",
"libc",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 4e604bf..965c518 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -39,6 +39,10 @@ gstreamer = "0.25"
gstreamer-app = "0.25"
gstreamer-video = "0.25"
zbus = "5"
+# Each app's window says its own app ID on Wayland (apps.rs): the GTK window under Tauri's.
+gtk = "0.18"
+gdk = "0.18"
+glib = "0.18"
[dev-dependencies]
image = { version = "0.25", default-features = false, features = ["jpeg"] }
diff --git a/src-tauri/src/apps.rs b/src-tauri/src/apps.rs
new file mode 100644
index 0000000..567ece6
--- /dev/null
+++ b/src-tauri/src/apps.rs
@@ -0,0 +1,156 @@
+//! Pomander as six apps on one engine: Notes, Reminders, Calendar, Contacts, Drive and Photos,
+//! each a window of its own, opened from its own launcher entry (`pomander --app notes`) — one
+//! process, one sign-in, one library and one sync behind all of them, as Microsoft 365 is one
+//! install with Word and Excel each in the Start menu.
+//!
+//! Each window is known to the desktop as its app: on Wayland it says its own app ID, so a
+//! dock shows Notes and Reminders as two apps with their own icons, each matched to its own
+//! launcher entry — not six windows under one Pomander icon. (Measured: GTK 3.24's
+//! `gdk_wayland_window_set_application_id` sets it per window, within one process.)
+
+use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder};
+
+/// The apps: the key the window and the engine use, and the name a person sees.
+pub const APPS: [(&str, &str); 6] = [
+ ("notes", "Notes"),
+ ("reminders", "Reminders"),
+ ("calendar", "Calendar"),
+ ("contacts", "Contacts"),
+ ("drivews", "Drive"),
+ ("photos", "Photos"),
+];
+
+/// The app a command line asks for: `--app notes` (or `--app=notes`); the Drive app answers
+/// to "drive" as well as its engine's own "drivews".
+pub fn asked(args: &[String]) -> Option<&'static str> {
+ let named = args.iter().enumerate().find_map(|(i, a)| {
+ a.strip_prefix("--app=")
+ .map(ToString::to_string)
+ .or_else(|| (a == "--app").then(|| args.get(i + 1).cloned()).flatten())
+ })?;
+ let named = if named == "drive" {
+ "drivews".to_string()
+ } else {
+ named
+ };
+ APPS.iter()
+ .find(|(key, _)| *key == named)
+ .map(|(key, _)| *key)
+}
+
+fn label(key: &str) -> String {
+ format!("app-{key}")
+}
+
+/// The app ID a window of `key` is known by: the app's own launcher entry's name, as the
+/// desktop matches them (`<identifier>.Notes.desktop`).
+pub fn app_id(app: &AppHandle, key: &str) -> String {
+ let name = APPS
+ .iter()
+ .find(|(k, _)| *k == key)
+ .map_or(key, |(_, n)| *n);
+ format!("{}.{name}", app.config().identifier)
+}
+
+/// The app's window, brought to the front, or made: its own window, showing that app alone.
+pub fn open(app: &AppHandle, key: &str) {
+ let Some((key, name)) = APPS.iter().find(|(k, _)| *k == key).copied() else {
+ return;
+ };
+ if let Some(w) = app.get_webview_window(&label(key)) {
+ w.show().ok();
+ w.unminimize().ok();
+ w.set_focus().ok();
+ return;
+ }
+ let made = WebviewWindowBuilder::new(
+ app,
+ label(key),
+ WebviewUrl::App(format!("index.html?app={key}").into()),
+ )
+ .title(name)
+ .inner_size(1040.0, 720.0)
+ .min_inner_size(480.0, 400.0)
+ // Shown by its own window_ready, once it has drawn: never a blank frame.
+ .visible(false)
+ .build();
+ let window = match made {
+ Ok(w) => w,
+ Err(e) => {
+ quiet!("the {name} window could not be made: {e}");
+ return;
+ }
+ };
+ if crate::tiling_compositor() {
+ window.set_decorations(false).ok();
+ }
+ #[cfg(target_os = "linux")]
+ {
+ let id = app_id(app, key);
+ let w = window.clone();
+ app.run_on_main_thread(move || own_app_id(&w, &id)).ok();
+ }
+}
+
+/// On Wayland, the window says it is its app, not Pomander as a whole. Set before it is first
+/// shown, so a dock and the compositor's rules see it as that app from the start.
+#[cfg(target_os = "linux")]
+fn own_app_id(window: &tauri::WebviewWindow, id: &str) {
+ use glib::translate::ToGlibPtr;
+ use gtk::prelude::*;
+ extern "C" {
+ fn gdk_wayland_window_set_application_id(
+ window: *mut gdk::ffi::GdkWindow,
+ id: *const std::ffi::c_char,
+ );
+ }
+ let Ok(gtk_window) = window.gtk_window() else {
+ return;
+ };
+ gtk_window.realize();
+ let Some(gdk_window) = gtk_window.window() else {
+ return;
+ };
+ // X11 has no app ID; the call is Wayland's alone.
+ if gdk_window.display().type_().name() != "GdkWaylandDisplay" {
+ return;
+ }
+ let Ok(id) = std::ffi::CString::new(id) else {
+ return;
+ };
+ let raw: *mut gdk::ffi::GdkWindow = gdk_window.to_glib_none().0;
+ // SAFETY: a live, realized GdkWindow of a Wayland display, and a NUL-terminated id that
+ // GDK copies before returning.
+ unsafe { gdk_wayland_window_set_application_id(raw, id.as_ptr()) };
+}
+
+/// Open an app's window from the interface (the tray, a search result for another app).
+#[tauri::command]
+pub fn app_open(key: String, app: AppHandle) {
+ open(&app, &key);
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn args(a: &[&str]) -> Vec<String> {
+ a.iter().map(ToString::to_string).collect()
+ }
+
+ #[test]
+ fn a_launcher_entry_names_its_app() {
+ assert_eq!(asked(&args(&["pomander", "--app", "notes"])), Some("notes"));
+ assert_eq!(
+ asked(&args(&["pomander", "--app=reminders"])),
+ Some("reminders")
+ );
+ assert_eq!(
+ asked(&args(&["pomander", "--app", "drive"])),
+ Some("drivews")
+ );
+ assert_eq!(asked(&args(&["pomander", "--background"])), None);
+ assert_eq!(asked(&args(&["pomander", "--app", "mail"])), None);
+ assert_eq!(asked(&args(&["pomander", "--app"])), None);
+ }
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 0dff82f..8de1efc 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -13,6 +13,7 @@ macro_rules! quiet {
}
mod alerts;
+mod apps;
mod cpu;
mod login;
mod mount;
@@ -3996,7 +3997,7 @@ fn window_fullscreen(window: tauri::WebviewWindow, on: bool) -> UiResult<bool> {
}
/// Whether this session runs under a tiling Wayland compositor, which manages windows itself.
-fn tiling_compositor() -> bool {
+pub(crate) fn tiling_compositor() -> bool {
let set = |k: &str| std::env::var_os(k).is_some_and(|v| !v.is_empty());
if set("HYPRLAND_INSTANCE_SIGNATURE") || set("SWAYSOCK") || set("NIRI_SOCKET") {
return true;
@@ -4016,7 +4017,17 @@ fn tiling_compositor() -> bool {
/// painted, and the window appears whole. Shown anyway after a few seconds, so a page that
/// never says so still leaves a window to use.
#[tauri::command]
-fn window_ready(app: tauri::AppHandle, needs_you: Option<bool>) {
+fn window_ready(app: tauri::AppHandle, window: tauri::WebviewWindow, needs_you: Option<bool>) {
+ // An app's own window (Notes, Reminders…): shown once it has drawn.
+ if window.label() != "main" {
+ window.show().ok();
+ window.set_focus().ok();
+ return;
+ }
+ // Opened as one app from its launcher entry: the whole-library window stays put away.
+ if LAUNCHED_AS_APP.load(Ordering::SeqCst) {
+ return;
+ }
// Started at login, with nothing for the person to do: everything runs, the window waits
// in the tray.
// Never without the tray to come back from.
@@ -4026,6 +4037,9 @@ fn window_ready(app: tauri::AppHandle, needs_you: Option<bool>) {
show_window(&app);
}
+/// Started from one app's launcher entry (`--app notes`): that app's window is what shows.
+static LAUNCHED_AS_APP: AtomicBool = AtomicBool::new(false);
+
/// Quince ended, the one way every exit takes — Quit in the tray, Ctrl-C, a logout's signal,
/// the last window closed: the window gone at once, no more work started ahead, the folders
/// let go of (never waited on past three seconds), then the process ended on the spot.
@@ -4038,7 +4052,7 @@ fn window_ready(app: tauri::AppHandle, needs_you: Option<bool>) {
fn shutdown(app: &tauri::AppHandle, code: i32) -> ! {
static ENDING: AtomicBool = AtomicBool::new(false);
if !ENDING.swap(true, Ordering::SeqCst) {
- if let Some(w) = app.get_webview_window("main") {
+ for w in app.webview_windows().values() {
w.hide().ok();
}
cpu::stop();
@@ -4049,8 +4063,9 @@ fn shutdown(app: &tauri::AppHandle, code: i32) -> ! {
}
fn show_when_ready(app: &tauri::AppHandle) {
- // Started at login: the window is the first window_ready's to show, or not.
- if login::background() {
+ // Started at login: the window is the first window_ready's to show, or not. Started as one
+ // app: that app's window shows instead.
+ if login::background() || LAUNCHED_AS_APP.load(Ordering::SeqCst) {
return;
}
let app = app.clone();
@@ -4076,11 +4091,26 @@ fn show_window(app: &tauri::AppHandle) {
/// A place in the tray, so Quince stays running — and ringing reminders — with its window
/// closed, and can be opened again or quit from there.
fn build_tray(app: &tauri::App) -> tauri::Result<()> {
+ use tauri::menu::PredefinedMenuItem;
use tauri::menu::{Menu, MenuItem};
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
let open = MenuItem::with_id(app, "open", "Open Pomander", true, None::<&str>)?;
+ // Each app on its own, as its launcher entry opens it.
+ let each: Vec<MenuItem<tauri::Wry>> = apps::APPS
+ .iter()
+ .map(|(key, name)| MenuItem::with_id(app, format!("app:{key}"), *name, true, None::<&str>))
+ .collect::<tauri::Result<_>>()?;
+ let line = PredefinedMenuItem::separator(app)?;
+ let line2 = PredefinedMenuItem::separator(app)?;
let quit = MenuItem::with_id(app, "quit", "Quit Pomander", true, None::<&str>)?;
- let menu = Menu::with_items(app, &[&open, &quit])?;
+ let mut items: Vec<&dyn tauri::menu::IsMenuItem<tauri::Wry>> = vec![&open, &line];
+ items.extend(
+ each.iter()
+ .map(|i| i as &dyn tauri::menu::IsMenuItem<tauri::Wry>),
+ );
+ items.push(&line2);
+ items.push(&quit);
+ let menu = Menu::with_items(app, &items)?;
let mut tray = TrayIconBuilder::with_id("quince")
.tooltip("Pomander")
.menu(&menu)
@@ -4088,7 +4118,11 @@ fn build_tray(app: &tauri::App) -> tauri::Result<()> {
.on_menu_event(|app, event| match event.id.as_ref() {
"open" => show_window(app),
"quit" => shutdown(app, 0),
- _ => {}
+ other => {
+ if let Some(key) = other.strip_prefix("app:") {
+ apps::open(app, key);
+ }
+ }
})
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
@@ -4114,8 +4148,12 @@ fn main() {
tauri::Builder::default()
// One Quince at a time: opening it again brings back the one already running, which
// may be sitting in the tray with its window closed.
- .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
- show_window(app);
+ .plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
+ // `--app notes` from a launcher entry: that app's window, in this same process.
+ match apps::asked(&args) {
+ Some(key) => apps::open(app, key),
+ None => show_window(app),
+ }
}))
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
@@ -4149,8 +4187,10 @@ fn main() {
// in the tray. Where no tray could be made there is nowhere to come back from, so
// there closing quits as it always did.
.on_window_event(|window, event| {
+ // An app's own window closes for good, giving its memory back; the whole-library
+ // window is put away, as the engine keeps running behind the tray.
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
- if window.app_handle().tray_by_id("quince").is_some() {
+ if window.label() == "main" && window.app_handle().tray_by_id("quince").is_some() {
api.prevent_close();
window.hide().ok();
}
@@ -4347,6 +4387,11 @@ fn main() {
if let Err(e) = build_tray(app) {
quiet!("no tray on this desktop, so closing the window quits: {e}");
}
+ let launched: Vec<String> = std::env::args().collect();
+ if let Some(key) = apps::asked(&launched) {
+ LAUNCHED_AS_APP.store(true, Ordering::SeqCst);
+ apps::open(app.handle(), key);
+ }
show_when_ready(app.handle());
// Photos uploads a quit left half done carry on.
photos::work(app.handle().clone());
@@ -4364,6 +4409,7 @@ fn main() {
auth_sign_out,
account_unsent,
search_everything,
+ apps::app_open,
login::login_item_status,
mount::drive_kept,
mount::drive_keep,
diff --git a/src/screens/Library.tsx b/src/screens/Library.tsx
index 25c7418..242bec9 100644
--- a/src/screens/Library.tsx
+++ b/src/screens/Library.tsx
@@ -52,6 +52,10 @@ const SCREENS: { key: string; name: string }[] = [
const LAST_KEY = "quince.library.screen";
const RAIL_KEY = "quince.library.rail";
+/** The one app this window is, when it was opened as one (`?app=notes`, from its launcher entry
+ * or the tray): that app alone, with no list of the others. Otherwise the whole library. */
+const ONLY = new URLSearchParams(window.location.search).get("app");
+
export function Library({ onSignOut }: { onSignOut: (keep: boolean) => Promise<void> }) {
const [services, setServices] = useState<string[]>([]);
const [selected, setSelected] = useState<string | null>(null);
@@ -125,7 +129,11 @@ export function Library({ onSignOut }: { onSignOut: (keep: boolean) => Promise<v
} catch {
// Without storage it opens on the first screen, which is fine.
}
- setSelected(last && (offered.includes(last) || last === "settings") ? last : (offered[0] ?? null));
+ setSelected(
+ ONLY && SCREENS.some((x) => x.key === ONLY)
+ ? ONLY
+ : last && (offered.includes(last) || last === "settings") ? last : (offered[0] ?? null),
+ );
setReady(true);
})
.catch((e) => setError(messageOf(e)));
@@ -239,7 +247,7 @@ export function Library({ onSignOut }: { onSignOut: (keep: boolean) => Promise<v
return (
<SyncProvider>
- <div className={`library enter-library${sidebarOpen ? " is-sidebar-open" : ""}${rail ? " is-rail" : ""}`}>
+ <div className={`library enter-library${sidebarOpen ? " is-sidebar-open" : ""}${rail ? " is-rail" : ""}${ONLY ? " is-app" : ""}`}>
{/* Only in a narrow window, where the sidebar gives its room to the content. */}
<button
className="sidebar-toggle"
diff --git a/src/styles/app.css b/src/styles/app.css
index 5ce34b4..3694e6c 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -530,6 +530,9 @@
}
.library { --side: 236px; }
.library.is-rail { --side: 84px; }
+/* A window that is one app (Notes, Reminders…): that app alone, no list of the others. */
+.library.is-app { --side: 34px; }
+.library.is-app > .sidebar, .library.is-app > .sidebar-toggle, .library.is-app > .sidebar-scrim { display: none; }
.sidebar-toggle, .sidebar-scrim, .compact-back { display: none; }
/*