Skip to content

Commit

Permalink
feat(desktop): show progress bar on downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Jul 5, 2024
1 parent e8fdfa5 commit b2892bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/components/Ipc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export default class Ipc extends Vue {
ipcRenderer.on('newConnections', () => {
this.$router.push({ path: '/recent_connections/0?oper=create' })
})
ipcRenderer.on('showProgress', (event, args) => {
const percentValue: any = args[0]
console.log(percentValue)
})
}
private unbindIpcEvents(): void {
Expand Down
12 changes: 7 additions & 5 deletions src/main/installCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ async function downloadMqttxCLI(downloadUrl: string, outputPath: string, win: Br

response.data.on('data', (chunk: string | any[]) => {
downloadedLength += chunk.length
const percent = ((downloadedLength / totalLength) * 100).toFixed(2)
// Send progress to UI
win.webContents.send('showProgress', percent)
const percent = (downloadedLength / totalLength).toFixed(2)
win.setProgressBar(parseFloat(percent))
})

writer.on('finish', () => {
win.webContents.send('showProgress', false)
win.setProgressBar(-1)
resolve()
})

writer.on('error', (err) => {
win.setProgressBar(-1)
writer.close()
fs.unlink(outputPath, () => {})
reject(err)
Expand All @@ -125,7 +127,7 @@ async function sudoInstall(outputPath: string, win: BrowserWindow): Promise<void
dialog.showMessageBox({
type: 'info',
title: 'Installation Completed',
message: 'MQTTX CLI has been successfully installed. You can run "mqttx" commands in the terminal now.',
message: 'MQTTX CLI has been successfully installed.\n\nYou can run "mqttx" commands in the terminal now.',
})
fs.unlink(outputPath, () => console.log('Downloaded file deleted.'))
}
Expand All @@ -136,7 +138,7 @@ function showDownloadedWindowsCLI(outputPath: string, fileName: string) {
dialog.showMessageBox({
type: 'info',
title: 'Download Completed',
message: `MQTTX CLI has been successfully downloaded. Please manually run '${fileName}' located at: ${outputPath} to use it.`,
message: `MQTTX CLI has been successfully downloaded.\n\nPlease manually run '${fileName}' located at: ${outputPath} to use it.`,
})
}

Expand Down

0 comments on commit b2892bc

Please sign in to comment.