Electron builder App takes long time to open after intalling Update

50 Views Asked by At

My application takes a long time to start again once the download has finished and installed the application. The application by itself only takes 2 seconds to open, but after updating, i.e. after running autoUpdater.quitAndInstall(true,true); the application closes and then takes about 50 seconds to open again. This is too long for the good user experience.

Using Angular with NSIS target with windows and S3.

package.json

{
  "name": "MyApp",
  "version": "1.0.0",
  "description": "My application",
  "author": "Author",
  "license": "ISC",
  "productName": "MyApp",
  "main": "main.js",
  "build": {
    "appId": "com.MyApp.DesktopApp",
    "asar": true,
    "win": {
      "target": [
        {
          "target": "nsis",
          "arch": [
            "x64"
          ]
        }
      ],
      "icon": "assets/desktop-app-logo.ico"
    },
    "nsis": {
      "installerIcon": "assets/logo-accent.ico",
      "uninstallerIcon": "assets/logo-accent.ico",
      "uninstallDisplayName": "MyApp",
      "oneClick": false,
      "artifactName": "MyApp-Setup-${version}.${ext}",
      "allowToChangeInstallationDirectory": true,
      "deleteAppDataOnUninstall": true
    },
    "files": [
        "*.*",
        "**/*",
        "node_modules/electron-updater/**/*",
        "node_modules/builder-util-runtime/**/*",
        "node_modules/graceful-fs/**/*",
        "node_modules/lazy-val/**/*",
        "node_modules/lodash.escaperegexp/**/*",
        "node_modules/lodash.isequal/**/*",
        "node_modules/sax/**/*",
        "node_modules/argparse/**/*",
        "node_modules/debug/**/*",
        "node_modules/fs-extra/**/*",
        "node_modules/jsonfile/**/*",
        "node_modules/js-yaml/**/*",
        "node_modules/lodash.escaperegexp/**/*",
        "node_modules/lodash.isequal/**/*",
        "node_modules/lru-cache/**/*",
        "node_modules/ms/**/*",
        "node_modules/rxjs/**/*",
        "node_modules/semver/**/*",
        "node_modules/tslib/**/*",
        "node_modules/typed-emitter/**/*",
        "node_modules/universalify/**/*",
        "node_modules/yallist/**/*",
        "node_modules/electron-log/**/*",
        "!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
        "!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
        "!**/node_modules/*.d.ts"
      ],
    "directories": {
      "output": "../installer"
    },
    "publish": {
      "provider": "s3",
      "bucket": "myBucket",
      "path": "desktop-repo",
      "region": "eu-west-1",
      "endpoint": "https://s3.eu-west-1.amazonaws.com"
    }
  },
  "dependencies": {
    "electron-updater": "6.1.1",
    "electron-log": "4.4.8"
  },
  "devDependencies": {
    "electron": "22.0.0",
    "electron-builder": "24.6.3"
  },
  "scripts": {
    "electron-installer-build": "electron-builder",
    "electron-installer-publish": "electron-builder -p always"
  }
}

Note: The reason for the long list of files in the files parameter is so that electron builder and all of it's dependencies gets copied over to the directory which is used to package the electron application.

Updater code in main.js

autoUpdater.on('error', (error) => {
  dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString())
})

autoUpdater.on('update-available', () => {
  dialog.showMessageBox({
    type: 'info',
    title: 'Found Updates',
    message: 'Found updates, do you want update now?',
    buttons: ['Sure', 'No']
  }).then((buttonIndex) => {
    if (buttonIndex === 0) {
      autoUpdater.downloadUpdate()
    }
    else {
      updater.enabled = true
      updater = null
    }
  })
})

autoUpdater.on('update-not-available', () => {
  dialog.showMessageBox({
    title: 'No Updates',
    message: 'Current version is up-to-date.'
  })
  updater.enabled = true
  updater = null
})

autoUpdater.on('update-downloaded', () => {
  dialog.showMessageBox({
    title: 'Install Updates',
    message: 'Updates downloaded, application will be quit for update...'
  }).then(() => {
    autoUpdater.quitAndInstall(true, true)
  })
})

So after running autoUpdater.quitAndInstall(true, true) the application closes , uninstalls, installs the new update and relaunches it successfully. However the time it takes to do all of this is too long. If I was to manually uninstall the application, reinstall it and launch the application myself it would not take that long. Is there anything I ccan do to decrease the time?

0

There are 0 best solutions below