@@ -24,6 +24,7 @@ import {
24
24
containerEngine ,
25
25
type ContainerProviderConnection ,
26
26
type ContainerCreateOptions ,
27
+ type Disposable ,
27
28
} from '@podman-desktop/api' ;
28
29
import type { PodmanConnection , PodmanConnectionEvent } from '../podmanConnection' ;
29
30
import instructlab_images from '../../assets/instructlab-images.json' ;
@@ -37,9 +38,10 @@ import { getRandomName } from '../../utils/randomUtils';
37
38
38
39
export const INSTRUCTLAB_CONTAINER_LABEL = 'ai-lab-instructlab-container' ;
39
40
40
- export class InstructlabManager {
41
+ export class InstructlabManager implements Disposable {
41
42
#initialized: boolean ;
42
43
#containerId: string | undefined ;
44
+ #disposables: Disposable [ ] ;
43
45
44
46
constructor (
45
47
private readonly appUserDirectory : string ,
@@ -49,9 +51,18 @@ export class InstructlabManager {
49
51
private telemetryLogger : TelemetryLogger ,
50
52
) {
51
53
this . #initialized = false ;
52
- this . podmanConnection . onPodmanConnectionEvent ( this . watchMachineEvent . bind ( this ) ) ;
53
- this . containerRegistry . onStartContainerEvent ( this . onStartContainerEvent . bind ( this ) ) ;
54
- this . containerRegistry . onStopContainerEvent ( this . onStopContainerEvent . bind ( this ) ) ;
54
+ this . #disposables = [ ] ;
55
+ }
56
+
57
+ init ( ) : void {
58
+ this . #disposables. push ( this . podmanConnection . onPodmanConnectionEvent ( this . watchMachineEvent . bind ( this ) ) ) ;
59
+ this . #disposables. push ( this . containerRegistry . onStartContainerEvent ( this . onStartContainerEvent . bind ( this ) ) ) ;
60
+ this . #disposables. push ( this . containerRegistry . onStopContainerEvent ( this . onStopContainerEvent . bind ( this ) ) ) ;
61
+ }
62
+
63
+ dispose ( ) : void {
64
+ this . #disposables. forEach ( disposable => disposable . dispose ( ) ) ;
65
+ this . #disposables = [ ] ;
55
66
}
56
67
57
68
private async refreshInstructlabContainer ( id ?: string ) : Promise < void > {
0 commit comments