-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adopt playground containers * Update packages/backend/src/managers/playground.ts Co-authored-by: axel7083 <[email protected]> * fix unit tests * use provider.onDidRegisterContainerConnection to know when providers are up * start adopt when podman only provider starts * create a dedicated class for listening the registration of podman provider * remove the getConnection method from PodmanConnection --------- Co-authored-by: axel7083 <[email protected]>
- Loading branch information
Showing
6 changed files
with
135 additions
and
9 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
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,65 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { type RegisterContainerConnectionEvent, provider } from '@podman-desktop/api'; | ||
|
||
type startupHandle = () => void; | ||
|
||
export class PodmanConnection { | ||
#firstFound = false; | ||
#toExecuteAtStartup: startupHandle[] = []; | ||
|
||
init(): void { | ||
// In case the extension has not yet registered, we listen for new registrations | ||
// and retain the first started podman provider | ||
const disposable = provider.onDidRegisterContainerConnection((e: RegisterContainerConnectionEvent) => { | ||
if (e.connection.type !== 'podman' || e.connection.status() !== 'started') { | ||
return; | ||
} | ||
if (this.#firstFound) { | ||
return; | ||
} | ||
this.#firstFound = true; | ||
for (const f of this.#toExecuteAtStartup) { | ||
f(); | ||
} | ||
this.#toExecuteAtStartup = []; | ||
disposable.dispose(); | ||
}); | ||
|
||
// In case at least one extension has already registered, we get one started podman provider | ||
const engines = provider | ||
.getContainerConnections() | ||
.filter(connection => connection.connection.type === 'podman') | ||
.filter(connection => connection.connection.status() === 'started'); | ||
if (engines.length > 0) { | ||
disposable.dispose(); | ||
this.#firstFound = true; | ||
} | ||
} | ||
|
||
// startupSubscribe registers f to be executed when a podman container provider | ||
// registers, or immediately if already registered | ||
startupSubscribe(f: startupHandle): void { | ||
if (this.#firstFound) { | ||
f(); | ||
} else { | ||
this.#toExecuteAtStartup.push(f); | ||
} | ||
} | ||
} |
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