Skip to content
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 4 commits into from
Jun 21, 2021
Merged

Auto update the app #256

merged 4 commits into from
Jun 21, 2021

Conversation

baruchiro
Copy link
Collaborator

@baruchiro baruchiro commented Jun 14, 2021

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:

AutoUpdate

And the main.log will look like this (The last 4 lines are from the relaunch):

[2021-06-14 21:05:01.107] [info]  Welcome to hiuvi log
[2021-06-14 21:05:01.120] [info]  Version: 0.0.7
[2021-06-14 21:05:10.756] [info]  Checking for update
[2021-06-14 21:05:13.953] [info]  Found version 0.0.8-test (url: hiuvi-Setup-0.0.8-test.exe)
[2021-06-14 21:21:58.576] [info]  Checking for update
[2021-06-14 21:22:00.136] [info]  Found version 0.0.8-test (url: hiuvi-Setup-0.0.8-test.exe)
[2021-06-14 21:22:02.525] [info]  Downloading update from hiuvi-Setup-0.0.8-test.exe
[2021-06-14 21:22:02.529] [debug] updater cache dir: C:\Users\baruchr\AppData\Local\hiuvi-updater
[2021-06-14 21:22:02.536] [info]  Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: Kaqzrs3Msfm0M3U+Sh1+QSleSFs4rb01mWygdLpu/RkpwWBqzKHtGJVVNje9i25IpOMCKA8pRvPdJuTMXwe6+Q==, expected: 7FiY31RnNGLZeLPIpHLLB9e45OE5h8qQhSc2OsbgBW6xCwo3ULYU949djQ/IteGlef096VMrBGCkFVbNacSQww==. Directory for cached update will be cleaned
[2021-06-14 21:22:02.555] [info]  Download block maps (old: "https://github.com/baruchiro/budget-tracking/releases/download/v0.0.8-test/hiuvi-Setup-0.0.8-test.exe.blockmap", new: https://github.com/baruchiro/budget-tracking/releases/download/v0.0.8-test/hiuvi-Setup-0.0.8-test.exe.blockmap)
[2021-06-14 21:22:03.175] [debug] UXSCPSWhD1Csh1p8+vjB+UsT duplicated in blockmap (same size), it doesn't lead to broken differential downloader, just corresponding block will be skipped)
[2021-06-14 21:22:03.177] [debug] ert0gfxuUhzLMGTpDn1MIO/1 duplicated in blockmap (same size), it doesn't lead to broken differential downloader, just corresponding block will be skipped)
[2021-06-14 21:22:03.181] [debug] [
  {
    "kind": 0,
    "start": 0,
    "end": 146689
  },
  {
    "kind": 0,
    "start": 111753,
    "end": 136584
  },
  {
    "kind": 0,
    "start": 171520,
    "end": 55781739
  }
]
[2021-06-14 21:22:03.221] [info]  Full: 54,474.35 KB, To download: 0 KB (0%)
[2021-06-14 21:22:03.228] [info]  Differential download: https://github.com/baruchiro/budget-tracking/releases/download/v0.0.8-test/hiuvi-Setup-0.0.8-test.exe
[2021-06-14 21:22:04.429] [error] Cannot download differentially, fallback to full download: Error: sha512 checksum mismatch, expected 7FiY31RnNGLZeLPIpHLLB9e45OE5h8qQhSc2OsbgBW6xCwo3ULYU949djQ/IteGlef096VMrBGCkFVbNacSQww==, got dYmc3SkFm32J2sVRy3fX1+F0J3Wh2fp48ktK9WzftWAqAxS8D9MdWoml1kpEK52d7r2lcJtotpqnuJjUbvuuSw==
    at Object.t.newError (C:\Users\baruchr\AppData\Local\Programs\hiuvi\resources\app.asar\background.js:2:29228)
    at b.validate (C:\Users\baruchr\AppData\Local\Programs\hiuvi\resources\app.asar\background.js:2:386303)
    at WriteStream.<anonymous> (C:\Users\baruchr\AppData\Local\Programs\hiuvi\resources\app.asar\background.js:2:403524)
    at WriteStream.emit (events.js:223:5)
    at WriteStream.EventEmitter.emit (domain.js:475:20)
    at internal/fs/streams.js:218:14
    at C:\Users\baruchr\AppData\Local\Programs\hiuvi\resources\app.asar\background.js:2:41856
    at FSReqCallback.oncomplete (fs.js:146:23)
[2021-06-14 21:22:24.746] [info]  New version 0.0.8-test has been downloaded to C:\Users\baruchr\AppData\Local\hiuvi-updater\pending\hiuvi-Setup-0.0.8-test.exe
[2021-06-14 21:22:30.110] [info]  Install on explicit quitAndInstall
[2021-06-14 21:22:30.112] [info]  Install: isSilent: false, isForceRunAfter: true
[2021-06-14 21:22:31.982] [info]  Update installer has already been triggered. Quitting application.
[2021-06-14 21:22:50.002] [info]  Welcome to hiuvi log
[2021-06-14 21:22:50.013] [info]  Version: 0.0.8-test
[2021-06-14 21:23:54.204] [info]  Checking for update
[2021-06-14 21:23:56.546] [info]  Update for version 0.0.8-test is not available (latest version: 0.0.8-test, downgrade is disallowed).

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]);
});
};
Copy link
Collaborator Author

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...

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));
};
Copy link
Collaborator Author

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...

@baruchiro baruchiro marked this pull request as ready for review June 15, 2021 15:12
@baruchiro baruchiro requested a review from brafdlog June 15, 2021 15:12
@baruchiro baruchiro merged commit 43ceb34 into master Jun 21, 2021
@baruchiro baruchiro deleted the baruchiro/issue153 branch June 21, 2021 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic notification to users
1 participant