Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
24 changes: 24 additions & 0 deletions Config/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using WindowsTermialTray.Keys;

namespace WindowsTermialTray.Config
{
public class App
{
public string ProcessName { get; set; }
public string ExeFilePath { get; set; }
public ModifierKeys ModifierKeys { get; set; }
public System.Windows.Forms.Keys Keys { get; set; }
}

public class Config
{
public virtual App[] Apps { get; set; }
}

public class DefaultConfig : Config
{
public override App[] Apps { get; set; } = new App[] {
new App { ProcessName = "WindowsTerminal", ExeFilePath = "wt.exe", ModifierKeys = ModifierKeys.Alt, Keys = System.Windows.Forms.Keys.T}
};
}
}
55 changes: 55 additions & 0 deletions Config/ConfigBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.IO;
using WindowsTermialTray.Config.Provider;

namespace WindowsTermialTray.Config
{
public class ConfigBuilder
{
private readonly List<IProvider> _providers;

private ConfigBuilder(List<IProvider> providers)
{
_providers = providers;
}

public static ConfigBuilder Create()
{
return new ConfigBuilder(new List<IProvider> { });
}

public ConfigBuilder AddDefault()
{
_providers.Add(new DefaultProvider());
return new ConfigBuilder(_providers);
}

public ConfigBuilder AddJsonFile(string jsonPath)
{
if (File.Exists(jsonPath))
{
var jsonString = File.ReadAllText(jsonPath);
_providers.Add(new JsonProvider(jsonString));
}

return new ConfigBuilder(_providers);
}

public Config Build()
{
foreach (var provider in _providers)
{
var config = provider.Load();
if (config != null)
{
return config;
}
else
{
continue;
}
}
return null;
}
}
}
10 changes: 10 additions & 0 deletions Config/Provider/DefaultProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace WindowsTermialTray.Config.Provider
{
class DefaultProvider : IProvider
{
public Config Load()
{
return new DefaultConfig();
}
}
}
11 changes: 11 additions & 0 deletions Config/Provider/IProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace WindowsTermialTray.Config.Provider
{
interface IProvider
{
/// <summary>
/// Load configurations.
/// </summary>
/// <exception cref="System.FormatException">Thrown when invalid data provided.</exception>
Config Load();
}
}
35 changes: 35 additions & 0 deletions Config/Provider/JsonProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Linq;
using System.Text.Json;

namespace WindowsTermialTray.Config.Provider
{
public class JsonProvider : IProvider
{
private readonly string _jsonString;

public JsonProvider(string jsonString)
{
_jsonString = jsonString;
}

public Config Load()
{
try
{
var config = JsonSerializer.Deserialize<Config>(_jsonString);
var hasNull = config.Apps.Any(a => a.GetType().GetProperties().Any(p => p.GetValue(a) == default));
if (hasNull)
{
throw new FormatException("json includes null value or some fields are missing");
}

return config;
}
catch (JsonException e)
{
throw new FormatException($"invalid json", e);
}
}
}
}
46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,44 @@ If you had multiple instances of an app, Termial Tray will store only one, so fe
## FAQ

