Visual Improvements (RichPresenceEventLog)

This commit is contained in:
WeeXnes 2022-06-24 17:35:08 +02:00
parent d76717779d
commit ffe05ef98a
6 changed files with 144 additions and 46 deletions

View file

@ -15,7 +15,7 @@ namespace WeeXnes.Core
public static string encryptionKey = "8zf5#RdyQ]$4x4_"; public static string encryptionKey = "8zf5#RdyQ]$4x4_";
public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes"); public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes");
public static string SettingsFileName = "settings.ini"; public static string SettingsFileName = "settings.ini";
public static string version = "3.1.1"; public static string version = "3.2";
public static bool info_isRpcRunning = false; public static bool info_isRpcRunning = false;
public static bool info_RpcAutoStart; public static bool info_RpcAutoStart;
public static string apiUrl = "http://www.weexnes.com:5169/"; public static string apiUrl = "http://www.weexnes.com:5169/";

View file

@ -0,0 +1,57 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
namespace WeeXnes.Core
{
public enum EventType
{
ProcessStartedEvent,
ProcessStoppedEvent,
RPCUpdateEvent,
RPCReadyEvent
}
public class customEvent
{
public string Content { get; set; }
public EventType Type { get; set; }
public string GradientColor1 { get; set; }
public string GradientColor2 { get; set; }
public customEvent(string content, EventType type)
{
this.Content = content;
this.Type = type;
if (this.Type == EventType.ProcessStartedEvent)
{
this.GradientColor1 = "#46db69";
this.GradientColor2 = "#33a34d";
}
else if (this.Type == EventType.ProcessStoppedEvent)
{
this.GradientColor1 = "#d1415d";
this.GradientColor2 = "#a33349";
}
else if (this.Type == EventType.RPCUpdateEvent)
{
this.GradientColor1 = "#3e65c9";
this.GradientColor2 = "#3352a3";
}
else if (this.Type == EventType.RPCReadyEvent)
{
this.GradientColor1 = "#c93eb4";
this.GradientColor2 = "#a33389";
}
}
public override string ToString()
{
return this.Content;
}
}
}

View file

@ -207,19 +207,48 @@
</LinearGradientBrush.GradientStops> </LinearGradientBrush.GradientStops>
</LinearGradientBrush> </LinearGradientBrush>
</Border.Background> </Border.Background>
<RichTextBox Grid.Row="1" <ScrollViewer Grid.Column="0" Background="Transparent" VerticalScrollBarVisibility="Hidden" Foreground="White"
Background="Transparent" Padding="5,5,0,5" Name="LogViewer">
BorderThickness="0" <StackPanel>
Foreground="White" <StackPanel>
IsReadOnly="True" <ItemsControl x:Name="ListViewVersions" ItemsSource="{Binding version}" Loaded="ListViewVersions_OnLoaded">
IsHitTestVisible="False" <ItemsControl.ItemTemplate>
Name="RpcLog"> <DataTemplate>
<RichTextBox.Resources> <StackPanel>
<Style TargetType="{x:Type Paragraph}"> <Border Width="689" Height="30" CornerRadius="4" Margin="0,3,0,0">
<Setter Property="Margin" Value="0"/> <Border.Background>
</Style> <LinearGradientBrush StartPoint="0 0" EndPoint="1 1">
</RichTextBox.Resources> <LinearGradientBrush.GradientStops>
</RichTextBox> <GradientStop Offset="0" Color="{Binding GradientColor1}" />
<GradientStop Offset="1" Color="{Binding GradientColor2}" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<TextBlock Margin="5 0" Text="{Binding Content}" FontSize="12"
Foreground="White"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Padding="10,0,0,0">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="1"/>
</TextBlock.Effect>
</TextBlock>
</Border>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Border> </Border>
</Grid> </Grid>

View file

