-
Notifications
You must be signed in to change notification settings - Fork 17
Allow Discord status to NOT update when stopped/paused #14
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
a5ec30b
a7ec424
36d74cb
8d02f35
13d4ba3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,38 +93,45 @@ int init() | |
|
|
||
| LoadSettingsFile(); | ||
|
|
||
| g_presenceInfo.InitializeDiscordRPC(); | ||
| if (g_pluginSettings.SendWhenPausedOrStopped) | ||
| { | ||
| g_presenceInfo.InitializeDiscordRPC(); | ||
|
|
||
| ReportIdleStatus(); | ||
| ReportIdleStatus(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void ReportIdleStatus() | ||
| { | ||
| if (!g_presenceInfo.HasDiscordModuleLoaded()) | ||
| { | ||
| if (g_pluginSettings.ApplicationID == "0") | ||
| return; | ||
|
|
||
| if (g_pluginSettings.ApplicationID == "0") | ||
| return; | ||
| if (!g_presenceInfo.IsDiscordRPCConnected()) | ||
| { | ||
| g_presenceInfo.InitializeDiscordRPC(); | ||
| } | ||
|
|
||
| g_presenceInfo.CurrentPlaybackState = Stopped; | ||
| g_presenceInfo.SetStartTimestamp(0); | ||
| g_presenceInfo.SetStateText("(Idle)"); | ||
| g_presenceInfo.ClearDetails(); | ||
|
|
||
| g_presenceInfo.PostToDiscord(); | ||
| g_presenceInfo.PostToDiscord(); | ||
| } | ||
|
|
||
| void ReportCurrentSongStatus(PlaybackState playbackState) | ||
| { | ||
| if (!g_presenceInfo.HasDiscordModuleLoaded()) | ||
| return; | ||
| assert(playbackState != Stopped); | ||
|
|
||
| if (g_pluginSettings.ApplicationID == "0") | ||
|
Owner
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. Comment about pre-existing- not a requested action
Contributor
Author
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. Are you talking about the ApplicationID check? I'd like to expose a 'validate' function or similar that gate the connection... or even whisk all of the 'get connected' or 'get disconnected' into a wrapper function to encapsulate that logic.
Owner
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. yeah, the ApplicationID check. For some reason it highlighted the wrong line. Not trying to de-rail your PR, this is probably another thing for another day. |
||
| return; | ||
|
|
||
| if (!g_presenceInfo.IsDiscordRPCConnected()) | ||
| { | ||
| g_presenceInfo.InitializeDiscordRPC(); | ||
| } | ||
|
|
||
| assert(playbackState != Stopped); | ||
| g_presenceInfo.CurrentPlaybackState = playbackState; | ||
| g_presenceInfo.SetStartTimestamp(0); | ||
| g_presenceInfo.SetStateText(playbackState == Playing ? "(Playing)" : "(Paused)"); | ||
|
|
@@ -163,12 +170,26 @@ void UpdateRichPresenceDetails() | |
| else if (isPlayingResult == Paused) | ||
| { | ||
| g_timer.Stop(); | ||
| ReportCurrentSongStatus(Paused); | ||
| if (g_pluginSettings.SendWhenPausedOrStopped) | ||
| { | ||
| ReportCurrentSongStatus(Paused); | ||
| } | ||
| else | ||
| { | ||
| g_presenceInfo.ShutdownDiscordRPC(); | ||
| } | ||
| } | ||
| else if (isPlayingResult == Stopped) | ||
| { | ||
| g_timer.Stop(); | ||
| ReportIdleStatus(); | ||
| if (g_pluginSettings.SendWhenPausedOrStopped) | ||
| { | ||
| ReportIdleStatus(); | ||
| } | ||
| else | ||
| { | ||
| g_presenceInfo.ShutdownDiscordRPC(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -198,6 +219,9 @@ void UpdateInMemorySettingsFromDialogState(HWND hWndDlg) | |
| { | ||
| g_pluginSettings.ApplicationID = stringData; | ||
| } | ||
|
|
||
| checkboxHwnd = GetDlgItem(hWndDlg, IDC_SEND_WHEN_PAUSE_OR_STOPPED); | ||
| g_pluginSettings.SendWhenPausedOrStopped = Button_GetCheck(checkboxHwnd) == BST_CHECKED; | ||
| } | ||
|
|
||
| void OnConfirmSettingsDialog(HWND hWndDlg) | ||
|
|
@@ -209,8 +233,9 @@ void OnConfirmSettingsDialog(HWND hWndDlg) | |
| bool applicationIDChanged = previousSettings.ApplicationID != g_pluginSettings.ApplicationID; | ||
| bool displayTitleSettingChanged = previousSettings.DisplayTitleInStatus != g_pluginSettings.DisplayTitleInStatus; | ||
| bool elapsedTimeChanged = previousSettings.ShowElapsedTime != g_pluginSettings.ShowElapsedTime; | ||
| bool sendOnPausedOrStopChanged = previousSettings.SendWhenPausedOrStopped != g_pluginSettings.SendWhenPausedOrStopped; | ||
|
|
||
| if (!applicationIDChanged && !displayTitleSettingChanged && !elapsedTimeChanged) | ||
| if (!applicationIDChanged && !displayTitleSettingChanged && !elapsedTimeChanged && !sendOnPausedOrStopChanged) | ||
| return; // Nothing to do | ||
|
|
||
| // Save settings to file | ||
|
|
@@ -233,6 +258,11 @@ void OnConfirmSettingsDialog(HWND hWndDlg) | |
| shouldUpdateRichPresenceDetails = true; | ||
| } | ||
|
|
||
| if (previousSettings.SendWhenPausedOrStopped != g_pluginSettings.SendWhenPausedOrStopped) | ||
| { | ||
| shouldUpdateRichPresenceDetails = true; | ||
| } | ||
|
|
||
| if (shouldUpdateRichPresenceDetails) | ||
| { | ||
| UpdateRichPresenceDetails(); | ||
|
|
@@ -263,6 +293,9 @@ void PopulateSettingsDialogFields(HWND hWndDlg) | |
|
|
||
| HWND editboxHwnd = GetDlgItem(hWndDlg, IDC_EDIT_DISCORD_APPLICATION_ID); | ||
| SetWindowTextA(editboxHwnd, g_pluginSettings.ApplicationID.c_str()); | ||
|
|
||
| checkboxHwnd = GetDlgItem(hWndDlg, IDC_SEND_WHEN_PAUSE_OR_STOPPED); | ||
| Button_SetCheck(checkboxHwnd, (g_pluginSettings.SendWhenPausedOrStopped ? BST_CHECKED : BST_UNCHECKED)); | ||
| } | ||
|
|
||
| // Dialogue box callback function | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,22 @@ std::string GetExecutableFileName() | |
| return std::string(buffer); | ||
| } | ||
|
|
||
| //used to convert strings to a usable string in MessageBox, example: | ||
| //std::wstring stemp = s2ws(executablePath); | ||
| //MessageBox(0, stemp.c_str(), L"", MB_OK); | ||
| //https://stackoverflow.com/a/27296 | ||
| std::wstring s2ws(const std::string& s) | ||
|
||
| { | ||
| int len; | ||
| int slength = (int)s.length() + 1; | ||
| len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); | ||
| wchar_t* buf = new wchar_t[len]; | ||
| MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); | ||
| std::wstring r(buf); | ||
| delete[] buf; | ||
| return r; | ||
| } | ||
|
|
||
| std::string GetExecutablePath() | ||
| { | ||
| std::string executableFileName = GetExecutableFileName(); | ||
|
|
@@ -51,6 +67,12 @@ void SaveSettingsFile() | |
| settingsFileWrite << "ShowElapsedTime:false" << "\n"; | ||
|
|
||
| settingsFileWrite << "ApplicationID:" << g_pluginSettings.ApplicationID << "\n"; | ||
|
|
||
| if (g_pluginSettings.SendWhenPausedOrStopped) | ||
| settingsFileWrite << "SendWhenPausedOrStopped:true" << "\n"; | ||
| else | ||
| settingsFileWrite << "SendWhenPausedOrStopped:false" << "\n"; | ||
|
|
||
| settingsFileWrite.close(); | ||
| } | ||
|
|
||
|
|
@@ -91,6 +113,7 @@ void LoadSettingsFile() | |
| static const char* displayTileInStatus_label = "DisplayTitleInStatus:"; | ||
| static const char* showElapsedTime_label = "ShowElapsedTime:"; | ||
| static const char* applicationID_label = "ApplicationID:"; | ||
| static const char* sendWhenPausedOrStopped_label = "SendWhenPausedOrStopped:"; | ||
|
|
||
| if (line.find(displayTileInStatus_label) == 0) | ||
| { | ||
|
|
@@ -105,6 +128,10 @@ void LoadSettingsFile() | |
| std::string value = line.substr(strlen(applicationID_label)); | ||
| g_pluginSettings.ApplicationID = value; | ||
| } | ||
| else if (line.find(sendWhenPausedOrStopped_label) == 0) | ||
| { | ||
| g_pluginSettings.SendWhenPausedOrStopped = GetBooleanSettingsFileValue(line, sendWhenPausedOrStopped_label); | ||
| } | ||
| } | ||
| } | ||
| else | ||
|
|
||
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.
weird formatting
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.
Eesh, indeed.
VS Code isn't formatting and I am doing it by hand. Missed this.