Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/channels/src/interface/system-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface SystemApi {
openExternal(uri: string): Promise<boolean>;
clipboardWriteText(text: string): Promise<void>;
getFreePort(startPort: number): Promise<number>;
getSystemName(): Promise<'linux' | 'mac' | 'windows' | undefined>;
}
57 changes: 57 additions & 0 deletions packages/extension/src/manager/system-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**********************************************************************
* Copyright (C) 2025 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 { describe, expect, test } from 'vitest';
import { SystemApiImpl } from '/@/manager/system-api';
import * as podmanDesktopApi from '@podman-desktop/api';

describe('getSystemName', async () => {
const systemApi = new SystemApiImpl();

test('should return linux', async () => {
(podmanDesktopApi.env.isLinux as boolean) = true;
(podmanDesktopApi.env.isMac as boolean) = false;
(podmanDesktopApi.env.isWindows as boolean) = false;
const systemName = await systemApi.getSystemName();
expect(systemName).toBe('linux');
});

test('should return mac', async () => {
(podmanDesktopApi.env.isLinux as boolean) = false;
(podmanDesktopApi.env.isMac as boolean) = true;
(podmanDesktopApi.env.isWindows as boolean) = false;
const systemName = await systemApi.getSystemName();
expect(systemName).toBe('mac');
});

test('should return windows', async () => {
(podmanDesktopApi.env.isLinux as boolean) = false;
(podmanDesktopApi.env.isMac as boolean) = false;
(podmanDesktopApi.env.isWindows as boolean) = true;
const systemName = await systemApi.getSystemName();
expect(systemName).toBe('windows');
});

test('should return undefined', async () => {
(podmanDesktopApi.env.isLinux as boolean) = false;
(podmanDesktopApi.env.isMac as boolean) = false;
(podmanDesktopApi.env.isWindows as boolean) = false;
const systemName = await systemApi.getSystemName();
expect(systemName).toBeUndefined();
});
});
11 changes: 11 additions & 0 deletions packages/extension/src/manager/system-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ export class SystemApiImpl implements SystemApi {
async getFreePort(startPort: number): Promise<number> {
return podmanDesktopApi.net.getFreePort(startPort);
}

async getSystemName(): Promise<'linux' | 'mac' | 'windows' | undefined> {
if (podmanDesktopApi.env.isLinux) {
return 'linux';
} else if (podmanDesktopApi.env.isMac) {
return 'mac';
} else if (podmanDesktopApi.env.isWindows) {
return 'windows';
}
return undefined;
}
}