-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto update the app #256
Merged
Merged
Auto update the app #256
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { ipcMain, dialog, ipcRenderer } from 'electron'; | ||
import { checkForUpdate, downloadUpdate, quitAndInstall } from './updater'; | ||
|
||
export default function initialize() { | ||
ipcMain.handle(SelectDirHandler.name, SelectDirHandler.handler); | ||
} | ||
|
||
export const SelectDirHandler = { | ||
name: 'SELECT_DIRECTORY_FOLDER', | ||
async handler() { | ||
const functions = { | ||
showSaveDialog: async () => { | ||
const dir = await dialog.showSaveDialog({}); | ||
|
||
return dir.filePath; | ||
}, | ||
invoke() { | ||
return ipcRenderer.invoke(this.name); | ||
}, | ||
checkForUpdate, | ||
downloadUpdate, | ||
quitAndInstall | ||
}; | ||
type Functions = typeof functions; | ||
|
||
export const ipcHandlers = Object.keys(functions).reduce((acc, funcName) => { | ||
acc[funcName] = () => ipcRenderer.invoke(funcName); | ||
return acc; | ||
}, {} as Functions); | ||
|
||
export const registerHandlers = () => { | ||
Object.keys(functions).forEach((funcName) => { | ||
ipcMain.handle(funcName, functions[funcName]); | ||
}); | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logger from '../logging/logger'; | ||
|
||
export type UpdateInfo = { | ||
version: string | ||
} | ||
|
||
const isRenderer = (process && process.type === 'renderer'); | ||
// There is a typing issue with 'electron-updater' I can't solve | ||
const autoUpdater = isRenderer ? {} : require('electron-updater').autoUpdater; // eslint-disable-line | ||
|
||
autoUpdater.logger = logger; | ||
autoUpdater.autoDownload = false; | ||
|
||
export const checkForUpdate = async () => new Promise<UpdateInfo | false>((resolve, reject) => { | ||
autoUpdater.once('error', reject); | ||
autoUpdater.once('update-available', (info: UpdateInfo) => resolve(info)); | ||
autoUpdater.once('update-not-available', () => resolve(false)); | ||
autoUpdater.checkForUpdates(); | ||
}); | ||
|
||
export const downloadUpdate = async () => new Promise<any>((resolve, reject) => { | ||
autoUpdater.once('error', reject); | ||
autoUpdater.once('update-downloaded', resolve); | ||
autoUpdater.downloadUpdate(); | ||
}); | ||
|
||
export const quitAndInstall = () => setImmediate(() => autoUpdater.quitAndInstall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<template> | ||
<div | ||
v-if="state === STATES.LOADING" | ||
class="progress" | ||
> | ||
<v-progress-linear | ||
:indeterminate="true" | ||
class="mr-2" | ||
color="black lighten-2" | ||
/> | ||
</div> | ||
<v-btn | ||
v-else-if="state === STATES.INIT" | ||
text | ||
small | ||
@click="checkUpdates" | ||
> | ||
<span class="mr-2">Check for updates</span> | ||
</v-btn> | ||
<div v-else-if="state === STATES.NO_NEW_VERSION"> | ||
No update available | ||
</div> | ||
<div v-else-if="state === STATES.NEW_VERSION_AVAIL"> | ||
<v-btn | ||
text | ||
small | ||
@click="downloadNewVersion" | ||
> | ||
Download version {{ updateInfo.version }} | ||
</v-btn> | ||
<v-btn | ||
text | ||
small | ||
@click="openGithubRelease" | ||
> | ||
Github | ||
<v-icon>mdi-open-in-new</v-icon> | ||
</v-btn> | ||
<v-btn | ||
text | ||
small | ||
@click="openCompare" | ||
> | ||
Compare | ||
<v-icon>mdi-open-in-new</v-icon> | ||
</v-btn> | ||
</div> | ||
<v-btn | ||
v-else-if="state === STATES.READY_TO_INSTALL" | ||
text | ||
small | ||
@click="quitAndInstall" | ||
> | ||
Quit and install | ||
</v-btn> | ||
<div v-else> | ||
Error during update | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref } from '@vue/composition-api'; | ||
import { ipcHandlers } from '@/handlers'; | ||
import { UpdateInfo } from '@/handlers/updater'; | ||
import { App } from '@/app-globals'; | ||
import { shell } from 'electron'; | ||
import { repository } from '../../../../package.json'; | ||
|
||
enum STATES { | ||
INIT, | ||
LOADING, | ||
ERROR, | ||
NEW_VERSION_AVAIL, | ||
NO_NEW_VERSION, | ||
READY_TO_INSTALL, | ||
} | ||
|
||
const currentVersion = App.getVersion(); | ||
|
||
export default defineComponent({ | ||
setup() { | ||
const state = ref(STATES.INIT); | ||
const updateInfo = ref<UpdateInfo|undefined>(); | ||
|
||
const checkUpdates = async () => { | ||
state.value = STATES.LOADING; | ||
ipcHandlers.checkForUpdate() | ||
.then((info) => { | ||
updateInfo.value = info || undefined; | ||
state.value = info | ||
? STATES.NEW_VERSION_AVAIL | ||
: STATES.NO_NEW_VERSION; | ||
}).catch(() => (state.value = STATES.ERROR)); | ||
}; | ||
const downloadNewVersion = async () => { | ||
state.value = STATES.LOADING; | ||
ipcHandlers.downloadUpdate() | ||
.then(() => (state.value = STATES.READY_TO_INSTALL)) | ||
.catch(() => (state.value = STATES.ERROR)); | ||
}; | ||
Comment on lines
+69
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of Automata, must be a better solution for this... |
||
const { quitAndInstall } = ipcHandlers; | ||
const openGithubRelease = () => { | ||
shell.openExternal(`${repository}/releases/tag/v${updateInfo?.value?.version}`); | ||
}; | ||
const openCompare = () => { | ||
shell.openExternal(`${repository}/compare/v${currentVersion}...v${updateInfo?.value?.version}`); | ||
}; | ||
|
||
return { | ||
STATES, | ||
state, | ||
updateInfo, | ||
currentVersion, | ||
checkUpdates, | ||
downloadNewVersion, | ||
quitAndInstall, | ||
openGithubRelease, | ||
openCompare | ||
}; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.progress { | ||
min-width: 10vw; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baaraak See the approach of this file...