question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

Tutorial 2

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:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
sudhamabcommented, Mar 27, 2020

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

autoUpdater.on("error", (event, err) => {
	log.error(err);
});

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

"mac": {
      "category": "public.app-category.productivity",
      "target": [
        "dmg",
        "zip"
      ],

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 know

However, I was able to restart the app and it loaded the latest version

1reaction
sudhamabcommented, Mar 24, 2020

I replaced autoUpdater.checkForUpdatesAndNotify(); with autoUpdater.checkForUpdates();

and then the following

autoUpdater.on("update-available", () => {
	log.info("auto updater sending update `available");`
	autoUpdater.downloadUpdates();
	mainWindow.webContents.send("update_available");
});

BUT it’s not working. No progress being logged.

Did I misunderstand something?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve errors uploading data to or downloading data from ...
I want to download data from Amazon Aurora and upload it to Amazon S3. How can I resolve an error I received while...
Read more >
Downloading an object - Amazon Simple Storage Service
Using the S3 console · Select the object and choose Download or choose Download as from the Actions menu if you want to...
Read more >
Error Responses - Amazon Simple Storage Service
Error Code Description HTTP Status Code AccessControlListNotSupported The bucket does not allow ACLs. 400 Bad Request AccessDenied Access Denied 403 Forbidden BucketAlreadyOwnedByYou 409 Conflict (in all...
Read more >
Amazon S3 integration - Amazon Relational Database Service
A file name prefix that file names must match to be downloaded. An empty prefix downloads all of the top level files in...
Read more >
Top 8 Ways to Fix Windows 11 Updates Not Downloading or ...
1. Run Windows Update Troubleshooter. Windows 11 includes a dedicated troubleshooter that can automatically scan, detect and fix any issues with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found