Skip to content

Commit cb89afa

Browse files
nesquenaclaude
andauthored
Tabs & sessions (v0.4.0): restore windows/tabs, per-tab profile dot, drag-reorder, macOS single-tab drag fix (#24)
* Tabs & sessions release (v0.4.0): restore windows/tabs, profile dot, drag-reorder, mac drag fix Restore the user's workspace across restart and in-app updates, plus three tab-management improvements. All cross-platform (macOS native tabs + Windows/Linux strip). #18 — Session restore. Persist each window's tabs (order, active, URL, and active profile) and replay them on the first successful connect of a launch instead of opening one bare tab. * New session.rs: Session/SessionWindow/SessionTab model in prefs.json under "session"; capture (deduped + empty-guarded, off-main with a main-thread read), and maybe_restore (first-connect-only, mode+target gated). * Win/Linux: strip::session_windows / restore_window; add_tab refactored into add_tab + add_tab_with so restore reuses the seed→navigate path. * macOS: native tab groups are the source of truth — macos::session_windows queries NSWindowTabGroup (objc2); windows::restore_macos_window rebuilds each group via the freeze-safe add_tabbed_window (invariant #12). Restored tabs are incognito + re-seeded with their saved profile selector. * URL reads are panic-guarded (session::capture_url) — wry's url() unwraps a nil WKWebView.URL on a not-yet-navigated webview; capture can race one. * Autosave: persist on structural changes + a 4s tick (frames / SPA routes). #8 — Per-tab profile dot (strip). TabEntry gains `profile` (the hermes_profile cookie value), captured after each load; shell.html renders a color-keyed dot (default profile = no dot) with the profile name in the tooltip. #19 — Drag-to-reorder strip tabs. strip::reorder_tab + tab_reorder command; shell.html drag handlers; active tab follows its label across the move. #22 — macOS single-tab window drag. Use WebKit-native -webkit-app-region:drag on .app-titlebar (interactive children no-drag) instead of Tauri's JS drag region, which no-ops in remote-origin webviews — so dragging works with one tab and no native tab bar. #5 (app-icon corner fringe) deferred — the artwork has a light border baked in; a clean fix needs the source logo, not pixel surgery. Noted in CHANGELOG. Verified on macOS: native-tab + strip restore both replay correctly, Cmd+T heartbeats 8/8 with no freeze, no panic. cargo test (12) + clippy + Windows cargo-xwin check all green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Review fixes: prevent macOS url()-on-nil SIGABRT in session capture; restore zero-window guard; cargo fmt Addresses the deep-review on PR #24. Blocking fix — macOS SIGABRT when the 4s autosave races a just-opened tab: wry's macOS url() unwraps a nil WKWebView.URL on a not-yet-navigated webview and panics; that panic poisons a tauri-runtime-wry mutex held mid-dispatch, so the deferred navigate() then aborts the process. session::capture_url's catch_unwind caught the unwind but can't undo the lock poisoning — guarding at the wrong layer. Real fix: only read a webview's live URL once it has committed a real navigation. New AppState.navigated set, marked in each on_page_load (after the about: guard) and gated in both session_windows paths; capture_url stays as a backstop. Cleaned up on tab/window close. Secondary: maybe_restore now returns false if restore built zero windows, so conn falls through to opening one bare window (a total restore failure can't leave the app window-less — which on Win/Linux could trip quit-on-last-close). Also: cargo fmt (the failing CI `test` check was fmt --check on the seed match arm). Re-verified on macOS with a slow fake server to widen the pre-navigation window: Cmd+T + repeated 4s autosave ticks → 8/8 heartbeats, no panic, no SIGABRT, no new crash report; native 2-tab group captures + restores as 1 window / 2 tabs (not a 2×1 split). fmt/clippy(-D warnings)/test(12) green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c173d44 commit cb89afa

14 files changed

Lines changed: 1176 additions & 105 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
# Changelog
22

3+
## [v0.4.0] — 2026-06-17
4+
5+
A tabs & sessions release across macOS, Windows, and Linux.
6+
7+
### Added
8+
9+
- **Your windows and tabs come back after you quit or update the app**
10+
(issue #18). The shell now remembers each window's tabs — their order, which
11+
one was active, each tab's URL, and each tab's profile — and restores them on
12+
the next launch (including after an in-app update relaunches). Previously
13+
every restart reopened a single empty tab and the rest were lost. Works on all
14+
three platforms: macOS rebuilds the native window tab groups; Windows/Linux
15+
rebuild the tab strip. Each restored tab reopens on the profile it was on (the
16+
profile selector is re-seeded). Notes: a server that requires login will ask
17+
you to sign in again after a restart (only the profile selector is persisted,
18+
never login/auth cookies); the session is saved for the server you're
19+
connected to and isn't restored if you switch to a different server.
20+
- **Per-tab profile dot** (issue #8, Windows/Linux tab strip). Each tab shows a
21+
small colored dot keyed to its active profile, so several profiles open at
22+
once are easy to tell apart at a glance; the default profile shows no dot.
23+
Hovering a tab shows its profile name. Pairs with the per-tab profile
24+
isolation added in v0.3.7/v0.3.8.
25+
- **Drag tabs left/right to reorder them** in the Windows/Linux tab strip
26+
(issue #19). macOS already reorders via native window tabs; the custom strip
27+
had no way to. The new order is what gets saved and restored.
28+
29+
### Fixed
30+
31+
- **macOS: you couldn't drag the window by the title bar when only one tab was
32+
open** (issue #22). Window dragging relied on Tauri's JS-based drag region,
33+
which doesn't work reliably in the remote-content webview — so with a single
34+
tab (no native tab bar to grab) the window wouldn't move. Dragging now uses
35+
WebKit's built-in native drag region (`-webkit-app-region`), which is
36+
independent of that fragile IPC and works regardless of how many tabs are
37+
open. (Same remote-webview limitation behind the earlier title (#15) and
38+
external-link (#12) fixes.)
39+
40+
### Known issues
41+
42+
- The app icon still shows a faint light edge on its rounded corners (issue #5)
43+
— the icon artwork has a light border baked in, so a clean fix needs the
44+
source logo and a proper icon pass rather than editing the rendered images.
45+
Tracked for a follow-up.
46+
347
## [v0.3.8] — 2026-06-16
448

549
### Fixed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hermes-webui-desktop",
3-
"version": "0.3.8",
3+
"version": "0.4.0",
44
"private": true,
55
"scripts": {
66
"tauri": "tauri"

‎src-tauri/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src-tauri/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes-webui-desktop"
3-
version = "0.3.8"
3+
version = "0.4.0"
44
description = "Hermes WebUI Desktop — cross-platform shell for hermes-webui"
55
edition = "2021"
66
license = "MIT"

‎src-tauri/src/bridge.rs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,32 @@ const PASTE_SUPPRESS: &str = r##"
5959

6060
/// S7/S8/S9 — macOS overlay-titlebar integration: traffic-light clearance,
6161
/// hide the page logo (collides with traffic lights), CSS rule for hiding the
62-
/// page titlebar when the native tab bar shows, drag region on .app-titlebar.
62+
/// page titlebar when the native tab bar shows, and a NATIVE drag region on
63+
/// `.app-titlebar`.
64+
///
65+
/// Window dragging uses WKWebView's built-in `-webkit-app-region: drag` (the
66+
/// same mechanism AppKit/Electron use for frameless drag) rather than Tauri's
67+
/// `data-tauri-drag-region`. The Tauri attribute drives dragging through a
68+
/// JS→native IPC that is unreliable in remote-origin webviews — the same
69+
/// remote-IPC fragility that broke titles (#15) and external links (#12) — so
70+
/// with a single tab (no native tab bar to drag) the window couldn't be moved
71+
/// at all (issue #22). `-webkit-app-region` is honored natively by WKWebView,
72+
/// independent of IPC/CSP/capability scope, and works regardless of tab count.
73+
/// Interactive children are marked `no-drag` so the titlebar's buttons/inputs
74+
/// still receive clicks. The `data-tauri-drag-region` attribute is kept as a
75+
/// belt-and-suspenders fallback (harmless when the CSS already handles it).
6376
const MACOS_TITLEBAR: &str = r##"
6477
try { document.documentElement.style.setProperty('--traffic-light-width', '80px'); } catch (e) {}
6578
(function () {
6679
try {
6780
var s = document.createElement('style');
68-
s.textContent = '.app-titlebar-icon { visibility: hidden !important; } body.hermes-mac-tabbed .app-titlebar { display: none !important; }';
81+
s.textContent =
82+
'.app-titlebar-icon { visibility: hidden !important; } ' +
83+
'body.hermes-mac-tabbed .app-titlebar { display: none !important; } ' +
84+
'.app-titlebar { -webkit-app-region: drag; } ' +
85+
'.app-titlebar button, .app-titlebar a, .app-titlebar input, .app-titlebar select, ' +
86+
'.app-titlebar textarea, .app-titlebar [role="button"], .app-titlebar [contenteditable], ' +
87+
'.app-titlebar [data-no-drag] { -webkit-app-region: no-drag; }';
6988
(document.head || document.documentElement).appendChild(s);
7089
} catch (e) {}
7190
})();

‎src-tauri/src/conn.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! | error window. Single-flight guarded.
44
55
use crate::state::AppState;
6-
use crate::{health, prefs, tunnel, windows};
6+
use crate::{health, prefs, session, tunnel, windows};
77
use std::sync::atomic::Ordering;
88
use std::time::Duration;
99
use tauri::{AppHandle, Manager};
@@ -143,7 +143,8 @@ fn run(app: &AppHandle) {
143143
if let Some(last) = content.last() {
144144
let _ = last.set_focus();
145145
}
146-
} else {
146+
} else if !session::maybe_restore(app) {
147+
// First connect with no replayable session → one fresh window.
147148
windows::open_browser(app, &p, false);
148149
}
149150
windows::set_offline_badge(app, false);

‎src-tauri/src/macos.rs‎

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use objc2::ClassType;
1818
use objc2_app_kit::{NSView, NSWindow, NSWindowOrderingMode, NSWindowTabbingMode};
1919
use objc2_foundation::{CGPoint, CGRect, CGSize};
2020
use std::ffi::c_void;
21-
use tauri::WebviewWindow;
21+
use tauri::{AppHandle, Manager, WebviewWindow};
2222

2323
// ---- GCD main-queue dispatch ----
2424
//
@@ -145,6 +145,124 @@ pub fn update_webview_layout(window: &WebviewWindow) -> bool {
145145
}
146146
}
147147

148+
/// Capture macOS content windows as session windows (issue #18). Native tab
149+
/// grouping is the source of truth (we get no KVO for user-driven
150+
/// drag-out/merge/reorder), so this queries each window's `NSWindowTabGroup`:
151+
/// windows in the same group become one session window, in the group's order,
152+
/// with the selected tab marked active. Per-tab profile comes from the
153+
/// `window_profiles` map (captured at page load); the URL from the live
154+
/// webview. MUST run on the main thread (AppKit + webview getters).
155+
pub fn session_windows(app: &AppHandle) -> Vec<crate::session::SessionWindow> {
156+
use crate::session::{SessionTab, SessionWindow};
157+
use std::collections::{HashMap, HashSet};
158+
159+
let wins = crate::windows::content_windows(app);
160+
let target = crate::prefs::load(app).target_url;
161+
let profiles = {
162+
let state = app.state::<crate::state::AppState>();
163+
let g = state.window_profiles.lock().unwrap();
164+
g.clone()
165+
};
166+
// ns_window pointer -> WebviewWindow
167+
let mut by_ptr: HashMap<usize, WebviewWindow> = HashMap::new();
168+
for w in &wins {
169+
if let Ok(ptr) = w.ns_window() {
170+
by_ptr.insert(ptr as usize, w.clone());
171+
}
172+
}
173+
174+
let mut seen: HashSet<usize> = HashSet::new();
175+
let mut out = Vec::new();
176+
for w in &wins {
177+
let Ok(self_ptr) = w.ns_window() else {
178+
continue;
179+
};
180+
if seen.contains(&(self_ptr as usize)) {
181+
continue;
182+
}
183+
let (mut ordered, selected) = tab_group_ptrs(w);
184+
if ordered.is_empty() {
185+
ordered.push(self_ptr as usize); // standalone window = a group of one
186+
}
187+
let mut tabs = Vec::new();
188+
let mut active = 0usize;
189+
for (i, ptr) in ordered.iter().enumerate() {
190+
seen.insert(*ptr);
191+
let Some(member) = by_ptr.get(ptr) else {
192+
continue;
193+
};
194+
// Only read the live URL once the window has committed a real
195+
// navigation — url() on a not-yet-navigated WKWebView unwraps a nil
196+
// NSURL and panics (poisoning a runtime mutex → SIGABRT).
197+
let url = if crate::session::has_navigated(app, member.label()) {
198+
crate::session::capture_url(|| member.url())
199+
} else {
200+
None
201+
}
202+
.unwrap_or_else(|| target.clone());
203+
if Some(i) == selected {
204+
active = tabs.len();
205+
}
206+
tabs.push(SessionTab {
207+
url,
208+
profile: profiles.get(member.label()).cloned(),
209+
});
210+
}
211+
if tabs.is_empty() {
212+
continue;
213+
}
214+
// The group shares one frame — read it off the queried window.
215+
let frame = if w.is_minimized().unwrap_or(false) || w.is_fullscreen().unwrap_or(false) {
216+
None
217+
} else if let (Ok(pos), Ok(sz)) = (w.outer_position(), w.inner_size()) {
218+
if sz.width >= 200 && sz.height >= 200 {
219+
Some([
220+
pos.x as i64,
221+
pos.y as i64,
222+
sz.width as i64,
223+
sz.height as i64,
224+
])
225+
} else {
226+
None
227+
}
228+
} else {
229+
None
230+
};
231+
out.push(SessionWindow {
232+
frame,
233+
active: active.min(tabs.len() - 1),
234+
tabs,
235+
});
236+
}
237+
out
238+
}
239+
240+
/// Ordered ns_window pointers of `window`'s native tab group + the selected
241+
/// index within that order. Empty vec when the window is in no tab group.
242+
fn tab_group_ptrs(window: &WebviewWindow) -> (Vec<usize>, Option<usize>) {
243+
let Ok(ptr) = window.ns_window() else {
244+
return (Vec::new(), None);
245+
};
246+
unsafe {
247+
let ns: &NSWindow = &*(ptr as *const NSWindow);
248+
let Some(group) = ns.tabGroup() else {
249+
return (Vec::new(), None);
250+
};
251+
let arr = group.windows();
252+
let count = arr.count();
253+
let mut ptrs = Vec::with_capacity(count);
254+
for i in 0..count {
255+
let w = arr.objectAtIndex(i);
256+
ptrs.push(&*w as *const NSWindow as usize);
257+
}
258+
let sel_idx = group.selectedWindow().and_then(|sel| {
259+
let sp = &*sel as *const NSWindow as usize;
260+
ptrs.iter().position(|p| *p == sp)
261+
});
262+
(ptrs, sel_idx)
263+
}
264+
}
265+
148266
/// Find the WKWebView in the content view hierarchy (wry adds it as a
149267
/// subview; search two levels deep to be safe).
150268
unsafe fn find_wk_webview(view: &NSView) -> Option<objc2::rc::Retained<NSView>> {

‎src-tauri/src/main.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod macos;
88
mod menu;
99
mod paste;
1010
mod prefs;
11+
mod session;
1112
mod state;
1213
mod strip;
1314
mod theme;
@@ -84,6 +85,11 @@ fn tab_close(app: tauri::AppHandle, window: String, tab: String) {
8485
std::thread::spawn(move || strip::close_tab(&app, &window, &tab));
8586
}
8687

88+
#[tauri::command]
89+
fn tab_reorder(app: tauri::AppHandle, window: String, tab: String, index: usize) {
90+
std::thread::spawn(move || strip::reorder_tab(&app, &window, &tab, index));
91+
}
92+
8793
#[tauri::command]
8894
fn new_window_cmd(app: tauri::AppHandle) {
8995
conn::open_new_session(&app, false);
@@ -176,6 +182,7 @@ fn main() {
176182
tab_new,
177183
tab_select,
178184
tab_close,
185+
tab_reorder,
179186
new_window_cmd,
180187
strip_menu
181188
])
@@ -242,6 +249,17 @@ fn main() {
242249
updater::spawn_check(&update_handle, false);
243250
});
244251
}
252+
// Session autosave (issue #18): periodically capture windows/tabs so
253+
// a frame move or an SPA navigation (neither of which fires a
254+
// structural event) is reflected. Cheap — `persist` writes only when
255+
// the captured session differs from the last write.
256+
{
257+
let sess_handle = handle.clone();
258+
std::thread::spawn(move || loop {
259+
std::thread::sleep(std::time::Duration::from_secs(4));
260+
session::persist(&sess_handle);
261+
});
262+
}
245263
// Chrome poller — the Tauri stand-in for the Swift app's
246264
// tabbedWindows KVO: keeps webview layout + tabbed class +
247265
// traffic-light var in sync with native tab-bar/fullscreen

0 commit comments

Comments
 (0)