0.1.1: device names with brackets, reopening the app

A device named like "Sen setup (CLI)" made kept-both copies unreadable:
the name was cut at the inner bracket, so tidying wrote the kept version
into a new note instead of the original. Copy names are now read by
matching brackets, and names with unpaired brackets are refused.
Opening Lune again while it runs brings its window back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 13:47:07 +07:00
parent 97dda528d3
commit 3f29810f96
8 changed files with 81 additions and 9 deletions

8
Cargo.lock generated
View File

@@ -2581,7 +2581,7 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
[[package]] [[package]]
name = "lune-core" name = "lune-core"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.23.1", "base64 0.23.1",
@@ -2601,7 +2601,7 @@ dependencies = [
[[package]] [[package]]
name = "lune-desktop" name = "lune-desktop"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@@ -2621,7 +2621,7 @@ dependencies = [
[[package]] [[package]]
name = "lunehub" name = "lunehub"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
@@ -2642,7 +2642,7 @@ dependencies = [
[[package]] [[package]]
name = "lunesync" name = "lunesync"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",

View File

@@ -4,4 +4,4 @@ members = ["core", "cli", "hub", "desktop"]
# One version for every part: the hub offers clients by it (D3). # One version for every part: the hub offers clients by it (D3).
[workspace.package] [workspace.package]
version = "0.1.0" version = "0.1.1"

View File

@@ -288,6 +288,9 @@ fn run_cli(cli: Cli) -> Result<()> {
if label.is_empty() { if label.is_empty() {
bail!("the label can't be empty"); bail!("the label can't be empty");
} }
if !lune_core::names::label_ok(&label) {
bail!(lune_core::names::LABEL_BRACKETS);
}
for h in &config.hubs { for h in &config.hubs {
h.set_label(&label)?; h.set_label(&label)?;
} }

View File

@@ -53,7 +53,9 @@ pub fn parse_copy(path: &str) -> Option<(String, String)> {
let file_start = path.rfind('/').map_or(0, |i| i + 1); let file_start = path.rfind('/').map_or(0, |i| i + 1);
let name = &path[file_start..]; let name = &path[file_start..];
let v = name.rfind(MARK)?; let v = name.rfind(MARK)?;
let open = name[..v].rfind(" (")?; // The " (" that matches the ")" after the mark: device labels may have brackets of their own, like
// "Sen setup (CLI)". Unbalanced labels fall back to the nearest " (".
let open = matching_open(&name[..v]).or_else(|| name[..v].rfind(" ("))?;
let label = &name[open + 2..v]; let label = &name[open + 2..v];
let rest = &name[v + MARK.len()..]; let rest = &name[v + MARK.len()..];
let close = rest.find(')')?; let close = rest.find(')')?;
@@ -66,18 +68,51 @@ pub fn parse_copy(path: &str) -> Option<(String, String)> {
Some((format!("{}{}{}", &path[..file_start], &name[..open], ext), label.to_string())) Some((format!("{}{}{}", &path[..file_start], &name[..open], ext), label.to_string()))
} }
/// Device labels end up inside kept-both names, so their brackets must pair up to be read back.
pub fn label_ok(label: &str) -> bool {
let mut depth = 0i32;
for c in label.chars() {
depth += match c {
'(' => 1,
')' => -1,
_ => 0,
};
if depth < 0 {
return false;
}
}
depth == 0
}
pub const LABEL_BRACKETS: &str = "a device name's brackets need to pair up, like \"Mac (work)\"";
/// Index of the " (" in `s` whose bracket is still open at the end of `s`.
fn matching_open(s: &str) -> Option<usize> {
let mut depth = 0usize;
for (i, c) in s.char_indices().rev() {
match c {
')' => depth += 1,
'(' if depth > 0 => depth -= 1,
'(' => return (i > 0 && s[..i].ends_with(' ')).then(|| i - 1),
_ => {}
}
}
None
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[test] #[test]
fn copy_names_round_trip() { fn copy_names_round_trip() {
for (p, l, n) in [("runbook.md", "Codex", 1), ("ops/vm list.md", "Hermes", 2), (".env", "VPS", 1), ("a.tar.gz", "x", 1), ("README", "Mac", 3)] { for (p, l, n) in [("runbook.md", "Codex", 1), ("ops/vm list.md", "Hermes", 2), (".env", "VPS", 1), ("a.tar.gz", "x", 1), ("README", "Mac", 3), ("welcome.md", "Sen setup (CLI)", 1), ("a (b).md", "Mac (old) (2)", 2)] {
let c = copy_name(p, l, n); let c = copy_name(p, l, n);
assert_eq!(parse_copy(&c), Some((p.to_string(), l.to_string())), "{c}"); assert_eq!(parse_copy(&c), Some((p.to_string(), l.to_string())), "{c}");
} }
assert_eq!(copy_name("ops/runbook.md", "Codex", 1), "ops/runbook (Codex's version).md"); assert_eq!(copy_name("ops/runbook.md", "Codex", 1), "ops/runbook (Codex's version).md");
assert_eq!(parse_copy("notes/plain.md"), None); assert_eq!(parse_copy("notes/plain.md"), None);
assert_eq!(parse_copy("Sen's version.md"), None); assert_eq!(parse_copy("Sen's version.md"), None);
assert!(label_ok("Sen setup (CLI)") && !label_ok("Mac (old") && !label_ok("Mac )old("));
} }
} }

View File

@@ -226,6 +226,25 @@ fn tidy_theirs_and_both() {
assert!(tidy::list(&a).unwrap().is_empty()); assert!(tidy::list(&a).unwrap().is_empty());
} }
#[test]
fn device_names_with_brackets_keep_both_and_tidy_cleanly() {
let w = World::new();
let a = w.device("Sen setup (CLI)");
write(&a, "welcome.md", "base\n");
save_and_sync(&a);
let b = w.device("Mac");
write(&a, "welcome.md", "tuesday\n");
write(&b, "welcome.md", "friday\n");
save_and_sync(&b);
save_and_sync(&a);
let kept = tidy::list(&a).unwrap();
assert_eq!(kept.len(), 1);
assert_eq!((kept[0].note.as_str(), kept[0].label.as_str()), ("welcome.md", "Sen setup (CLI)"));
tidy::keep(&a, &kept[0].copy, Keep::Mine).unwrap();
assert_eq!(read(&a, "welcome.md"), b"tuesday\n");
assert_eq!(snapshot(&a.root).len(), 1, "no stray notes");
}
#[test] #[test]
fn deleted_on_one_side_edited_on_the_other_keeps_the_edit() { fn deleted_on_one_side_edited_on_the_other_keeps_the_edit() {
let w = World::new(); let w = World::new();

View File

@@ -94,6 +94,9 @@ pub fn connect(
if label.is_empty() { if label.is_empty() {
return Err("give this Mac a name your team will see".into()); return Err("give this Mac a name your team will see".into());
} }
if !lune_core::names::label_ok(label) {
return Err(lune_core::names::LABEL_BRACKETS.into());
}
let mut config = Config::load().map_err(plain)?; let mut config = Config::load().map_err(plain)?;
let request = match (hub_url, code) { let request = match (hub_url, code) {
(Some(hub), Some(code)) if !hub.trim().is_empty() && !code.trim().is_empty() => { (Some(hub), Some(code)) if !hub.trim().is_empty() && !code.trim().is_empty() => {

View File

@@ -410,8 +410,17 @@ fn main() {
let _ = window.hide(); let _ = window.hide();
} }
}) })
.run(tauri::generate_context!()) .build(tauri::generate_context!())
.expect("Lune couldn't start"); .expect("Lune couldn't start")
.run(|app, event| {
// Opening Lune again (Finder, Launchpad) while it runs in the menu bar brings its window back.
#[cfg(target_os = "macos")]
if let tauri::RunEvent::Reopen { .. } = event {
show_window(app);
}
#[cfg(not(target_os = "macos"))]
let _ = (app, event);
});
} }
async fn tokio_sleep(d: Duration) { async fn tokio_sleep(d: Duration) {

View File

@@ -107,6 +107,9 @@ fn check_label(label: &str) -> Result<String, ApiError> {
if label.is_empty() || label.len() > 40 { if label.is_empty() || label.len() > 40 {
return Err(bad("a device label needs 1–40 characters")); return Err(bad("a device label needs 1–40 characters"));
} }
if !lune_core::names::label_ok(label) {
return Err(bad(lune_core::names::LABEL_BRACKETS));
}
Ok(label.to_string()) Ok(label.to_string())
} }