Skip to content

Commit 8a312d4

Browse files
committed
Implement the API call to custom explorer via ipublicapi, and migrate the exist call to explorer to the api call.
1 parent b3a04a9 commit 8a312d4

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,12 @@ public interface IPublicAPI
190190
/// <typeparam name="T">Type for Serialization</typeparam>
191191
/// <returns></returns>
192192
void SaveSettingJsonStorage<T>() where T : new();
193+
194+
/// <summary>
195+
/// Open Directory in explorer configured by user
196+
/// </summary>
197+
/// <param name="DirectoryPath">Directory Path to open</param>
198+
/// <param name="FileName">Extra FileName Info</param>
199+
public void OpenDirectory(string DirectoryPath, string FileName = null);
193200
}
194201
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using Flow.Launcher.Infrastructure.Logger;
2323
using Flow.Launcher.Infrastructure.Storage;
2424
using System.Collections.Concurrent;
25+
using Flow.Launcher.Plugin.SharedCommands;
26+
using System.Diagnostics;
2527

2628
namespace Flow.Launcher
2729
{
@@ -158,7 +160,7 @@ public void SavePluginSettings()
158160
if (!_pluginJsonStorages.ContainsKey(type))
159161
_pluginJsonStorages[type] = new PluginJsonStorage<T>();
160162

161-
return ((PluginJsonStorage<T>) _pluginJsonStorages[type]).Load();
163+
return ((PluginJsonStorage<T>)_pluginJsonStorages[type]).Load();
162164
}
163165

164166
public void SaveSettingJsonStorage<T>() where T : new()
@@ -167,15 +169,30 @@ public void SavePluginSettings()
167169
if (!_pluginJsonStorages.ContainsKey(type))
168170
_pluginJsonStorages[type] = new PluginJsonStorage<T>();
169171

170-
((PluginJsonStorage<T>) _pluginJsonStorages[type]).Save();
172+
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
171173
}
172174

173175
public void SaveJsonStorage<T>(T settings) where T : new()
174176
{
175177
var type = typeof(T);
176178
_pluginJsonStorages[type] = new PluginJsonStorage<T>(settings);
177179

178-
((PluginJsonStorage<T>) _pluginJsonStorages[type]).Save();
180+
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
181+
}
182+
183+
public void OpenDirectory(string DirectoryPath, string FileName = null)
184+
{
185+
using Process explorer = new Process();
186+
var explorerInfo = _settingsVM.Settings.CustomExplorer;
187+
explorer.StartInfo = new ProcessStartInfo
188+
{
189+
FileName = explorerInfo.Path,
190+
Arguments = FileName is null ?
191+
explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) :
192+
explorerInfo.FileArgument.Replace("%d", DirectoryPath).Replace("%f",
193+
Path.IsPathRooted(FileName) ? FileName : Path.Combine(DirectoryPath, FileName))
194+
};
195+
explorer.Start();
179196
}
180197

181198
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
@@ -188,7 +205,7 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe
188205
{
189206
if (GlobalKeyboardEvent != null)
190207
{
191-
return GlobalKeyboardEvent((int) keyevent, vkcode, state);
208+
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
192209
}
193210

194211
return true;

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private void OnPluginDirecotyClick(object sender, MouseButtonEventArgs e)
231231
{
232232
var directory = viewModel.SelectedPlugin.PluginPair.Metadata.PluginDirectory;
233233
if (!string.IsNullOrEmpty(directory))
234-
FilesFolders.OpenPath(directory);
234+
PluginManager.API.OpenDirectory(directory);
235235
}
236236
}
237237
#endregion
@@ -269,7 +269,7 @@ private void OnCloseExecuted(object sender, ExecutedRoutedEventArgs e)
269269

270270
private void OpenPluginFolder(object sender, RoutedEventArgs e)
271271
{
272-
FilesFolders.OpenPath(Path.Combine(DataLocation.DataDirectory(), Constant.Themes));
272+
PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Themes));
273273
}
274274

275275
private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
3434
{
3535
try
3636
{
37-
FilesFolders.OpenPath(path);
37+
Context.API.OpenDirectory(path);
3838
return true;
3939
}
4040
catch (Exception ex)
@@ -101,7 +101,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
101101
Score = 500,
102102
Action = c =>
103103
{
104-
FilesFolders.OpenPath(retrievedDirectoryPath);
104+
Context.API.OpenDirectory(retrievedDirectoryPath);
105105
return true;
106106
},
107107
TitleToolTip = retrievedDirectoryPath,
@@ -150,7 +150,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
150150
}
151151
else if (c.SpecialKeyState.CtrlPressed)
152152
{
153-
FilesFolders.OpenContainingFolder(filePath);
153+
Context.API.OpenDirectory(Path.GetDirectoryName(filePath), filePath);
154154
}
155155
else
156156
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private List<Result> Commands()
304304
Action = c =>
305305
{
306306
var logPath = Path.Combine(DataLocation.DataDirectory(), "Logs", Constant.Version);
307-
FilesFolders.OpenPath(logPath);
307+
context.API.OpenDirectory(logPath);
308308
return true;
309309
}
310310
},
@@ -326,7 +326,7 @@ private List<Result> Commands()
326326
IcoPath = "Images\\app.png",
327327
Action = c =>
328328
{
329-
FilesFolders.OpenPath(DataLocation.DataDirectory());
329+
context.API.OpenDirectory(DataLocation.DataDirectory());
330330
return true;
331331
}
332332
}

0 commit comments

Comments
 (0)