A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
fix: isolate Gitea cards and align the contribution calendar
andrey0b536440b603
diff --git a/windows/src-tauri/src/integrations.rs b/windows/src-tauri/src/integrations.rsindex e589b6f8..217d43c4 100644--- a/windows/src-tauri/src/integrations.rs+++ b/windows/src-tauri/src/integrations.rs@@ -135,12 +135,14 @@ fn gitea_api_base() -> Option<String> {if !matches!(parsed.scheme(), "http" | "https") || parsed.host_str().is_none() {return None;}- Some(format!("{}/api/v1", url.trim_end_matches('/')))+ Some(format!("{}/api/v1", parsed.as_str().trim_end_matches('/')))}async fn poll_gitea(app: AppHandle) {+ if PAUSED.load(Ordering::Relaxed) || !enabled(&app, "integration_gitea") { return; }let (Some(token), Some(base)) = (secrets::get("gitea-token"), gitea_api_base()) else { return };- let http = client();+ let Ok(http) = reqwest::Client::builder().timeout(TIMEOUT)+ .redirect(reqwest::redirect::Policy::none()).build() else { return };let user = http.get(format!("{base}/user")).header("Authorization", format!("token {token}")).send().await;let Ok(response) = user else { return };if !response.status().is_success() {@@ -235,13 +237,21 @@ fn civil_day(day: i64) -> (i32, u32, u32, u8) {fn gitea_activity(heatmap: &[Value], fetched_at: u64) -> GitHubActivity {let today = (fetched_at / 86_400_000) as i64;+ let mut start = today - 364;+ start -= i64::from(civil_day(start).3);let mut weeks: Vec<Vec<ContributionDay>> = Vec::new();- for chunk in (0..161).map(|offset| today - 160 + offset).collect::<Vec<_>>().chunks(7) {- weeks.push(chunk.iter().map(|&day| {- let count = heatmap.iter().find_map(|entry| { let ts = entry.get("timestamp")?.as_i64()?; let d = if ts > 10_000_000_000 { ts / 86_400_000 } else { ts / 86_400 }; (d == day).then(|| entry.get("contributions").and_then(Value::as_i64).unwrap_or(0)) }).unwrap_or(0);- let (y, m, d, weekday) = civil_day(day); ContributionDay { date: format!("{y:04}-{m:02}-{d:02}"), count,- level: if count == 0 { 0 } else if count == 1 { 1 } else if count < 4 { 2 } else if count < 8 { 3 } else { 4 }, weekday }- }).collect());+ for day in start..=today {+ let (y, m, d, weekday) = civil_day(day);+ if weekday == 0 || weeks.is_empty() { weeks.push(Vec::new()); }+ let count = heatmap.iter().find_map(|entry| {+ let ts = entry.get("timestamp")?.as_i64()?;+ let entry_day = if ts > 10_000_000_000 { ts / 86_400_000 } else { ts / 86_400 };+ (entry_day == day).then(|| entry.get("contributions").and_then(Value::as_i64).unwrap_or(0).max(0))+ }).unwrap_or(0);+ weeks.last_mut().unwrap().push(ContributionDay {+ date: format!("{y:04}-{m:02}-{d:02}"), count, weekday,+ level: if count == 0 { 0 } else if count == 1 { 1 } else if count < 4 { 2 } else if count < 8 { 3 } else { 4 },+ });}let total = weeks.iter().flatten().map(|d| d.count).sum(); GitHubActivity { total, weeks, fetched_at }}@@ -1140,6 +1150,26 @@ fn fmt_value(v: &Value) -> String {mod tests {use super::*;+ #[test]+ fn gitea_calendar_keeps_full_weeks_and_yearly_totals() {+ let today = 20_000_i64;+ let activity = gitea_activity(&[+ json!({ "timestamp": (today - 300) * 86_400, "contributions": 5 }),+ json!({ "timestamp": today * 86_400_000, "contributions": 2 }),+ ], today as u64 * 86_400_000);+ assert_eq!(activity.total, 7);+ assert!(activity.weeks.iter().flatten().count() >= 365);+ for week in &activity.weeks {+ assert_eq!(week[0].weekday, 0);+ for (index, day) in week.iter().enumerate() {+ assert_eq!(day.weekday as usize, index);+ }+ }+ let last = activity.weeks.last().unwrap().last().unwrap();+ assert_eq!(last.count, 2);+ }++#[test]fn github_card_data_sends_only_what_is_known() {let mut cache = GitHubCache::default();diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rsindex 6afb2117..4fd0ef0e 100644--- a/windows/src-tauri/src/lib.rs+++ b/windows/src-tauri/src/lib.rs@@ -243,12 +243,23 @@ fn open_gitea() {fn open_gitea_url(url: String) {let (Ok(target), Some(base)) = (reqwest::Url::parse(&url), secrets::get("gitea-url")) else { return };let Ok(instance) = reqwest::Url::parse(&base) else { return };- if matches!(target.scheme(), "http" | "https") && target.scheme() == instance.scheme()- && target.host_str() == instance.host_str() && target.port_or_known_default() == instance.port_or_known_default() {+ if is_gitea_instance_url(&target, &instance) {open_url(url);}}+fn is_gitea_instance_url(target: &reqwest::Url, instance: &reqwest::Url) -> bool {+ if !matches!(target.scheme(), "http" | "https")+ || target.scheme() != instance.scheme()+ || target.host_str() != instance.host_str()+ || target.port_or_known_default() != instance.port_or_known_default()+ {+ return false;+ }+ let base = instance.path().trim_end_matches('/');+ base.is_empty() || target.path() == base || target.path().starts_with(&format!("{base}/"))+}+/// "Open terminal" opens the working folder in VS Code when `code` is on PATH,/// and falls back to the file manager otherwise.#[tauri::command]@@ -994,7 +1005,25 @@ pub fn run() {#[cfg(test)]mod tests {- use super::diff_file;+ use super::{diff_file, is_gitea_instance_url};++ #[test]+ fn gitea_links_stay_on_the_configured_instance() {+ let instance = reqwest::Url::parse("https://git.example.com/team/").unwrap();+ assert!(is_gitea_instance_url(+ &reqwest::Url::parse("https://git.example.com/team/me/project").unwrap(),+ &instance,+ ));+ assert!(!is_gitea_instance_url(+ &reqwest::Url::parse("https://git.example.com/other/project").unwrap(),+ &instance,+ ));+ assert!(!is_gitea_instance_url(+ &reqwest::Url::parse("https://evil.example/team/me/project").unwrap(),+ &instance,+ ));+ }+#[test]fn only_an_existing_file_by_its_full_path_reaches_the_editor() {diff --git a/windows/src/views/github.ts b/windows/src/views/github.tsindex 7835d638..34cba118 100644--- a/windows/src/views/github.ts+++ b/windows/src/views/github.ts@@ -18,15 +18,18 @@ import {} from "../core/github";const GITHUB_RED = "#F4505E";+export interface ForgeCardOptions {+ title: string;+ color: string;+ provider?: "github" | "gitea";+ refreshId?: string;+ profileUrl?: string;+}+/** Each provider keeps its selected list across re-renders. */+const openSections = new Map<string, GitHubSection>();-export interface ForgeCardOptions { title: string; color: string; gitea?: boolean }-let forge: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED };--/** Which list the detail view shows; kept across re-renders of the card. */-let openSection: GitHubSection = "myPRs";--function open(url: string) {- if (forge.gitea) { void Bridge.openGiteaUrl(url); return; }+function open(url: string, forge: ForgeCardOptions) {+ if (forge.provider === "gitea") { void Bridge.openGiteaUrl(url); return; }const safe = safeGitHubUrl(url);if (safe) void Bridge.openUrl(safe);}@@ -59,11 +62,10 @@ export function githubPulseCard(openDetail: () => void,options: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED },): HTMLElement {- forge = options;+ const forge = options;const show = (section: GitHubSection) => {- openSection = section;- if (forge.gitea) void Bridge.refreshIntegration("integration_gitea");- else void Bridge.githubRefresh(section === "activity" ? "activity" : "pulse");+ openSections.set(forge.provider ?? "github", section);+ if (forge.refreshId) void Bridge.refreshIntegration(forge.refreshId); else void Bridge.githubRefresh(section === "activity" ? "activity" : "pulse");openDetail();};@@ -124,9 +126,9 @@ function row(onOpen: () => void, ...children: (HTMLElement | null)[]): HTMLElemereturn el;}-function prRow(pr: GitHubPR, showCI: boolean): HTMLElement {+function prRow(pr: GitHubPR, showCI: boolean, forge: ForgeCardOptions): HTMLElement {return row(- () => open(pr.url),+ () => open(pr.url, forge),showCI ? ciDot(pr.ci) : h("i", { class: "gh-gap" }),h("span", { class: "gh-ref", text: `${shortRepo(pr.repo)}#${pr.number}` }),h("span", { class: "gh-title", text: pr.title }),@@ -134,10 +136,10 @@ function prRow(pr: GitHubPR, showCI: boolean): HTMLElement {);}-function repoRow(repo: GitHubRepoCI): HTMLElement {+function repoRow(repo: GitHubRepoCI, forge: ForgeCardOptions): HTMLElement {const word = ciWord(repo.ci);return row(- () => open(forge.gitea ? repo.url : actionsUrl(repo.url)),+ () => open(forge.provider === "gitea" ? repo.url : actionsUrl(repo.url), forge),ciDot(repo.ci),h("span", { class: "gh-ref", text: shortRepo(repo.repo) }),h("span", { class: "gh-title", text: repo.branch }),@@ -168,11 +170,11 @@ export function openRow(el: HTMLElement | undefined) {if (el) rowOpens.get(el)?.();}-function listDetail(section: Exclude<GitHubSection, "activity">, pulse: GitHubPulse, onBack: () => void): HTMLElement {+function listDetail(section: Exclude<GitHubSection, "activity">, pulse: GitHubPulse, onBack: () => void, forge: ForgeCardOptions): HTMLElement {const rows: HTMLElement[] =section === "mainCI"- ? pulse.mainCI.map(repoRow)- : (section === "myPRs" ? pulse.myPRs : pulse.toReview).map((pr) => prRow(pr, section === "myPRs"));+ ? pulse.mainCI.map((repo) => repoRow(repo, forge))+ : (section === "myPRs" ? pulse.myPRs : pulse.toReview).map((pr) => prRow(pr, section === "myPRs", forge));const body =rows.length === 0? h("div", { class: "gh-empty", text: GH_STRINGS.nothingHere })@@ -193,11 +195,12 @@ function activityDetail(stats: GitHubStats | null,login: string,onBack: () => void,+ forge: ForgeCardOptions,): HTMLElement {const right = h("button", {class: "gh-head-right",text: activityHeader(activity, stats, null),- onclick: () => forge.gitea ? void Bridge.openGitea() : open(profileUrl(login)),+ onclick: () => open(forge.profileUrl ?? profileUrl(login), forge),});let picked: ContributionDay | null = null;@@ -239,8 +242,9 @@ export function githubDetail(onBack: () => void,options: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED },): HTMLElement {- forge = options;+ const forge = options;+ const openSection = openSections.get(forge.provider ?? "github") ?? "myPRs";return openSection === "activity"- ? activityDetail(activity, stats, pulse.login, onBack)- : listDetail(openSection, pulse, onBack);+ ? activityDetail(activity, stats, pulse.login, onBack, forge)+ : listDetail(openSection, pulse, onBack, forge);}diff --git a/windows/src/views/integrations.ts b/windows/src/views/integrations.tsindex 569c5fcf..ea6a5981 100644--- a/windows/src/views/integrations.ts+++ b/windows/src/views/integrations.ts@@ -479,7 +479,7 @@ export function renderIntegrationCard(task: AgentTask, hooks: IntegrationCardHooif (task.id === "integration_gitea") {const d = get(task.id); const pulse = readPulse(d);if (pulse) {- const options: ForgeCardOptions = { title: "Gitea", color: "#609926", gitea: true };+ const options: ForgeCardOptions = { title: "Gitea", color: "#609926", provider: "gitea", refreshId: "integration_gitea", profileUrl: typeof d.profileUrl === "string" ? d.profileUrl : undefined };return hooks.detailOpen ? githubDetail(pulse, readStats(d), readActivity(d), hooks.closeDetail, options) : githubPulseCard(pulse, readStats(d), readActivity(d), hooks.openDetail, options);}}diff --git a/windows/tests/github.test.mjs b/windows/tests/github.test.mjsindex e7cffee4..ee037b10 100644--- a/windows/tests/github.test.mjs+++ b/windows/tests/github.test.mjs@@ -247,3 +247,26 @@ test("Ctrl+↓ ↑ highlight a list row, Ctrl+O does what its click does", asyncopenRow(undefined);assert.equal(sent("open_url").length, 1);});+++test("forge callbacks and selected sections survive rendering a different provider", async () => {+ const { installFakeDom } = await import("./fakedom.mjs");+ installFakeDom();+ const { githubDetail, githubPulseCard, listRows, openRow } = await import("../src/views/github.ts");+ const pulse = { login: "me", fetchedAt: 1, myPRs: [pr("me/app#1", "success")], toReview: [], mainCI: [] };+ const options = { title: "Gitea", color: "#609926", provider: "gitea", refreshId: "integration_gitea" };+ const card = githubPulseCard(pulse, null, null, () => {}, options);+ githubPulseCard(pulse, null, null, () => {});+ calls.length = 0;+ card.find(".gh-stat")[0].fire("click");+ assert.deepEqual(sent("refresh_integration"), [{ id: "integration_gitea" }]);+ assert.deepEqual(sent("github_refresh"), []);+ const rows = listRows(githubDetail(pulse, null, null, () => {}, options));+ const githubCard = githubPulseCard(pulse, { totalRepos: 1, totalStars: 0 }, activity, () => {});+ githubCard.find(".gh-spark")[0].fire("click");+ githubDetail(pulse, null, activity, () => {});+ openRow(rows[0]);+ assert.deepEqual(sent("open_gitea_url"), [{ url: pulse.myPRs[0].url }]);+ assert.equal(listRows(githubDetail(pulse, null, null, () => {}, options)).length, 1);+ githubCard.find(".gh-stat")[0].fire("click");+});