Skip to content

Commit 2b40107

Browse files
authored
Merge pull request #3848 from Flow-Launcher/sys_plugin_improvement
Improve Sys plugin
2 parents c02ef0e + d874076 commit 2b40107

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,5 +613,17 @@ public interface IPublicAPI
613613
/// Invoked when the actual theme of the application has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
614614
/// </summary>
615615
event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
616+
617+
/// <summary>
618+
/// Get the user data directory of Flow Launcher.
619+
/// </summary>
620+
/// <returns></returns>
621+
string GetDataDirectory();
622+
623+
/// <summary>
624+
/// Get the log directory of Flow Launcher.
625+
/// </summary>
626+
/// <returns></returns>
627+
string GetLogDirectory();
616628
}
617629
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeCha
599599
remove => _mainVM.ActualApplicationThemeChanged -= value;
600600
}
601601

602+
public string GetDataDirectory() => DataLocation.DataDirectory();
603+
604+
public string GetLogDirectory() => DataLocation.VersionLogDirectory;
605+
602606
#endregion
603607

604608
#region Private Methods

Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
</PropertyGroup>
3838

3939
<ItemGroup>
40-
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
4140
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
4241
</ItemGroup>
4342

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_restart_computer">Are you sure you want to restart the computer?</system:String>
6464
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_restart_computer_advanced">Are you sure you want to restart the computer with Advanced Boot Options?</system:String>
6565
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_logoff_computer">Are you sure you want to log off?</system:String>
66+
<system:String x:Key="flowlauncher_plugin_sys_dlgtitle_error">Error</system:String>
67+
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed">Failed to empty the recycle bin. This might happen if:{0}- Some items are currently in use{0}- Some items can't be deleted due to permissions{0}Please close any applications that might be using these files and try again.</system:String>
6668

6769
<system:String x:Key="flowlauncher_plugin_sys_command_keyword_setting_window_title">Command Keyword Setting</system:String>
6870
<system:String x:Key="flowlauncher_plugin_sys_custom_command_keyword">Custom Command Keyword</system:String>

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System.Linq;
66
using System.Runtime.InteropServices;
77
using System.Windows;
8-
using Flow.Launcher.Infrastructure;
9-
using Flow.Launcher.Infrastructure.UserSettings;
108
using Windows.Win32;
119
using Windows.Win32.Foundation;
1210
using Windows.Win32.Security;
@@ -52,6 +50,8 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n
5250
private const SHUTDOWN_REASON REASON = SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER |
5351
SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED;
5452

53+
private const string Documentation = "https://flowlauncher.com/docs/#/usage-tips";
54+
5555
private PluginInitContext _context;
5656
private Settings _settings;
5757
private ThemeSelector _themeSelector;
@@ -338,11 +338,9 @@ private List<Result> Commands(Query query)
338338
var result = PInvoke.SHEmptyRecycleBin(new(), string.Empty, 0);
339339
if (result != HRESULT.S_OK && result != HRESULT.E_UNEXPECTED)
340340
{
341-
_context.API.ShowMsgBox("Failed to empty the recycle bin. This might happen if:\n" +
342-
"- A file in the recycle bin is in use\n" +
343-
"- You don't have permission to delete some items\n" +
344-
"Please close any applications that might be using these files and try again.",
345-
"Error",
341+
_context.API.ShowMsgBox(
342+
string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_empty_recycle_bin_failed"), Environment.NewLine),
343+
_context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_error"),
346344
MessageBoxButton.OK, MessageBoxImage.Error);
347345
}
348346

@@ -404,6 +402,8 @@ private List<Result> Commands(Query query)
404402
IcoPath = "Images\\app.png",
405403
Action = c =>
406404
{
405+
// Hide the window first then open setting dialog because main window can be topmost window which will still display on top of the setting dialog for a while
406+
_context.API.HideMainWindow();
407407
_context.API.OpenSettingDialog();
408408
return true;
409409
}
@@ -445,11 +445,11 @@ private List<Result> Commands(Query query)
445445
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
446446
Title = "Open Log Location",
447447
IcoPath = "Images\\app.png",
448-
CopyText = DataLocation.VersionLogDirectory,
449-
AutoCompleteText = DataLocation.VersionLogDirectory,
448+
CopyText = _context.API.GetLogDirectory(),
449+
AutoCompleteText = _context.API.GetLogDirectory(),
450450
Action = c =>
451451
{
452-
_context.API.OpenDirectory(DataLocation.VersionLogDirectory);
452+
_context.API.OpenDirectory(_context.API.GetLogDirectory());
453453
return true;
454454
}
455455
},
@@ -458,11 +458,11 @@ private List<Result> Commands(Query query)
458458
Title = "Flow Launcher Tips",
459459
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe897"),
460460
IcoPath = "Images\\app.png",
461-
CopyText = Constant.Documentation,
462-
AutoCompleteText = Constant.Documentation,
461+
CopyText = Documentation,
462+
AutoCompleteText = Documentation,
463463
Action = c =>
464464
{
465-
_context.API.OpenUrl(Constant.Documentation);
465+
_context.API.OpenUrl(Documentation);
466466
return true;
467467
}
468468
},
@@ -471,11 +471,11 @@ private List<Result> Commands(Query query)
471471
Title = "Flow Launcher UserData Folder",
472472
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xf12b"),
473473
IcoPath = "Images\\app.png",
474-
CopyText = DataLocation.DataDirectory(),
475-
AutoCompleteText = DataLocation.DataDirectory(),
474+
CopyText = _context.API.GetDataDirectory(),
475+
AutoCompleteText = _context.API.GetDataDirectory(),
476476
Action = c =>
477477
{
478-
_context.API.OpenDirectory(DataLocation.DataDirectory());
478+
_context.API.OpenDirectory(_context.API.GetDataDirectory());
479479
return true;
480480
}
481481
},

0 commit comments

Comments
 (0)