Skip to content

Commit

Permalink
完善通知显示。
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjz authored and chenjz committed May 27, 2024
1 parent 1b67f8e commit a85078c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions PeachPlayer/Foundation/Interactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Interactions
{

public static Interaction<string, bool?> ShowNote { get; } = new();
public static Interaction<string, bool?> ShowError { get; } = new();

}
}
6 changes: 5 additions & 1 deletion PeachPlayer/ViewModels/FilmTelevisionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;

namespace PeachPlayer.ViewModels;
Expand Down Expand Up @@ -51,7 +52,10 @@ public FilmTelevisionViewModel(ISourceService _source = null)
private async void LoadSource()
{
if (string.IsNullOrEmpty(ConfigStorage.Instance.AppConfig.SourceUrl))
{
_ = Interactions.ShowError.Handle("请先配置数据源地址。");
return;
}
//测试加载数据
var req = await source.LoadConfig(ConfigStorage.Instance.AppConfig.SourceUrl);
if (req)
Expand All @@ -60,7 +64,7 @@ private async void LoadSource()

public async void SwitchSite(SiteModel site)
{
var aa = Interactions.ShowNote.Handle("cersasdaosdjiaodjoi阿斯达结算单");

Types.Clear();
await vod.InitSite(site);
var filter = await vod.HomeAsync();
Expand Down
41 changes: 28 additions & 13 deletions PeachPlayer/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using Avalonia.Styling;
using Avalonia.Xaml.Interactivity;
using PeachPlayer.Foundation;
using PeachPlayer.ViewModels;
using ReactiveUI;
using Splat;
using System;
using System.Reactive.Disposables;
using System.Runtime.InteropServices;
using System.Threading.Tasks;


namespace PeachPlayer.Views;

public partial class MainWindow : ReactiveWindow<MainWindowModel>
public partial class MainWindow : Window
{
Path maximizeIcon;
ToolTip maximizeToolTip;
Expand Down Expand Up @@ -51,8 +48,8 @@ public MainWindow()
}
SubscribeToWindowState();

this.WhenActivated(action =>
action(Interactions.ShowNote.RegisterHandler(NotifyMessage)));
Interactions.ShowNote.RegisterHandler(cxt => NotifyMessage(cxt));
Interactions.ShowError.RegisterHandler(cxt => NotifyMessage(cxt, NotificationType.Error));

}

Expand Down Expand Up @@ -154,13 +151,31 @@ private void MainWindow_PointerPressed(object? sender, PointerPressedEventArgs e


WindowNotificationManager windowNotiManager;
public async Task NotifyMessage(IInteractionContext<string, bool?> context)

public void NotifyMessage(IInteractionContext<string, bool?> context, NotificationType notificationType = NotificationType.Information)
{
var title = "信息";
switch (notificationType)
{
case NotificationType.Information:
title = "信息";
break;
case NotificationType.Success:
title = "成功";
break;
case NotificationType.Warning:
title = "警告";
break;
case NotificationType.Error:
title = "异常";
break;
default:
break;
}
if (windowNotiManager == null)
windowNotiManager = new WindowNotificationManager(TopLevel.GetTopLevel(this));
TaskCompletionSource source = new TaskCompletionSource();
windowNotiManager.Show(new Notification("提示", context.Input));
await source.Task;
windowNotiManager.Show(new Notification(title, context.Input, notificationType));
context.SetOutput(true);
}

}

0 comments on commit a85078c

Please sign in to comment.