electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.45k stars 513 forks source link

Using Electron-Forge make, creating start menu shortcut on windows #191

Closed ghost closed 7 years ago

ghost commented 7 years ago

Please describe your issue:

I've spent the weekend trying to get a basic app installed on windows. The squirrel installer makes the executable just fine, and installs it in the %appdata% folder (even accessible from Control Panel -> Programs & Features), but does not create a shortcut anywhere that can be searched for from the start menu. I'm packaging the software for coworkers who I don't necessarily trust to find the executable without a shortcut.

I tried using the Electron-Winstaller blurb on handling Squirrel Events, but it doesn't create the shortcut, and when I run the setup.exe it asks me if my index.js (main) was compiled.

How do I use 'Electron-Forge make' and yet still influence squirrel to create a start menu shortcut?

*Console output when you run electron-forge with the environment variable `DEBUG=electron-forge:`. (Instructions on how to do so here). Please include the stack trace if one exists.**

Put the console output here

What command line arguments are you passing?

Put the arguments here

What does your config.forge data in package.json look like?

"config": {
    "forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "dmg"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {
        "asar": true,
        "quiet": true,
        "icon": "./build/icon",
        "win32metadata": {
          "CompanyName": "***",
          "ProductName": "Auth Time"
        }
      },
      "electronInstallerDMG": {
        "appPath": "***",
        "name": "AuthTime",
        "icon": "./build/icon"
      },
      "electronWinstallerConfig": {
        "appDirectory": "./out/AuthTime-win32",
        "setupIcon": "./build/icon.ico",
        "setupExe": "setup.exe",
        "setupMSI": "setup.msi",
        "noMsi": false
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "jonpowers",
        "name": "authtime"
      },
      "windowsStoreConfig": {
        "packageName": "***"
      }
    }
  }

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-forge init is a good starting point, if that is not the source of your problem.

MarshallOfSound commented 7 years ago

I tried using the Electron-Winstaller blurb on handling Squirrel Events

Without any code or tangible errors to share I cant help you with this. If you post you're code or the error messages you are getting (with traces) I can try help you out.

That said, this is more of a question than an issue so closing out for now. If you provide the information I'll help you out in this issue thread :+1:

ghost commented 7 years ago

I don't know how to get that output. I added DEBUG=electron-forge:* as a command line arg and it did nothing different. I also don't see any verbose flag for electron-forge make.

MarshallOfSound commented 7 years ago

Can you provide the code you are using to try make the shortcut?

ghost commented 7 years ago

This is at the top of the entry point to my application, before mainWindow is created. I used the Electron-Forge init boilerplate.

var app = require('app');
var path = require('path');
var cp = require('child_process');

var handleSquirrelEvent = function() {
   if (process.platform != 'win32') {
      return false;
   }

   function executeSquirrelCommand(args, done) {
      var updateDotExe = path.resolve(path.dirname(process.execPath), 
         '..', 'update.exe');
      var child = cp.spawn(updateDotExe, args, { detached: true });

      child.on('close', function(code) {
         done();
      });
   };

   function install(done) {
      var target = path.basename(process.execPath);
      executeSquirrelCommand(["--createShortcut", target], done);
   };

   function uninstall(done) {
      var target = path.basename(process.execPath);
      executeSquirrelCommand(["--removeShortcut", target], done);
   };

   var squirrelEvent = process.argv[1];

   switch (squirrelEvent) {

      case '--squirrel-install':
         install(app.quit);
         return true;

      case '--squirrel-updated':
         install(app.quit);
         return true;

      case '--squirrel-obsolete':
         app.quit();
         return true;

      case '--squirrel-uninstall':
         uninstall(app.quit);
         return true;
   }

   return false;
};

if (handleSquirrelEvent()) {
   return;
}
MarshallOfSound commented 7 years ago

Can't see anything obviously wrong with that code. Does your apps name have a space in it?

Can you upload the SquirrelSetup log file from your local install, should have some useful logging info

Lastly can you set the stdio of the child process to inherit and then launch the installed exe file from command prompt. You should see any logs come through correctly.

ghost commented 7 years ago

I took out the space in my app's name, but it is still failing.

SquirrelSetup.log:

2017-04-03 10:13:31> Program: Starting Squirrel Updater: --install .
2017-04-03 10:13:36> Program: Starting install, writing to C:\Users\jpowers\AppData\Local\SquirrelTemp
2017-04-03 10:13:41> Program: About to install to: C:\Users\jpowers\AppData\Local\AuthTime
2017-04-03 10:13:47> CheckForUpdateImpl: Couldn't write out staging user ID, this user probably shouldn't get beta anything: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\jpowers\AppData\Local\AuthTime\packages\.betaId'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
   at System.IO.File.WriteAllText(String path, String contents, Encoding encoding)
   at Squirrel.UpdateManager.CheckForUpdateImpl.getOrCreateStagedUserId()
2017-04-03 10:13:47> CheckForUpdateImpl: Failed to load local releases, starting from scratch: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\jpowers\AppData\Local\AuthTime\packages\RELEASES'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Squirrel.Utility.LoadLocalReleases(String localReleaseFile)
   at Squirrel.UpdateManager.CheckForUpdateImpl.<CheckForUpdate>d__2.MoveNext()
