pulsar-edit / pulsar

A Community-led Hyper-Hackable Text Editor
https://pulsar-edit.dev
Other
3.21k stars 133 forks source link

Add Pulsar to PATH #978

Open zhaolinlau opened 4 months ago

zhaolinlau commented 4 months ago

Thanks in advance for your bug report!

What happened?

When I check the Add Pulsar to PATH, it pops up errors as below:

Error Running Script: Error: Command failed: powershell.exe -File 'C:\Users\Win10\AppData\Local\Programs\Pulsar\resources\modifyWindowsPath.ps1' -installdir 'C:\Users\Win10\AppData\Local\Programs\Pulsar' -remove FALSE File C:\Users\Win10\AppData\Local\Programs\Pulsar\resources\modifyWindowsPath.ps1 cannot be loaded. The file C:\Users\Win10\AppData\Local\Programs\Pulsar\resources\modifyWindowsPath.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. + CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnauthorizedAccess

Pulsar version

1.116.0

Which OS does this happen on?

🪟 Windows

OS details

11

Which CPU architecture are you running this on?

x86_64/AMD64

What steps are needed to reproduce this?

  1. add powershell.exe to path
  2. download and install pulsar
  3. run pulsar as admin
  4. check the Add Pulsar to PATH
  5. the errors come up

Additional Information:

No response

confused-Techie commented 4 months ago

Thanks a ton for reporting this!

There's a few things I want to go ahead and clarify on whats going on here:

1) Did you need to run Pulsar as Admin? This should no longer be required to add Pulsar to the PATH no matter if you have a per-user or system install. But if that was giving you any errors that'd be awesome to know. 2) Would you mind checking the current ExecutionPolicy of your system? Just running Get-ExecutionPolicy in any PowerShell terminal should return this information to you.

Also you mentioned having to add PowerShell to the PATH on Windows, I was under the assumption it should always be in the PATH just like cmd or other internal Windows essentials. Is this something you had removed? Or is this a work device that is significantly locked down?


To clarify on expected behavior with the reworked PATH adding of Pulsar v1.116.0 it should look like:

  1. Launch Pulsar v1.116.0
  2. Check Add Pulsar to PATH
  3. It just works, no manual need to modify PATH, or run anything as admin.

(Just adding the above to make sure everyone's on the same page)

DeeDeeG commented 4 months ago

FWIW, if I do Set-ExecutionPolicy -Scope CurrentUser Default (which sets the policy to Restricted, see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4)...

Then it gives me an error that the script cannot be run.

If I do Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, then it works as intended (with the usual requirement of restarting before it takes effect for cmd.exes or other terminals one might open).

(I must have had it on RemoteSigned during testing for the updated/simplified "Add Pulsar to PATH" checkbox. I believe it is quite popular (for people who actually intend to run powershell .ps1 scripts on their non-server Windows machines) to set RemoteSigned Execution Policy.)

confused-Techie commented 4 months ago

@DeeDeeG Well I'll be. Seems mine is also on RemoteSigned likely due to previous work I've done, without realizing I had it changed during development of this feature.

Seems strange that it would suddenly break now, when we were able to run a PowerShell script just fine before.

But regardless with this now being an issue, I wonder what our best way of resolving it is. Since we don't sign Pulsar on Windows at all due to cost

DeeDeeG commented 4 months ago

If it's possible to re-write in cmd.exe or "do it in JS", that might be the best thing? Since I don't think batch/cmd scripts are locked down in quite the same way? (And we're definitely allowed to run JS if we've gotten this far, heh.)

confused-Techie commented 4 months ago

@DeeDeeG While technically we could do it in cmd we would then be relegated to the setx command only, which I know we've previously discussed the downsides.

I wonder if we could maybe do:

  1. Sign only this file in some none uber expensive way
  2. Load the script into a child process as PowerShell and just run it as if it was running on the terminal. Not sure if that'd actually get around the issue, but might be worth a try