Skip to content

Commit 365f02a

Browse files
committed
Add sending while typing feature with toggle setting
1 parent 59d2d6a commit 365f02a

File tree

5 files changed

+123
-21
lines changed

5 files changed

+123
-21
lines changed

VRCOSC/App.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="VRCOSC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<userSettings>
9+
<VRCOSC.Properties.Settings>
10+
<setting name="SendWhileTyping" serializeAs="String">
11+
<value>False</value>
12+
</setting>
13+
</VRCOSC.Properties.Settings>
14+
</userSettings>
15+
</configuration>

VRCOSC/MainWindow.xaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:VRCOSC"
7+
xmlns:properties="clr-namespace:VRCOSC.Properties"
78
mc:Ignorable="d"
8-
Title="VRC OSC Chatbox v0.2" Height="450" Width="800">
9+
Title="VRC OSC Chatbox v0.3" Height="450" Width="800">
910
<Grid Background="#222222">
1011
<Grid.ColumnDefinitions>
1112
<ColumnDefinition />
@@ -27,7 +28,6 @@
2728
Grid.Row="1"
2829
HorizontalAlignment="Center"
2930
VerticalAlignment="Center"
30-
3131
FontSize="24"
3232
/>
3333

@@ -44,7 +44,7 @@
4444
TextWrapping="Wrap"
4545
FontSize="20"
4646
MaxLength="144"
47-
Height="128"
47+
Height="128"
4848
/>
4949
<TextBlock Name="NumberLetter"
5050
Grid.Row="3"
@@ -69,5 +69,16 @@
6969
VerticalAlignment="Bottom"
7070
Grid.Column="2"
7171
Grid.Row="5" Margin="8,8,8,8"/>
72+
<CheckBox
73+
Name="SendWhileTypingCheckBox"
74+
Content="Send while typing"
75+
Foreground="White"
76+
HorizontalAlignment="Center"
77+
VerticalAlignment="Bottom"
78+
Grid.Column="1"
79+
Grid.Row="5"
80+
Margin="8,8,8,8"
81+
Checked="SendWhileTypingCheckBoxChanged"
82+
Unchecked="SendWhileTypingCheckBoxChanged"/>
7283
</Grid>
7384
</Window>

VRCOSC/MainWindow.xaml.cs

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-

2-
using System;
3-
using System.Collections.Generic;
1+
using System.Collections.Concurrent;
42
using System.ComponentModel;
5-
using System.Linq;
6-
using System.Net;
3+
using System.Threading.Tasks;
74
using System.Windows;
8-
using System.Windows.Documents;
95
using System.Windows.Input;
6+
using VRCOSC.Properties;
107

118
namespace VRCOSC
129
{
@@ -20,6 +17,23 @@ public partial class MainWindow : Window
2017

2118
private string currentText = string.Empty;
2219

20+
private SharpOSC.UDPSender? sender = null;
21+
22+
private ConcurrentStack<string> messageBuffer = new ConcurrentStack<string>();
23+
24+
private Task? currentMessageTask = null;
25+
26+
private SharpOSC.UDPSender Sender
27+
{
28+
get
29+
{
30+
if (sender == null)
31+
{
32+
sender = new SharpOSC.UDPSender(vrcAddress, vrcPort);
33+
}
34+
return sender;
35+
}
36+
}
2337

2438
public string CurrentText {
2539
get
@@ -44,22 +58,30 @@ public MainWindow()
4458
InitializeComponent();
4559
DataContext = this;
4660
UpdateCharacterCount();
61+
SendWhileTypingCheckBox.IsChecked = Settings.Default.SendWhileTyping;
62+
}
63+
64+
protected override void OnClosing(CancelEventArgs e)
65+
{
66+
SaveSettings();
67+
base.OnClosing(e);
4768
}
4869

4970
public void SendOSCMessage()
5071
{
51-
// /chatbox/input s b
52-
var message = new SharpOSC.OscMessage("/chatbox/input", CurrentText, true);
53-
var sender = new SharpOSC.UDPSender(vrcAddress, vrcPort);
54-
sender.Send(message);
72+
QueueMessage();
5573
}
5674

5775
public void SendOSCTypingSignal(bool typing)
5876
{
77+
if (SendWhileTypingCheckBox.IsChecked.GetValueOrDefault())
78+
{
79+
QueueMessage();
80+
}
81+
5982
// /chatbox/typing b
6083
var message = new SharpOSC.OscMessage("/chatbox/typing", typing);
61-
var sender = new SharpOSC.UDPSender(vrcAddress, vrcPort);
62-
sender.Send(message);
84+
Sender.Send(message);
6385
}
6486

6587
private void ClearMessage()
@@ -74,6 +96,40 @@ private void UpdateCharacterCount()
7496
SendOSCTypingSignal(ChatBox.Text.Length > 0);
7597
}
7698

99+
private void QueueMessage()
100+
{
101+
messageBuffer.Push(CurrentText);
102+
103+
if (currentMessageTask == null)
104+
{
105+
currentMessageTask = Task.Run(async () =>
106+
{
107+
// Keep sending while we have messages to process
108+
while (messageBuffer.Count > 0)
109+
{
110+
// Only process if we have messages
111+
if (messageBuffer.TryPop(out var result) && !string.IsNullOrWhiteSpace(result))
112+
{
113+
// Only clear if we have a non-empty message to avoid clearing prematurely
114+
messageBuffer.Clear();
115+
var message = new SharpOSC.OscMessage("/chatbox/input", result, true);
116+
Sender.Send(message);
117+
118+
// Delay suggested by vrc
119+
await Task.Delay(1500);
120+
}
121+
}
122+
currentMessageTask = null;
123+
});
124+
}
125+
}
126+
127+
private void SaveSettings()
128+
{
129+
Settings.Default.SendWhileTyping = SendWhileTypingCheckBox.IsChecked.GetValueOrDefault();
130+
Settings.Default.Save();
131+
}
132+
77133
private void SendClick(object sender, RoutedEventArgs e)
78134
{
79135
SendOSCMessage();
@@ -93,5 +149,10 @@ private void TextChanged(object sender, System.Windows.Controls.TextChangedEvent
93149
{
94150
UpdateCharacterCount();
95151
}
152+
153+
private void SendWhileTypingCheckBoxChanged(object sender, RoutedEventArgs e)
154+
{
155+
SaveSettings();
156+
}
96157
}
97158
}

VRCOSC/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VRCOSC/Properties/Settings.settings

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
3-
<Profiles>
4-
<Profile Name="(Default)" />
5-
</Profiles>
6-
</SettingsFile>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="VRCOSC.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="SendWhileTyping" Type="System.Boolean" Scope="User">
6+
<Value Profile="(Default)">False</Value>
7+
</Setting>
8+
</Settings>
9+
</SettingsFile>

0 commit comments

Comments
 (0)