mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
feat(gui): show snapshot policy, withheld snapshots and not-migrated clones; raise visible window
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23b7970644
commit
e3a16a494c
3 files changed
+84
-3
No files matched your search
@@ -199,6 +199,17 @@ fn render(ui: &MainWindow) {
|
|||||||
ui.set_wt_count(agg.worktrees as i32);
|
ui.set_wt_count(agg.worktrees as i32);
|
||||||
ui.set_attention_count(agg.attention as i32);
|
ui.set_attention_count(agg.attention as i32);
|
||||||
ui.set_has_config(snap.config.is_some());
|
ui.set_has_config(snap.config.is_some());
|
||||||
|
let nm: Vec<SharedString> = snap
|
||||||
|
.status
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|s| s["not_migrated"].as_array())
|
||||||
|
.map(|a| {
|
||||||
|
a.iter()
|
||||||
|
.filter_map(|p| p.as_str().map(SharedString::from))
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
ui.set_not_migrated(ModelRc::from(Rc::new(VecModel::from(nm))));
|
||||||
|
|
||||||
let empty = Vec::new();
|
let empty = Vec::new();
|
||||||
let repos: Vec<Repo> = snap
|
let repos: Vec<Repo> = snap
|
||||||
@@ -243,6 +254,7 @@ fn render(ui: &MainWindow) {
|
|||||||
phase: s(r, "phase").into(),
|
phase: s(r, "phase").into(),
|
||||||
last_sync: model::ago(r["last_sync"].as_u64().unwrap_or(0), now).into(),
|
last_sync: model::ago(r["last_sync"].as_u64().unwrap_or(0), now).into(),
|
||||||
error: r["last_error"].as_str().unwrap_or("").into(),
|
error: r["last_error"].as_str().unwrap_or("").into(),
|
||||||
|
withheld: r["snapshots_withheld"].as_str().unwrap_or("").into(),
|
||||||
path: path.into(),
|
path: path.into(),
|
||||||
wts: ModelRc::from(Rc::new(VecModel::from(wts))),
|
wts: ModelRc::from(Rc::new(VecModel::from(wts))),
|
||||||
}
|
}
|
||||||
@@ -286,6 +298,7 @@ fn render(ui: &MainWindow) {
|
|||||||
time: model::clock(e["ts"].as_u64().unwrap_or(0), off).into(),
|
time: model::clock(e["ts"].as_u64().unwrap_or(0), off).into(),
|
||||||
kind: s(e, "kind").into(),
|
kind: s(e, "kind").into(),
|
||||||
repo: e["repo"].as_str().unwrap_or("–").into(),
|
repo: e["repo"].as_str().unwrap_or("–").into(),
|
||||||
|
tone: model::log_tone(&s(e, "kind")).into(),
|
||||||
msg: s(e, "msg").lines().next().unwrap_or("").into(),
|
msg: s(e, "msg").lines().next().unwrap_or("").into(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@@ -350,6 +363,11 @@ fn toast(ui: &MainWindow, msg: &str, bad: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_window(ui: &MainWindow, core: &Core) {
|
fn show_window(ui: &MainWindow, core: &Core) {
|
||||||
|
// Slint exposes no xdg-activation, so an already visible window is raised by re-mapping it:
|
||||||
|
// a fresh toplevel is what the compositor focuses.
|
||||||
|
if core.visible.load(Ordering::SeqCst) && ui.window().is_visible() {
|
||||||
|
let _ = ui.hide();
|
||||||
|
}
|
||||||
let _ = ui.show();
|
let _ = ui.show();
|
||||||
// On Wayland a window shown from an idle (hidden) loop is not mapped until another event
|
// On Wayland a window shown from an idle (hidden) loop is not mapped until another event
|
||||||
// arrives; a one-shot redraw request provides it.
|
// arrives; a one-shot redraw request provides it.
|
||||||
|
|||||||
@@ -112,6 +112,15 @@ pub fn aggregate(status: Option<&Value>) -> Aggregate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Colour key of an activity event kind.
|
||||||
|
pub fn log_tone(kind: &str) -> &'static str {
|
||||||
|
match kind {
|
||||||
|
"error" | "watch_error" => "error",
|
||||||
|
"state" | "snapshots_withheld" | "snapshots_purged" | "declined" => "warn",
|
||||||
|
_ => "ok",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Last two path components, e.g. `work/api`.
|
/// Last two path components, e.g. `work/api`.
|
||||||
pub fn short(path: &str) -> String {
|
pub fn short(path: &str) -> String {
|
||||||
let parts: Vec<&str> = path.split('/').filter(|p| !p.is_empty()).collect();
|
let parts: Vec<&str> = path.split('/').filter(|p| !p.is_empty()).collect();
|
||||||
@@ -172,7 +181,7 @@ fn names(v: Option<&Value>) -> Vec<String> {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One line per group: routes (private + public), owners and layout.
|
/// One line per group: routes (private + public), snapshot policy, owners and layout.
|
||||||
pub fn group_summary(g: &Value) -> String {
|
pub fn group_summary(g: &Value) -> String {
|
||||||
let mut s = format!("primary {}", str_of(g, "primary"));
|
let mut s = format!("primary {}", str_of(g, "primary"));
|
||||||
let mirrors = names(g.get("mirror_to"));
|
let mirrors = names(g.get("mirror_to"));
|
||||||
@@ -186,6 +195,9 @@ pub fn group_summary(g: &Value) -> String {
|
|||||||
s += &format!(" → {}", pm.join(", "));
|
s += &format!(" → {}", pm.join(", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(p) = g.get("snapshots").and_then(Value::as_str) {
|
||||||
|
s += &format!(" · snapshots: {p}");
|
||||||
|
}
|
||||||
if let Some(o) = g
|
if let Some(o) = g
|
||||||
.get("owners")
|
.get("owners")
|
||||||
.and_then(Value::as_object)
|
.and_then(Value::as_object)
|
||||||
@@ -231,6 +243,13 @@ pub fn settings_sections(cfg: &Value) -> Vec<Section> {
|
|||||||
"Largest synced file".into(),
|
"Largest synced file".into(),
|
||||||
format!("{} MiB", num("max_file_mb", 50)),
|
format!("{} MiB", num("max_file_mb", 50)),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"Snapshots (default)".into(),
|
||||||
|
sync.and_then(|s| s.get("snapshots"))
|
||||||
|
.and_then(Value::as_str)
|
||||||
|
.unwrap_or("private-only")
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
let providers = cfg
|
let providers = cfg
|
||||||
.get("providers")
|
.get("providers")
|
||||||
@@ -361,6 +380,14 @@ mod tests {
|
|||||||
assert!(parse_import_listing("nothing to import").is_empty());
|
assert!(parse_import_listing("nothing to import").is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn log_tones() {
|
||||||
|
assert_eq!(log_tone("snapshots_withheld"), "warn");
|
||||||
|
assert_eq!(log_tone("snapshots_purged"), "warn");
|
||||||
|
assert_eq!(log_tone("snapshots_enabled"), "ok");
|
||||||
|
assert_eq!(log_tone("watch_error"), "error");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn formatting() {
|
fn formatting() {
|
||||||
assert_eq!(short("/home/u/Workspace/work/api"), "work/api");
|
assert_eq!(short("/home/u/Workspace/work/api"), "work/api");
|
||||||
@@ -383,18 +410,23 @@ mod tests {
|
|||||||
"providers": {"gitea": {"kind": "gitea", "url": "https://g.example"}, "gh": {"kind": "github"}},
|
"providers": {"gitea": {"kind": "gitea", "url": "https://g.example"}, "gh": {"kind": "github"}},
|
||||||
"groups": [{"name": "work", "primary": "gitea", "mirror_to": ["gh"],
|
"groups": [{"name": "work", "primary": "gitea", "mirror_to": ["gh"],
|
||||||
"owners": {"gitea": "Org", "gh": "org-gh"},
|
"owners": {"gitea": "Org", "gh": "org-gh"},
|
||||||
|
"snapshots": "none",
|
||||||
"public": {"primary": "gh", "mirror_to": ["gitea"]}}],
|
"public": {"primary": "gh", "mirror_to": ["gitea"]}}],
|
||||||
"config_repo": {"name": "grove-config", "provider": "gitea"}
|
"config_repo": {"name": "grove-config", "provider": "gitea"}
|
||||||
});
|
});
|
||||||
let s = settings_sections(&cfg);
|
let s = settings_sections(&cfg);
|
||||||
assert_eq!(s[0].1[0], ("Name".into(), "pca".into()));
|
assert_eq!(s[0].1[0], ("Name".into(), "pca".into()));
|
||||||
assert_eq!(s[0].1[2].1, "60 s");
|
assert_eq!(s[0].1[2].1, "60 s");
|
||||||
|
assert_eq!(
|
||||||
|
s[0].1[4],
|
||||||
|
("Snapshots (default)".into(), "private-only".into())
|
||||||
|
);
|
||||||
// Providers come out sorted by id.
|
// Providers come out sorted by id.
|
||||||
assert_eq!(s[1].1[0].1, "github");
|
assert_eq!(s[1].1[0].1, "github");
|
||||||
assert_eq!(s[1].1[1].1, "gitea · https://g.example");
|
assert_eq!(s[1].1[1].1, "gitea · https://g.example");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s[2].1[0].1,
|
s[2].1[0].1,
|
||||||
"primary gitea · mirrors: gh · public: gh → gitea · owners: gh=org-gh, gitea=Org · bare-worktrees"
|
"primary gitea · mirrors: gh · public: gh → gitea · snapshots: none · owners: gh=org-gh, gitea=Org · bare-worktrees"
|
||||||
);
|
);
|
||||||
assert_eq!(s[3].1[0].1, "grove-config on gitea");
|
assert_eq!(s[3].1[0].1, "grove-config on gitea");
|
||||||
assert_eq!(group_name("work → gitea"), "work");
|
assert_eq!(group_name("work → gitea"), "work");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export struct Repo {
|
|||||||
phase: string,
|
phase: string,
|
||||||
last-sync: string,
|
last-sync: string,
|
||||||
error: string,
|
error: string,
|
||||||
|
withheld: string,
|
||||||
wts: [Wt],
|
wts: [Wt],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ export struct LogRow {
|
|||||||
kind: string,
|
kind: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
msg: string,
|
msg: string,
|
||||||
|
tone: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export struct Kv {
|
export struct Kv {
|
||||||
@@ -176,6 +178,7 @@ export component MainWindow inherits Window {
|
|||||||
in property <int> wt-count;
|
in property <int> wt-count;
|
||||||
in property <int> attention-count;
|
in property <int> attention-count;
|
||||||
in property <[Repo]> repos;
|
in property <[Repo]> repos;
|
||||||
|
in property <[string]> not-migrated;
|
||||||
in property <[LogRow]> log;
|
in property <[LogRow]> log;
|
||||||
in property <[string]> groups;
|
in property <[string]> groups;
|
||||||
in property <[string]> providers;
|
in property <[string]> providers;
|
||||||
@@ -355,6 +358,22 @@ export component MainWindow inherits Window {
|
|||||||
text: "Start it with `systemctl --user start groved` (or run `groved` in a terminal).";
|
text: "Start it with `systemctl --user start groved` (or run `groved` in a terminal).";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !root.offline && root.not-migrated.length > 0: Card {
|
||||||
|
Text {
|
||||||
|
text: "Not migrated clones";
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
Muted {
|
||||||
|
text: "These clones are in your workspace but not managed by grove yet: run `grove add` for each one to bring it into a group.";
|
||||||
|
}
|
||||||
|
|
||||||
|
for p in root.not-migrated: Muted {
|
||||||
|
text: p;
|
||||||
|
font-size: 12px;
|
||||||
|
overflow: elide;
|
||||||
|
}
|
||||||
|
}
|
||||||
if !root.offline && root.loading: Muted {
|
if !root.offline && root.loading: Muted {
|
||||||
text: "Loading…";
|
text: "Loading…";
|
||||||
}
|
}
|
||||||
@@ -403,6 +422,13 @@ export component MainWindow inherits Window {
|
|||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.withheld != "": Text {
|
||||||
|
text: "snapshots withheld: " + r.withheld;
|
||||||
|
color: #d98e1f;
|
||||||
|
font-size: 12px;
|
||||||
|
overflow: elide;
|
||||||
|
}
|
||||||
|
|
||||||
if r.error != "": Text {
|
if r.error != "": Text {
|
||||||
text: r.error;
|
text: r.error;
|
||||||
color: #d9483b;
|
color: #d9483b;
|
||||||
@@ -496,6 +522,11 @@ export component MainWindow inherits Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if root.detail.withheld != "": Text {
|
||||||
|
text: "snapshots withheld: " + root.detail.withheld;
|
||||||
|
color: #d98e1f;
|
||||||
|
wrap: word-wrap;
|
||||||
|
}
|
||||||
if root.detail.error != "": Text {
|
if root.detail.error != "": Text {
|
||||||
text: root.detail.error;
|
text: root.detail.error;
|
||||||
color: #d9483b;
|
color: #d9483b;
|
||||||
@@ -646,7 +677,7 @@ export component MainWindow inherits Window {
|
|||||||
Text {
|
Text {
|
||||||
width: 90px;
|
width: 90px;
|
||||||
text: e.kind;
|
text: e.kind;
|
||||||
color: Tone.of(e.kind == "error" || e.kind == "watch_error" ? "error" : e.kind == "state" ? "warn" : "ok");
|
color: Tone.of(e.tone);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user