@ -28,11 +28,12 @@ namespace WeeXnes.MVVM.View
/// </summary> /// </summary>
public partial class DiscordRpcView : UserControl public partial class DiscordRpcView : UserControl
{ {
public List<customEvent> events = new List<customEvent>();
//static bool shouldBeRunning = false; //static bool shouldBeRunning = false;
BackgroundWorker backgroundWorker = new BackgroundWorker(); BackgroundWorker backgroundWorker = new BackgroundWorker();
List<Game> Games = new List<Game>(); List<Game> Games = new List<Game>();
Game lastSelectedGame = null; Game lastSelectedGame = null;
public static string logContent = null; public static customEvent logContent = null;
public static UpdateVar<string> triggerLogupdate = new UpdateVar<string>(); public static UpdateVar<string> triggerLogupdate = new UpdateVar<string>();
public DiscordRpcView() public DiscordRpcView()
{ {
@ -47,8 +48,8 @@ namespace WeeXnes.MVVM.View
}; };
InitializeSettings(); InitializeSettings();
CheckForAutostart(); CheckForAutostart();
} }
public void CheckFolders() public void CheckFolders()
{ {
if (!Globals.settings_RpcItemsPath_Bool.Value) if (!Globals.settings_RpcItemsPath_Bool.Value)
@ -80,25 +81,28 @@ namespace WeeXnes.MVVM.View
backgroundWorker.DoWork += BackgroundWorker_DoWork; backgroundWorker.DoWork += BackgroundWorker_DoWork;
Refresh(); Refresh();
} }
public void writeLog(string _content, bool _timestamp = true) public void writeLog(customEvent _content, bool _timestamp = true)
{ {
string timestamp = DateTime.Now.ToString("HH:mm:ss"); string timestamp = DateTime.Now.ToString("HH:mm:ss");
if (_timestamp) /*if (_timestamp)
{ {
_content = "[" + timestamp + "] " + _content; _content = "[" + timestamp + "] " + _content;
} }
Console.WriteLine(_content); */
this.Dispatcher.Invoke(() => this.Dispatcher.Invoke(() =>
{ {
RpcLog.AppendText(_content + "\n"); //RpcLog.AppendText(_content + "\n");
RpcLog.ScrollToEnd(); //RpcLog.ScrollToEnd();
ListViewVersions.Items.Add(_content);
LogViewer.ScrollToEnd();
}); });
} }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{ {
Globals.info_isRpcRunning = true; Globals.info_isRpcRunning = true;
writeLog("Thread Started"); writeLog(new customEvent("Thread Started", EventType.ProcessStartedEvent));
bool runWorker = true; bool runWorker = true;
int delay = 2000; int delay = 2000;
while (runWorker) while (runWorker)
@ -129,7 +133,7 @@ namespace WeeXnes.MVVM.View
{ {
game.isRunning = false; game.isRunning = false;
} }
writeLog("Thread Closed"); writeLog(new customEvent("Thread Closed",EventType.ProcessStoppedEvent));
} }
public void runBackgroundWorker() public void runBackgroundWorker()
{ {
@ -313,5 +317,10 @@ namespace WeeXnes.MVVM.View
stopBackgroundWorker(); stopBackgroundWorker();
} }
private void ListViewVersions_OnLoaded(object sender, RoutedEventArgs e)
{
}
} }
} }

View file