### **Can I manage other apps like Windows Terminal with Quake Style?**
Yes of course! But you need to dig into code. Just download this repo, go to `TerminalTracyIcon.cs` file and find this section:
```C#
_appTrayList.AddRange(new []
{
new TrayApp("WindowsTerminal", "wt.exe", ModifierKeys.Alt, Keys.Oemtilde)
// Add your other tray apps here
// new TrayApp("ProcessName", "exec.exe", ModifierKeys.Ctrl, Keys.Oemtilde)
});
You can configure settings by `config.json` like below.

#### config.json
```json
{
"Apps": [
{
"ProcessName": "WindowsTerminal",
"ExeFilePath": "wt.exe",
"ModifierKeys": 1,
"Keys": 84
},
{
"ProcessName": "Spotify",
"ExeFilePath": "Spotify.exe",
"ModifierKeys": 1,
"Keys": 83
}
]
}
```
The json should be located at:
1. same directory as `WindowsTermialTray.exe`
1. `$env:LOCALAPPDATA\WindowsTermialTray\config.json`

From here you can add other apps, but you need to specify and know:

* Your app [ProcessName](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process?view=powershell-7).
* Your app executable.
* Unique pair of `ModifierKey` and `Key`.

When you find out everything - add your app in code with parameters (and comment Windows Terminal if don't want it), and follow steps in [installation section](#installation), to build `.exe` file.

### **Why building and adding other apps is so difficult?**
Because I didn't prepared this. For now this little app is for me, but if you like it too - tell me, and I'll continue to contribuiting it!
* Unique pair of `ModifierKey` and [Key](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.keys).
#### ModifierKey
- Alt: 1
- Control: 2
- Shift: 4
- Win: 8

### **Will you be contributing this Termial Tray?**
Nah. I hope that MS add *Quake Style* behaviour for Windows Terminal, but if not, or some people find Termial Tray useful for other Jobs - I'll start to work on this app, to make it more powerfull and usefull.

### **Your code is a mess, shame on you**
Thanks for your opinion! I'm not an expert in .NET and this kind of system apps - I created this to fit my personal needs and added it here for people (if they want to benefit from this solution). But if you're expert, please share your opinion about this project with me - I'll fix and update code to be clean and fast.
Thanks for your opinion! I'm not an expert in .NET and this kind of system apps - I created this to fit my personal needs and added it here for people (if they want to benefit from this solution). But if you're expert, please share your opinion about this project with me - I'll fix and update code to be clean and fast.
36 changes: 28 additions & 8 deletions TerminalTrayIcon.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using WindowsTermialTray;
using WindowsTermialTray.Keys;
using WindowsTermialTray.Config;
using WindowsTermialTray.Properties;

namespace WindowsTerminalTray
Expand All @@ -28,13 +28,28 @@ public TerminalTrayIcon()

contextMenu.MenuItems.Add(exitItem);

var configFileName = "config.json";
Config config = null;
try
{
config = ConfigBuilder.Create()
.AddJsonFile(Path.Combine(Environment.CurrentDirectory, configFileName))
.AddJsonFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.ProductName, configFileName))
.AddDefault().Build();
}
catch (FormatException)
{
OpenMessageBox("Settings couldn't be loaded from file.\nCheck for syntax error, including invalid value.");
Application.Exit();
}

_appTrayList = new List<TrayApp>();
_appTrayList.AddRange(new []
foreach (var app in config.Apps)
{
new TrayApp("WindowsTerminal", "wt.exe", ModifierKeys.Alt, Keys.Oemtilde)
// Add your other tray apps here
// new TrayApp("ProcessName", "exec.exe", ModifierKeys.Ctrl, Keys.Oemtilde)
});
_appTrayList.AddRange(new[] {
new TrayApp(app.ProcessName, app.ExeFilePath, app.ModifierKeys, app.Keys)
});
}

Ni = new NotifyIcon
{
Expand All @@ -54,5 +69,10 @@ private void Close(object Sender, EventArgs e)
}

public void Dispose() { }

private void OpenMessageBox(string message)
{
MessageBox.Show(message, Application.ProductName);
}
}
}
}
6 changes: 4 additions & 2 deletions TrayApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ private void RunApp()
process.StartInfo.FileName = _exec;
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
while (_appProcess == null)

var start = DateTime.Now;
while (_appProcess == null && DateTime.Now - start < TimeSpan.FromMilliseconds(1000))
{
_appProcess = Process.GetProcesses().FirstOrDefault(x => x.ProcessName.Equals(_processName) && !x.HasExited);
Thread.Sleep(100);
Expand All @@ -108,4 +110,4 @@ public void Dispose()
_hook.Dispose();
}
}
}
}
6 changes: 6 additions & 0 deletions WindowsTermialTray.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsTerminalTray", "WindowsTerminalTray.csproj", "{CBC9BB16-8421-4641-9850-B950D82F4022}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{B783C3E2-7D28-4217-A915-266562E2C3F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{CBC9BB16-8421-4641-9850-B950D82F4022}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBC9BB16-8421-4641-9850-B950D82F4022}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBC9BB16-8421-4641-9850-B950D82F4022}.Release|Any CPU.Build.0 = Release|Any CPU
{B783C3E2-7D28-4217-A915-266562E2C3F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B783C3E2-7D28-4217-A915-266562E2C3F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B783C3E2-7D28-4217-A915-266562E2C3F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B783C3E2-7D28-4217-A915-266562E2C3F5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 37 additions & 0 deletions WindowsTerminalTray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,39 @@
<ApplicationIcon>terminal-tray.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encodings.Web.5.0.1\lib\net461\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Json.5.0.2\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -71,6 +102,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\Config.cs" />
<Compile Include="Config\ConfigBuilder.cs" />
<Compile Include="Config\Provider\DefaultProvider.cs" />
<Compile Include="Config\Provider\IProvider.cs" />
<Compile Include="Config\Provider\JsonProvider.cs" />
<Compile Include="TrayApp.cs" />
<Compile Include="Keys\KeyboardHook.cs" />
<Compile Include="Program.cs" />
Expand All @@ -86,6 +122,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
12 changes: 12 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="5.0.1" targetFramework="net472" />
<package id="System.Text.Json" version="5.0.2" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>
Loading