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 not working on WIN10 #2977

Closed
damianobarbati opened this issue Jun 4, 2018 · 9 comments
Closed

Auto-update not working on WIN10 #2977

damianobarbati opened this issue Jun 4, 2018 · 9 comments

Comments

@damianobarbati
Copy link

Here what I'm experiencing:

  • I have both releases 0.1.31 and 0.1.32 on the repo GitHub
  • I install 0.1.31
  • I start 0.1.31
  • nothing is prompt (should checkForUpdateAndNotify() notify user about the new update?)
  • app closes

Code:

app.on('ready', async () => {
    //try to update!
    try {
        const info = await autoUpdater.checkForUpdatesAndNotify();
        logger.info('checkForUpdatesAndNotify');
        logger.info(JSON.stringify(info));

        autoUpdater.on('update-downloaded', info => {
            const quitAndInstalled = autoUpdater.quitAndInstall();
            logger.info('quitAndInstalled');
            logger.info(quitAndInstalled);
        });

        autoUpdater.on('update-available', arg => {
            logger.info('update-available');
            logger.info(arg);
        });

        autoUpdater.on('update-not-available', arg => {
            logger.info('update-not-available');
            logger.info(arg);
        });

        autoUpdater.on('download-progress', arg => {
            logger.info('download-progress');
            logger.info(arg);
        });

        autoUpdater.on('error', error => {
            logger.info('error');
            logger.info(error.message);
            logger.info(error.stack);
        });
    }
    catch (error) {
        logger.info('autoupdate failed');
    }

    createWindow();
    createOrSyncTrayAndMenu();
});

Here what log.log in %appdata% says:

C:\Users\damiano\AppData\Roaming\TAV>type log.log
[2018-06-04 15:58:22.514] [info] ["C:\\Users\\damiano\\AppData\\Local\\Programs\\TAV\\TAV.exe"]
[2018-06-04 15:58:22.579] [info] { defaultProtocolClientSet: true }
[2018-06-04 15:58:23.119] [info] Checking for update
[2018-06-04 15:58:23.365] [info] Generated new staging user ID: d3158bfd-196b-5f31-86ff-5d8941285791
[2018-06-04 15:58:26.478] [info] Found version 0.1.33 (url: TAV.exe)
[2018-06-04 15:58:26.478] [info] Downloading update from TAV.exe
[2018-06-04 15:58:26.478] [info] checkForUpdatesAndNotify
[2018-06-04 15:58:26.478] [info] {"versionInfo":{"version":"0.1.33","files":[{"url":"TAV.exe","sha512":"WdNsGytxp51XzHTEwUijfcG7H1fTt9jcWeQZb+0ukDUpj+i1btPqvVO6sysjwq03QZQP9/2F9mMbcm5+99rfAg==","size":46203281}],"path":"TAV.exe","sha512":"WdNsGytxp51XzHTEwUijfcG7H1fTt9jcWeQZb+0ukDUpj+i1btPqvVO6sysjwq03QZQP9/2F9mMbcm5+99rfAg==","sha2":"8a0c29d271deae77b0d4799c6678fd3a3cf743df03aa9a0703dadfe7d378b4fb","releaseDate":"2018-06-04T10:12:02.502Z","releaseName":"0.1.33","releaseNotes":""},"updateInfo":{"version":"0.1.33","files":[{"url":"TAV.exe","sha512":"WdNsGytxp51XzHTEwUijfcG7H1fTt9jcWeQZb+0ukDUpj+i1btPqvVO6sysjwq03QZQP9/2F9mMbcm5+99rfAg==","size":46203281}],"path":"TAV.exe","sha512":"WdNsGytxp51XzHTEwUijfcG7H1fTt9jcWeQZb+0ukDUpj+i1btPqvVO6sysjwq03QZQP9/2F9mMbcm5+99rfAg==","sha2":"8a0c29d271deae77b0d4799c6678fd3a3cf743df03aa9a0703dadfe7d378b4fb","releaseDate":"2018-06-04T10:12:02.502Z","releaseName":"0.1.33","releaseNotes":""},"cancellationToken":{"domain":null,"_events":{},"_eventsCount":0,"parentCancelHandler":null,"_parent":null,"_cancelled":false},"downloadPromise":{"isFulfilled":false,"isRejected":false}}
[2018-06-04 15:58:26.633] [info] No cached update available

I can see a temp.exe file in the app data folder:

