microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
109.5k stars 6.45k forks source link

PowerToys Run Web Search plugin can't open Arc #32782

Open hankyusa opened 4 months ago

hankyusa commented 4 months ago

Microsoft PowerToys version

0.80.1

Installation method

Microsoft Store

Running as admin

No

Area(s) with issue?

PowerToys Run

Steps to reproduce

  1. Set the default browser as Arc.
  2. Enable PoerToys Run and the built-in Web Search plugin with direct activation command set to "??".
  3. Trigger PowerToys Run, type "?? my search query".
  4. Select the "Search the web in Arc" option.

✔️ Expected Behavior

Open a new tab in Arc and navigate to search results page for "my search query".

❌ Actual Behavior

Sometimes an error message appears saying "Failed to open Arc". Other times focus switches to Arc, but no new tab is opened.

Other Software

Arc from The Browser Company

github-actions[bot] commented 4 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

hankyusa commented 4 months ago

Possible duplicate of #31803.

hankyusa commented 4 months ago

I can't find Arc on the Microsoft Store, but according to u/itmeBlurb "it installs using Microsoft's App Installer format, which is ran through the MS Store."

This makes me believe the issue is Wox.Plugin.Common.DefaultBrowserInfo.Path since that had a similar issue (#19260) when Firefox was installed through the Microsoft Store. I think the fix (#20350) should be similar.

I was going to submit a pull request, but don't really know what I'm doing. Here's my the change I'd make to src/modules/launcher/Wox.Plugin/Common/DefaultBrowserInfo.cs.

                    // HACK: for browsers installed through Microsoft Store
                    // When installed through Microsoft Store the commandPattern does not have
                    // quotes for the path. As the Program Files does have a space
                    // the extracted path would be invalid, here we add the quotes to fix it.
                    const string ArcExecutableName = "arc.exe";
                    const string FirefoxExecutableName = "firefox.exe";
                    string executableName = commandPattern.Contains(ArcExecutableName) ? ArcExecutableName : commandPattern.Contains(FirefoxExecutableName) ? FirefoxExecutableName : '';
                    if (!string.IsNullOrEmpty(executableName) && commandPattern.Contains(@"\WindowsApps\") && (!commandPattern.StartsWith('\"')))
                    {
                        var pathEndIndex = commandPattern.IndexOf(executableName, StringComparison.Ordinal) + executableName.Length;
                        commandPattern = commandPattern.Insert(pathEndIndex, "\"");
                        commandPattern = commandPattern.Insert(0, "\"");
                    }
ethanfangg commented 4 months ago

I can't find Arc on the Microsoft Store, but according to u/itmeBlurb "it installs using Microsoft's App Installer format, which is ran through the MS Store."

This makes me believe the issue is Wox.Plugin.Common.DefaultBrowserInfo.Path since that had a similar issue (#19260) when Firefox was installed through the Microsoft Store. I think the fix (#20350) should be similar.

I was going to submit a pull request, but don't really know what I'm doing. Here's my the change I'd make to src/modules/launcher/Wox.Plugin/Common/DefaultBrowserInfo.cs.

                    // HACK: for browsers installed through Microsoft Store
                    // When installed through Microsoft Store the commandPattern does not have
                    // quotes for the path. As the Program Files does have a space
                    // the extracted path would be invalid, here we add the quotes to fix it.
                    const string ArcExecutableName = "arc.exe";
                    const string FirefoxExecutableName = "firefox.exe";
                    string executableName = commandPattern.Contains(ArcExecutableName) ? ArcExecutableName : commandPattern.Contains(FirefoxExecutableName) ? FirefoxExecutableName : '';
                    if (!string.IsNullOrEmpty(executableName) && commandPattern.Contains(@"\WindowsApps\") && (!commandPattern.StartsWith('\"')))
                    {
                        var pathEndIndex = commandPattern.IndexOf(executableName, StringComparison.Ordinal) + executableName.Length;
                        commandPattern = commandPattern.Insert(pathEndIndex, "\"");
                        commandPattern = commandPattern.Insert(0, "\"");
                    }

@hankyusa, @jaimecbernardo might be able to help consult here if you submit a PR, does look similar to https://github.com/microsoft/PowerToys/issues/19260 and the fix https://github.com/microsoft/PowerToys/pull/20350

TheRedDeveloper commented 1 week ago

I tried fixing this in the code, but it's seemingly impossible. To fix this follow these simple steps:

  1. Create a .bat file wherever you want, named whatever you want, containing this code:
    @echo off
    setlocal enabledelayedexpansion
    set "input=%*"
    if "%input:~0,1%"=="?" (
    set "search=%input:~2%"
    if /i "!search:~0,4!"=="http" (
        set "url=!search!"
    ) else (
        set "url=https://www.google.com/search?q=!search: =+!"
    )
    ) else (
    set "url=%input%"
    )
    C:\Windows\System32\rundll32.exe url.dll,FileProtocolHandler !url!
    endlocal
  2. Open the Registry Editor.
  3. Paste this into the path bar at the top:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
  4. Look for the thing called ProgId, double click it and copy the value data.
  5. In the path bar at the top, go to HKEY_CLASSES_ROOT\[INSERT YOUR COPIED VALUE DATA HERE]\shell\open\command. Remember to insert your copied value data.
  6. Go back to your .bat file and copy the path to it by going left-click > Copy as path on Windows 11 or Home > Copy path on Windows 10.
  7. Go back to the Registry Editor window, double click on (Default) and paste in the path you just copied.
  8. Just restart PowerToys
sonniydsgn commented 1 week ago

@TheRedDeveloper, cool solution, thank you! The only pity is that the Cyrillic alphabet is not processed, because it needs to be encoded

As far as I know, batch doesn't have any easy solutions for this, so I'm trying to rewrite it in another language

TheRedDeveloper commented 1 week ago

@sonniydsgn Yeah, this was just a quick and dirty solution, using .bat files in production is generally a horrible idea. They're literally called batch because they're for quickly batching programs together. Somebody should make a quick .exe with Rust or Python, maybe I'll do that.

TheRedDeveloper commented 1 week ago

@sonniydsgn I coded a clean solution in Rust. https://github.com/TheRedDeveloper/ArcRunner Everyone, go use it. It's super easy to use, and has proper URL-Encoding.

[!IMPORTANT]
Don't forget to leave the repository a star.