Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermue committed Jan 21, 2023
1 parent a71bc74 commit 0d53048
Show file tree
Hide file tree
Showing 50 changed files with 3,355 additions and 0 deletions.
Binary file added Images/Dialog_deutsch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Dialog_english.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# VPN Connections
A little helper tool that shows the current state of the selected VPN connection as tray icon.

![Configuration Dialog](Images/Dialog_english.png "Configuration Dialog")


The tool is customizable and you can configure the following settings:
- The name of the connection that should be tracked.
- When the icon should be shown. This can be never, always or only when connected or disconnected.
- The color of the tray icon in connected or disconnected stated. The color can either be manually configured or take the current accent color.
- If a notification message should be shown either never, when the state changed or when connected or disconnected.
- Decide if the tool should be run at startup of windows or not.
- What should happen if you click or double click with the left or right mouse button on the icon. Should the configuration dialog be opened, explicit connected or disconnected, change the connection state or close this application.

Additionally the tool has two command line arguments:
- `-show` will on startup automatically show the configuration dialog.
- `-culture` let you define the current language of the tool. English will be taken by default or if the desired language is not available. Currently additionally available is German only.

<br/>
<br/>

![Configuration Dialog German](Images/Dialog_deutsch.png "Configuration Dialog German")
39 changes: 39 additions & 0 deletions VpnConnections.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VpnConnections", "VpnConnections\VpnConnections.csproj", "{26B548A1-BF23-4FEE-9D9C-DC0A649C8FD7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A2A78439-5936-4D8C-8BB4-7A8DDC762041}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Images", "Images", "{A1D63A3B-3390-458F-B5B2-ACCBF94A055D}"
ProjectSection(SolutionItems) = preProject
Images\Dialog_deutsch.png = Images\Dialog_deutsch.png
Images\Dialog_english.png = Images\Dialog_english.png
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{26B548A1-BF23-4FEE-9D9C-DC0A649C8FD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26B548A1-BF23-4FEE-9D9C-DC0A649C8FD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26B548A1-BF23-4FEE-9D9C-DC0A649C8FD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26B548A1-BF23-4FEE-9D9C-DC0A649C8FD7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A1D63A3B-3390-458F-B5B2-ACCBF94A055D} = {A2A78439-5936-4D8C-8BB4-7A8DDC762041}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4FF118B5-305B-4E85-A055-974093D9F22F}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions VpnConnections/DTOs/ClickAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel;
using VpnConnections.Localization;

namespace VpnConnections.DTOs
{
public enum ClickAction
{
[DescriptionLocalized("Open configuration dialog")]
OpenConfiguration,

[DescriptionLocalized("Connect only")]
ConnectOnly,

[DescriptionLocalized("Disconnect only")]
DisconnectOnly,

[DescriptionLocalized("Toggle connection state")]
ToggleConnectionState,

//// ToDo: Tell explorer to show taskbar VPN connections dialog
//[DescriptionLocalized("Open connections")]
//OpenConnectionDialog,

[DescriptionLocalized("Close application")]
CloseApplication,
}
}
19 changes: 19 additions & 0 deletions VpnConnections/DTOs/IconVisibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using VpnConnections.Localization;

namespace VpnConnections.DTOs
{
public enum IconVisibility
{
[DescriptionLocalized("Always")]
Always,

[DescriptionLocalized("Only connected")]
OnlyConnected,

[DescriptionLocalized("Only disconnected")]
OnlyDisconnected,

[DescriptionLocalized("Never")]
Never,
}
}
19 changes: 19 additions & 0 deletions VpnConnections/DTOs/ShowNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using VpnConnections.Localization;