C:\Users\damiano\AppData\Roaming\TAV>dir
 Il volume nell'unità C non ha etichetta.
 Numero di serie del volume: 12F5-187B

 Directory di C:\Users\damiano\AppData\Roaming\TAV

04/06/2018  15:58    <DIR>          .
04/06/2018  15:58    <DIR>          ..
04/06/2018  15:58                36 .updaterId
04/06/2018  15:58    <DIR>          Cache
04/06/2018  15:58            28.672 Cookies
04/06/2018  15:58                 0 Cookies-journal
04/06/2018  15:58    <DIR>          GPUCache
04/06/2018  15:57        46.203.376 installer.exe
04/06/2018  15:58             1.703 log.log
04/06/2018  15:58    <DIR>          logs
04/06/2018  15:58         5.377.381 temp-installer-0.1.33.exe <== here!

But If I try to open it manually I get the following:
screen shot 2018-06-04 at 16 02 34

I see the temp-installer.exe is just 5MB while the .exe in the release on GitHub is 44MB.
I'm not sure whether a differential download is made (is this possible?) but I think the file download failed without firing the 'error' event (resulting a corrupted .exe file).
Furthermore update-downloaded event is not logged, so probably the app is not closed by the autoUpdater.quitAndInstall() call?

What do you think? Is this a bug?

Versions and nsis config:

{
    "build": {
        ...
        "asar": true,
        "win": {
            "target": "nsis",
            "icon": "./icons/logo.ico",
            "publisherName": "Translated SRL"
        },
        "nsis": {
            "oneClick": false,
            "perMachine": true,
            "allowElevation": true,
            "deleteAppDataOnUninstall": true,
            "createDesktopShortcut": "always",
            "menuCategory": "Translated - TAV",
            "installerHeaderIcon": "./icons/logo.ico",
            "installerIcon": "./icons/logo.ico",
            "uninstallerIcon": "./icons/logo.ico",
            "installerSidebar": "./icons/win-installer-sidebar.bmp",
            "installerHeader": "./icons/win-installer-header.bmp",
            "uninstallerSidebar": "./icons/win-uninstaller-sidebar.bmp",
            "license": "./assets/license.txt"
        },
        ...
    },
    "dependencies": {
        "auto-launch": "^5.0.5",
        "better-console": "^1.0.1",
        "electron-log": "^2.2.14",
        "electron-updater": "^2.21.10",
        "lodash": "^4.17.10",
        "luxon": "^1.2.1",
        "mz": "^2.7.0",
        "sleep-promise": "^6.0.0",
        "typeface-montserrat": "^0.0.54",
        "ws": "^5.1.1"
    },
    "devDependencies": {
        "babel-eslint": "^8.2.3",
        "electron": "^2.0.1",
        "electron-builder": "^20.13.4",
        "electron-debug": "^1.5.0",
        "electron-reload": "^1.2.2",
        "eslint": "^4.19.1",
        "eslint-loader": "^2.0.0",
        "eslint-plugin-jest": "^21.15.0",
        "eslint-plugin-react": "^7.7.0",
        "png2icns": "^0.0.1"
    }
}
@damianobarbati
Copy link
Author

Confirming this bug on the latest versions of electron / electron-updater / electron-builder.

Thanks to @marceloavf for reporting in the other mentioned issue a working combo of versions:

"electron": "1.8.4",
"electron-builder": "20.8.1",
"electron-updater": "2.21.4",

Somewhere when downloading current electron-updater dies.

@peterdanis
Copy link
Contributor

peterdanis commented Jun 17, 2018

If you are using checkForUpdateAndNotify method, it will trigger a notification, and install the update automatically after the app quits. No need to call quitAndInstall.

@damianobarbati
Copy link
Author

damianobarbati commented Jul 20, 2018

@peterdanis @develar where is this documented in the docs?
checkForUpdateAndNotify method, it will trigger a notification, and install the update automatically after the app quits

I'm having so much problems with this, it actually never worked and it is so hard to test (I need to build and push every time 2 releases, the first containing the logic update to test and the second to test the update itself!).

My app just shuts itself down after downloading the __update__ folder.
The __update__ folder holds a broken .exe downloaded inside.
It cannot be run and its size is less than expected one:

