Skip to content

Commit

Permalink
add update download progress
Browse files Browse the repository at this point in the history
  • Loading branch information
iwate committed Jun 10, 2020
1 parent 3ee595f commit 232c74d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Aiplugs.PoshApp/ElectronIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ public static void Setup(ScriptsService scriptsService)
Electron.AutoUpdater.QuitAndInstall();
});

Electron.AutoUpdater.OnDownloadProgress += (info) =>
{
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "update-downloading", info.Percent);
};

Electron.AutoUpdater.OnUpdateDownloaded += (info) =>
{
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Expand Down
1 change: 1 addition & 0 deletions src/Aiplugs.PoshApp/Views/Shared/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<partial name="PowershellUI/PromptForCredential" />
<partial name="PowershellUI/LogForError" />
<partial name="PowershellUI/Log" />
<partial name="PowershellUI/ProgressForUpdate" />
<partial name="PowershellUI/ProgressForGit" />
<partial name="PowershellUI/Progress" />
<partial name="PowershellUI/Status" />
Expand Down
1 change: 1 addition & 0 deletions src/Aiplugs.PoshApp/Views/Shared/PowershellUI/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template id="powershell-ui-component">
<div class="d-flex" style="width:100%">
<PowershellUIStatus></PowershellUIStatus>
<PowershellUIProgressForUpdate></PowershellUIProgressForUpdate>
<span class="flex-grow-1"></span>
<PowershellUIPromptForCredential></PowershellUIPromptForCredential>
<PowershellUIPromptForChoice></PowershellUIPromptForChoice>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template id="powershell-ui-progress-for-update-component">
<span class="d-flex align-center" v-if="!updateDownloading">
Downloading update... {{updateDownloading}}
</span>
</template>
<script>
Vue.component('powershelluiprogressforupdate', {
template: '#powershell-ui-progress-for-update-component',
computed: {
...Vuex.mapState('ipc', ['updateDownloading'])
}
})
</script>
8 changes: 8 additions & 0 deletions src/Aiplugs.PoshApp/wwwroot/js/store/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
export default {
namespaced: true,
state: {
updateDownloading: null,
updateAvailable: false,
selectedDirectory: {},
selectedFile: {}
},
mutations: {
setUpdateDownloading(state, progress) {
state.updateDownloading = progress;
},
setUpdateAvailable(state) {
state.updateDownloading = null;
state.updateAvailable = true;
},
clearUpdateAvailable(state) {
Expand Down Expand Up @@ -65,6 +70,9 @@ export default {
};

export function ipcPlugin(store) {
ipcRenderer.on('update-downloading', (sender, progress) => {
store.commit('ipc/setUpdateDownloading', progress);
});
ipcRenderer.on('update-available', sender => {
store.commit('ipc/setUpdateAvailable');
});
Expand Down

0 comments on commit 232c74d

Please sign in to comment.