@ -7,9 +7,15 @@ using System.Threading.Tasks;
using WeeXnes.Core; using WeeXnes.Core;
using WeeXnes.MVVM.View; using WeeXnes.MVVM.View;
using DiscordRPC; using DiscordRPC;
using DiscordRPC.Message;
using EventType = WeeXnes.Core.EventType;
namespace WeeXnes.RPC namespace WeeXnes.RPC
{ {
class EventCache
{
public static string cache1 = "";
}
public class Game public class Game
{ {
public DiscordRpcClient client { get; set; } public DiscordRpcClient client { get; set; }
@ -44,25 +50,8 @@ namespace WeeXnes.RPC
{ {
client.Initialize(); client.Initialize();
} }
client.OnReady += (sender, e) => client.OnReady += ClientOnOnReady;
{ client.OnPresenceUpdate += ClientOnOnPresenceUpdate;
/*
Globals.logContent.Value = "[" + this.ProcessName + ".exe] -> Received Ready from user " + e.User.Username;
Globals.logUpdateTrigger.Value = "mgjnoeimgje";
*/
DiscordRpcView.logContent = "[" + this.ProcessName + ".exe] -> Received Ready from user " + e.User.Username;
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
};
client.OnPresenceUpdate += (sender, e) =>
{
/*
Globals.logContent.Value = "[" + this.ProcessName + ".exe] ->Received Update!";
Globals.logUpdateTrigger.Value = "mgjnoeimgje";
*/
DiscordRpcView.logContent = "[" + this.ProcessName + ".exe] -> Received Update on RPC";
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
};
client.SetPresence(new RichPresence() client.SetPresence(new RichPresence()
{ {
Details = this.details, Details = this.details,
@ -80,11 +69,26 @@ namespace WeeXnes.RPC
client.UpdateStartTime(); client.UpdateStartTime();
} }
} }
private void ClientOnOnPresenceUpdate(object sender, PresenceMessage args)
{
DiscordRpcView.logContent = new customEvent("[" + this.ProcessName + ".exe] ➜ Received Update on " + args.Name, EventType.RPCUpdateEvent);
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
}
private void ClientOnOnReady(object sender, ReadyMessage args)
{
DiscordRpcView.logContent = new customEvent("[" + this.ProcessName + ".exe] ➜ Received Ready from user " + args.User.Username, EventType.RPCReadyEvent);
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
}
public void stop() public void stop()
{ {
if (this.client.IsInitialized) if (this.client.IsInitialized)
{ {
client.ClearPresence(); client.ClearPresence();
client.OnReady -= ClientOnOnReady;
client.OnPresenceUpdate -= ClientOnOnPresenceUpdate;
} }
} }
public void checkState(Process[] processes) public void checkState(Process[] processes)
@ -110,12 +114,11 @@ namespace WeeXnes.RPC
//message.running(this.ProcessName); //message.running(this.ProcessName);
start(); start();
string output = this.Name + " [" + this.ProcessName + ".exe] started";
/* /*
Globals.logContent.Value = output; Globals.logContent.Value = output;
Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg"; Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg";
*/ */
DiscordRpcView.logContent = output; DiscordRpcView.logContent = new customEvent("↪ " + this.Name + " [" + this.ProcessName + ".exe] started", EventType.ProcessStartedEvent);
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
this.isRunning = true; this.isRunning = true;
} }
@ -127,12 +130,11 @@ namespace WeeXnes.RPC
//Do when Process is closed //Do when Process is closed
//message.closed(this.ProcessName); //message.closed(this.ProcessName);
stop(); stop();
string output = this.Name + " [" + this.ProcessName + ".exe] closed";
/* /*
Globals.logContent.Value = output; Globals.logContent.Value = output;
Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg"; Globals.logUpdateTrigger.Value = "mjfgoklemkgoeg";
*/ */
DiscordRpcView.logContent = output; DiscordRpcView.logContent = new customEvent( "↩ " + this.Name + " [" + this.ProcessName + ".exe] closed", EventType.ProcessStoppedEvent);
DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog"; DiscordRpcView.triggerLogupdate.Value = "nlejgmolegjog";
this.isRunning = false; this.isRunning = false;

View file

@ -60,6 +60,7 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Core\ApiResponse.cs" /> <Compile Include="Core\ApiResponse.cs" />
<Compile Include="Core\customEvent.cs" />
<Compile Include="Misc\UpdateMessage.xaml.cs"> <Compile Include="Misc\UpdateMessage.xaml.cs">
<DependentUpon>UpdateMessage.xaml</DependentUpon> <DependentUpon>UpdateMessage.xaml</DependentUpon>
</Compile> </Compile>