-
-
Notifications
You must be signed in to change notification settings - Fork 286
Refactor post-grab actions: fix memory leaks, improve performance, enhance maintainability #607
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39a00f5
Initial plan
Copilot 542cf17
Address PR review comments: fix hash code, improve string concatenati…
Copilot e618c81
Fix TrimEachLine logic and use Tag-based menu item identification
Copilot ddd73c3
Remove unused import and extract magic strings to constants
Copilot 481aad0
Use explicit types instead of var to respect editor config style
Copilot 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,13 +22,10 @@ public static List<ButtonInfo> GetAvailablePostGrabActions() | |
| List<ButtonInfo> allPostGrabActions = [.. GetDefaultPostGrabActions()]; | ||
|
|
||
| // Add other relevant actions from AllButtons that are marked as relevant for FullscreenGrab | ||
| foreach (ButtonInfo button in ButtonInfo.AllButtons) | ||
| { | ||
| if (button.IsRelevantForFullscreenGrab && !allPostGrabActions.Any(b => b.ButtonText == button.ButtonText)) | ||
| { | ||
| allPostGrabActions.Add(button); | ||
| } | ||
| } | ||
| var relevantActions = ButtonInfo.AllButtons | ||
| .Where(button => button.IsRelevantForFullscreenGrab && !allPostGrabActions.Any(b => b.ButtonText == button.ButtonText)); | ||
|
|
||
| allPostGrabActions.AddRange(relevantActions); | ||
|
|
||
| return [.. allPostGrabActions.OrderBy(b => b.OrderNumber)]; | ||
| } | ||
|
|
@@ -144,11 +141,12 @@ public static bool GetCheckState(ButtonInfo action) | |
| try | ||
| { | ||
| Dictionary<string, bool>? checkStates = JsonSerializer.Deserialize<Dictionary<string, bool>>(statesJson); | ||
| if (checkStates is not null && checkStates.TryGetValue(action.ButtonText, out bool storedState)) | ||
| if (checkStates is not null | ||
| && checkStates.TryGetValue(action.ButtonText, out bool storedState) | ||
| && action.DefaultCheckState == DefaultCheckState.LastUsed) | ||
| { | ||
| // If the action is set to LastUsed, use the stored state | ||
| if (action.DefaultCheckState == DefaultCheckState.LastUsed) | ||
| return storedState; | ||
| return storedState; | ||
| } | ||
| } | ||
| catch (JsonException) | ||
|
|
@@ -202,11 +200,14 @@ public static async Task<string> ExecutePostGrabAction(ButtonInfo action, string | |
|
|
||
| case "TrimEachLine_Click": | ||
| string[] stringSplit = text.Split(Environment.NewLine); | ||
| string finalString = ""; | ||
| foreach (string line in stringSplit) | ||
| if (!string.IsNullOrWhiteSpace(line)) | ||
| finalString += line.Trim() + Environment.NewLine; | ||
| result = finalString; | ||
| var trimmedLines = stringSplit | ||
|
||
| .Where(line => !string.IsNullOrWhiteSpace(line)) | ||
| .Select(line => line.Trim()) | ||
| .ToArray(); | ||
|
|
||
| result = trimmedLines.Length == 0 | ||
| ? string.Empty | ||
| : string.Join(Environment.NewLine, trimmedLines) + Environment.NewLine; | ||
| break; | ||
|
|
||
| case "RemoveDuplicateLines_Click": | ||
|
|
||
This file contains hidden or 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.
Respect editor config style and use explicit types
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.
Changed to explicit type
IEnumerable<ButtonInfo>in commit 481aad0.