From 4406598ed782fa069a8c3b295955b3640327f9a6 Mon Sep 17 00:00:00 2001 From: Enguerrand de Ribaucourt Date: Tue, 7 Jan 2025 14:45:59 +0100 Subject: [PATCH] UI: Improve Toaster notification The notification now allows the user to re-open the browser or stop the Toaster server. --- client/src/ui/BitbakeCommands.ts | 22 ++++++++++++++-------- client/src/ui/ClientNotificationManager.ts | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/src/ui/BitbakeCommands.ts b/client/src/ui/BitbakeCommands.ts index 7cf90840..6d7bd428 100644 --- a/client/src/ui/BitbakeCommands.ts +++ b/client/src/ui/BitbakeCommands.ts @@ -214,12 +214,22 @@ async function runTaskCommand (bitbakeWorkspace: BitbakeWorkspace, bitBakeProjec export let isToasterStarted = false +function openToasterBrowser (): void { + const DEFAULT_TOASTER_PORT = 8000 + const url = `http://localhost:${DEFAULT_TOASTER_PORT}` + void vscode.env.openExternal(vscode.Uri.parse(url)).then(success => { + if (!success) { + void vscode.window.showErrorMessage(`Failed to open URL ${url}`) + } + }) +} + async function startToasterInBrowser (bitbakeDriver: BitbakeDriver): Promise { if (isToasterStarted) { - void vscode.window.showInformationMessage('Toaster is already started') + openToasterBrowser(); + clientNotificationManager.showToasterStarted() return } - const DEFAULT_TOASTER_PORT = 8000 const command = `nohup bash -c "${bitbakeDriver.composeToasterCommand('start')}"` const process = await runBitbakeTerminalCustomCommand(bitbakeDriver, command, 'Toaster') process.onExit((e) => { @@ -228,12 +238,8 @@ async function startToasterInBrowser (bitbakeDriver: BitbakeDriver): Promise { - if (!success) { - void vscode.window.showErrorMessage(`Failed to open URL ${url}`) - } - }) + openToasterBrowser() + clientNotificationManager.showToasterStarted() }) } diff --git a/client/src/ui/ClientNotificationManager.ts b/client/src/ui/ClientNotificationManager.ts index 9e77e691..fad895fb 100644 --- a/client/src/ui/ClientNotificationManager.ts +++ b/client/src/ui/ClientNotificationManager.ts @@ -87,6 +87,24 @@ You can configure the sources' workspace to use the Yocto SDK for cross-compilat }) } + showToasterStarted (): void { + void window.showInformationMessage( + 'Toaster has been started and opened in your browser. Stop it with the "BitBake: Stop Toaster" command.', + 'Re-open browser', + 'Stop Toaster', + 'Close' + ) + .then((item) => { + if (item === 'Re-open browser') { + void commands.executeCommand('bitbake.start-toaster-in-browser') + } else if (item === 'Stop Toaster') { + void commands.executeCommand('bitbake.stop-toaster') + } + }, (reason) => { + logger.warn('Could not show toaster started dialog: ' + reason) + }) + } + private neverShowAgain (method: string): Thenable { if (this._memento === undefined) { throw new Error('ClientNotificationManager Memento not set')