diff --git a/BililiveRecorder.Cli/Configure/ConfigInstructions.gen.cs b/BililiveRecorder.Cli/Configure/ConfigInstructions.gen.cs index adbb680..4bdd686 100644 --- a/BililiveRecorder.Cli/Configure/ConfigInstructions.gen.cs +++ b/BililiveRecorder.Cli/Configure/ConfigInstructions.gen.cs @@ -28,6 +28,7 @@ namespace BililiveRecorder.Cli.Configure WebHookUrls, WebHookUrlsV2, WpfShowTitleAndArea, + WpfNotifyStreamStart, Cookie, LiveApiHost, TimingCheckInterval, @@ -80,6 +81,7 @@ namespace BililiveRecorder.Cli.Configure GlobalConfig.Add(GlobalConfigProperties.WebHookUrls, new ConfigInstruction(config => config.HasWebHookUrls = false, (config, value) => config.WebHookUrls = value) { Name = "WebHookUrls", CanBeOptional = true }); GlobalConfig.Add(GlobalConfigProperties.WebHookUrlsV2, new ConfigInstruction(config => config.HasWebHookUrlsV2 = false, (config, value) => config.WebHookUrlsV2 = value) { Name = "WebHookUrlsV2", CanBeOptional = true }); GlobalConfig.Add(GlobalConfigProperties.WpfShowTitleAndArea, new ConfigInstruction(config => config.HasWpfShowTitleAndArea = false, (config, value) => config.WpfShowTitleAndArea = value) { Name = "WpfShowTitleAndArea", CanBeOptional = true }); + GlobalConfig.Add(GlobalConfigProperties.WpfNotifyStreamStart, new ConfigInstruction(config => config.HasWpfNotifyStreamStart = false, (config, value) => config.WpfNotifyStreamStart = value) { Name = "WpfNotifyStreamStart", CanBeOptional = true }); GlobalConfig.Add(GlobalConfigProperties.Cookie, new ConfigInstruction(config => config.HasCookie = false, (config, value) => config.Cookie = value) { Name = "Cookie", CanBeOptional = true }); GlobalConfig.Add(GlobalConfigProperties.LiveApiHost, new ConfigInstruction(config => config.HasLiveApiHost = false, (config, value) => config.LiveApiHost = value) { Name = "LiveApiHost", CanBeOptional = true }); GlobalConfig.Add(GlobalConfigProperties.TimingCheckInterval, new ConfigInstruction(config => config.HasTimingCheckInterval = false, (config, value) => config.TimingCheckInterval = value) { Name = "TimingCheckInterval", CanBeOptional = true }); diff --git a/BililiveRecorder.Core/Config/V3/Config.gen.cs b/BililiveRecorder.Core/Config/V3/Config.gen.cs index 91629e2..3e0427a 100644 --- a/BililiveRecorder.Core/Config/V3/Config.gen.cs +++ b/BililiveRecorder.Core/Config/V3/Config.gen.cs @@ -125,10 +125,15 @@ namespace BililiveRecorder.Core.Config.V3 public string? WebHookUrlsV2 => this.GetPropertyValue(); /// - /// 在界面显示标题和分区 + /// 桌面版在界面显示标题和分区 /// public bool WpfShowTitleAndArea => this.GetPropertyValue(); + /// + /// 桌面版开播时弹出系统通知 + /// + public bool WpfNotifyStreamStart => this.GetPropertyValue(); + /// /// Cookie /// @@ -304,13 +309,21 @@ namespace BililiveRecorder.Core.Config.V3 public Optional OptionalWebHookUrlsV2 { get => this.GetPropertyValueOptional(nameof(this.WebHookUrlsV2)); set => this.SetPropertyValueOptional(value, nameof(this.WebHookUrlsV2)); } /// - /// 在界面显示标题和分区 + /// 桌面版在界面显示标题和分区 /// public bool WpfShowTitleAndArea { get => this.GetPropertyValue(); set => this.SetPropertyValue(value); } public bool HasWpfShowTitleAndArea { get => this.GetPropertyHasValue(nameof(this.WpfShowTitleAndArea)); set => this.SetPropertyHasValue(value, nameof(this.WpfShowTitleAndArea)); } [JsonProperty(nameof(WpfShowTitleAndArea)), EditorBrowsable(EditorBrowsableState.Never)] public Optional OptionalWpfShowTitleAndArea { get => this.GetPropertyValueOptional(nameof(this.WpfShowTitleAndArea)); set => this.SetPropertyValueOptional(value, nameof(this.WpfShowTitleAndArea)); } + /// + /// 桌面版开播时弹出系统通知 + /// + public bool WpfNotifyStreamStart { get => this.GetPropertyValue(); set => this.SetPropertyValue(value); } + public bool HasWpfNotifyStreamStart { get => this.GetPropertyHasValue(nameof(this.WpfNotifyStreamStart)); set => this.SetPropertyHasValue(value, nameof(this.WpfNotifyStreamStart)); } + [JsonProperty(nameof(WpfNotifyStreamStart)), EditorBrowsable(EditorBrowsableState.Never)] + public Optional OptionalWpfNotifyStreamStart { get => this.GetPropertyValueOptional(nameof(this.WpfNotifyStreamStart)); set => this.SetPropertyValueOptional(value, nameof(this.WpfNotifyStreamStart)); } + /// /// Cookie /// @@ -450,6 +463,8 @@ namespace BililiveRecorder.Core.Config.V3 public bool WpfShowTitleAndArea => true; + public bool WpfNotifyStreamStart => false; + public string Cookie => @""; public string LiveApiHost => @"https://api.live.bilibili.com"; diff --git a/BililiveRecorder.Core/IRecorder.cs b/BililiveRecorder.Core/IRecorder.cs index ffafe24..b18e408 100644 --- a/BililiveRecorder.Core/IRecorder.cs +++ b/BililiveRecorder.Core/IRecorder.cs @@ -17,6 +17,7 @@ namespace BililiveRecorder.Core event EventHandler>? RecordFileClosed; event EventHandler>? IOStats; event EventHandler>? RecordingStats; + event EventHandler StreamStarted; IRoom AddRoom(int roomid); IRoom AddRoom(int roomid, bool enabled); diff --git a/BililiveRecorder.Core/Recorder.cs b/BililiveRecorder.Core/Recorder.cs index 9ac3387..12a4c19 100644 --- a/BililiveRecorder.Core/Recorder.cs +++ b/BililiveRecorder.Core/Recorder.cs @@ -52,6 +52,7 @@ namespace BililiveRecorder.Core public event EventHandler>? RecordFileClosed; public event EventHandler>? IOStats; public event EventHandler>? RecordingStats; + public event EventHandler? StreamStarted; #pragma warning disable CS0067 // The event 'Recorder.PropertyChanged' is never used public event PropertyChangedEventHandler? PropertyChanged; #pragma warning restore CS0067 // The event 'Recorder.PropertyChanged' is never used @@ -175,6 +176,7 @@ namespace BililiveRecorder.Core if (room.Streaming) { _ = Task.Run(async () => await this.basicWebhookV2.SendStreamStartedAsync(new StreamStartedEventArgs(room)).ConfigureAwait(false)); + _ = Task.Run(() => StreamStarted?.Invoke(this, room)); } else { diff --git a/BililiveRecorder.WPF/Pages/RoomListPage.xaml b/BililiveRecorder.WPF/Pages/RoomListPage.xaml index 8a6df49..cfe42c2 100644 --- a/BililiveRecorder.WPF/Pages/RoomListPage.xaml +++ b/BililiveRecorder.WPF/Pages/RoomListPage.xaml @@ -67,6 +67,7 @@ + diff --git a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs index 9744800..e60ff08 100644 --- a/BililiveRecorder.WPF/Pages/RootPage.xaml.cs +++ b/BililiveRecorder.WPF/Pages/RootPage.xaml.cs @@ -267,6 +267,21 @@ You can uninstall me in system settings.", "安装成功 Installed", MessageBoxB (Application.Current.MainWindow as NewMainWindow)!.HideToTray = true; NetworkChangeDetector.Enable(); + // 开播提醒系统通知,乱,但它能跑起来 ┑( ̄Д  ̄)┍ + recorder.StreamStarted += (sender, room) => + { + if (!recorder.Config.Global.WpfNotifyStreamStart) + return; + + _ = this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => + { + if (Application.Current.MainWindow is NewMainWindow nmw) + { + nmw.ShowBalloonTipCallback?.Invoke(room.Name + " 开播了", $"{room.AreaNameParent} · {room.AreaNameChild}\n{room.Title}", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.None); + } + })); + }; + _ = Task.Run(async () => { await Task.Delay(150); diff --git a/BililiveRecorder.WPF/Pages/SettingsPage.xaml b/BililiveRecorder.WPF/Pages/SettingsPage.xaml index 9358cf8..4becfe6 100644 --- a/BililiveRecorder.WPF/Pages/SettingsPage.xaml +++ b/BililiveRecorder.WPF/Pages/SettingsPage.xaml @@ -107,6 +107,9 @@ + + +