[2018-07-20 13:00:13.964] [info] Downloading update from TAV.exe
[2018-07-20 13:00:13.980] [info] No cached update info available
[2018-07-20 13:00:13.982] [info] Download block maps (old: "https://github.com/translated/tav-releases/releases/download/6.3.0-beta.7/TAV.exe.blockmap", new: https://github.com/translated/tav-releases/releases/download/6.3.0-beta.8/TAV.exe.blockmap)
[2018-07-20 13:00:15.343] [info] File has 859 changed blocks
[2018-07-20 13:00:15.346] [info] Full: 80,286.13 KB, To download: 17,740.52 KB (22%)
[2018-07-20 13:00:16.186] [info] Differential download: https://github.com/translated/tav-releases/releases/download/6.3.0-beta.8/TAV.exe
[2018-07-20 13:00:16.385] [info] Redirect to https://github-production-release-asset-2e65be.s3.amazonaws.com/137188552/5c4da848-8c1c-11e8-8a4c-14acfe98d6fc

//did it just die here?

C:\Users\damiano\AppData\Roaming\TAV>dir __update__
 Volume in drive C has no label.
 Volume Serial Number is 5CDB-5F5A

 Directory of C:\Users\damiano\AppData\Roaming\TAV\__update__

20/07/2018  13:00    <DIR>          .
20/07/2018  13:00    <DIR>          ..
20/07/2018  13:00         8.104.642 temp-TAV.exe // isn't this expected to be 17,740.52 KB?
               1 File(s)      8.104.642 bytes
               2 Dir(s)  256.744.120.320 bytes free

C:\Users\damiano\AppData\Roaming\TAV>

Logic is trimmed down from original post down to:

app.on('ready', async () => {
    //check for updates every minute
    if(isPacked) {
        checkForUpdates();
        setInterval(checkForUpdates, 60000);
    }
});

I see a similar weird behaviour if I:

  • install the application
  • try to reinstall the application (or newer version)

The app is closed and the installer exits before the last page (the one prompting the "run application flag").
Running the installer when the app is closed results in no error.
All the issues mentions the facts that makeSingleInstance is not a problem but I'm afraid that's the cause of it.

Any thoughts? Not sure why this issue was closed though 😅

@peterdanis
Copy link
Contributor

@damianobarbati
Please do not use quitAndInstall if you are using checkForUpdatesAndNotify. If you use only checkForUpdatesAndNotify, it will not quit your app. It will install the update automatically when you quit the app. If your app is exiting without your intervention, the issue is somewhere else.

I assume you don't use the code which you posted in the first comment (with both quitAndInstall and checkForUpdatesAndNotify).

For testing purposes you can "fake" app version by setting autoUpdater.currentVersion = "x.y.z" (maybe in conjunction with autoUpdater.allowPrerelease = true)

@damianobarbati
Copy link
Author

damianobarbati commented Jul 20, 2018

@peterdanis thanks for helping. You're correct, actual code is trimmed down to:

//single instance logic!!!
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { //eslint-disable-line
    if (window) {
        if (!state.id) {
            if(process.platform === 'win32') {
                if(window.isMinimized())
                    window.restore();
                window.focus();
            }
            else if(process.platform === 'darwin') {
                app.dock.show();
                setTimeout(() => {
                    if(window.isMinimized())
                        window.restore();
                    window.focus();
                }, 250);
            }
        }
        else {
            setTimeout(() => notifier.notifyWelcome(state.available, icons.trayAvailable, icons.trayBusy), 250);
        }
    }

    return (++runningInstances > 1);
});

if (shouldQuit) {
    app.quit();
}

//autoupdate logic!!!
app.on('ready', async () => {
    //check for updates every minute
    if(isPacked) {
        checkForUpdates();
        setInterval(checkForUpdates, 60000);
    }
});

const checkForUpdates = () => {
    autoUpdater.checkForUpdatesAndNotify(); //no need for quitAndInstall => https://github.com/electron-userland/electron-builder/issues/2977#issuecomment-397887981
};

const createWindow = () => {
    //...logic 

    window.on('close', () => {
        app.quit();
        window = null;
    });

    window.on('closed', () => {
        app.quit();
        window = null;
    });

    //...logic 
}

How can I fake the upgrade like that? I always need to:

  • change the logic into the installed the application on Windows
  • thus packing it first and then publishing it to github
  • then push another version to let the previous installed with new logic installation trigger the upload to the new one

@damianobarbati
Copy link
Author

@peterdanis may this be the cause in some way? Does checkForUpdatesAndNotify involves the same behaviour?

Note: autoUpdater.quitAndInstall() will close all application windows first and only emit before-quit event on app after that. This is different from the normal quit event sequence.

@peterdanis
Copy link
Contributor

