diff --git a/Directory.Packages.props b/Directory.Packages.props
index 48e9452a86..82062064eb 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -3,6 +3,7 @@
true
+
diff --git a/src/ui/Logic/DiscordRPC.cs b/src/ui/Logic/DiscordRPC.cs
new file mode 100644
index 0000000000..5cf2bd961c
--- /dev/null
+++ b/src/ui/Logic/DiscordRPC.cs
@@ -0,0 +1,36 @@
+using DiscordRPC;
+
+public class DiscordRPCMain
+{
+ private DiscordRpcClient _client;
+
+ public void Initialize()
+ {
+ // Aplication ID
+ _client = new DiscordRpcClient("1301527670818996244");
+ _client.Initialize();
+ }
+
+ public void UpdatePresence(string fileName = "No file opened")
+ {
+ if (_client != null)
+ {
+ _client.SetPresence(new RichPresence
+ {
+ State = fileName,
+ Timestamps = Timestamps.Now,
+ Assets = new Assets
+ {
+ LargeImageKey = "logo", // Image
+ LargeImageText = "Subtitle Edit"
+ }
+ });
+ }
+ }
+
+
+ public void Shutdown()
+ {
+ _client?.Dispose();
+ }
+}
diff --git a/src/ui/Program.cs b/src/ui/Program.cs
index b5ec6e58ec..c2e6962adc 100644
--- a/src/ui/Program.cs
+++ b/src/ui/Program.cs
@@ -8,28 +8,63 @@ namespace Nikse.SubtitleEdit
{
internal static class Program
{
- ///
- /// The main entry point for the application.
- ///
+ private static DiscordRPCMain discordRpcMain;
+ private static System.Windows.Forms.Timer timer;
+ private static string lastFileName = "";
+
[STAThread]
private static void Main()
{
#if !DEBUG
- // Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException += Application_ThreadException;
-
- // Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-
- // Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
+
+ // Initialize Discord RPC
+ discordRpcMain = new DiscordRPCMain();
+ discordRpcMain.Initialize();
+
+ // Set up the timer to monitor the window title
+ timer = new System.Windows.Forms.Timer();
+ timer.Interval = 2000; // Check every 2 seconds
+ timer.Tick += CheckWindowTitle;
+ timer.Start();
+
Application.Run(new Main());
+
+ // Shutdown Discord RPC
+ discordRpcMain.Shutdown();
+ }
+
+ private static void CheckWindowTitle(object sender, EventArgs e)
+ {
+ try
+ {
+ var process = Process.GetCurrentProcess();
+ var windowTitle = process.MainWindowTitle;
+
+ if (!string.IsNullOrEmpty(windowTitle) && windowTitle != lastFileName)
+ {
+ lastFileName = windowTitle;
+
+ // Extract name from the window
+ var fileName = windowTitle.Contains(" - ") ? windowTitle.Split(new string[] { " - " }, StringSplitOptions.None)[0] : "No file opened";
+ discordRpcMain.UpdatePresence($"Editing: {fileName}");
+ }
+ }
+ catch
+ {
+ timer.Stop();
+ timer.Dispose();
+ }
}
+
+
// Handle the UI exceptions by showing a dialog box, and asking the user whether or not they wish to abort execution.
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj
index 5715fea048..ebca1f4eeb 100644
--- a/src/ui/SubtitleEdit.csproj
+++ b/src/ui/SubtitleEdit.csproj
@@ -269,6 +269,7 @@
+