From 0239c6f14238cd62e43d7b42701ca92f56c5b897 Mon Sep 17 00:00:00 2001 From: BoiHanny Date: Mon, 24 Jul 2023 20:00:40 +0200 Subject: [PATCH] When you are done editing a message, it will auto-focus into the 'send a new message' box. Bug fix: When in chat edit mode and the live edit is turned off, exiting the edit mode would not apply the changes. Other: Code clean-up. --- vrcosc-magicchatbox/MainWindow.xaml.cs | 1290 ++++++++++++------------ 1 file changed, 628 insertions(+), 662 deletions(-) diff --git a/vrcosc-magicchatbox/MainWindow.xaml.cs b/vrcosc-magicchatbox/MainWindow.xaml.cs index 08fcd99c..235df234 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml.cs +++ b/vrcosc-magicchatbox/MainWindow.xaml.cs @@ -21,29 +21,18 @@ namespace vrcosc_magicchatbox { public partial class MainWindow : Window { - public float samplingTime = 1; - public static readonly DependencyProperty ShadowOpacityProperty = DependencyProperty.Register("ShadowOpacity", typeof(double), typeof(MainWindow), new PropertyMetadata(0.0)); - - DispatcherTimer backgroundCheck = new DispatcherTimer(); - private System.Timers.Timer pauseTimer; - private System.Timers.Timer ChatUpdateTimer; private static List _activeCancellationTokens = new List(); private static double _shadowOpacity; - public static double ShadowOpacity - { - get => _shadowOpacity; - set - { - if (_shadowOpacity != value) - { - _shadowOpacity = value; - ShadowOpacityChanged?.Invoke(null, EventArgs.Empty); - } - } - } - - public static event EventHandler ShadowOpacityChanged; + public static readonly DependencyProperty ShadowOpacityProperty = DependencyProperty.Register( + "ShadowOpacity", + typeof(double), + typeof(MainWindow), + new PropertyMetadata(0.0)); + DispatcherTimer backgroundCheck = new DispatcherTimer(); + private System.Timers.Timer ChatUpdateTimer; + private System.Timers.Timer pauseTimer; + public float samplingTime = 1; public MainWindow() @@ -69,102 +58,121 @@ public MainWindow() ChangeMenuItem(ViewModel.Instance.CurrentMenuItem); scantick(); //OSCReader.StartListening(); - } - public void SelectTTS() + public static event EventHandler ShadowOpacityChanged; + + private void AddFav_Click(object sender, RoutedEventArgs e) { - foreach (var voice in TikTokTTSVoices_combo.Items) + Random random = new Random(); + int randomId = random.Next(10, 99999999); + bool IsActive = false; + if(ViewModel.Instance.StatusList.Count() == 0) { - if (voice is Voice && (voice as Voice).ApiName == ViewModel.Instance.SelectedTikTokTTSVoice?.ApiName) - { - TikTokTTSVoices_combo.SelectedItem = voice; - break; - } + IsActive = true; } - } - public void SelectTTSOutput() - { - foreach (var AudioDevice in PlaybackOutputDeviceComboBox.Items) + if(ViewModel.Instance.NewStatusItemTxt.Count() > 0 && ViewModel.Instance.NewStatusItemTxt.Count() < 141) { - if (AudioDevice is AudioDevice && (AudioDevice as AudioDevice).FriendlyName == ViewModel.Instance.SelectedPlaybackOutputDevice?.FriendlyName) + ViewModel.Instance.StatusList + .Add( + new StatusItem + { + CreationDate = DateTime.Now, + IsActive = IsActive, + IsFavorite = false, + msg = ViewModel.Instance.NewStatusItemTxt, + MSGID = randomId + }); + ViewModel.Instance.StatusList = new ObservableCollection( + ViewModel.Instance.StatusList.OrderByDescending(x => x.CreationDate)); + if(ViewModel.Instance.NewStatusItemTxt.ToLower() == "sr4 series" || + ViewModel.Instance.NewStatusItemTxt.ToLower() == "boihanny") { - PlaybackOutputDeviceComboBox.SelectedItem = AudioDevice; - break; + ViewModel.Instance.Egg_Dev = true; + MessageBox.Show( + "u found the dev egggmoooodeee", + "Egg", + MessageBoxButton.OK, + MessageBoxImage.Information); } + ViewModel.Instance.NewStatusItemTxt = string.Empty; + ViewModel.SaveStatusList(); } } - - private void SaveDataToDisk(object sender, System.ComponentModel.CancelEventArgs e) + private void Button_close_Click(object sender, RoutedEventArgs e) { - try - { - this.Hide(); - DataController.ManageSettingsXML(true); - DataController.SaveAppList(); - DataController.SaveMediaSessions(); - System.Environment.Exit(1); - } - catch (Exception ex) - { + this.Visibility = Visibility.Hidden; + this.Close(); + } - Logging.WriteException(ex, makeVMDump: true, MSGBox: true, exitapp: true); - } + private void Button_minimize_Click(object sender, RoutedEventArgs e) + { this.WindowState = WindowState.Minimized; } - } - private void Timer(object sender, EventArgs e) + private void ButtonChattingTxt_Click(object sender, RoutedEventArgs e) { - - bool ChatItemActive = ViewModel.Instance.LastMessages.Any(x => x.IsRunning); - - if (ViewModel.Instance.ScanPause && ChatItemActive) + string chat = ViewModel.Instance.NewChattingTxt; + if(chat.Length > 0 && chat.Length <= 141 && ViewModel.Instance.MasterSwitch) { - if (pauseTimer == null) + foreach(ChatItem Chatitem in ViewModel.Instance.LastMessages) { - ViewModel.Instance.CountDownUI = false; - pauseTimer = new System.Timers.Timer(); - pauseTimer.Interval = 1000; - pauseTimer.Elapsed += PauseTimer_Tick; - pauseTimer.Start(); - if(ViewModel.Instance.KeepUpdatingChat) + Chatitem.CanLiveEdit = false; + Chatitem.CanLiveEditRun = false; + Chatitem.MsgReplace = string.Empty; + Chatitem.IsRunning = false; + } + OSCController.CreateChat(true); + int smalldelay = ViewModel.Instance.ChatAddSmallDelay + ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) + : 0; + OSCSender.SendOSCMessage(ViewModel.Instance.ChatFX, smalldelay); + DataController.SaveChatList(); + if(ViewModel.Instance.TTSTikTokEnabled == true) + { + if(DataAndSecurity.DataController.PopulateOutputDevices(true)) { - if (ChatUpdateTimer == null) - { - - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - if (lastsendchat != null) - { - lastsendchat.LiveEditButtonTxt = "Sending..."; - } - ChatUpdateTimer = new System.Timers.Timer(); - ChatUpdateTimer.Interval = (int)(ViewModel.Instance.ChattingUpdateRate * 1000); - ChatUpdateTimer.Elapsed += ChatUpdateTimer_Tick; - ChatUpdateTimer.Start(); - } + ViewModel.Instance.ChatFeedbackTxt = "Requesting TTS..."; + TTSGOAsync(chat); + } else + { + ViewModel.Instance.ChatFeedbackTxt = "Error setting output device."; } } + + Timer(null, null); + RecentScroll.ScrollToEnd(); } - else + } + + private void CancelEditbutton_Click(object sender, RoutedEventArgs e) + { + try { - if (pauseTimer != null) - { - pauseTimer.Stop(); - pauseTimer = null; - } - if (ChatUpdateTimer != null) - { - ChatUpdateTimer.Stop(); - ChatUpdateTimer = null; - } + var button = sender as Button; + var item = button.Tag as StatusItem; + item.editMsg = string.Empty; + item.IsEditing = false; + } catch(Exception) + { + } + } - ViewModel.Instance.CountDownUI = true; - scantick(); + private void CancelEditChatbutton_Click(object sender, RoutedEventArgs e) + { + var Button = sender as Button; + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); + + if(!string.IsNullOrEmpty(lastsendchat.MainMsg)) + { + lastsendchat.CanLiveEditRun = false; + lastsendchat.Msg = lastsendchat.MainMsg; } + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; } private void ChatUpdateTimer_Tick(object sender, System.Timers.ElapsedEventArgs e) @@ -173,335 +181,303 @@ private void ChatUpdateTimer_Tick(object sender, System.Timers.ElapsedEventArgs lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); try { - if (ViewModel.Instance.KeepUpdatingChat && lastsendchat != null) + if(ViewModel.Instance.KeepUpdatingChat && lastsendchat != null) { - if (lastsendchat.Msg.Length > 0 && lastsendchat.Msg.Length <= 141 && ViewModel.Instance.MasterSwitch) + if(lastsendchat.Msg.Length > 0 && lastsendchat.Msg.Length <= 141 && ViewModel.Instance.MasterSwitch) { string Complete_msg = null; - if (ViewModel.Instance.PrefixChat == true) + if(ViewModel.Instance.PrefixChat == true) { Complete_msg = "💬 " + lastsendchat.Msg; - } - else + } else { Complete_msg = lastsendchat.Msg; } ViewModel.Instance.OSCtoSent = Complete_msg; OSCSender.SendOSCMessage(false); } - - } - else + } else { - foreach (var item in ViewModel.Instance.LastMessages) + foreach(var item in ViewModel.Instance.LastMessages) { item.CanLiveEdit = false; item.CanLiveEditRun = false; - item.MsgReplace = ""; + item.MsgReplace = string.Empty; item.IsRunning = false; } } + } catch(Exception ex) + { + Logging.WriteException(ex, makeVMDump: false, MSGBox: false); } - catch (Exception ex) { Logging.WriteException(ex, makeVMDump: false, MSGBox: false); } } - private void PauseTimer_Tick(object sender, System.Timers.ElapsedEventArgs e) - { - try - { - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - - ViewModel.Instance.ScanPauseCountDown--; - Application.Current.Dispatcher.Invoke(() => - { - ViewModel.Instance.ScanPauseCountDown = ViewModel.Instance.ScanPauseCountDown; - if(lastsendchat != null) - { - lastsendchat.CanLiveEdit = ViewModel.Instance.ChatLiveEdit; - lastsendchat.LiveEditButtonTxt = ViewModel.Instance.RealTimeChatEdit ? "Live Edit (" + ViewModel.Instance.ScanPauseCountDown + ")" : "Edit (" + ViewModel.Instance.ScanPauseCountDown + ")"; - } - - }); - - if (ViewModel.Instance.ScanPauseCountDown <= 0 || !ViewModel.Instance.ScanPause) - { - ViewModel.Instance.ScanPause = false; - pauseTimer.Stop(); - pauseTimer = null; - if (ViewModel.Instance.ScanPauseCountDown != 0) - { - ViewModel.Instance.ScanPauseCountDown = 0; - } - - OSCController.ClearChat(lastsendchat); - OSCSender.SendOSCMessage(false); - Timer(null, null); - } - } - catch (Exception ex) { Logging.WriteException(ex, makeVMDump: false, MSGBox: false); } + private void CheckUpdateBtnn_Click(object sender, RoutedEventArgs e) { ManualUpdateCheckAsync(); } + private void ClearChat_Click(object sender, RoutedEventArgs e) + { + ViewModel.Instance.LastMessages.Clear(); + DataController.SaveChatList(); + StopChat_Click(null, null); } - public void scantick() + private void ClearnupKeepSettings_Click(object sender, RoutedEventArgs e) { - try + int ItemRemoved = WindowActivity.CleanAndKeepAppsWithSettings(); + if(ItemRemoved > 0) { - if (ViewModel.Instance.IntgrScanSpotify_OLD == true) - { - ViewModel.Instance.PlayingSongTitle = SpotifyActivity.CurrentPlayingSong(); - ViewModel.Instance.SpotifyActive = SpotifyActivity.SpotifyIsRunning(); - } - if (ViewModel.Instance.IntgrScanWindowActivity == true) - { - ViewModel.Instance.FocusedWindow = WindowActivity.GetForegroundProcessName(); - } - - ViewModel.Instance.IsVRRunning = WindowActivity.IsVRRunning(); - if (ViewModel.Instance.IntgrScanWindowTime == true) - ViewModel.Instance.CurrentTime = SystemStats.GetTime(); - ViewModel.Instance.ChatFeedbackTxt = ""; - OSCController.BuildOSC(); - OSCSender.SendOSCMessage(false); - } - catch (Exception ex) + ViewModel.Instance.DeletedAppslabel = $"Removed {ItemRemoved} apps from history"; + } else { - Logging.WriteException(ex, makeVMDump: false, MSGBox: false); + ViewModel.Instance.DeletedAppslabel = $"No apps removed from history"; } - } - public static void ChangeMenuItem(int changeINT) + private void DeleteButton_Click(object sender, RoutedEventArgs e) { - ViewModel.Instance.CurrentMenuItem = changeINT; - ViewModel.Instance.MenuItem_0_Visibility = "Hidden"; - ViewModel.Instance.MenuItem_1_Visibility = "Hidden"; - ViewModel.Instance.MenuItem_2_Visibility = "Hidden"; - ViewModel.Instance.MenuItem_3_Visibility = "Hidden"; - if (ViewModel.Instance.CurrentMenuItem == 0) - { - ViewModel.Instance.MenuItem_0_Visibility = "Visible"; - return; - } - else if (ViewModel.Instance.CurrentMenuItem == 1) - { - ViewModel.Instance.MenuItem_1_Visibility = "Visible"; - return; - } - else if (ViewModel.Instance.CurrentMenuItem == 2) + try { - ViewModel.Instance.MenuItem_2_Visibility = "Visible"; - return; - } - else if (ViewModel.Instance.CurrentMenuItem == 3) + var button = sender as Button; + var item = button.Tag as StatusItem; + if(item.msg.ToLower() == "sr4 series" || item.msg.ToLower() == "boihanny") + { + ViewModel.Instance.Egg_Dev = false; + MessageBox.Show( + "damn u left the dev egggmoooodeee", + "Egg", + MessageBoxButton.OK, + MessageBoxImage.Information); + } + ViewModel.Instance.StatusList.Remove(item); + ViewModel.SaveStatusList(); + } catch(Exception) { - ViewModel.Instance.MenuItem_3_Visibility = "Visible"; - return; } - ChangeMenuItem(0); } - - private void Update_Click(object sender, RoutedEventArgs e) - { - if (ViewModel.Instance.ScanPause != true) - { - OSCController.BuildOSC(); - } - } + private void Discord_Click(object sender, RoutedEventArgs e) + { Process.Start("explorer", "https://discord.gg/ZaSFwBfhvG"); } private void Drag_area_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (e.ChangedButton == MouseButton.Left) + if(e.ChangedButton == MouseButton.Left) this.DragMove(); } - - private void Button_close_Click(object sender, RoutedEventArgs e) + private void Editbutton_Checked(object sender, RoutedEventArgs e) { - this.Visibility = Visibility.Hidden; - this.Close(); + try + { + var button = sender as ToggleButton; + var item = button.Tag as StatusItem; + if((bool)button.IsChecked) + { + item.editMsg = item.msg; + // Find the TextBox in the same container as the ToggleButton + var parent = VisualTreeHelper.GetParent(button); + while(!(parent is ContentPresenter)) + { + parent = VisualTreeHelper.GetParent(parent); + } + var contentPresenter = parent as ContentPresenter; + var dataTemplate = contentPresenter.ContentTemplate; + var editTextBox = (TextBox)dataTemplate.FindName("EditTextBox", contentPresenter); + editTextBox.Focus(); + // Set the cursor at the end of the text + editTextBox.CaretIndex = editTextBox.Text.Length; + } else + { + if(item.editMsg.Count() < 145 && !string.IsNullOrEmpty(item.editMsg)) + { + item.msg = item.editMsg; + item.IsEditing = false; + item.editMsg = string.Empty; + item.LastEdited = DateTime.Now; + } + } + } catch(Exception) + { + } } - private void Button_minimize_Click(object sender, RoutedEventArgs e) + private void EditChatTextBox_KeyDown(object sender, KeyEventArgs e) { - this.WindowState = WindowState.Minimized; - } + var textbox = sender as TextBox; + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - private void NewVersion_MouseUp(object sender, MouseButtonEventArgs e) - { - if (ViewModel.Instance.CanUpdate) + if(ViewModel.Instance.RealTimeChatEdit) { - ViewModel.Instance.CanUpdate = false; - ViewModel.Instance.CanUpdateLabel = false; - Task.Run(() => UpdateApp.PrepareUpdate()); - } - else + if(e.Key == Key.Enter) + { + lastsendchat.CanLiveEditRun = false; + lastsendchat.MainMsg = textbox.Text; + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; + } + if(e.Key == Key.Escape) + { + if(!string.IsNullOrEmpty(lastsendchat.MainMsg)) + { + lastsendchat.CanLiveEditRun = false; + lastsendchat.Msg = lastsendchat.MainMsg; + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; + } + } + } else { - Process.Start("explorer", "http://github.com/BoiHanny/vrcosc-magicchatbox/releases"); + if(e.Key == Key.Enter) + { + if(textbox != null && lastsendchat != null) + { + if(lastsendchat.Msg != textbox.Text) + { + lastsendchat.MainMsg = textbox.Text; + lastsendchat.Msg = textbox.Text; + lastsendchat.CanLiveEditRun = false; + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; + } + } + } + if(e.Key == Key.Escape) + { + if(!string.IsNullOrEmpty(lastsendchat.MainMsg)) + { + lastsendchat.CanLiveEditRun = false; + lastsendchat.Msg = lastsendchat.MainMsg; + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; + } + } } - } - private void MasterSwitch_Click(object sender, RoutedEventArgs e) + private void EditChatTextBox_TextChanged(object sender, TextChangedEventArgs e) { - if (ViewModel.Instance.MasterSwitch == true) - { - backgroundCheck.Start(); - } - else + if(ViewModel.Instance.RealTimeChatEdit) { - backgroundCheck.Stop(); - } - - } + var textbox = sender as TextBox; + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - private void MenuButton_0_Click(object sender, RoutedEventArgs e) - { - ChangeMenuItem(0); + if(textbox != null && lastsendchat != null) + { + if(lastsendchat.Msg != textbox.Text) + { + lastsendchat.Msg = textbox.Text; + } + } + } } - private void MenuButton_1_Click(object sender, RoutedEventArgs e) + private void FavBox_KeyDown(object sender, KeyEventArgs e) { - ChangeMenuItem(1); + try + { + if(e.Key == Key.Enter) + { + AddFav_Click(sender, e); + } + if(e.Key == Key.Escape) + { + ViewModel.Instance.NewStatusItemTxt = string.Empty; + } + } catch(Exception ex) + { + Logging.WriteException(ex, makeVMDump: false, MSGBox: false); + } } - private void MenuButton_2_Click(object sender, RoutedEventArgs e) - { - ChangeMenuItem(2); - } + private void Favbutton_Click(object sender, RoutedEventArgs e) { ViewModel.SaveStatusList(); } - private void MenuButton_3_Click(object sender, RoutedEventArgs e) - { - ChangeMenuItem(3); - } + private void Github_Click(object sender, RoutedEventArgs e) + { Process.Start("explorer", "https://github.com/BoiHanny/vrcosc-magicchatbox"); } - private void DeleteButton_Click(object sender, RoutedEventArgs e) + private void GitHubChanges_MouseUp(object sender, MouseButtonEventArgs e) { - try + if(ViewModel.Instance.tagURL == null) { - var button = sender as Button; - var item = button.Tag as StatusItem; - if (item.msg.ToLower() == "sr4 series" || item.msg.ToLower() == "boihanny") - { - ViewModel.Instance.Egg_Dev = false; - MessageBox.Show("damn u left the dev egggmoooodeee", "Egg", MessageBoxButton.OK, MessageBoxImage.Information); - } - ViewModel.Instance.StatusList.Remove(item); - ViewModel.SaveStatusList(); - } - catch (Exception) + Process.Start("explorer", "http://github.com/BoiHanny/vrcosc-magicchatbox/releases"); + } else { - + Process.Start("explorer", ViewModel.Instance.tagURL); } } - private void SortUsed_Click(object sender, RoutedEventArgs e) + private void IntelliChatAIapiPage_MouseUp(object sender, MouseButtonEventArgs e) + { Process.Start("explorer", "https://platform.openai.com/account/api-keys"); } + + private void IntgrIntelliWing_btn_Click(object sender, RoutedEventArgs e) + { ViewModel.Instance.IntgrIntelliWing = !ViewModel.Instance.IntgrIntelliWing; } + + private void LearnMoreAboutHeartbtn_MouseUp(object sender, MouseButtonEventArgs e) { - ViewModel.Instance.StatusList = new ObservableCollection(ViewModel.Instance.StatusList.OrderByDescending(x => x.LastUsed)); + Process.Start( + "explorer", + "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/How-to-Set-Up-MagicChatbox-with-Pulsoid-for-VRChat-%F0%9F%92%9C"); } - private void SortFav_Click(object sender, RoutedEventArgs e) + private void LearnMoreAboutIntelliChatAI_MouseUp(object sender, MouseButtonEventArgs e) + { Process.Start("explorer", "https://openai.com/product"); } + + private void LearnMoreAboutSpotifybtn_MouseUp(object sender, MouseButtonEventArgs e) { - ViewModel.Instance.StatusList = new ObservableCollection(ViewModel.Instance.StatusList.OrderByDescending(x => x.IsFavorite).ThenBy(x => x.LastUsed)); + Process.Start( + "explorer", + "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/How-to-Use-the-Spotify-Integration-%F0%9F%8E%B5"); } - private void SortDate_Click(object sender, RoutedEventArgs e) + private void LearnMoreAboutTTSbtn_MouseUp(object sender, MouseButtonEventArgs e) { - { - ViewModel.Instance.StatusList = new ObservableCollection(ViewModel.Instance.StatusList.OrderByDescending(x => x.CreationDate)); - } + Process.Start( + "explorer", + "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/Play-TTS-Output-of-MagicChatbox-to-Main-Audio-Device-and-Microphone-in-VRChat-Using-VB-Audio-Cable-(Simple-Setup)"); } - private void FavBox_KeyDown(object sender, KeyEventArgs e) + private void MakeDataDump_Click(object sender, RoutedEventArgs e) { try { - if (e.Key == Key.Enter) - { - AddFav_Click(sender, e); - } - if (e.Key == Key.Escape) - { - ViewModel.Instance.NewStatusItemTxt = ""; - } - } - catch (Exception ex) + Logging.ViewModelDump(); + Process.Start("explorer.exe", ViewModel.Instance.LogPath); + } catch(Exception ex) { - Logging.WriteException(ex, makeVMDump: false, MSGBox: false); + Logging.WriteException(ex); } } - private void NewFavText_TextChanged(object sender, TextChangedEventArgs e) + private async Task ManualUpdateCheckAsync() + { await Task.Run(() => DataController.CheckForUpdateAndWait(true)); } + + private void MasterSwitch_Click(object sender, RoutedEventArgs e) { - var textBox = sender as TextBox; - int count = textBox.Text.Count(); - ViewModel.Instance.StatusBoxCount = $"{count.ToString()}/140"; - if (count > 140) - { - int overmax = count - 140; - ViewModel.Instance.StatusBoxColor = "#FFFF9393"; - ViewModel.Instance.StatusTopBarTxt = $"You're soaring past the 140 char limit by {overmax}. Reign in that message!"; - } - else if (count == 0) + if(ViewModel.Instance.MasterSwitch == true) { - ViewModel.Instance.StatusBoxColor = "#FF504767"; - ViewModel.Instance.StatusTopBarTxt = $""; - } - else + backgroundCheck.Start(); + } else { - ViewModel.Instance.StatusBoxColor = "#FF2C2148"; - if (count > 22) - { - ViewModel.Instance.StatusTopBarTxt = $"Buckle up! Keep it tight to 20-25 or integrations may suffer."; - } - else - { - ViewModel.Instance.StatusTopBarTxt = $""; - } + backgroundCheck.Stop(); } } - private void AddFav_Click(object sender, RoutedEventArgs e) - { - Random random = new Random(); - int randomId = random.Next(10, 99999999); - bool IsActive = false; - if (ViewModel.Instance.StatusList.Count() == 0) - { - IsActive = true; - } + private void MenuButton_0_Click(object sender, RoutedEventArgs e) { ChangeMenuItem(0); } - if (ViewModel.Instance.NewStatusItemTxt.Count() > 0 && ViewModel.Instance.NewStatusItemTxt.Count() < 141) - { - ViewModel.Instance.StatusList.Add(new StatusItem { CreationDate = DateTime.Now, IsActive = IsActive, IsFavorite = false, msg = ViewModel.Instance.NewStatusItemTxt, MSGID = randomId }); - ViewModel.Instance.StatusList = new ObservableCollection(ViewModel.Instance.StatusList.OrderByDescending(x => x.CreationDate)); - if (ViewModel.Instance.NewStatusItemTxt.ToLower() == "sr4 series" || ViewModel.Instance.NewStatusItemTxt.ToLower() == "boihanny") - { - ViewModel.Instance.Egg_Dev = true; - MessageBox.Show("u found the dev egggmoooodeee", "Egg", MessageBoxButton.OK, MessageBoxImage.Information); - } - ViewModel.Instance.NewStatusItemTxt = ""; - ViewModel.SaveStatusList(); + private void MenuButton_1_Click(object sender, RoutedEventArgs e) { ChangeMenuItem(1); } - } - } + private void MenuButton_2_Click(object sender, RoutedEventArgs e) { ChangeMenuItem(2); } - private void Favbutton_Click(object sender, RoutedEventArgs e) - { - ViewModel.SaveStatusList(); - } + private void MenuButton_3_Click(object sender, RoutedEventArgs e) { ChangeMenuItem(3); } - private void ResetFavorites_Click(object sender, RoutedEventArgs e) + private void NewChattingTxt_KeyDown(object sender, KeyEventArgs e) { - string xml = System.IO.Path.Combine(ViewModel.Instance.DataPath, "StatusList.xml"); - if (File.Exists(xml)) + if(e.Key == Key.Enter) { - File.Delete(xml); + ButtonChattingTxt_Click(sender, e); + } + if (e.Key == Key.Escape) + { + ViewModel.Instance.NewChattingTxt = string.Empty; } - ViewModel.Instance.StatusList.Clear(); - DataAndSecurity.DataController.LoadStatusList(); - ViewModel.SaveStatusList(); - ChangeMenuItem(1); } private void NewChattingTxt_TextChanged(object sender, TextChangedEventArgs e) @@ -509,386 +485,296 @@ private void NewChattingTxt_TextChanged(object sender, TextChangedEventArgs e) var textBox = sender as TextBox; int count = textBox.Text.Count(); ViewModel.Instance.ChatBoxCount = $"{count.ToString()}/140"; - if (count > 140) + if(count > 140) { int overmax = count - 140; ViewModel.Instance.ChatBoxColor = "#FFFF9393"; ViewModel.Instance.ChatTopBarTxt = $"You're soaring past the 140 char limit by {overmax}."; - } - else if (count == 0) + } else if(count == 0) { ViewModel.Instance.ChatBoxColor = "#FF504767"; - ViewModel.Instance.ChatTopBarTxt = $""; - } - else + ViewModel.Instance.ChatTopBarTxt = string.Empty; + } else { ViewModel.Instance.ChatBoxColor = "#FF2C2148"; - ViewModel.Instance.ChatTopBarTxt = $""; - + ViewModel.Instance.ChatTopBarTxt = string.Empty; } OSCSender.TypingIndicatorAsync(true); - } - private void NewChattingTxt_KeyDown(object sender, KeyEventArgs e) + private void NewFavText_TextChanged(object sender, TextChangedEventArgs e) { - if (e.Key == Key.Enter) + var textBox = sender as TextBox; + int count = textBox.Text.Count(); + ViewModel.Instance.StatusBoxCount = $"{count.ToString()}/140"; + if(count > 140) { - ButtonChattingTxt_Click(sender, e); - } - if (e.Key == Key.Escape) + int overmax = count - 140; + ViewModel.Instance.StatusBoxColor = "#FFFF9393"; + ViewModel.Instance.StatusTopBarTxt = $"You're soaring past the 140 char limit by {overmax}. Reign in that message!"; + } else if(count == 0) { - ViewModel.Instance.NewChattingTxt = ""; - } - } - - - private void ButtonChattingTxt_Click(object sender, RoutedEventArgs e) - { - string chat = ViewModel.Instance.NewChattingTxt; - if (chat.Length > 0 && chat.Length <= 141 && ViewModel.Instance.MasterSwitch) + ViewModel.Instance.StatusBoxColor = "#FF504767"; + ViewModel.Instance.StatusTopBarTxt = string.Empty; + } else { - foreach (ChatItem Chatitem in ViewModel.Instance.LastMessages) + ViewModel.Instance.StatusBoxColor = "#FF2C2148"; + if(count > 22) { - Chatitem.CanLiveEdit = false; - Chatitem.CanLiveEditRun = false; - Chatitem.MsgReplace = ""; - Chatitem.IsRunning = false; - } - OSCController.CreateChat(true); - int smalldelay = ViewModel.Instance.ChatAddSmallDelay ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) : 0; - OSCSender.SendOSCMessage(ViewModel.Instance.ChatFX, smalldelay); - DataController.SaveChatList(); - if (ViewModel.Instance.TTSTikTokEnabled == true) + ViewModel.Instance.StatusTopBarTxt = $"Buckle up! Keep it tight to 20-25 or integrations may suffer."; + } else { - if (DataAndSecurity.DataController.PopulateOutputDevices(true)) - { - ViewModel.Instance.ChatFeedbackTxt = "Requesting TTS..."; - TTSGOAsync(chat); - } - else - { - ViewModel.Instance.ChatFeedbackTxt = "Error setting output device."; - } - + ViewModel.Instance.StatusTopBarTxt = string.Empty; } - - Timer(null, null); - RecentScroll.ScrollToEnd(); } } - public static async Task TTSGOAsync(string chat, bool resent = false) + private void NewVersion_MouseUp(object sender, MouseButtonEventArgs e) { - try + if(ViewModel.Instance.CanUpdate) { - if (ViewModel.Instance.TTSCutOff) - { - foreach (var tokenSource in _activeCancellationTokens) - { - tokenSource.Cancel(); - } - _activeCancellationTokens.Clear(); - } - - - byte[] audioFromApi = await TTSController.GetAudioBytesFromTikTokAPI(chat); - if (audioFromApi != null) - { - var cancellationTokenSource = new CancellationTokenSource(); - _activeCancellationTokens.Add(cancellationTokenSource); - ViewModel.Instance.ChatFeedbackTxt = "TTS is playing..."; - await TTSController.PlayTikTokAudioAsSpeech(cancellationTokenSource.Token, audioFromApi, ViewModel.Instance.SelectedPlaybackOutputDevice.DeviceNumber); - if (resent) - { - ViewModel.Instance.ChatFeedbackTxt = "Chat was sent again with TTS."; - } - else - { - ViewModel.Instance.ChatFeedbackTxt = "Chat was sent with TTS."; - } - - - _activeCancellationTokens.Remove(cancellationTokenSource); - } - else - { - ViewModel.Instance.ChatFeedbackTxt = "Error getting TTS from online servers."; - } - - } - catch (OperationCanceledException ex) - { - ViewModel.Instance.ChatFeedbackTxt = "TTS cancelled"; - Logging.WriteException(ex, makeVMDump: true, MSGBox: false); - } - catch (Exception ex) - { - ViewModel.Instance.ChatFeedbackTxt = "Error sending a chat with TTS"; - } - } - - - - - private void StopChat_Click(object sender, RoutedEventArgs e) - { - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - OSCController.ClearChat(lastsendchat); - int smalldelay = ViewModel.Instance.ChatAddSmallDelay ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) : 0; - OSCSender.SendOSCMessage(false, smalldelay); - Timer(null, null); - foreach (var token in _activeCancellationTokens) + ViewModel.Instance.CanUpdate = false; + ViewModel.Instance.CanUpdateLabel = false; + Task.Run(() => UpdateApp.PrepareUpdate()); + } else { - token.Cancel(); + Process.Start("explorer", "http://github.com/BoiHanny/vrcosc-magicchatbox/releases"); } } - private void ClearChat_Click(object sender, RoutedEventArgs e) - { - ViewModel.Instance.LastMessages.Clear(); - DataController.SaveChatList(); - StopChat_Click(null, null); - } - - private void TikTokTTSVoices_combo_SelectionChanged(object sender, SelectionChangedEventArgs e) + private async void OpenAIAPITestConnection_ClickAsync(object sender, RoutedEventArgs e) { - if (sender is ComboBox comboBox) - { - var selectedVoice = comboBox.SelectedItem as Voice; - if (selectedVoice != null) - { - ViewModel.Instance.SelectedTikTokTTSVoice = selectedVoice; - ViewModel.Instance.RecentTikTokTTSVoice = selectedVoice.ApiName; - } - } - + //ChatModelMsg action = ViewModel.Instance.OpenAIAPIBuiltInActions.FirstOrDefault(a => a.FriendlyName == "Add Emojis"); + //ChatModelMsg response = await OpenAIClient.ExecuteActionAsync(action, ViewModel.Instance.NewChattingTxt); + //ViewModel.Instance.NewChattingTxt = response.Content; + ViewModel.Instance.OpenAIAPITestResponse = await OpenAIClient.TestAPIConnection(); } - private void PlaybackOutputDeviceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - ViewModel.Instance.RecentPlayBackOutput = ViewModel.Instance.SelectedPlaybackOutputDevice.FriendlyName; - } - private void OpenLogFolder_Click(object sender, RoutedEventArgs e) - { - try - { - if (DataController.CreateIfMissing(ViewModel.Instance.LogPath)) - Process.Start("explorer.exe", ViewModel.Instance.LogPath); - } - catch (Exception ex) - { - Logging.WriteException(ex); - } - } + private void OpenAITerms_MouseUp(object sender, MouseButtonEventArgs e) + { Process.Start("explorer", "https://openai.com/policies/plugin-terms"); } private void OpenConfigFolder_Click(object sender, RoutedEventArgs e) { try { - if (DataController.CreateIfMissing(ViewModel.Instance.DataPath)) + if(DataController.CreateIfMissing(ViewModel.Instance.DataPath)) Process.Start("explorer.exe", ViewModel.Instance.DataPath); - } - catch (Exception ex) + } catch(Exception ex) { - Logging.WriteException(ex); } } - private void MakeDataDump_Click(object sender, RoutedEventArgs e) + private void OpenLogFolder_Click(object sender, RoutedEventArgs e) { try { - Logging.ViewModelDump(); - Process.Start("explorer.exe", ViewModel.Instance.LogPath); - } - catch (Exception ex) + if(DataController.CreateIfMissing(ViewModel.Instance.LogPath)) + Process.Start("explorer.exe", ViewModel.Instance.LogPath); + } catch(Exception ex) { - Logging.WriteException(ex); } } - private void GitHubChanges_MouseUp(object sender, MouseButtonEventArgs e) + private void PauseTimer_Tick(object sender, System.Timers.ElapsedEventArgs e) { - if (ViewModel.Instance.tagURL == null) - { - Process.Start("explorer", "http://github.com/BoiHanny/vrcosc-magicchatbox/releases"); - } - else + try { - Process.Start("explorer", ViewModel.Instance.tagURL); - } - - } - - private void ToggleVoicebtn_Click(object sender, RoutedEventArgs e) - { - OSCSender.ToggleVoice(true); - } - - private void LearnMoreAboutTTSbtn_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start("explorer", "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/Play-TTS-Output-of-MagicChatbox-to-Main-Audio-Device-and-Microphone-in-VRChat-Using-VB-Audio-Cable-(Simple-Setup)"); - } + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - private void LearnMoreAboutIntelliChatAI_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start("explorer", "https://openai.com/product"); - } + ViewModel.Instance.ScanPauseCountDown--; + Application.Current.Dispatcher + .Invoke( + () => + { + ViewModel.Instance.ScanPauseCountDown = ViewModel.Instance.ScanPauseCountDown; + if(lastsendchat != null) + { + lastsendchat.CanLiveEdit = ViewModel.Instance.ChatLiveEdit; + lastsendchat.LiveEditButtonTxt = ViewModel.Instance.RealTimeChatEdit + ? "Live Edit (" + ViewModel.Instance.ScanPauseCountDown + ")" + : "Edit (" + ViewModel.Instance.ScanPauseCountDown + ")"; + } + }); - private void IntelliChatAIapiPage_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start("explorer", "https://platform.openai.com/account/api-keys"); - } + if(ViewModel.Instance.ScanPauseCountDown <= 0 || !ViewModel.Instance.ScanPause) + { + ViewModel.Instance.ScanPause = false; + pauseTimer.Stop(); + pauseTimer = null; + if(ViewModel.Instance.ScanPauseCountDown != 0) + { + ViewModel.Instance.ScanPauseCountDown = 0; + } - private async void OpenAIAPITestConnection_ClickAsync(object sender, RoutedEventArgs e) - { - //ChatModelMsg action = ViewModel.Instance.OpenAIAPIBuiltInActions.FirstOrDefault(a => a.FriendlyName == "Add Emojis"); - //ChatModelMsg response = await OpenAIClient.ExecuteActionAsync(action, ViewModel.Instance.NewChattingTxt); - //ViewModel.Instance.NewChattingTxt = response.Content; - ViewModel.Instance.OpenAIAPITestResponse = await OpenAIClient.TestAPIConnection(); + OSCController.ClearChat(lastsendchat); + OSCSender.SendOSCMessage(false); + Timer(null, null); + } + } catch(Exception ex) + { + Logging.WriteException(ex, makeVMDump: false, MSGBox: false); + } } + private void PlaybackOutputDeviceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { ViewModel.Instance.RecentPlayBackOutput = ViewModel.Instance.SelectedPlaybackOutputDevice.FriendlyName; } - private void OpenAITerms_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start("explorer", "https://openai.com/policies/plugin-terms"); - - } - - private void IntgrIntelliWing_btn_Click(object sender, RoutedEventArgs e) + private void ResetFavorites_Click(object sender, RoutedEventArgs e) { - ViewModel.Instance.IntgrIntelliWing = !ViewModel.Instance.IntgrIntelliWing; + string xml = System.IO.Path.Combine(ViewModel.Instance.DataPath, "StatusList.xml"); + if(File.Exists(xml)) + { + File.Delete(xml); + } + ViewModel.Instance.StatusList.Clear(); + DataAndSecurity.DataController.LoadStatusList(); + ViewModel.SaveStatusList(); + ChangeMenuItem(1); } - private void LearnMoreAboutSpotifybtn_MouseUp(object sender, MouseButtonEventArgs e) + private void ResetWindowActivity_Click(object sender, RoutedEventArgs e) { - Process.Start("explorer", "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/How-to-Use-the-Spotify-Integration-%F0%9F%8E%B5"); + int ItemRemoved = WindowActivity.ResetWindowActivity(); + if(ItemRemoved > 0) + { + ViewModel.Instance.DeletedAppslabel = "All apps from history"; + } } - private void SmartClearnup_Click(object sender, RoutedEventArgs e) + + private void SaveDataToDisk(object sender, System.ComponentModel.CancelEventArgs e) { - int ItemRemoved = WindowActivity.SmartCleanup(); - if (ItemRemoved > 0) + try { - ViewModel.Instance.DeletedAppslabel = $"Removed {ItemRemoved} apps from history"; - - } - else + this.Hide(); + DataController.ManageSettingsXML(true); + DataController.SaveAppList(); + DataController.SaveMediaSessions(); + System.Environment.Exit(1); + } catch(Exception ex) { - ViewModel.Instance.DeletedAppslabel = $"No apps removed from history"; + Logging.WriteException(ex, makeVMDump: true, MSGBox: true, exitapp: true); } } - private void ClearnupKeepSettings_Click(object sender, RoutedEventArgs e) + private void SmartClearnup_Click(object sender, RoutedEventArgs e) { - int ItemRemoved = WindowActivity.CleanAndKeepAppsWithSettings(); - if (ItemRemoved > 0) + int ItemRemoved = WindowActivity.SmartCleanup(); + if(ItemRemoved > 0) { ViewModel.Instance.DeletedAppslabel = $"Removed {ItemRemoved} apps from history"; - } - else + } else { ViewModel.Instance.DeletedAppslabel = $"No apps removed from history"; } } - private void ResetWindowActivity_Click(object sender, RoutedEventArgs e) + private void SortDate_Click(object sender, RoutedEventArgs e) { - int ItemRemoved = WindowActivity.ResetWindowActivity(); - if (ItemRemoved > 0) { - ViewModel.Instance.DeletedAppslabel = "All apps from history"; + ViewModel.Instance.StatusList = new ObservableCollection( + ViewModel.Instance.StatusList.OrderByDescending(x => x.CreationDate)); } } - private async Task ManualUpdateCheckAsync() - { - await Task.Run(() => DataController.CheckForUpdateAndWait(true)); - } - private void CheckUpdateBtnn_Click(object sender, RoutedEventArgs e) + private void SortEdited_Click(object sender, RoutedEventArgs e) { - ManualUpdateCheckAsync(); + { + ViewModel.Instance.StatusList = new ObservableCollection( + ViewModel.Instance.StatusList.OrderByDescending(x => x.LastEdited)); + } } - private void Discord_Click(object sender, RoutedEventArgs e) + private void SortFav_Click(object sender, RoutedEventArgs e) { - Process.Start("explorer", "https://discord.gg/ZaSFwBfhvG"); + ViewModel.Instance.StatusList = new ObservableCollection( + ViewModel.Instance.StatusList.OrderByDescending(x => x.IsFavorite).ThenBy(x => x.LastUsed)); } - private void Github_Click(object sender, RoutedEventArgs e) + private void SortUsed_Click(object sender, RoutedEventArgs e) { - Process.Start("explorer", "https://github.com/BoiHanny/vrcosc-magicchatbox"); + ViewModel.Instance.StatusList = new ObservableCollection( + ViewModel.Instance.StatusList.OrderByDescending(x => x.LastUsed)); } - private void LearnMoreAboutHeartbtn_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start("explorer", "https://github.com/BoiHanny/vrcosc-magicchatbox/wiki/How-to-Set-Up-MagicChatbox-with-Pulsoid-for-VRChat-%F0%9F%92%9C"); - } - private void CancelEditbutton_Click(object sender, RoutedEventArgs e) + private void StopChat_Click(object sender, RoutedEventArgs e) { - try + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); + OSCController.ClearChat(lastsendchat); + int smalldelay = ViewModel.Instance.ChatAddSmallDelay + ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) + : 0; + OSCSender.SendOSCMessage(false, smalldelay); + Timer(null, null); + foreach(var token in _activeCancellationTokens) { - var button = sender as Button; - var item = button.Tag as StatusItem; - item.editMsg = ""; - item.IsEditing = false; + token.Cancel(); } - catch (Exception) - { + } + private void TikTokTTSVoices_combo_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if(sender is ComboBox comboBox) + { + var selectedVoice = comboBox.SelectedItem as Voice; + if(selectedVoice != null) + { + ViewModel.Instance.SelectedTikTokTTSVoice = selectedVoice; + ViewModel.Instance.RecentTikTokTTSVoice = selectedVoice.ApiName; + } } } - private void Editbutton_Checked(object sender, RoutedEventArgs e) + private void Timer(object sender, EventArgs e) { - try + bool ChatItemActive = ViewModel.Instance.LastMessages.Any(x => x.IsRunning); + + if(ViewModel.Instance.ScanPause && ChatItemActive) { - var button = sender as ToggleButton; - var item = button.Tag as StatusItem; - if ((bool)button.IsChecked) + if(pauseTimer == null) { - item.editMsg = item.msg; - // Find the TextBox in the same container as the ToggleButton - var parent = VisualTreeHelper.GetParent(button); - while (!(parent is ContentPresenter)) + ViewModel.Instance.CountDownUI = false; + pauseTimer = new System.Timers.Timer(); + pauseTimer.Interval = 1000; + pauseTimer.Elapsed += PauseTimer_Tick; + pauseTimer.Start(); + if(ViewModel.Instance.KeepUpdatingChat) { - parent = VisualTreeHelper.GetParent(parent); + if(ChatUpdateTimer == null) + { + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); + if(lastsendchat != null) + { + lastsendchat.LiveEditButtonTxt = "Sending..."; + } + ChatUpdateTimer = new System.Timers.Timer(); + ChatUpdateTimer.Interval = (int)(ViewModel.Instance.ChattingUpdateRate * 1000); + ChatUpdateTimer.Elapsed += ChatUpdateTimer_Tick; + ChatUpdateTimer.Start(); + } } - var contentPresenter = parent as ContentPresenter; - var dataTemplate = contentPresenter.ContentTemplate; - var editTextBox = (TextBox)dataTemplate.FindName("EditTextBox", contentPresenter); - editTextBox.Focus(); - // Set the cursor at the end of the text - editTextBox.CaretIndex = editTextBox.Text.Length; } - else + } else + { + if(pauseTimer != null) { - if (item.editMsg.Count() < 145 && !string.IsNullOrEmpty(item.editMsg)) - { - item.msg = item.editMsg; - item.IsEditing = false; - item.editMsg = ""; - item.LastEdited = DateTime.Now; - } + pauseTimer.Stop(); + pauseTimer = null; + } + if(ChatUpdateTimer != null) + { + ChatUpdateTimer.Stop(); + ChatUpdateTimer = null; } - } - catch (Exception) - { - } - } - - private void SortEdited_Click(object sender, RoutedEventArgs e) - { - { - ViewModel.Instance.StatusList = new ObservableCollection(ViewModel.Instance.StatusList.OrderByDescending(x => x.LastEdited)); + ViewModel.Instance.CountDownUI = true; + scantick(); } } @@ -896,14 +782,15 @@ private void ToggleButton_Checked(object sender, RoutedEventArgs e) { try { + ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); var button = sender as ToggleButton; var item = button.Tag as ChatItem; - if ((bool)button.IsChecked) + if((bool)button.IsChecked) { item.MsgReplace = item.Msg + " "; var parent = VisualTreeHelper.GetParent(button); - while (!(parent is ContentPresenter)) + while(!(parent is ContentPresenter)) { parent = VisualTreeHelper.GetParent(parent); } @@ -917,30 +804,67 @@ private void ToggleButton_Checked(object sender, RoutedEventArgs e) EditChatTextBox.CaretIndex = EditChatTextBox.Text.Length; item.Opacity_backup = item.Opacity; item.Opacity = "1"; - } - else + } else { + if (ViewModel.Instance.RealTimeChatEdit) + { + if (item != null && lastsendchat != null) + { + if (lastsendchat.Msg != item.MsgReplace) + { + lastsendchat.MainMsg = item.MsgReplace; + lastsendchat.Msg = item.MsgReplace; + lastsendchat.CanLiveEditRun = false; + } + } + } item.Opacity = item.Opacity_backup; + NewChattingTxt.Focus(); + NewChattingTxt.CaretIndex = NewChattingTxt.Text.Length; } - } - catch (Exception) + } catch(Exception) { } } - private void CancelEditChatbutton_Click(object sender, RoutedEventArgs e) + private void ToggleVoicebtn_Click(object sender, RoutedEventArgs e) { OSCSender.ToggleVoice(true); } + + + private void Update_Click(object sender, RoutedEventArgs e) { - var Button = sender as Button; - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); + if(ViewModel.Instance.ScanPause != true) + { + OSCController.BuildOSC(); + } + } - if (!string.IsNullOrEmpty(lastsendchat.MainMsg)) + public static void ChangeMenuItem(int changeINT) + { + ViewModel.Instance.CurrentMenuItem = changeINT; + ViewModel.Instance.MenuItem_0_Visibility = "Hidden"; + ViewModel.Instance.MenuItem_1_Visibility = "Hidden"; + ViewModel.Instance.MenuItem_2_Visibility = "Hidden"; + ViewModel.Instance.MenuItem_3_Visibility = "Hidden"; + if(ViewModel.Instance.CurrentMenuItem == 0) { - lastsendchat.CanLiveEditRun = false; - lastsendchat.Msg = lastsendchat.MainMsg; - } + ViewModel.Instance.MenuItem_0_Visibility = "Visible"; + return; + } else if(ViewModel.Instance.CurrentMenuItem == 1) + { + ViewModel.Instance.MenuItem_1_Visibility = "Visible"; + return; + } else if(ViewModel.Instance.CurrentMenuItem == 2) + { + ViewModel.Instance.MenuItem_2_Visibility = "Visible"; + return; + } else if(ViewModel.Instance.CurrentMenuItem == 3) + { + ViewModel.Instance.MenuItem_3_Visibility = "Visible"; + return; + } + ChangeMenuItem(0); } - public void OnSendAgain(object sender, RoutedEventArgs e) { @@ -948,18 +872,18 @@ public void OnSendAgain(object sender, RoutedEventArgs e) { var button = sender as Button; var item = button.Tag as ChatItem; - if (ViewModel.Instance.MasterSwitch == false) + if(ViewModel.Instance.MasterSwitch == false) { ViewModel.Instance.ChatFeedbackTxt = "Sent to VRChat is off"; return; } - if (button != null) + if(button != null) { - foreach (ChatItem Chatitem in ViewModel.Instance.LastMessages) + foreach(ChatItem Chatitem in ViewModel.Instance.LastMessages) { Chatitem.CanLiveEdit = false; Chatitem.CanLiveEditRun = false; - Chatitem.MsgReplace = ""; + Chatitem.MsgReplace = string.Empty; Chatitem.IsRunning = false; } item.CanLiveEdit = ViewModel.Instance.ChatLiveEdit; @@ -969,109 +893,151 @@ public void OnSendAgain(object sender, RoutedEventArgs e) string savedtxt = ViewModel.Instance.NewChattingTxt; ViewModel.Instance.NewChattingTxt = item.Msg; OSCController.CreateChat(false); - int smalldelay = ViewModel.Instance.ChatAddSmallDelay ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) : 0; - if (ViewModel.Instance.ChatFX && ViewModel.Instance.ChatSendAgainFX) + int smalldelay = ViewModel.Instance.ChatAddSmallDelay + ? (int)(ViewModel.Instance.ChatAddSmallDelayTIME * 1000) + : 0; + if(ViewModel.Instance.ChatFX && ViewModel.Instance.ChatSendAgainFX) { OSCSender.SendOSCMessage(false, smalldelay); - } - else + } else { OSCSender.SendOSCMessage(false, smalldelay); } ViewModel.Instance.NewChattingTxt = savedtxt; - if (ViewModel.Instance.TTSTikTokEnabled == true && ViewModel.Instance.TTSOnResendChat) + if(ViewModel.Instance.TTSTikTokEnabled == true && ViewModel.Instance.TTSOnResendChat) { - if (DataAndSecurity.DataController.PopulateOutputDevices(true)) + if(DataAndSecurity.DataController.PopulateOutputDevices(true)) { ViewModel.Instance.ChatFeedbackTxt = "Requesting TTS..."; MainWindow.TTSGOAsync(item.Msg, true); - } - else + } else { ViewModel.Instance.ChatFeedbackTxt = "Error setting output device."; } - } - else + } else { ViewModel.Instance.ChatFeedbackTxt = "Message sent again"; } Timer(null, null); - } - - } - catch (Exception ex) + } catch(Exception ex) { Logging.WriteException(ex, makeVMDump: true, MSGBox: false); } - } - private void EditChatTextBox_TextChanged(object sender, TextChangedEventArgs e) + public void scantick() { - if(ViewModel.Instance.RealTimeChatEdit) + try { - var textbox = sender as TextBox; - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - - if (textbox != null && lastsendchat != null) + if(ViewModel.Instance.IntgrScanSpotify_OLD == true) { - if (lastsendchat.Msg != textbox.Text) - { - lastsendchat.Msg = textbox.Text; - } + ViewModel.Instance.PlayingSongTitle = SpotifyActivity.CurrentPlayingSong(); + ViewModel.Instance.SpotifyActive = SpotifyActivity.SpotifyIsRunning(); + } + if(ViewModel.Instance.IntgrScanWindowActivity == true) + { + ViewModel.Instance.FocusedWindow = WindowActivity.GetForegroundProcessName(); } + + ViewModel.Instance.IsVRRunning = WindowActivity.IsVRRunning(); + if(ViewModel.Instance.IntgrScanWindowTime == true) + ViewModel.Instance.CurrentTime = SystemStats.GetTime(); + ViewModel.Instance.ChatFeedbackTxt = string.Empty; + OSCController.BuildOSC(); + OSCSender.SendOSCMessage(false); + } catch(Exception ex) + { + Logging.WriteException(ex, makeVMDump: false, MSGBox: false); } - } - private void EditChatTextBox_KeyDown(object sender, KeyEventArgs e) + public void SelectTTS() { - var textbox = sender as TextBox; - ChatItem? lastsendchat = ViewModel.Instance.LastMessages.FirstOrDefault(x => x.IsRunning); - - if(ViewModel.Instance.RealTimeChatEdit) + foreach(var voice in TikTokTTSVoices_combo.Items) { - if (e.Key == Key.Enter) + if(voice is Voice && (voice as Voice).ApiName == ViewModel.Instance.SelectedTikTokTTSVoice?.ApiName) { - lastsendchat.CanLiveEditRun = false; - lastsendchat.MainMsg = textbox.Text; + TikTokTTSVoices_combo.SelectedItem = voice; + break; } - if (e.Key == Key.Escape) - { - if (!string.IsNullOrEmpty(lastsendchat.MainMsg)) - { - lastsendchat.CanLiveEditRun = false; - lastsendchat.Msg = lastsendchat.MainMsg; - } + } + } + public void SelectTTSOutput() + { + foreach(var AudioDevice in PlaybackOutputDeviceComboBox.Items) + { + if(AudioDevice is AudioDevice && + (AudioDevice as AudioDevice).FriendlyName == + ViewModel.Instance.SelectedPlaybackOutputDevice?.FriendlyName) + { + PlaybackOutputDeviceComboBox.SelectedItem = AudioDevice; + break; } } - else + } + + public static async Task TTSGOAsync(string chat, bool resent = false) + { + try { - if (e.Key == Key.Enter) + if(ViewModel.Instance.TTSCutOff) { - if (textbox != null && lastsendchat != null) + foreach(var tokenSource in _activeCancellationTokens) { - if (lastsendchat.Msg != textbox.Text) - { - lastsendchat.MainMsg = textbox.Text; - lastsendchat.Msg = textbox.Text; - lastsendchat.CanLiveEditRun = false; - } - } + tokenSource.Cancel(); + } + _activeCancellationTokens.Clear(); } - if (e.Key == Key.Escape) + + + byte[] audioFromApi = await TTSController.GetAudioBytesFromTikTokAPI(chat); + if(audioFromApi != null) { - if (!string.IsNullOrEmpty(lastsendchat.MainMsg)) + var cancellationTokenSource = new CancellationTokenSource(); + _activeCancellationTokens.Add(cancellationTokenSource); + ViewModel.Instance.ChatFeedbackTxt = "TTS is playing..."; + await TTSController.PlayTikTokAudioAsSpeech( + cancellationTokenSource.Token, + audioFromApi, + ViewModel.Instance.SelectedPlaybackOutputDevice.DeviceNumber); + if(resent) { - lastsendchat.CanLiveEditRun = false; - lastsendchat.Msg = lastsendchat.MainMsg; + ViewModel.Instance.ChatFeedbackTxt = "Chat was sent again with TTS."; + } else + { + ViewModel.Instance.ChatFeedbackTxt = "Chat was sent with TTS."; } + + + _activeCancellationTokens.Remove(cancellationTokenSource); + } else + { + ViewModel.Instance.ChatFeedbackTxt = "Error getting TTS from online servers."; + } + } catch(OperationCanceledException ex) + { + ViewModel.Instance.ChatFeedbackTxt = "TTS cancelled"; + Logging.WriteException(ex, makeVMDump: true, MSGBox: false); + } catch(Exception ex) + { + ViewModel.Instance.ChatFeedbackTxt = "Error sending a chat with TTS"; + } + } + + public static double ShadowOpacity + { + get => _shadowOpacity; + set + { + if(_shadowOpacity != value) + { + _shadowOpacity = value; + ShadowOpacityChanged?.Invoke(null, EventArgs.Empty); } } - } } } \ No newline at end of file