Skip to content

Commit

Permalink
UI: Improve Toaster notification
Browse files Browse the repository at this point in the history
The notification now allows the user to re-open the browser or stop the
Toaster server.
  • Loading branch information
deribaucourt committed Jan 7, 2025
1 parent 0bd851f commit 002649f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
22 changes: 14 additions & 8 deletions client/src/ui/BitbakeCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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) => {
Expand All @@ -228,12 +238,8 @@ async function startToasterInBrowser (bitbakeDriver: BitbakeDriver): Promise<voi
return
}
isToasterStarted = true
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}`)
}
})
openToasterBrowser()
clientNotificationManager.showToasterStarted()
})
}

Expand Down
18 changes: 18 additions & 0 deletions client/src/ui/ClientNotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (this._memento === undefined) {
throw new Error('ClientNotificationManager Memento not set')
Expand Down

0 comments on commit 002649f

Please sign in to comment.