Skip to content

Commit 586121d

Browse files
committed
修复有链接但是接收不到文件的bug,
修复最小化到托盘时无法接收文件的bug。 优化托盘图标管理和调试信息 在 `MainWindow.xaml.cs` 中添加了 `H.NotifyIcon.EfficiencyMode` 的引用,并将托盘图标的可见性设置为隐藏,同时引入了效率模式设置。 在 `NavItemReceiver.xaml.cs` 中更新了 WiFi 相关的调试输出信息,使其更为准确,并注释掉了一些与设备连接相关的代码,以避免不必要的操作。 在 `NavItemSend.xaml.cs` 中修改了清理资源时的调试输出信息,提升了代码的可读性。
1 parent 32411fb commit 586121d

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

MainWindow.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using H.NotifyIcon;
22
using H.NotifyIcon.Core;
3+
using H.NotifyIcon.EfficiencyMode;
34
using Microsoft.UI.Xaml;
45
using Microsoft.UI.Xaml.Controls;
56
using System;
@@ -30,7 +31,7 @@ public static string GetCurrentFile(string filename)
3031
{
3132
this.Show();
3233
this.Activate();
33-
TrayIcon.Visibility = Visibility.Visible;
34+
TrayIcon.Visibility = Visibility.Collapsed;
3435
});
3536
public ICommand CloseWindowCommand => new RelayCommand(() =>
3637
{
@@ -46,7 +47,8 @@ public MainWindow()
4647
this.AppWindow.SetIcon(GetCurrentFile("Assets\\LocalDrop.ico"));
4748

4849
TrayIcon.ContextFlyout = TrayMenu;
49-
this.TrayIcon.Visibility = Visibility.Visible;
50+
EfficiencyModeUtilities.SetEfficiencyMode(false);
51+
//this.TrayIcon.Visibility = Visibility.Visible;
5052
// 处理窗口关闭事件
5153
this.Closed += (sender, args) =>
5254
{

NavItemReceiver.xaml.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
4545
}
4646
private void CleanupResources()
4747
{
48-
Debug.WriteLine("清理资源");
48+
Debug.WriteLine("清理接收资源");
4949
// 1. 停止WiFi广播
5050
if (_publisher.Status == WiFiDirectAdvertisementPublisherStatus.Started)
5151
{
@@ -164,11 +164,11 @@ private void BeginBroadcast()
164164
_publisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
165165
_publisher.Advertisement.ListenStateDiscoverability =
166166
WiFiDirectAdvertisementListenStateDiscoverability.Normal;
167-
Debug.WriteLine("开始扫描");
167+
Debug.WriteLine("开始广播");
168168
_publisher.Start();
169169
if (_publisher.Status != WiFiDirectAdvertisementPublisherStatus.Started)
170170
{
171-
Debug.WriteLine("扫描失败");
171+
Debug.WriteLine("广播失败");
172172
}
173173

174174
//AssociationEndpoint 关联的终结点。 这包括其他电脑、平板电脑和手机。
@@ -181,6 +181,7 @@ private void BeginBroadcast()
181181
new string[] { "System.Devices.WiFiDirect.InformationElements" }
182182
);
183183
connectionListener.ConnectionRequested += ConnectionRequestedHandler;
184+
Debug.WriteLine("开始监听");
184185
}
185186
else
186187
{
@@ -198,23 +199,25 @@ private async void ConnectionRequestedHandler(
198199
var request = args.GetConnectionRequest();
199200
try
200201
{
201-
var device = await WiFiDirectDevice.FromIdAsync(request.DeviceInformation.Id);
202-
if (device.ConnectionStatus == WiFiDirectConnectionStatus.Connected)
202+
//var device = await WiFiDirectDevice.FromIdAsync(request.DeviceInformation.Id);
203+
//if (device == null)
204+
// return;
205+
//if (device.ConnectionStatus == WiFiDirectConnectionStatus.Connected)
206+
//{
207+
// var endpointPairs = device.GetConnectionEndpointPairs();
208+
// foreach (var pair in endpointPairs)
209+
// {
210+
// 启动文件接收器
211+
if (receiver.IsListening == false)
203212
{
204-
var endpointPairs = device.GetConnectionEndpointPairs();
205-
foreach (var pair in endpointPairs)
206-
{
207-
// 启动文件接收器
208-
if (receiver.IsListening == false)
209-
{
210-
Debug.WriteLine($"LocalServiceName:{pair.LocalServiceName} RemoteServiceName:{pair.RemoteServiceName}");
211-
Debug.WriteLine($"LocalHostName:{pair.LocalHostName} RemoteHostName:{pair.RemoteHostName}");
213+
//Debug.WriteLine($"LocalServiceName:{pair.LocalServiceName} RemoteServiceName:{pair.RemoteServiceName}");
214+
//Debug.WriteLine($"LocalHostName:{pair.LocalHostName} RemoteHostName:{pair.RemoteHostName}");
212215

213-
await receiver.StartAsync(port);
216+
await receiver.StartAsync(port);
214217

215-
}
216-
}
217218
}
219+
// }
220+
//}
218221
}
219222
catch (Exception ex)
220223
{

NavItemSend.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
172172
}
173173
private void CleanupResources()
174174
{
175-
Debug.WriteLine("开始清理资源");
175+
Debug.WriteLine("开始清理发送资源");
176176
// 1. 停止设备扫描和广播
177177
if (_deviceWatcher != null)
178178
{

0 commit comments

Comments
 (0)