-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DIscord RPC #8961
Open
leexey
wants to merge
3
commits into
SubtitleEdit:main
Choose a base branch
from
leexey:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
DIscord RPC #8961
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,33 +3,70 @@ | |
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Windows.Forms; | ||
using DiscordRPC; | ||
using System.Timers; | ||
|
||
namespace Nikse.SubtitleEdit | ||
{ | ||
internal static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
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 (Exception ex) | ||
{ | ||
Console.WriteLine("Error updating Discord RPC: " + ex.Message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe on recursive fail just disable & dispose the timer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. god i completely forgot about that sorry |
||
} | ||
} | ||
|
||
|
||
|
||
// 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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this been used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was testing other things and committing with that... it's already been removed 👍 thanks for noticing