electron / windows-installer

Build Windows Installers for Electron apps
MIT License
1.56k stars 261 forks source link

Installer does not create StartMenu and Desktop shortcuts #251

Open ltomov opened 6 years ago

ltomov commented 6 years ago

The installer installs the app into some %APPDATA% folder and user has no way of finding the app or launching it.

In order to create these shortcuts I now go into this folder and run the Update.exe with some parameters and it creates the shortcuts, but the installer itself does not do it automatically.

I'm surprised that this has not been reported already - is this something that used to work before? I'm using Windows 10.

benjtinsley commented 6 years ago

@ltomov I ran into this same issue. As far as I can tell, this is a bypass squirrel windows does to install apps, instead of doing it in Program Files. I'm not quite sure the benefit of doing it this way, but it may be related to the autoupdates.

to get the installation working, you'll need to configure your squirrel updater.

i have something like this right near the top of my main.js file:

import { app } from 'electron'

if (require('electron-squirrel-startup')) app.quit()
// if first time install on windows, do not run application, rather
// let squirrel installer do its work
const setupEvents = require('./installers/setup-events')
if (setupEvents.handleSquirrelEvent()) {
  process.exit()
}

your package.json file will obviously need that electron-squirrel-startup package installed.

then my installer/setup-events.js looks like this:

import { app } from 'electron'

// check out https://github.com/electron/windows-installer#handling-squirrel-events
// for more information on squirrel events for windows

module.exports = {
  handleSquirrelEvent: function() {
    if (process.argv.length === 1) {
      return false
    }

    const ChildProcess = require('child_process')
    const path = require('path')

    const appFolder = path.resolve(process.execPath, '..')
    const rootAtomFolder = path.resolve(appFolder, '..')
    const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'))
    const exeName = path.basename(process.execPath)

    const spawn = function(command, args) {
      let spawnedProcess

      try {
        spawnedProcess = ChildProcess.spawn(command, args, { detached: true })
      } catch (error) {
        console.warn(error)
      }

      return spawnedProcess
    }

    const spawnUpdate = function(args) {
      return spawn(updateDotExe, args)
    }

    const squirrelEvent = process.argv[1]
    switch (squirrelEvent) {
      case '--squirrel-install':
      case '--squirrel-updated':
        // Optionally do things such as:
        // - Add your .exe to the PATH
        // - Write to the registry for things like file associations and
        //   explorer context menus

        // Install desktop and start menu shortcuts
        spawnUpdate(['--createShortcut', exeName])

        setTimeout(app.quit, 1000)
        break

      case '--squirrel-uninstall':
        // Undo anything you did in the --squirrel-install and
        // --squirrel-updated handlers

        // Remove desktop and start menu shortcuts
        spawnUpdate(['--removeShortcut', exeName])

        setTimeout(app.quit, 1000)
        break

      case '--squirrel-obsolete':
        // This is called on the outgoing version of your app before
        // we update to the new version - it's the opposite of
        // --squirrel-updated

        app.quit()
        break
    }
  }
}

this is taken pretty much straight from the README of this repo with a few changes to remove unused vars.

this has worked for me, hopefully it will do the same for you. however, the app is still installed in appData, which i think confuses any windows signtool verification programs.

ltomov commented 6 years ago

@benjtinsley thanks a lot for the explanation - I'll try that.

itzsaga commented 5 years ago

What @benjtinsley wrote above works for me.

Jotune commented 5 years ago

Default behavior should not create a desktop or start menu shortcuts anyway. An app can be portable or run from a removable device.

If you need this feature as default, you can have a look to electron-squirrel-startup

issue should be closed

Madeindreams commented 3 years ago

In my case. I first struggle to get the icon to be picked up by the packaging process.

Using electron-builder I was getting a warning like what the default icon would be used.

So on the first installation i had the default icon on my desktop and the start menu. But i was trying to get my own icon. I achieved that by using the right config in the package.json and after many installation the icon was not getting added to the desktop even if I had deleted the first default one.

It's only after performing an uninstall from windows that the next install added the right icon back to the desktop. So you might want to try that.