-
-
Notifications
You must be signed in to change notification settings - Fork 364
Fix environment exit & Wait image cache save before restarting & Add settings saving lock & Do not crash when caught exception saving #3417
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry, I forget to fix typos here and please review. |
This comment has been minimized.
This comment has been minimized.
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (1)
14-19
: Consider usingLazy<T>
for thread-safe API initialization.The current lazy initialization approach works, but isn't thread-safe. If multiple threads access the
API
property simultaneously, you could end up with multiple instances.-private static IPublicAPI api = null; -private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>(); +private static readonly Lazy<IPublicAPI> lazyApi = new Lazy<IPublicAPI>(() => Ioc.Default.GetRequiredService<IPublicAPI>()); +private static IPublicAPI API => lazyApi.Value;Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (2)
11-16
: Consider usingLazy<T>
for thread-safe API initialization.The current lazy initialization approach works, but isn't thread-safe. If multiple threads access the
API
property simultaneously, you could end up with multiple instances.-private static IPublicAPI api = null; -private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>(); +private static readonly Lazy<IPublicAPI> lazyApi = new Lazy<IPublicAPI>(() => Ioc.Default.GetRequiredService<IPublicAPI>()); +private static IPublicAPI API => lazyApi.Value;Don't forget to add
using System;
at the top of the file to supportLazy<T>
.
1-51
: Consider reducing code duplication between storage classes.The error handling implementation in both
FlowLauncherJsonStorage
andPluginJsonStorage
is nearly identical. Consider refactoring to reduce duplication.You could:
- Create a common base class with error handling
- Use a composition approach with an error handler service
- Create extension methods for adding error handling to Task objects
If base class methods are non-virtual, the current approach with
new
methods is appropriate.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
Flow.Launcher.Core/Updater.cs
(4 hunks)Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs
(2 hunks)Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Flow.Launcher.Core/Updater.cs
🧰 Additional context used
🧬 Code Definitions (2)
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (2)
Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (2)
Save
(26-36)Task
(38-48)Flow.Launcher.Infrastructure/Storage/JsonStorage.cs (3)
Save
(182-190)Task
(44-73)Task
(192-198)
Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (3)
Flow.Launcher.Infrastructure/Storage/JsonStorage.cs (9)
T
(113-139)T
(141-149)T
(151-169)JsonStorage
(15-212)JsonStorage
(32-34)JsonStorage
(36-42)Save
(182-190)Task
(44-73)Task
(192-198)Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (2)
Save
(36-46)Task
(48-58)Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs (3)
Save
(137-147)Task
(38-85)Task
(125-135)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: gitStream.cm
🔇 Additional comments (6)
Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs (3)
2-5
: Added necessary import statements.The new imports are correctly added to support the new functionality for asynchronous operations, dependency injection, and plugin API access.
48-58
: Improved error handling for the SaveAsync method.The asynchronous version correctly implements exception handling similar to the synchronous version, maintaining consistency in error handling approach.
36-46
:✅ Verification successful
Improved error handling for the Save method.
Good addition of try-catch block to prevent crashes when saving settings fails. The error is properly logged instead of being silently swallowed.
Verify this implementation aligns with the PR objectives of preventing crashes during saving operations.
🏁 Script executed:
#!/bin/bash # Check if the base class methods are virtual or override-able rg -A 1 -B 1 "public\s+(virtual\s+)?(void\s+Save|Task\s+SaveAsync)" Flow.Launcher.Infrastructure/Storage/JsonStorage.csLength of output: 159
Verification Complete: Enhanced Error Handling Implementation
The implementation of the
Save
method inPluginJsonStorage.cs
now includes robust error handling. The try-catch block prevents crashes by catching exceptions from the non-virtualbase.Save()
method (as confirmed inFlow.Launcher.Infrastructure/Storage/JsonStorage.cs
). The error is appropriately logged with the class name and file path, aligning with the PR objectives.
- No further changes are needed as the use of the
new
keyword is valid given that the base method is not virtual.Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs (3)
2-5
: Added necessary import statements.The new imports are correctly added to support the new functionality for asynchronous operations, dependency injection, and plugin API access.
26-36
: Improved error handling for the Save method.Good addition of try-catch block to prevent crashes when saving settings fails. The error is properly logged instead of being silently swallowed.
38-48
: Improved error handling for the SaveAsync method.The asynchronous version correctly implements exception handling similar to the synchronous version, maintaining consistency in error handling approach.
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. Forbidden patterns 🙅 (1)In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves. These forbidden patterns matched content: s.b. workaround(s)
If the flagged items are 🤯 false positivesIf items relate to a ...
|
Sorry for asking your review again. I didn't handle conflict resolution well causing me to need an additional commit to fix it. |
Fix
Environment.Exit(0)
issueSince #3367 has introduced
Application.Current.Shutdown
for app dispose, usingEnvironment.Exit(0)
will cause issue.Wait image cache save
Before restarting app, we should wait
ImageLoader.SaveAsync
.Add settings save lock
Make multiple thread safe.
Do not crash when caught exception in saving
Use try when calling
JsonStorage
andBinaryStorage
save.Test