@omercnet/paseo-fresh-worktrees 1.2.0-next.111.1 → 1.2.0-next.115.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.client.ts +32 -6
  2. package/package.json +1 -1
package/index.client.ts CHANGED
@@ -13,6 +13,10 @@ interface WorkspaceEntry {
13
13
  workspaceDirectory: string | null;
14
14
  }
15
15
 
16
+ interface ReleasableSubscription {
17
+ release(): Promise<void>;
18
+ }
19
+
16
20
  export default function contribute(client: PluginClientContext) {
17
21
  const buttons = new Map<string, PluginButtonRegistration>();
18
22
  const checks = new Map<string, Promise<void>>();
@@ -22,6 +26,18 @@ export default function contribute(client: PluginClientContext) {
22
26
  >();
23
27
  const projectRoots = new Map<string, string>();
24
28
  let stopped = false;
29
+ let workspaceSubscription: ReleasableSubscription | undefined;
30
+ let releaseSubscriptionPromise: Promise<void> | undefined;
31
+ let initializationFailed = false;
32
+
33
+ function releaseWorkspaceSubscription(): Promise<void> {
34
+ if (releaseSubscriptionPromise) return releaseSubscriptionPromise;
35
+ const subscription = workspaceSubscription;
36
+ workspaceSubscription = undefined;
37
+ if (!subscription) return Promise.resolve();
38
+ releaseSubscriptionPromise = subscription.release();
39
+ return releaseSubscriptionPromise;
40
+ }
25
41
 
26
42
  function removeIndicator(workspaceId: string) {
27
43
  buttons.get(workspaceId)?.remove();
@@ -129,17 +145,26 @@ export default function contribute(client: PluginClientContext) {
129
145
  }
130
146
  });
131
147
 
132
- void Promise.all([
133
- client.paseo.projects.list(),
134
- client.paseo.workspaces.list({ subscribe: { subscriptionId: "fresh-worktrees-status" } }),
135
- ])
148
+ const workspaceList = client.paseo.workspaces.list({ subscribe: {} }).then(async (result) => {
149
+ workspaceSubscription = result.subscription;
150
+ if (stopped || initializationFailed) await releaseWorkspaceSubscription();
151
+ return result;
152
+ });
153
+
154
+ void Promise.all([client.paseo.projects.list(), workspaceList])
136
155
  .then(([{ projects }, { entries }]) => {
137
156
  if (stopped) return;
138
157
  for (const project of projects) projectRoots.set(project.projectId, project.projectRootPath);
139
158
  for (const workspace of entries) trackWorkspace(workspace);
140
159
  })
141
- .catch((error) => {
142
- console.warn("[fresh-worktrees] Could not list workspaces", error);
160
+ .catch(async (error) => {
161
+ initializationFailed = true;
162
+ try {
163
+ await releaseWorkspaceSubscription();
164
+ } catch (releaseError) {
165
+ console.warn("[fresh-worktrees] Could not release workspace observation", releaseError);
166
+ }
167
+ if (!stopped) console.warn("[fresh-worktrees] Could not list workspaces", error);
143
168
  });
144
169
 
145
170
  const interval = setInterval(() => {
@@ -158,5 +183,6 @@ export default function contribute(client: PluginClientContext) {
158
183
  buttons.clear();
159
184
  workspaceLocations.clear();
160
185
  projectRoots.clear();
186
+ return releaseWorkspaceSubscription();
161
187
  };
162
188
  }
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "shared",
32
32
  "paseo-plugin.json"
33
33
  ],
34
- "version": "1.2.0-next.111.1",
34
+ "version": "1.2.0-next.115.1",
35
35
  "type": "module",
36
36
  "packageManager": "npm@11.19.1",
37
37
  "engines": {