添加托盘图标基本功能

This commit is contained in:
Genteure 2018-12-11 00:57:40 +08:00
parent 0c2953f662
commit 5de773aacd
5 changed files with 72 additions and 3 deletions

View File

@ -17,7 +17,8 @@ namespace BililiveRecorder.Core.Config
/// </summary>
[JsonIgnore]
[Utils.DoNotCopyProperty]
public string WorkDirectory { get; set; }
public string WorkDirectory { get => _workDirectory; set => SetField(ref _workDirectory, value); }
/// <summary>
/// 房间号列表
@ -71,5 +72,6 @@ namespace BililiveRecorder.Core.Config
private uint _cuttingNumber = 10;
private EnabledFeature _enabledFeature = EnabledFeature.Both;
private AutoCuttingMode _cuttingMode = AutoCuttingMode.Disabled;
private string _workDirectory;
}
}

View File

@ -62,6 +62,9 @@
<Reference Include="DeltaCompressionDotNet.PatchApi, Version=1.1.0.0, Culture=neutral, PublicKeyToken=3e8888ee913ed789, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.PatchApi.dll</HintPath>
</Reference>
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsAPICodePack-Core.1.1.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
@ -102,6 +105,7 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />

View File

@ -3,11 +3,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:BililiveRecorder.WPF"
mc:Ignorable="d"
MinHeight="400" MinWidth="650"
Title="录播姬" Height="450" Width="800"
Loaded="Window_Loaded" Closing="Window_Closing">
Loaded="Window_Loaded" Closing="Window_Closing" StateChanged="Window_StateChanged">
<Grid>
<Grid.Resources>
<ResourceDictionary>
@ -22,6 +23,43 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--<local:UpdateBarUserControl Grid.Row="0" x:Name="UpdateBar"/>-->
<tb:TaskbarIcon x:Name="NotifyIcon" Visibility="Collapsed" IconSource="/ico.ico" TrayLeftMouseUp="Taskbar_Click">
<tb:TaskbarIcon.TrayToolTip>
<Border BorderBrush="Black" BorderThickness="1" Background="White" CornerRadius="1">
<StackPanel Margin="5">
<TextBlock FontSize="14" Text="{Binding Title}"/>
<TextBlock FontSize="13" Text="{Binding Recorder.Config.WorkDirectory,Mode=OneWay}" Margin="0,0,0,7"/>
<ItemsControl ItemsSource="{Binding Recorder}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource RSC}" Mode="OneWay">
<Binding Path="IsMonitoring" Mode="OneWay"/>
<Binding Path="IsRecording" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Text="{Binding DownloadSpeedPersentage,StringFormat=0.##%,Mode=OneWay}" Margin="5,0,0,0"/>
<TextBlock Margin="5,0" Text="{Binding RealRoomid,Mode=OneWay}"/>
<TextBlock Text="{Binding StreamerName,Mode=OneWay}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
</tb:TaskbarIcon.TrayToolTip>
<tb:TaskbarIcon.ContextMenu>
<ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<!--<MenuItem IsCheckable="True">不弹出提醒</MenuItem>-->
<MenuItem Header="退出">
<MenuItem Header="确认退出" Click="Taskbar_Quit_Click"/>
</MenuItem>
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>

View File

@ -1,6 +1,7 @@
using Autofac;
using BililiveRecorder.Core;
using BililiveRecorder.FlvProcessor;
using Hardcodet.Wpf.TaskbarNotification;
using NLog;
using System;
using System.Collections.ObjectModel;
@ -63,7 +64,7 @@ namespace BililiveRecorder.WPF
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Title += " 版本号: " + BuildInfo.Version + " " + BuildInfo.HeadShaShort;
Title += " " + BuildInfo.Version + " " + BuildInfo.HeadShaShort;
string workdir = string.Empty;
try
@ -92,6 +93,8 @@ namespace BililiveRecorder.WPF
Environment.Exit(-2);
return;
}
NotifyIcon.Visibility = Visibility.Visible;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@ -270,6 +273,27 @@ namespace BililiveRecorder.WPF
private IRecordedRoom _GetSenderAsRecordedRoom(object sender) => (sender as Button)?.DataContext as IRecordedRoom;
private void Taskbar_Quit_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Hide();
NotifyIcon.ShowBalloonTip("B站录播姬", "录播姬已最小化到托盘,左键单击图标恢复界面。", BalloonIcon.Info);
}
}
private void Taskbar_Click(object sender, RoutedEventArgs e)
{
Show();
WindowState = WindowState.Normal;
Topmost ^= true;
Topmost ^= true;
Focus();
}
}
}

View File

@ -2,6 +2,7 @@
<packages>
<package id="Autofac" version="4.8.1" targetFramework="net462" />
<package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net462" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net462" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net462" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net462" />
<package id="NLog" version="4.5.10" targetFramework="net462" />