namespace VpnConnections.DTOs
{
public enum ShowNotification
{
[DescriptionLocalized("Never")]
Never,

[DescriptionLocalized("On connection change")]
OnConnectionChange,

[DescriptionLocalized("On connected only")]
OnConnectedOnly,

[DescriptionLocalized("On disconnected only")]
OnDisconnectedOnly,
}
}
26 changes: 26 additions & 0 deletions VpnConnections/DTOs/VpnConnectionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace VpnConnections.DTOs
{
public class VpnConnectionSettings
{
public string ConnectionName { get; set; } = string.Empty;
public ShowNotification ShowNotification { get; set; }
public bool AccentColorForConnected { get; set; }
public string? TrayIconConnectedColor { get; set; } = "128, 255, 128";
public bool AccentColorForDisonnected { get; set; }
public string? TrayIconDisconnectedColor { get; set; } = "255, 128, 128";
public ClickAction TrayIconLeftMouseButtonClick { get; set; } = ClickAction.OpenConfiguration;
public ClickAction TrayIconLeftMouseButtonDoubleClick { get; set; } = ClickAction.OpenConfiguration;
public ClickAction TrayIconRightMouseButtonClick { get; set; } = ClickAction.OpenConfiguration;
public ClickAction TrayIconRightMouseButtonDoubleClick { get; set; } = ClickAction.CloseApplication;
public IconVisibility TrayIconVisibility { get; set; }
public bool RunOnStartup { get; set; }

public bool ActionConfigured(ClickAction clickAction)
{
return TrayIconLeftMouseButtonClick == clickAction
|| TrayIconLeftMouseButtonDoubleClick == clickAction
|| TrayIconRightMouseButtonClick == clickAction
|| TrayIconRightMouseButtonDoubleClick == clickAction;
}
}
}
104 changes: 104 additions & 0 deletions VpnConnections/Design/ColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace VpnConnections.Design
{
public class ColorConverter : TypeConverter
{
public static Color From(string? color)
{
if (string.IsNullOrWhiteSpace(color))
return Color.Transparent;

var values = color
.Split(',')
.Select(v => int.TryParse(v, out int number) ? number : 0)
.ToList();

return values.Count switch
{
0 or 1 or 2 => Color.Transparent,
3 => Color.FromArgb(values[0], values[1], values[2]),
_ => Color.FromArgb(values[0], values[1], values[2], values[3]),
};
}

public static string? From(Color color)
{
return color.A == byte.MaxValue
? $"{color.R}, {color.G}, {color.B}"
: $"{color.A}, {color.R}, {color.G}, {color.B}";
}

public static Color From(Windows.UI.Color color)
{
return Color.FromArgb(color.A, color.R, color.G, color.B);
}

public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
if (sourceType == typeof(string))
return true;

if (sourceType == typeof(Color))
return true;

if (sourceType == typeof(Windows.UI.Color))
return true;

return base.CanConvertFrom(context, sourceType);
}

public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType)
{
if (destinationType == typeof(string))
return true;

if (destinationType == typeof(Color))
return true;

if (destinationType == typeof(Windows.UI.Color))
return true;

return base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
switch (value)
{
case string text:
return From(text);

case Color color:
return color;

case Windows.UI.Color color:
return Color.FromArgb(color.A, color.R, color.G, color.B);

default:
return base.ConvertFrom(context, culture, value);
}
}

public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
var color = value as Color?;

if (color.HasValue)
{
if (destinationType == typeof(string))
return From(color.Value);

if (destinationType == typeof(Color))
return color.Value;

if (destinationType == typeof(Windows.UI.Color))
return Windows.UI.Color.FromArgb(color.Value.A, color.Value.R, color.Value.G, color.Value.B);
}

return base.ConvertTo(context, culture, value, destinationType);
}
}
}
17 changes: 17 additions & 0 deletions VpnConnections/Design/ConnectionNameConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel;
using VpnConnections.Vpn;

namespace VpnConnections.Design
{
public class ConnectionNameConverter : StringConverter
{
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{
return new StandardValuesCollection(VpnConnection.ConnectionNames.ToList());
}

public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => true;

public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
}
}
Loading

0 comments on commit 0d53048

Please sign in to comment.