Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tray options #52

Closed
wants to merge 10 commits into from
Closed
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
12 changes: 12 additions & 0 deletions main/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<client.Properties.Settings>
<setting name="FirstRun" serializeAs="String">
<value>True</value>
</setting>
</client.Properties.Settings>
</userSettings>
</configuration>
3 changes: 1 addition & 2 deletions main/Forms/frmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ public partial class frmClient : Form
public frmClient()
{
System.Runtime.ProfileOptimization.StartProfile("frmClient.Profile");
InitializeComponent();
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
Reload();

currentVersion.Text = "v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();

githubVersion.Text = Task.Run(() => getVersionData()).Result;
Expand Down
67 changes: 67 additions & 0 deletions main/IconApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using client.Forms;
using client.Properties;
using System;
using System.Drawing;

namespace client
{
class IconApplicationContext : TrayIconApplicationContext
{
private frmClient frmClient;

public IconApplicationContext()
{
TrayIcon.Icon = Resources.Icon;
TrayIcon.Visible = true;

ContextMenu.Items.Add("Taskbar Group", null, this.SettingsContextMenuClickHandler);
ContextMenu.Items.Add("E&xit", null, this.ExitContextMenuClickHandler);

if (Properties.Settings.Default.FirstRun == true)
{
frmClient = new frmClient();
frmClient.Show();

//Change the value since the program has run once now
Properties.Settings.Default.FirstRun = false;
Properties.Settings.Default.Save();
}
}

protected override void OnApplicationExit(EventArgs e)
{
base.OnApplicationExit(e);
}

private void ExitContextMenuClickHandler(object sender, EventArgs eventArgs)
{
this.ExitThread();
}

private void SettingsContextMenuClickHandler(object sender, EventArgs eventArgs)
{
this.ShowSettings();
}

private void ShowSettings()
{
if (frmClient != null)
{
if (frmClient.IsDisposed)
{
frmClient = new frmClient();
frmClient.Show();
}
else
{
frmClient.BringToFront();
}
}
else
{
frmClient = new frmClient();
frmClient.Show();
}
}
}
}
10 changes: 10 additions & 0 deletions main/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions main/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<data name="Error" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Error.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="NumDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NumDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
14 changes: 13 additions & 1 deletion main/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions main/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="client.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="FirstRun" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
94 changes: 94 additions & 0 deletions main/TrayIconApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using client.Forms;
using client.Properties;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace client
{
public abstract class TrayIconApplicationContext : ApplicationContext
{
private readonly NotifyIcon _notifyIcon;
private readonly ContextMenuStrip _contextMenu;
private frmClient _frmClient;
protected TrayIconApplicationContext()
{
_contextMenu = new ContextMenuStrip();
_notifyIcon = new NotifyIcon();
_frmClient = new frmClient();

Application.ApplicationExit += this.ApplicationExitHandler;

this.TrayIcon.MouseDoubleClick += TrayIcon_MouseDoubleClick;

this.TrayIcon.Icon = Resources.Icon;
this.TrayIcon.ContextMenuStrip = this.ContextMenu;
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetCursorPos(ref Win32Point pt);

[StructLayout(LayoutKind.Sequential)]
internal struct Win32Point
{
public Int32 X;
public Int32 Y;
};
public static Point GetMousePosition()
{
var w32Mouse = new Win32Point();
GetCursorPos(ref w32Mouse);

return new Point(w32Mouse.X, w32Mouse.Y);
}

private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (_frmClient.IsDisposed)
{
_frmClient = new frmClient();
_frmClient.Show();
}
else
{ _frmClient.Show(); }
}

if (e.Button == MouseButtons.Right)
{
_contextMenu.Show(GetMousePosition());
_contextMenu.Visible = true;
}
}

protected virtual void OnApplicationExit(EventArgs e)
{
if (_notifyIcon != null)
{
_notifyIcon.Visible = false;
_notifyIcon.Dispose();
}
}

private void ApplicationExitHandler(object sender, EventArgs e)
{
if (_contextMenu != null)
_contextMenu.Dispose();

this.OnApplicationExit(e);
}

protected ContextMenuStrip ContextMenu
{
get { return _contextMenu; }
}
protected NotifyIcon TrayIcon
{
get { return _notifyIcon; }
}
}
}

2 changes: 1 addition & 1 deletion main/client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void Main()
{
// See comment above
SetCurrentProcessExplicitAppUserModelID("tjackenpacken.taskbarGroup.main");
Application.Run(new frmClient());
Application.Run(new IconApplicationContext());
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions main/client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="Classes\MainPath.cs" />
<Compile Include="Classes\ProgramShortcut.cs" />
<Compile Include="Classes\ShellLink.cs" />
<Compile Include="IconApplicationContext.cs" />
<Compile Include="Forms\frmClient.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -114,6 +115,7 @@
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TrayIconApplicationContext.cs" />
<Compile Include="User controls\ucCategoryPanel.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down