peterdanis commented Jul 20, 2018

checkForUpdatesAndNotify does not close your app windows for sure. Its standard behavior is to check for update, download it, notify user (there is an issue with notifications in 1709+ Win10, check electron/electron#10864) and install the update in the background when user (or something else) closes the app.

For testing:

  • set autoUpdater.currentVersion = "6.1.0" anywhere before you call the update logic
  • package the app locally (on your PC/vm)
  • run it

No need to push it to Github.

@damianobarbati
Copy link
Author

Smart move, thanks @peterdanis! I'm packing locally triggering the update without pushing to GitHub.

However the app just dies in the middle of downloading update with no error.
I tried removing the makeSingleInstance logic but it doesn't matter.
Notification with checkForUpdatesAndNotify never worked.

Any idea? I've run out of ideas 😔

@brennomarques
Copy link

Do you want some help, for example: I have an application that can update what this server does not, but it downloads that update but does not update, something that is missing? follow my .json and main.js

{
  "name": "assistente",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "dist": "electron-builder"
  },
  "build": {
    "appId": "com.example.app",
    "publish": [
      {
        "provider": "generic",
        "url": "http://localhost:80/"
      }
    ]
  },
  "devDependencies": {
    "electron": "^8.2.5",
    "electron-builder": "^22.6.0"
  },
  "dependencies": {
    "electron-log": "^4.1.2",
    "electron-updater": "^4.3.1"
  }
}
const { app, BrowserWindow, dialog } = require('electron')
const { autoUpdater } = require("electron-updater")
const log = require('electron-log');

autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';


function createWindow() {
    // Cria uma janela de navegação.
    let win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntegration: true
        }
    })

    // e carregar o index.html do aplicativo.
    win.loadFile('index.html')
    autoUpdater.checkForUpdates();
}

app.whenReady().then(createWindow)

autoUpdater.on('update-available', info => {
    log.info('update-available');
    const dialogOpts = {
        type: 'info',
        buttons: ['Atualizar', 'Agora Não'],
        title: 'Atualização do Aplicativo',
        message: 'Atualização Disponível',
        detail: 'Uma nova versão do Assistente está disponível. É preciso reiniciar o aplicativo para aplicar as atualizações.'
    }

    dialog.showMessageBox(dialogOpts, (response) => {
        if (response === 0) autoUpdater.quitAndInstall()
    })

});

The .logs file looks like this ...,

[2020-05-18 11:34:00.555] [info] Checking for update
[2020-05-18 11:34:01.995] [info] Found version 2.0.0 (url: assistente Setup 2.0.0.exe)
[2020-05-18 11:34:02.001] [info] update-available
[2020-05-18 11:34:02.012] [info] Downloading update from assistente Setup 2.0.0.exe
[2020-05-18 11:34:02.028] [info] Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: r0pMhztQ0DLw1hL4ttKErU9RX1nLHC55sG2z7UDlUskA/rprCq7oVhZSUXa0qiSb2s16kapo6WAuwaBy2vSXZQ==, expected: qH+svT/BpBErAhpds6f5XeZRjNGpR+qZOcle/BQYjhIgDiQASs0siPQaCtNynelen3mbu4G5neWL9tNOeN18pw==. Directory for cached update will be cleaned
[2020-05-18 11:34:02.053] [info] Download block maps (old: "http://localhost/assistente%20Setup%201.0.0.exe.blockmap", new: http://localhost/assistente%20Setup%202.0.0.exe.blockmap)
[2020-05-18 11:34:02.093] [error] Cannot download differentially, fallback to full download: Error: Cannot download "http://localhost/assistente%20Setup%201.0.0.exe.blockmap", status 404: Not Found
    at ClientRequest.<anonymous> (C:\Users\brenno\AppData\Local\Programs\seu-app\resources\app.asar\node_modules\builder-util-runtime\out\httpExecutor.js:280:26)
    at ClientRequest.emit (events.js:210:5)
    at SimpleURLLoaderWrapper.<anonymous> (electron/js2c/browser_init.js:2510:12)
    at SimpleURLLoaderWrapper.emit (events.js:210:5)
[2020-05-18 11:34:03.697] [info] New version 2.0.0 has been downloaded to C:\Users\brenno\AppData\Local\assistente-updater\pending\assistente Setup 2.0.0.exe
[2020-05-18 11:34:06.910] [info] Auto install update on quit
[2020-05-18 11:34:06.918] [info] Install: isSilent: true, isForceRunAfter: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants