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

新增托盘右键菜单,更新WpfUI版本 #247

Closed
wants to merge 4 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
3 changes: 2 additions & 1 deletion Desktop/Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="2.0.5" />
<PackageReference Include="Notification.Wpf" Version="8.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="WPF-UI" Version="4.0.0" />
<PackageReference Include="WPF-UI.Tray" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Desktop/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@

<ui:TitleBar Margin="0,2,0,0" Name="UI_TitleBar" Height="30" Title="{Binding ProgramTitle}" Grid.Row="0" Icon="pack://application:,,,/DDTV.ico" />
</Grid>
<Grid>
<local:NotifyIcon x:Name="notifyIcon" />
</Grid>
<Grid>
<ui:SnackbarPresenter Height="150" Name="MainSnackbar" VerticalAlignment="Bottom"></ui:SnackbarPresenter>
</Grid>
<ContentPresenter x:Name="RootContentDialogPresenter" />
</Grid>


</ui:FluentWindow>
61 changes: 31 additions & 30 deletions Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindow : FluentWindow
/// <summary>
/// 后台托盘
/// </summary>
private NotifyIcon notifyIcon = null;
//private Wpf.Ui.Tray.Controls.NotifyIcon notifyIcon = null;
/// <summary>
/// 系统托盘通知
/// </summary>
Expand Down Expand Up @@ -73,7 +73,8 @@ public MainWindow()
Thread.Sleep(1000);
//初始化各种page
Init();
}
InitializeNotifyIcon();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"UI初始化出现重大错误,错误堆栈{ex.ToString()}");
Expand Down Expand Up @@ -101,9 +102,10 @@ public void Init()
SnackbarService = Desktop.App._MainSnackbarServiceProvider.GetRequiredService<ISnackbarService>();
SnackbarService.SetSnackbarPresenter(MainSnackbar);
//初始化托盘
notify();
//初始化确认窗口
_contentDialogService.SetDialogHost(RootContentDialogPresenter);
//notify(); 已弃用
InitializeNotifyIcon();
//初始化确认窗口
_contentDialogService.SetDialogHost(RootContentDialogPresenter);
//初始化标题和远程模式标志以及检查远程和本地版本号一致性
InitializeTitleMode();
//监听开播事件,用于开播提醒
Expand Down Expand Up @@ -230,23 +232,22 @@ public static Process RuningInstance(bool IsStart = true)
catch (Exception) { }
return null;
}
private void notify()
{
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Text = "DDTV";
notifyIcon.Icon = new System.Drawing.Icon("DDTV.ico");
notifyIcon.Visible = true;
notifyIcon.DoubleClick += NotifyIcon_Click;
StateChanged += MainWindow_StateChanged; ;
}

/// <summary>
/// 窗口缩小事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void MainWindow_StateChanged(object? sender, EventArgs e)



private void InitializeNotifyIcon()
{
NotifyIcon notifyIconWindow = new NotifyIcon();
StateChanged += MainWindow_StateChanged;
}

/// <summary>
/// 窗口缩小事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void MainWindow_StateChanged(object? sender, EventArgs e)
{
if (Config.Core_RunConfig._ZoomOutMode != 0 && this.WindowState == WindowState.Minimized)
{
Expand All @@ -265,15 +266,15 @@ private void NotifyIcon_Click(object? sender, EventArgs e)
this.WindowState = WindowState.Normal; // 设置窗口状态为正常
}




/// <summary>
/// 开播事件,触发开播提醒
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void DetectRoom_LiveStart(object? sender, (RoomCardClass Card, bool Danma_MessageReceived) LiveInvoke)
/// <summary>
/// 开播事件,触发开播提醒
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void DetectRoom_LiveStart(object? sender, (RoomCardClass Card, bool Danma_MessageReceived) LiveInvoke)
{
RoomCardClass roomCard = LiveInvoke.Card;
List<TriggerType> triggerTypes = sender as List<TriggerType> ?? new List<TriggerType>();
Expand Down
20 changes: 20 additions & 0 deletions Desktop/NotifyIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="Desktop.NotifyIcon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tray="http://schemas.lepo.co/wpfui/2022/xaml/tray"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
>
<tray:NotifyIcon
TooltipText="DDTV"
Icon="pack://application:,,,/Assets/DDTV.ico"
Visibility="Visible"
LeftClick="NotifyIcon_Click">

<tray:NotifyIcon.Menu>
<ContextMenu>
<MenuItem Name="exitMenu" Header="退出"/>
<MenuItem Name="forceShowMenu" Header="强制显示" />
</ContextMenu>
</tray:NotifyIcon.Menu>
</tray:NotifyIcon>
</UserControl>
72 changes: 72 additions & 0 deletions Desktop/NotifyIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Desktop.Views.Pages;
using Core;
using Core.LogModule;
using Core.RuntimeObject;
using Desktop.Models;
using Desktop.Views.Pages;
using Desktop.Views.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf.Ui.Controls;

namespace Desktop
{
public partial class NotifyIcon
{
public NotifyIcon()
{
InitializeComponent();
initMenu();
}
private void initMenu()
{
exitMenu.Click += RightClickExit;
forceShowMenu.Click += rightClickForceShow;

}
private void RightClickExit(object sender, RoutedEventArgs e)
{
if (!MainWindow.IsProgrammaticClose)
{
System.Windows.MessageBoxResult result = MessageBox.Show("确认要关闭DDTV吗?\r\n关闭后所有录制任务以及播放窗口均会结束。", "关闭确认", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question);
if (result == System.Windows.MessageBoxResult.Yes)
{
DataPage.Timer_DataPage?.Dispose();
DataSource.LoginStatus.Timer_LoginStatus?.Dispose();
Environment.Exit(-114514);
}
}
}

private void rightClickForceShow(object sender, RoutedEventArgs e)
{
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
if (mainWindow != null)
{
mainWindow.Show();
mainWindow.WindowState = WindowState.Normal;
mainWindow.Left = (SystemParameters.PrimaryScreenWidth - mainWindow.ActualWidth) / 2;
mainWindow.Top = (SystemParameters.PrimaryScreenHeight - mainWindow.ActualHeight) / 2;
mainWindow.Activate();
}
}
private void NotifyIcon_Click(object? sender, EventArgs e)
{
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
mainWindow.Show();
mainWindow.WindowState = WindowState.Normal;
}
}

}
Loading