Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Apr 11, 2023
1 parent db09f7b commit b09f26b
Show file tree
Hide file tree
Showing 23 changed files with 339 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

!*/Libs/x64
!*/Libs/ARM64
19 changes: 19 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$ErrorActionPreference = "Stop"

[xml]$xml = Get-Content -Path "$PSScriptRoot\Directory.Build.Props"
$version = $xml.Project.PropertyGroup.Version

foreach ($platform in "ARM64", "x64")
{
if (Test-Path -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken\bin")
{
Remove-Item -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken\bin\*" -Recurse
}

dotnet build $PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken.sln -c Release /p:Platform=$platform

Remove-Item -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken\bin\*" -Recurse -Include *.xml, *.pdb, PowerToys.*, Wox.*
Rename-Item -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken\bin\$platform\Release" -NewName "GitKraken"

Compress-Archive -Path "$PSScriptRoot\Community.PowerToys.Run.Plugin.GitKraken\bin\$platform\GitKraken" -DestinationPath "$PSScriptRoot\GitKraken-$version-$platform.zip"
}
31 changes: 31 additions & 0 deletions Community.PowerToys.Run.Plugin.GitKraken.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Community.PowerToys.Run.Plugin.GitKraken", "Community.PowerToys.Run.Plugin.GitKraken/Community.PowerToys.Run.Plugin.GitKraken.csproj", "{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Debug|ARM64.ActiveCfg = Debug|ARM64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Debug|ARM64.Build.0 = Debug|ARM64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Debug|x64.ActiveCfg = Debug|x64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Debug|x64.Build.0 = Debug|x64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Release|ARM64.ActiveCfg = Release|ARM64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Release|ARM64.Build.0 = Release|ARM64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Release|x64.ActiveCfg = Release|x64
{59418FCB-BD51-4002-ABAB-3AFE7E516E1F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A57D8BAF-CEE6-4F90-B091-3C3741005E77}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platforms>x64;ARM64;ARM64</Platforms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
<Reference Include="PowerToys.Common.UI">
<HintPath>Libs\x64\PowerToys.Common.UI.dll</HintPath>
</Reference>
<Reference Include="PowerToys.ManagedCommon">
<HintPath>Libs\x64\PowerToys.ManagedCommon.dll</HintPath>
</Reference>
<Reference Include="PowerToys.Settings.UI.Lib">
<HintPath>Libs\x64\PowerToys.Settings.UI.Lib.dll</HintPath>
</Reference>
<Reference Include="Wox.Infrastructure">
<HintPath>Libs\x64\Wox.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Wox.Plugin">
<HintPath>Libs\x64\Wox.Plugin.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM64'">
<Reference Include="PowerToys.Common.UI">
<HintPath>Libs\ARM64\PowerToys.Common.UI.dll</HintPath>
</Reference>
<Reference Include="PowerToys.ManagedCommon">
<HintPath>Libs\ARM64\PowerToys.ManagedCommon.dll</HintPath>
</Reference>
<Reference Include="PowerToys.Settings.UI.Lib">
<HintPath>Libs\ARM64\PowerToys.Settings.UI.Lib.dll</HintPath>
</Reference>
<Reference Include="Wox.Infrastructure">
<HintPath>Libs\ARM64\Wox.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Wox.Plugin">
<HintPath>Libs\ARM64\Wox.Plugin.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="Images\GitKraken.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\GitKraken.light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;

namespace Community.PowerToys.Run.Plugin.GitKraken.Helpers
{
public class RepositoryQuery
{
private readonly string _profilesPath = Environment.ExpandEnvironmentVariables(@"%APPDATA%\.gitkraken\profiles");

public IEnumerable<(string Name, string Path)> GetAll()
{
if (!Directory.Exists(_profilesPath))
{
yield break;
}

var profilesDirectories = Directory.GetDirectories(_profilesPath);
if (profilesDirectories.Length == 0)
{
yield break;
}

// TODO the directory may contain more than one profile
var localRepoCachePath = Path.Combine(profilesDirectories.First(), "localRepoCache");
if (!File.Exists(localRepoCachePath))
{
yield break;
}

using var fs = new FileStream(localRepoCachePath, FileMode.Open, FileAccess.Read);
using var sr = new StreamReader(fs);
var json = sr.ReadToEnd();
var parsed = JsonDocument.Parse(json);
parsed.RootElement.TryGetProperty("localRepoCache", out var localRepoCache);
if (localRepoCache.ValueKind != JsonValueKind.Array)
{
yield break;
}

foreach (var repo in localRepoCache.EnumerateArray())
{
if (repo.ValueKind != JsonValueKind.String)
{
continue;
}

var repoPath = repo.ToString().Replace("\\.git", string.Empty);
var directory = new DirectoryInfo(repoPath);
if (!directory.Exists)
{
continue;
}

yield return new(directory.Name, directory.FullName.TrimEnd('\\'));
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
81 changes: 81 additions & 0 deletions Community.PowerToys.Run.Plugin.GitKraken/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using Community.PowerToys.Run.Plugin.GitKraken.Helpers;
using ManagedCommon;
using Wox.Infrastructure;
using Wox.Plugin;

namespace Community.PowerToys.Run.Plugin.GitKraken
{
public class Main : IPlugin
{
private readonly RepositoryQuery _repositoryQuery;
private PluginInitContext? _context;
private string? _icoPath;

public string Name => "GitKraken";

public string Description => "Open GitKraken repositories.";

public Main()
{
_repositoryQuery = new RepositoryQuery();
}

public void Init(PluginInitContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
}

public List<Result> Query(Query query)
{
var results = new List<Result>();

foreach (var (name, path) in _repositoryQuery.GetAll())
{
var score = StringMatcher.FuzzySearch(query.Search, name);
if (string.IsNullOrWhiteSpace(query.Search) || score.Score > 0)
{
results.Add(new Result
{
Title = name,
SubTitle = path,
Score = score.Score,
TitleHighlightData = score.MatchData,
IcoPath = _icoPath,
Action = _ =>
{
Helper.OpenInShell("gitkraken", $"-p \"{path}\"", runWithHiddenWindow: true);
return true;
},
});
}
}

return results.OrderBy(r => r.Title).ToList();
}

private void UpdateIconPath(Theme theme)
{
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
{
_icoPath = "Images/GitKraken.light.png";
}
else
{
_icoPath = "Images/GitKraken.dark.png";
}
}

private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
}
}
14 changes: 14 additions & 0 deletions Community.PowerToys.Run.Plugin.GitKraken/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ID": "582B10E1E9144702B5E18C3EDC3FF466",
"Disabled": false,
"ActionKeyword": "}",
"IsGlobal": false,
"Name": "GitKraken",
"Author": "davidegiacometti",
"Version": "1.0.0",
"Language": "csharp",
"Website": "https://aka.ms/powertoys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.GitKraken.dll",
"IcoPathDark": "Images\\GitKraken.dark.png",
"IcoPathLight": "Images\\GitKraken.light.png"
}
17 changes: 17 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<Version>0.0.1</Version>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
<AdditionalFiles Include="..\StyleCop.json" Link="StyleCop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Reviewed")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:Elements should appear in the correct order", Justification = "Reviewed")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:Field names should not begin with underscore", Justification = "Reviewed")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:Static elements should appear before instance elements", Justification = "Reviewed")]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PowerToys Run: GitKraken plugin

Simple [PowerToys Run](https://learn.microsoft.com/windows/powertoys/run) experimental plugin for quickly open [GitKraken](https://www.gitkraken.com/) repositories.

## Requirements

- GitKraken 9.x
- PowerToys minimum version 0.68.0

## Installation

- Download the latest release
- Extract to `%LOCALAPPDATA%\Microsoft\PowerToys\PowerToys Run\Plugins`
- Restart PowerToys
26 changes: 26 additions & 0 deletions StyleCop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"xmlHeader": false,
"companyName": "Davide Giacometti",
"copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information.",
"variables": {
"licenseName": "MIT",
"licenseFile": "LICENSE"
},
"documentExposedElements": false,
"documentInterfaces": false
},
"layoutRules": {
"newlineAtEndOfFile": "require"
},
"indentation": {
"indentationSize": 4
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace",
"systemUsingDirectivesFirst": true
}
}
}

0 comments on commit b09f26b

Please sign in to comment.