private async void LogRedirectToggleButton_OnChecked(object sender, RoutedEventArgs e) { try { if (!await LoginCenterAPIWarpper.DoAuth(PluginMain)) { LogRedirectToggleButton.IsChecked = false; } } catch (Exception) { LogRedirectToggleButton.IsChecked = false; } }
/// <summary> /// 应用设置 /// </summary> /// <param name="config"></param> private void ApplyConfig(Config config) { Player.PlayerType = config.PlayerType; Player.DirectSoundDevice = config.DirectSoundDevice; Player.WaveoutEventDevice = config.WaveoutEventDevice; Player.Volume = config.Volume; Player.IsUserPrior = config.IsUserPrior; Player.IsPlaylistEnabled = config.IsPlaylistEnabled; SearchModules.PrimaryModule = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == config.PrimaryModuleId) ?? SearchModules.NullModule; SearchModules.SecondaryModule = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == config.SecondaryModuleId) ?? SearchModules.NullModule; DanmuHandler.MaxTotalSongNum = config.MaxTotalSongNum; DanmuHandler.MaxPersonSongNum = config.MaxPersonSongNum; Writer.ScribanTemplate = config.ScribanTemplate; IsLogRedirectDanmaku = config.IsLogRedirectDanmaku; LogDanmakuLengthLimit = config.LogDanmakuLengthLimit; LogRedirectToggleButton.IsEnabled = LoginCenterAPIWarpper.CheckLoginCenter(); if (LogRedirectToggleButton.IsEnabled && IsLogRedirectDanmaku) { Task.Run(async() => { await Task.Delay(2000); // 其实不应该这么写的,不太合理 IsLogRedirectDanmaku = await LoginCenterAPIWarpper.DoAuth(PluginMain); }); } else { IsLogRedirectDanmaku = false; } Playlist.Clear(); foreach (var item in config.Playlist) { item.Module = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == item.ModuleId); if (item.Module != null) { Playlist.Add(item); } } Blacklist.Clear(); foreach (var item in config.Blacklist) { Blacklist.Add(item); } }
public void Log(string text) { PluginMain.Log(text); if (IsLogRedirectDanmaku) { Task.Run(() => { try { if (!PluginMain.RoomId.HasValue) { return; } string finalText = text.Substring(0, Math.Min(text.Length, LogDanmakuLengthLimit)); string result = LoginCenterAPIWarpper.Send(PluginMain.RoomId.Value, finalText); if (result == null) { PluginMain.Log("发送弹幕时网络错误"); } else { var j = JObject.Parse(result); if (j["msg"].ToString() != string.Empty) { PluginMain.Log("发送弹幕时服务器返回:" + j["msg"].ToString()); } } } catch (Exception ex) { if (ex.GetType().FullName.Equals("LoginCenter.API.PluginNotAuthorizedException")) { IsLogRedirectDanmaku = false; } else { PluginMain.Log("弹幕发送错误 " + ex.ToString()); } } }); } }
internal static bool CheckLoginCenter() { if (isLoginCenterChecked) { return(warpper != null); } try { warpper = new LoginCenterAPIWarpper(); return(true); } catch (Exception) { return(false); } finally { isLoginCenterChecked = true; } }
/// <summary> /// 应用设置 /// </summary> /// <param name="config"></param> private void ApplyConfig(Config config) { LogRedirectToggleButton.IsEnabled = LoginCenterAPIWarpper.CheckLoginCenter(); Player.PlayerType = config.PlayerType; Player.DirectSoundDevice = config.DirectSoundDevice; Player.WaveoutEventDevice = config.WaveoutEventDevice; Player.Volume = config.Volume; Player.IsUserPrior = config.IsUserPrior; Player.IsPlaylistEnabled = config.IsPlaylistEnabled; Player.MaxPlayTime = config.MaxPlayTime; DanmuHandler.IsAllowCancelPlayingSong = config.IsAllowCancelPlayingSong; DanmuHandler.MaxTotalSongNum = config.MaxTotalSongNum; DanmuHandler.MaxPersonSongNum = config.MaxPersonSongNum; DanmuHandler.AdminCommand = config.AdminCommand; DanmuHandler.Vote4NextCount = config.Vote4NextCount; Writer.ScribanTemplate = config.ScribanTemplate; IsLogRedirectDanmaku = LogRedirectToggleButton.IsEnabled && config.IsLogRedirectDanmaku; LogDanmakuLengthLimit = config.LogDanmakuLengthLimit; SearchModules.PrimaryModule = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == config.PrimaryModuleId) ?? SearchModules.NullModule; SearchModules.SecondaryModule = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == config.SecondaryModuleId) ?? SearchModules.NullModule; Playlist.Clear(); foreach (var item in config.Playlist) { item.Module = SearchModules.Modules.FirstOrDefault(x => x.UniqueId == item.ModuleId); if (item.Module != null) { Playlist.Add(item); } } Blacklist.Clear(); foreach (var item in config.Blacklist) { Blacklist.Add(item); } ApplyConfigReady = true; }