Skip to content

Commit 6852de3

Browse files
committed
UI: Improve Toaster notification
The notification now allows the user to re-open the browser or stop the Toaster server.
1 parent b9d5ecd commit 6852de3

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

client/src/ui/BitbakeCommands.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,22 @@ async function runTaskCommand (bitbakeWorkspace: BitbakeWorkspace, bitBakeProjec
215215

216216
export let isToasterStarted = false
217217

218+
function openToasterBrowser (): void {
219+
const DEFAULT_TOASTER_PORT = 8000
220+
const url = `http://localhost:${DEFAULT_TOASTER_PORT}`
221+
void vscode.env.openExternal(vscode.Uri.parse(url)).then(success => {
222+
if (!success) {
223+
void vscode.window.showErrorMessage(`Failed to open URL ${url}`)
224+
}
225+
})
226+
}
227+
218228
async function startToasterInBrowser (bitbakeDriver: BitbakeDriver): Promise<void> {
219229
if (isToasterStarted) {
220-
void vscode.window.showInformationMessage('Toaster is already started')
230+
openToasterBrowser();
231+
clientNotificationManager.showToasterStarted()
221232
return
222233
}
223-
const DEFAULT_TOASTER_PORT = 8000
224234
const command = `nohup bash -c "${bitbakeDriver.composeToasterCommand('start')}"`
225235
const process = await runBitbakeTerminalCustomCommand(bitbakeDriver, command, 'Toaster')
226236
process.onExit((e) => {
@@ -229,12 +239,8 @@ async function startToasterInBrowser (bitbakeDriver: BitbakeDriver): Promise<voi
229239
return
230240
}
231241
isToasterStarted = true
232-
const url = `http://localhost:${DEFAULT_TOASTER_PORT}`
233-
void vscode.env.openExternal(vscode.Uri.parse(url)).then(success => {
234-
if (!success) {
235-
void vscode.window.showErrorMessage(`Failed to open URL ${url}`)
236-
}
237-
})
242+
openToasterBrowser()
243+
clientNotificationManager.showToasterStarted()
238244
})
239245
}
240246

client/src/ui/ClientNotificationManager.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ You can configure the sources' workspace to use the Yocto SDK for cross-compilat
8787
})
8888
}
8989

90+
showToasterStarted (): void {
91+
void window.showInformationMessage(
92+
'Toaster has been started and opened in your browser. Stop it with the "BitBake: Stop Toaster" command.',
93+
'Re-open browser',
94+
'Stop Toaster',
95+
'Close'
96+
)
97+
.then((item) => {
98+
if (item === 'Re-open browser') {
99+
void commands.executeCommand('bitbake.start-toaster-in-browser')
100+
} else if (item === 'Stop Toaster') {
101+
void commands.executeCommand('bitbake.stop-toaster')
102+
}
103+
}, (reason) => {
104+
logger.warn('Could not show toaster started dialog: ' + reason)
105+
})
106+
}
107+
90108
private neverShowAgain (method: string): Thenable<void> {
91109
if (this._memento === undefined) {
92110
throw new Error('ClientNotificationManager Memento not set')

0 commit comments

Comments
 (0)