Skip to content

Commit 5b1ae6a

Browse files
authored
fix(extension: podman): wrap Podman update with withProgress to create visible task (podman-desktop#14809)
fix: wrap Podman update with withProgress to create visible task Wrap the Podman update operation with extensionApi.window.withProgress to display a visible task in the task bar when updating Podman. Fixes podman-desktop#13635 Signed-off-by: SACHIN KUMAR <mrmister680@gmail.com>
1 parent 66bc6d0 commit 5b1ae6a

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

extensions/podman/packages/extension/src/extension.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ beforeEach(async () => {
237237
};
238238
vi.resetAllMocks();
239239
(extensionApi.env.createTelemetryLogger as Mock).mockReturnValue(telemetryLogger);
240+
241+
// Mock withProgress to execute the task immediately
242+
vi.mocked(extensionApi.window.withProgress).mockImplementation((_options, task) => {
243+
return task({ report: vi.fn() }, {} as extensionApi.CancellationToken);
244+
});
245+
240246
extension.initTelemetryLogger();
241247
extension.initExtensionNotification();
242248
extension.resetShouldNotifySetup();
@@ -299,6 +305,7 @@ vi.mock('@podman-desktop/api', async () => {
299305
showInformationMessage: vi.fn(),
300306
showWarningMessage: vi.fn(),
301307
showNotification: vi.fn(),
308+
withProgress: vi.fn(),
302309
createStatusBarItem: () => ({
303310
show: vi.fn(),
304311
dispose: vi.fn(),
@@ -323,6 +330,11 @@ vi.mock('@podman-desktop/api', async () => {
323330
from: vi.fn(),
324331
create: vi.fn(),
325332
},
333+
CancellationToken: {},
334+
ProgressLocation: {
335+
TASK_WIDGET: 'TASK_WIDGET',
336+
APP_ICON: 'APP_ICON',
337+
},
326338
fs: {
327339
createFileSystemWatcher: vi.fn(),
328340
},
@@ -1683,6 +1695,54 @@ test('should register update when there are multiple Podman installations but cu
16831695
expect(registerUpdateMock).toHaveBeenCalled();
16841696
});
16851697

1698+
test('update should be wrapped with withProgress to create a visible task', async () => {
1699+
extension.initExtensionContext({ subscriptions: [] } as unknown as extensionApi.ExtensionContext);
1700+
1701+
const extensionContext = { subscriptions: [], storagePath: '' } as unknown as extensionApi.ExtensionContext;
1702+
const podmanInstall: PodmanInstall = new PodmanInstall(
1703+
extensionContext,
1704+
telemetryLogger,
1705+
{} as unknown as Installer,
1706+
undefined,
1707+
);
1708+
1709+
vi.spyOn(podmanCli, 'findPodmanInstallations').mockResolvedValue(['/usr/local/bin/podman']);
1710+
1711+
vi.spyOn(podmanInstall, 'checkForUpdate').mockResolvedValue({
1712+
hasUpdate: true,
1713+
bundledVersion: 'v5.0.0',
1714+
installedVersion: 'v4.9.0',
1715+
});
1716+
1717+
vi.spyOn(podmanInstall, 'performUpdate').mockResolvedValue();
1718+
1719+
const withProgressSpy = vi.spyOn(extensionApi.window, 'withProgress');
1720+
1721+
const installedPodman = { version: '4.9.0' } as InstalledPodman;
1722+
1723+
let updater: extensionApi.ProviderUpdate | undefined;
1724+
registerUpdateMock.mockImplementation((update: extensionApi.ProviderUpdate) => {
1725+
updater = update;
1726+
});
1727+
1728+
await extension.registerUpdatesIfAny(provider, installedPodman, podmanInstall);
1729+
1730+
expect(registerUpdateMock).toHaveBeenCalled();
1731+
expect(updater).toBeDefined();
1732+
1733+
// Call the update function
1734+
await updater?.update({} as extensionApi.Logger);
1735+
1736+
// Verify withProgress was called with correct parameters
1737+
expect(withProgressSpy).toHaveBeenCalledWith(
1738+
{ location: extensionApi.ProgressLocation.TASK_WIDGET, title: 'Updating Podman' },
1739+
expect.any(Function),
1740+
);
1741+
1742+
// Verify performUpdate was called
1743+
expect(podmanInstall.performUpdate).toHaveBeenCalledWith(provider, installedPodman);
1744+
});
1745+
16861746
test('provider is registered with edit capabilities on MacOS', async () => {
16871747
// Mock platform to be darwin
16881748
vi.mocked(extensionApi.env).isMac = true;

extensions/podman/packages/extension/src/extension.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,16 @@ export async function registerUpdatesIfAny(
993993
update: () => {
994994
// disable notification before the update to prevent the notification to be shown and re-enabled when update is done
995995
extensionNotifications.shouldNotifySetup = false;
996-
return podmanInstall
997-
.performUpdate(provider, installedPodman)
998-
.finally(() => (extensionNotifications.shouldNotifySetup = true));
996+
return extensionApi.window.withProgress(
997+
{ location: extensionApi.ProgressLocation.TASK_WIDGET, title: 'Updating Podman' },
998+
async () => {
999+
try {
1000+
return await podmanInstall.performUpdate(provider, installedPodman);
1001+
} finally {
1002+
extensionNotifications.shouldNotifySetup = true;
1003+
}
1004+
},
1005+
);
9991006
},
10001007
preflightChecks: () => podmanInstall.getUpdatePreflightChecks() ?? [],
10011008
});

0 commit comments

Comments
 (0)