mongodb-js / electron-squirrel-startup

Default Squirrel.Windows event handler for your Electron apps.
Apache License 2.0
217 stars 41 forks source link

No shortcut when using "requested-execution-level": "requireAdministrator" #37

Open tymmesyde opened 5 years ago

tymmesyde commented 5 years ago

I'm using forge and I need to request admin rights for my app but when i do that, there no shortcut created on the Desktop. When i remove requested-execution-level from my package.json, it works. What should I do ?

"forge": {
      "packagerConfig": {
        "name": "MyApp",
        "win32metadata": {
          "requested-execution-level": "requireAdministrator"
        }
      },
gogomarine commented 4 years ago

Same here. Pretty wired.

gogomarine commented 4 years ago

I just resolve this problem by handling squirrel event: --squirrel-firstrun, based on project electron-squirrel-startup

You can check my code below. In my case I just quit immediately after create shortcut on firstrun.

var path = require('path');
var spawn = require('child_process').spawn;
var app = require('electron').app;

var run = function(args, done) {
  var updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
  // debug('Spawning `%s` with args `%s`', updateExe, args);
  spawn(updateExe, args, {
    detached: true
  }).on('close', done);
};

var check = function() {
  if (process.platform === 'win32') {
    var cmd = process.argv[1];
    // debug('processing squirrel command `%s`', cmd);
    var target = path.basename(process.execPath);

    if (cmd === '--squirrel-firstrun') {
      run(['--createShortcut=' + target + ''], app.quit);
      return true;
    }

    if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
      run(['--createShortcut=' + target + ''], app.quit);
      return true;
    }
    if (cmd === '--squirrel-uninstall') {
      run(['--removeShortcut=' + target + ''], app.quit);
      return true;
    }
    if (cmd === '--squirrel-obsolete') {
      app.quit();
      return true;
    }

  }
  return false;
};

module.exports = check();
hivenet-adnanetellou commented 2 years ago

Hey thanks for the hint I'd like to do the same, but if my app declares "requested-execution-level": "requireAdministrator" No Squirel hook is being called (so I don't get a --squirrel-uninstall for ex) Did you found a solution for this ?

deleonjulio commented 1 month ago

Same here, any update?