From ef5ce12fb57ccac2347616b5a1168d259b808f78 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Mon, 3 Jul 2023 16:05:08 +0200 Subject: [PATCH] subscribe to fetch events --- src/lib/api/ipc/git/fetches.ts | 10 ++++++++++ src/lib/api/ipc/git/index.ts | 1 + src/routes/repo/[projectId]/remoteBranches.ts | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/lib/api/ipc/git/fetches.ts diff --git a/src/lib/api/ipc/git/fetches.ts b/src/lib/api/ipc/git/fetches.ts new file mode 100644 index 000000000..94a36430d --- /dev/null +++ b/src/lib/api/ipc/git/fetches.ts @@ -0,0 +1,10 @@ +import { listen } from '$lib/ipc'; + +export function subscribe( + params: { projectId: string }, + callback: (params: { projectId: string }) => Promise | void +) { + return listen<{ head: string }>(`project://${params.projectId}/git/fetch`, (event) => + callback({ ...params, ...event.payload }) + ); +} diff --git a/src/lib/api/ipc/git/index.ts b/src/lib/api/ipc/git/index.ts index a902c772b..404a739a0 100644 --- a/src/lib/api/ipc/git/index.ts +++ b/src/lib/api/ipc/git/index.ts @@ -5,6 +5,7 @@ export type { Activity } from './activities'; export * as heads from './heads'; export * as diffs from './diffs'; export * as indexes from './indexes'; +export * as fetches from './fetches'; import { invoke } from '$lib/ipc'; diff --git a/src/routes/repo/[projectId]/remoteBranches.ts b/src/routes/repo/[projectId]/remoteBranches.ts index 442a308f1..e0d104c7d 100644 --- a/src/routes/repo/[projectId]/remoteBranches.ts +++ b/src/routes/repo/[projectId]/remoteBranches.ts @@ -1,4 +1,5 @@ import { invoke } from '$lib/ipc'; +import { git } from '$lib/api/ipc'; import type { BranchData } from './types'; import { writable, type Loadable } from 'svelte-loadable-store'; import { error } from '$lib/toasts'; @@ -30,11 +31,11 @@ export function getRemoteBranches( function createWriteable(projectId: string) { return writable(getRemoteBranchesData(projectId), (set) => { - setInterval(() => { + git.fetches.subscribe({ projectId }, () => { getRemoteBranchesData(projectId).then((branches) => { set(sortBranchData(branches)); }); - }, 60000); // poll since we don't have a way to subscribe to changes + }); }); }