Sync desktop with public relay and add verified device connection management
This commit is contained in:
1 parent
87e888af69
commit
51c4f86918
17 files changed
+1289
-118
No files matched your search
@@ -18,19 +18,32 @@ public partial class App : Application
|
||||
desktop.MainWindow = window;
|
||||
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||||
void Show() { window.Show(); window.WindowState = WindowState.Normal; window.Activate(); }
|
||||
async Task QuitAsync()
|
||||
{
|
||||
if (quitting) return;
|
||||
quitting = true;
|
||||
try { await vm.ShutdownAsync(); }
|
||||
finally { desktop.Shutdown(); }
|
||||
}
|
||||
var menu = new NativeMenu();
|
||||
var show = new NativeMenuItem("打开设备工作台"); show.Click += (_, _) => Show(); menu.Items.Add(show);
|
||||
menu.Items.Add(new NativeMenuItem("断开当前连接") { Command = vm.DisconnectCommand });
|
||||
menu.Items.Add(new NativeMenuItemSeparator());
|
||||
var quit = new NativeMenuItem("退出并断开连接");
|
||||
quit.Click += async (_, _) => { quitting = true; await vm.ShutdownAsync(); desktop.Shutdown(); };
|
||||
quit.Click += async (_, _) => await QuitAsync();
|
||||
menu.Items.Add(quit);
|
||||
using var stream = Avalonia.Platform.AssetLoader.Open(new Uri("avares://Ads.Desktop/Assets/app.png"));
|
||||
var tray = new TrayIcon { ToolTipText = "ADS · Android 设备工作台", Icon = new WindowIcon(stream), Menu = menu, Command = new RelayCommand(Show) };
|
||||
TrayIcon.SetIcons(this, new TrayIcons { tray });
|
||||
vm.PropertyChanged += (_, change) => {
|
||||
if (change.PropertyName is nameof(vm.Status) or nameof(vm.ActiveDeviceId))
|
||||
tray.ToolTipText = "ADS · " + vm.Status;
|
||||
};
|
||||
window.Closing += async (_, e) => {
|
||||
if (quitting) return;
|
||||
e.Cancel = true;
|
||||
if (vm.MinimizeToTray) window.Hide();
|
||||
else { quitting = true; await vm.ShutdownAsync(); desktop.Shutdown(); }
|
||||
else await QuitAsync();
|
||||
};
|
||||
desktop.Exit += (_, _) => { tray.Dispose(); vm.Dispose(); };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user