-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding LocalRepositoryRegistry
Signed-off-by: axel7083 <[email protected]>
- Loading branch information
Showing
8 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/backend/src/registries/LocalRepositoryRegistry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { LocalRepository } from '@shared/src/models/ILocalRepository'; | ||
import * as podmanDesktopApi from '@podman-desktop/api'; | ||
import { MSG_LOCAL_REPOSITORY_UPDATE } from '@shared/Messages'; | ||
import type { Webview } from '@podman-desktop/api'; | ||
|
||
/** | ||
* The LocalRepositoryRegistry is responsible for keeping track of the directories where recipe are cloned | ||
*/ | ||
export class LocalRepositoryRegistry { | ||
// Map path => LocalRepository | ||
private repositories: Map<string, LocalRepository> = new Map(); | ||
|
||
constructor(private webview: Webview) {} | ||
|
||
register(localRepository: LocalRepository): podmanDesktopApi.Disposable { | ||
this.repositories.set(localRepository.path, localRepository); | ||
this.notify(); | ||
|
||
return podmanDesktopApi.Disposable.create(() => { | ||
this.unregister(localRepository.path); | ||
}); | ||
} | ||
|
||
unregister(path: string): void { | ||
this.repositories.delete(path); | ||
this.notify(); | ||
} | ||
|
||
getLocalRepositories(): LocalRepository[] { | ||
return Object.values(this.repositories); | ||
} | ||
|
||
private notify() { | ||
this.webview.postMessage({ | ||
id: MSG_LOCAL_REPOSITORY_UPDATE, | ||
body: this.getLocalRepositories(), | ||
}).catch((err: unknown) => { | ||
console.error('Something went wrong while notifying local repositories update', err); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Readable } from 'svelte/store'; | ||
import { readable } from 'svelte/store'; | ||
import { MSG_LOCAL_REPOSITORY_UPDATE, MSG_NEW_RECIPE_STATE } from '@shared/Messages'; | ||
import { rpcBrowser, studioClient } from '/@/utils/client'; | ||
import type { LocalRepository } from '@shared/src/models/ILocalRepository'; | ||
|
||
export const localRepositories: Readable<LocalRepository[]> = readable<LocalRepository[]>( | ||
[], | ||
set => { | ||
const sub = rpcBrowser.subscribe(MSG_LOCAL_REPOSITORY_UPDATE, msg => { | ||
set(msg); | ||
}); | ||
// Initialize the store manually | ||
studioClient.getLocalRepositories().then(state => { | ||
set(state); | ||
}); | ||
return () => { | ||
sub.unsubscribe(); | ||
}; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface LocalRepository { | ||
path: string; | ||
recipeId: string; | ||
} |