PowerToys插件擴展(類似Alfred)


在mac系統除了自帶的Spotlight還有一個很好用的工具叫Alfred

image
image

在windows系統也有一個很好用的工具叫PowerToys,是微軟的一個開源項目

image
image

https://github.com/microsoft/PowerToys

從上面的github地址可以下載安裝包。

image
image

它有很多快捷功能,請大家自己研究吧。今天要說的是PowerToys Run

image
image

默認的喚起快捷鍵是 Alt+Space

但是PowerToys Run有一個問題,就是自帶的文件搜索功能是基於系統索引的,搜索的速度慢,還經常找不到我想要找的文件。看見很多人在Issue里面提希望能支持Everything搜索,官方說有社區提供了插件了 https://github.com/IzaiahSun/PowerToys

從這個大佬的releases里面下載下來

image
image

然后定位到zip里的modules\launcher\plugins,將整個Community.PowerToys.Run.Plugin.Everything文件夾復制到系統中已經安裝好的PowerToys目錄\modules\launcher\Plugins中,最后重啟PowerToys即可!

下面才是重點:

PowerToys Run的功能在開始以插件的形式提供之后,想要擴展自己的功能是非常簡單的,我們只需要寫代碼加入自己的邏輯就好了。

因為我經常會用idea,我就寫了幾行代碼來擴展一下,如果是java項目的文件夾,可以直接用idea打開。效果如下圖:

image
image

//判斷是否為java工程文件夾
public static bool CanRunIdea(string path)
{
    if (File.Exists(path))
    {
        return path.EndsWith("pom.xml");
    }

    var buildGradleFile = System.IO.Path.Combine(path, "build.gradle");
    if (File.Exists(buildGradleFile))
    {
        return true;
    }

    var pomFile = System.IO.Path.Combine(path, "pom.xml");
    if (File.Exists(pomFile))
    {
        return true;
    }

    return false;
}

//創建運行idea的按鈕以及點擊按鈕事件的觸發
private static ContextMenuResult CreateRunIdeaContextMenu(SearchResult record)
{
    return new ContextMenuResult
    {
        PluginName = Assembly.GetExecutingAssembly().GetName().Name,
        Title = Properties.Resources.Community_plugin_everything_run_as_idea,
        Glyph = "\xEC58",
        FontFamily = "Segoe MDL2 Assets",
        AcceleratorKey = Key.F1,
        AcceleratorModifiers = ModifierKeys.Windows,
        Action = _ =>
        {
            try
            {
                Task.Run(() => {
                    var idea = Environment.GetEnvironmentVariable("idea");
                    if (string.IsNullOrEmpty(idea))
                    {
                        RunCommand($"idea \"{record.FullPath}\"", record.FullPath);
                    }
                    else
                    {
                        RunCommand($"\"{idea}\" \"{record.FullPath}\"", record.FullPath);
                    }
                });
                return true;
            }
            catch (System.Exception e)
            {
                Log.Exception($"Failed to run {record.FullPath} as idea, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType);
                return false;
            }
        },
    };
}

代碼很簡單,如果識別到了是java項目文件夾,就展示一個icon圖標按鈕,點擊用idea打開。

idea的啟動path 你可以配置在環境變量里面,

image
image

如果你用是Toolsbox的話,idea會經常更新版本,每次升級都得重新改環境變量嫌麻煩,那么Toolsbox的這個功能可以設置下

image
image

然后把上圖中的Shell腳本的文件夾設置到 環境變量的PATH里面 就一勞永逸了!

image
image

想要獲取我更改后的EveryThing插件的可以公眾號發送文本文字:PowerToys

下載后解壓到你本機PowerToys目錄

比如我的本機是:

C:\Program Files\PowerToys\modules\launcher\Plugins

image

 

Enjoy!!!

關注公眾號,我開發的開源工具分享給你!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM