mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 08:02:32 +00:00
fix: replace workspace port advertised listener (#3539)
This commit is contained in:
@@ -258,6 +258,26 @@ describe('registerWorkspacePortHandlers', () => {
|
||||
port: 3002
|
||||
})
|
||||
})
|
||||
|
||||
it('unsubscribes the previous advertised URL listener when handlers are registered again', () => {
|
||||
const store = makeStore()
|
||||
const firstUnsubscribe = vi.fn()
|
||||
const secondUnsubscribe = vi.fn()
|
||||
const onDidChange = vi
|
||||
.fn()
|
||||
.mockReturnValueOnce(firstUnsubscribe)
|
||||
.mockReturnValueOnce(secondUnsubscribe)
|
||||
|
||||
registerWorkspacePortHandlers(store as never, {
|
||||
advertisedUrlEvents: { onDidChange }
|
||||
})
|
||||
registerWorkspacePortHandlers(store as never, {
|
||||
advertisedUrlEvents: { onDidChange }
|
||||
})
|
||||
|
||||
expect(firstUnsubscribe).toHaveBeenCalledTimes(1)
|
||||
expect(secondUnsubscribe).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
function workspacePort({ pid, port }: { pid: number; port: number }): WorkspacePort {
|
||||
|
||||
@@ -19,6 +19,8 @@ type WorkspacePortHandlersOptions = {
|
||||
getWindows?: () => BrowserWindow[]
|
||||
}
|
||||
|
||||
let unsubscribeAdvertisedUrlChanges: (() => void) | null = null
|
||||
|
||||
export function registerWorkspacePortHandlers(
|
||||
store: Store,
|
||||
options: WorkspacePortHandlersOptions = {}
|
||||
@@ -27,7 +29,8 @@ export function registerWorkspacePortHandlers(
|
||||
const advertisedUrlEvents = options.advertisedUrlEvents ?? advertisedUrlWatcher
|
||||
const getWindows = options.getWindows ?? (() => BrowserWindow.getAllWindows())
|
||||
|
||||
advertisedUrlEvents.onDidChange((event) => {
|
||||
unsubscribeAdvertisedUrlChanges?.()
|
||||
unsubscribeAdvertisedUrlChanges = advertisedUrlEvents.onDidChange((event) => {
|
||||
const localWorktrees = getStoreWorkspacePortProbes(store)
|
||||
if (!localWorktrees.some((worktree) => worktree.id === event.worktreeId)) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user