Skip to content

Commit 298e4aa

Browse files
author
RandomEngy
committed
Adding option to minimize VidCoder to the system tray rather than the task bar.
1 parent bbf86a1 commit 298e4aa

15 files changed

Lines changed: 196 additions & 27 deletions

Installer/VidCoder-x64.iss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Source: "..\Lib\Ookii.Dialogs.Wpf.dll"; DestDir: "{app}"
3333
Source: "..\Lib\Ookii.Dialogs.Wpf.pdb"; DestDir: "{app}"
3434
Source: "..\Lib\Microsoft.Practices.Unity.dll"; DestDir: "{app}"
3535
Source: "..\Lib\Microsoft.Practices.Unity.Configuration.dll"; DestDir: "{app}"
36+
Source: "..\Lib\Hardcodet.Wpf.TaskbarNotification.dll"; DestDir: "{app}"
3637
Source: "..\VidCoder\BuiltInPresets.xml"; DestDir: "{app}"
3738
Source: "..\Lib\x64\hb.dll"; DestDir: "{app}"
3839
Source: "..\Lib\x64\System.Data.SQLite.dll"; DestDir: "{app}"

Installer/VidCoder-x86.iss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Source: "..\Lib\Ookii.Dialogs.Wpf.dll"; DestDir: "{app}"
3030
Source: "..\Lib\Ookii.Dialogs.Wpf.pdb"; DestDir: "{app}"
3131
Source: "..\Lib\Microsoft.Practices.Unity.dll"; DestDir: "{app}"
3232
Source: "..\Lib\Microsoft.Practices.Unity.Configuration.dll"; DestDir: "{app}"
33+
Source: "..\Lib\Hardcodet.Wpf.TaskbarNotification.dll"; DestDir: "{app}"
3334
Source: "..\VidCoder\BuiltInPresets.xml"; DestDir: "{app}"
3435
Source: "..\Lib\x86\hb.dll"; DestDir: "{app}"
3536
Source: "..\Lib\x86\System.Data.SQLite.dll"; DestDir: "{app}"
45.5 KB
Binary file not shown.
95.5 KB
Binary file not shown.

VidCoder/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@
128128
<Setting Name="SourceHistory" Type="System.String" Scope="User">
129129
<Value Profile="(Default)" />
130130
</Setting>
131+
<Setting Name="MinimizeToTray" Type="System.Boolean" Scope="User">
132+
<Value Profile="(Default)">False</Value>
133+
</Setting>
131134
</Settings>
132135
</SettingsFile>

VidCoder/Services/TrayService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using VidCoder.View;
6+
using Microsoft.Practices.Unity;
7+
8+
namespace VidCoder.Services
9+
{
10+
public class TrayService
11+
{
12+
public void ShowBalloonMessage(string title, string message)
13+
{
14+
Unity.Container.Resolve<MainWindow>().ShowBalloonMessage(title, message);
15+
}
16+
}
17+
}

VidCoder/VidCoder.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
<Reference Include="HandBrakeInterop">
115115
<HintPath>..\Lib\$(Platform)\HandBrakeInterop.dll</HintPath>
116116
</Reference>
117+
<Reference Include="Hardcodet.Wpf.TaskbarNotification">
118+
<HintPath>..\Lib\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
119+
</Reference>
117120
<Reference Include="Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
118121
<HintPath>..\Lib\Microsoft.Practices.Unity.dll</HintPath>
119122
</Reference>
@@ -309,12 +312,14 @@
309312
<Compile Include="Services\ProcessAutoPause.cs" />
310313
<Compile Include="Services\Processes.cs" />
311314
<Compile Include="Services\SystemOperations.cs" />
315+
<Compile Include="Services\TrayService.cs" />
312316
<Compile Include="Utilities\ListSynchronizer\IListItemConverter.cs" />
313317
<Compile Include="Services\Logger.cs" />
314318
<Compile Include="Utilities\ListSynchronizer\MultiSelectorBehaviors.cs" />
315319
<Compile Include="Settings.cs" />
316320
<Compile Include="Utilities\ListSynchronizer\TwoListSynchronizer.cs" />
317321
<Compile Include="Utilities\RefireControl.cs" />
322+
<Compile Include="View\RestoreWindowCommand.cs" />
318323
<Compile Include="Utilities\SourceHistory.cs" />
319324
<Compile Include="Utilities\SystemSleepManagement.cs" />
320325
<Compile Include="Utilities\UIUtilities.cs" />

