-
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
Conversation
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
baruchiro
commented
Jun 15, 2021
Comment on lines
1
to
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]); | ||
}); | ||
}; |
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...
baruchiro
commented
Jun 15, 2021
Comment on lines
+69
to
+100
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)); | ||
}; |
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.
Kind of Automata, must be a better solution for this...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix #153
This PR is about using Electron auto-update feature.
It looks like this, and you can see it live if you downloading the v7.0.0 from my fork:
And the
main.log
will look like this (The last 4 lines are from the relaunch):