MainView.axaml.cs 962 B

12345678910111213141516171819202122232425262728
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Interactivity;
  4. using PCL.Communist.ViewModels;
  5. namespace PCL.Communist.Views;
  6. public partial class MainView : UserControl
  7. {
  8. public MainView()
  9. {
  10. InitializeComponent();
  11. }
  12. private async void OpenLoginSite(object? sender, RoutedEventArgs e)
  13. {
  14. if (DataContext is not MainViewModel model || TopLevel.GetTopLevel(this) is not { } top) return;
  15. try
  16. {
  17. var uri = new Uri(model.LoginAddress);
  18. if (uri.Scheme != "https" || (uri.Host != "microsoft.com" && !uri.Host.EndsWith(".microsoft.com", StringComparison.Ordinal)))
  19. throw new InvalidOperationException("登录网页地址无法验证,请重新发起微软登录。");
  20. if (!await top.Launcher.LaunchUriAsync(uri)) model.Status = "请在浏览器打开显示的登录地址。";
  21. }
  22. catch (Exception ex) { model.Status = ex.Message; }
  23. }
  24. }