VidCoder/View/MainWindow.xaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
xmlns:model="clr-namespace:HandBrake.Interop;assembly=HandBrakeInterop"
88
xmlns:resx="clr-namespace:VidCoder.Properties"
99
xmlns:VidCoderDragDrop="clr-namespace:VidCoder.DragDropUtils"
10-
xmlns:Encoding="clr-namespace:HandBrake.Interop.Model.Encoding;assembly=HandBrakeInterop"
11-
xmlns:Model="clr-namespace:HandBrake.Interop.Model;assembly=HandBrakeInterop" Title="VidCoder"
10+
xmlns:Encoding="clr-namespace:HandBrake.Interop.Model.Encoding;assembly=HandBrakeInterop"
11+
xmlns:Model="clr-namespace:HandBrake.Interop.Model;assembly=HandBrakeInterop" Title="VidCoder"
12+
xmlns:tb="http://www.hardcodet.net/taskbar"
1213
Width="671"
1314
Height="445"
1415
MinWidth="617"
1516
MinHeight="445"
1617
Style="{StaticResource NormalWindow}"
17-
Closing="Window_Closing" AllowDrop="True" PreviewDrop="HandleDrop" PreviewDragOver="Window_PreviewDragOver" MouseDown="Window_MouseDown">
18+
Closing="Window_Closing" AllowDrop="True" PreviewDrop="HandleDrop" PreviewDragOver="Window_PreviewDragOver" MouseDown="Window_MouseDown" StateChanged="Window_StateChanged">
1819
<Window.Resources>
1920
<local:EnumDisplayer Type="{x:Type Encoding:VideoEncoder}" x:Key="VideoEncoderChoices" />
2021
<local:EnumDisplayer Type="{x:Type Model:VideoRangeType}" x:Key="VideoRangeTypeChoices" />
@@ -216,6 +217,7 @@
216217
<EventSetter Event="MouseDoubleClick" Handler="HandleCompletedItemDoubleClick" />
217218
<Setter Property="ContextMenu" Value="{StaticResource CompletedItemContextMenu}" />
218219
</Style>
220+
<local:RestoreWindowCommand x:Key="RestoreWindowCommand" />
219221
</Window.Resources>
220222
<Window.TaskbarItemInfo>
221223
<TaskbarItemInfo ProgressValue="{Binding OverallEncodeProgressFraction}" ProgressState="{Binding EncodeProgressState}" />
@@ -231,6 +233,7 @@
231233
<KeyBinding Key="T" Modifiers="Control" Command="{Binding QueueTitlesCommand}" />
232234
<KeyBinding Key="D" Modifiers="Control" Command="{Binding PickOutputPathCommand}" />
233235
</Window.InputBindings>
236+
234237
<Grid>
235238
<Grid.RowDefinitions>
236239
<RowDefinition Height="Auto" />
@@ -240,6 +243,13 @@
240243
<RowDefinition Height="*" />
241244
<RowDefinition Height="Auto" />
242245
</Grid.RowDefinitions>
246+
<tb:TaskbarIcon
247+
Name="trayIcon"
248+
Visibility="{Binding ShowTrayIcon, Converter={StaticResource VisibilityConverter}}"
249+
IconSource="/VidCoder_icon.ico"
250+
LeftClickCommand="{StaticResource RestoreWindowCommand}"
251+
DoubleClickCommand="{StaticResource RestoreWindowCommand}"
252+
ToolTipText="{Binding TrayIconToolTip}"/>
243253
<Menu Height="22">
244254
<MenuItem Header="File">
245255
<MenuItem

VidCoder/View/MainWindow.xaml.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Windows.Media;
1111
using System.Windows.Media.Imaging;
1212
using System.Windows.Navigation;
13+
using Hardcodet.Wpf.TaskbarNotification;
1314
using VidCoder.ViewModel;
1415
using VidCoder.Model;
1516
using System.Collections.ObjectModel;
@@ -80,8 +81,15 @@ public MainWindow()
8081
Storyboard.SetTargetProperty(presetGlowFadeUp, new PropertyPath("Opacity"));
8182
Storyboard.SetTargetName(presetGlowFadeDown, "PresetGlowEffect");
8283
Storyboard.SetTargetProperty(presetGlowFadeDown, new PropertyPath("Opacity"));
84+
85+
this.Loaded += (e, o) =>
86+
{
87+
this.RestoredWindowState = this.WindowState;
88+
};
8389
}
8490

91+
public WindowState RestoredWindowState { get; set; }
92+
8593
public void HandleDrop(object sender, DragEventArgs e)
8694
{
8795
var data = e.Data as DataObject;
@@ -111,6 +119,14 @@ public void HandleDrop(object sender, DragEventArgs e)
111119
}
112120
}
113121

122+
public void ShowBalloonMessage(string title, string message)
123+
{
124+
if (this.trayIcon.Visibility == Visibility.Visible)
125+
{
126+
this.trayIcon.ShowBalloonTip(title, message, BalloonIcon.Info);
127+
}
128+
}
129+
114130
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
115131
{
116132
this.viewModel = this.DataContext as MainViewModel;
@@ -399,6 +415,23 @@ private void Window_MouseDown(object sender, MouseButtonEventArgs e)
399415
}
400416
}
401417

418+
private void Window_StateChanged(object sender, EventArgs e)
419+
{
420+
if (this.WindowState == WindowState.Maximized || this.WindowState == WindowState.Normal)
421+
{
422+
this.RestoredWindowState = this.WindowState;
423+
}
424+
425+
if (this.viewModel != null)
426+
{
427+
this.viewModel.RefreshTrayIcon(this.WindowState == WindowState.Minimized);
428+
if (this.viewModel.ShowTrayIcon)
429+
{
430+
this.Hide();
431+
}
432+
}
433+
}
434+
402435
private bool HitElement(FrameworkElement element, Point clickedPoint)
403436
{
404437
Point relativePoint = this.destinationEditBox.TransformToAncestor(this).Transform(new Point(0, 0));

0 commit comments

Comments
 (0)