update-available detected but not downloading with Amazon S3
See original GitHub issue- Version: ^21.2.0
- Version: ^4.2.2
- Target: Mac
Hi Team,
Thanks for this great library and hope you are all safe at home during these tough times.
We have been trying very hard to make the auto update work . First we tried with github private repo and updates were not getting detected.
Then we switched to Amazon S3. The update-available event gets triggered but the latest update doesn’t seem to be downloading. We are not getting any error either.
The “download-progress” event does not triggered.
The code for main.js is as follows
const { app, BrowserWindow, ipcMain, powerMonitor } = require("electron");
const { autoUpdater } = require("electron-updater");
const log = require("electron-log");
const isDev = require("electron-is-dev");
let mainWindow, authWindow, zoomAuthWindow;
function createWindow() {
const startUrl =
process.env.ELECTRON_START_URL ||
url.format({
pathname: path.join(__dirname, "../index.html"),
protocol: "file:",
slashes: true
});
mainWindow = new BrowserWindow({
width: 1400,
height: 800,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: true
}
});
console.log("URL", startUrl);
mainWindow.loadURL(startUrl);
mainWindow.on("closed", function() {
mainWindow = null;
});
if (isDev) {
log.info("running in dev");
} else {
log.info("running in PROD");
autoUpdater.checkForUpdatesAndNotify();
}
}
app.on("ready", () => {
createWindow();
});
ipcMain.on("app_version", event => {
log.info("received event ", app.getVersion());
event.sender.send("app_version", { version: app.getVersion() });
});
autoUpdater.on("checking-for-update", () => {
log.info("checking for updates");
});
autoUpdater.on("update-available", () => {
log.info("auto updater sending update available");
mainWindow.webContents.send("update_available");
});
autoUpdater.on("download-progress", progressObj => {
log.info("Tracking progress");
var log_message = "Download speed: " + progressObj.bytesPerSecond;
log_message = log_message + " - Downloaded " + progressObj.percent + "%";
log_message =
log_message +
" (" +
progressObj.transferred +
"/" +
progressObj.total +
")";
log.info(log_message);
mainWindow.webContents.send("download_progress", log_message);
});
autoUpdater.on("update-not-available", () => {
log.info("auto updater sending update NOT available");
mainWindow.webContents.send("update_not_available");
});
autoUpdater.on("update-downloaded", () => {
log.info("auto updater sending update downloaded");
mainWindow.webContents.send("update_downloaded");
});
ipcMain.on("restart_app", () => {
autoUpdater.quitAndInstall();
});
The index.html file is as follows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
<style>
#notification {
position: fixed;
bottom: 20px;
left: 20px;
width: 200px;
padding: 20px;
border-radius: 5px;
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
z-index: 3002
}
.hidden {
display: none;
}
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">
</div>
<div id="notification" class="hidden">
<p id="version"></p>
<p id="message"></p>
<button id="close-button" onClick="closeNotification()">
Close
</button>
<button id="restart-button" onClick="restartApp()" class="hidden">
Restart
</button>
</div>
<script>
const {
ipcRenderer
} = require('electron');
const log = require("electron-log");
const version = document.getElementById('version');
const notification = document.getElementById('notification');
const message = document.getElementById('message');
const restartButton = document.getElementById('restart-button');
ipcRenderer.send('app_version');
ipcRenderer.on('app_version', (event, arg) => {
log.info('ipcRenderer on app_version')
ipcRenderer.removeAllListeners('app_version');
version.innerText = 'Version ' + arg.version;
});
ipcRenderer.on('update_not_available', () => {
log.info('ipcRenderer on update_not_available')
ipcRenderer.removeAllListeners('update_not_available');
message.innerText = 'NO update is available';
notification.classList.remove('hidden');
});
ipcRenderer.on('update_available', () => {
log.info('ipcRenderer on update_available')
ipcRenderer.removeAllListeners('update_available');
message.innerText = 'A new update is available. Downloading now...';
notification.classList.remove('hidden');
});
ipcRenderer.on('download_progress', (progress_message) => {
log.info('ipcRenderer on download_progress')
ipcRenderer.removeAllListeners('update_available');
message.innerText = progress_message;
notification.classList.remove('hidden');
});
ipcRenderer.on('update_downloaded', () => {
log.info('ipcRenderer on update_downloaded')
ipcRenderer.removeAllListeners('update_downloaded');
message.innerText = 'Update Downloaded. It will be installed on restart. Restart now?';
restartButton.classList.remove('hidden');
notification.classList.remove('hidden');
});
function closeNotification() {
notification.classList.add('hidden');
}
function restartApp() {
ipcRenderer.send('restart_app');
}
</script>
</body>
</html>
The two main tutorials we followed were as follows Tutorial 1
Would be grateful if you can help us identify what is going wrong as we need to release a version asap.
PS I didn’t comment inside this issue in case this has anything to do with S3.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top GitHub Comments
Thanks Krzysztof! I finally got it to work with a couple of unknowns ( 1 issue stated at the end)
So yes, the logs were there as you stated. I turned on the public read on each flle manually apart from changing the bucket policy also to public read fully including for ACL.
Also, after adding
I realized that it was also expecting a zip version of the dmg on S3. which I had removed this from my package.json for local runs to save space
Once I added this to the package.json as below, it all worked saving the error which i have pasted at the end
Got some good offline help from Marc Parillo ( @nbcnc ). Can’t tag him here unfortunately
The 2 unknowns are
1. I got one error after the download completed
Error: ENOENT: no such file or directory, rename '/Users/xyz/Library/Application Support/Caches/electron-sample-updater/pending/temp-XYZ ABC-1.0.0-mac.zip' -> '/Users/xyz/Library/Application Support/Caches/electron-sample-updater/pending/XYZ ABC-1.0.0-mac.zip'
2. While it was downloading, the autoUpdated(“on-progress”) seemed to get called twice almost simultaneously Not sure if it’s because both dmg and zip are being downloaded simultaneously but would be good to knowHowever, I was able to restart the app and it loaded the latest version
I replaced autoUpdater.checkForUpdatesAndNotify(); with autoUpdater.checkForUpdates();
and then the following
BUT it’s not working. No progress being logged.
Did I misunderstand something?