2017-04-03 10:13:48> CheckForUpdateImpl: Reading RELEASES file from C:\Users\jpowers\AppData\Local\SquirrelTemp
2017-04-03 10:13:49> CheckForUpdateImpl: First run or local directory is corrupt, starting from scratch
2017-04-03 10:13:51> ApplyReleasesImpl: Writing files to app directory: C:\Users\jpowers\AppData\Local\AuthTime\app-1.0.0
2017-04-03 10:13:52> LogHost: Rigging execution stub for lib/net45/AuthTime_ExecutionStub.exe to C:\Users\jpowers\AppData\Local\AuthTime\AuthTime.exe
2017-04-03 10:14:28> ApplyReleasesImpl: Squirrel Enabled Apps: [C:\Users\jpowers\AppData\Local\AuthTime\app-1.0.0\AuthTime.exe]
2017-04-03 10:14:46> ApplyReleasesImpl: Couldn't run Squirrel hook, continuing: C:\Users\jpowers\AppData\Local\AuthTime\app-1.0.0\AuthTime.exe: System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at Squirrel.Utility.<>c__DisplayClass11_0.<InvokeProcessAsync>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Squirrel.Utility.<InvokeProcessAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Squirrel.UpdateManager.ApplyReleasesImpl.<>c__DisplayClass10_0.<<invokePostInstall>b__0>d.MoveNext()
2017-04-03 10:14:47> ApplyReleasesImpl: Starting fixPinnedExecutables
2017-04-03 10:14:47> ApplyReleasesImpl: Examining Pin: Adobe Acrobat Reader DC .lnk
2017-04-03 10:14:47> ApplyReleasesImpl: Examining Pin: Brackets.lnk
2017-04-03 10:14:47> ApplyReleasesImpl: Examining Pin: Command Prompt (2).lnk
2017-04-03 10:14:47> ApplyReleasesImpl: Examining Pin: Command Prompt.lnk
2017-04-03 10:14:48> ApplyReleasesImpl: Examining Pin: Google Chrome.lnk
2017-04-03 10:14:48> ApplyReleasesImpl: Examining Pin: GroupWise.lnk
2017-04-03 10:14:48> ApplyReleasesImpl: Examining Pin: JetBrains WebStorm 2016.3.3.lnk
2017-04-03 10:14:48> ApplyReleasesImpl: Examining Pin: Microsoft Office Excel 2007.lnk
2017-04-03 10:14:48> ApplyReleasesImpl: Examining Pin: notepad++.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Examining Pin: SQL Server 2014 Management Studio.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Examining Pin: Sublime Text 3.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Examining Pin: Visual Studio 2017.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Examining Pin: Windows Explorer.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Examining Pin: Windows PowerShell ISE.lnk
2017-04-03 10:14:49> ApplyReleasesImpl: Fixing up tray icons
2017-04-03 10:14:50> ApplyReleasesImpl: Couldn't rewrite shim RegKey, most likely no apps are shimmed: System.NullReferenceException: Object reference not set to an instance of an object.
   at Squirrel.UpdateManager.ApplyReleasesImpl.<unshimOurselves>b__13_0(RegistryView view)
2017-04-03 10:14:50> ApplyReleasesImpl: Couldn't rewrite shim RegKey, most likely no apps are shimmed: System.NullReferenceException: Object reference not set to an instance of an object.
   at Squirrel.UpdateManager.ApplyReleasesImpl.<unshimOurselves>b__13_0(RegistryView view)
2017-04-03 10:14:50> ApplyReleasesImpl: cleanDeadVersions: for version 1.0.0
2017-04-03 10:14:50> ApplyReleasesImpl: cleanDeadVersions: exclude folder app-1.0.0
ghost commented 7 years ago

And I honestly don't know how to approach your third request, but I'm searching

MarshallOfSound commented 7 years ago

No need, there's your issue.

2017-04-03 10:14:46> ApplyReleasesImpl: Couldn't run Squirrel hook, continuing: C:\Users\jpowers\AppData\Local\AuthTime\app-1.0.0\AuthTime.exe: System.OperationCanceledException: The operation was canceled.

Not sure why the hook would fail with that message but that's why your shortcut isn't being made. The hook isn't being called at still.

Should do some research into that error message and try figure out what's going on. Peruse the issues over at Squirrel.Windows, one of them might point you in a good direction.

ghost commented 7 years ago

Thank you for your help! I may have a few more questions as this search isn't turning up too much.

I'm curious though, am I asking these questions in the right place?

vitorregisrr commented 5 years ago

But how can i just do not create this shortcut? My client dont wanna it, there is a way?

malept commented 5 years ago

If you don't want the shortcut, don't use electron-squirrel-startup.

vitorregisrr commented 5 years ago

How can i desabilite that using electron forge? This is done by default.

malept commented 5 years ago

Remove the module from package.json and from your src/index.js (or whatever your main javascript/typescript/etc. file is named).