Skip to content

Commit 4406598

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 f544261 commit 4406598

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
@@ -214,12 +214,22 @@ async function runTaskCommand (bitbakeWorkspace: BitbakeWorkspace, bitBakeProjec
214214

215215
export let isToasterStarted = false
216216

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

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)