Skip to content

Commit 092b459

Browse files
authored
Detect URL and install
1 parent 8f8636a commit 092b459

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,37 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
302302
.ToList();
303303
}
304304

305+
internal List<Result> InstallFromWeb(string url)
306+
{
307+
var fileName = url.Split("/").Last();
308+
var filePath = Path.Combine(DataLocation.PluginsDirectory, fileName);
309+
var plugin = new UserPlugin
310+
{
311+
ID = "",
312+
Name = fileName.Split(".").First(),
313+
Author = "N/A",
314+
UrlDownload = url
315+
};
316+
var result = new Result
317+
{
318+
Title = $"{url}",
319+
SubTitle = $"Download and Install from URL",
320+
Action = e =>
321+
{
322+
if (e.SpecialKeyState.CtrlPressed)
323+
{
324+
SearchWeb.NewTabInBrowser(url);
325+
return ShouldHideWindow;
326+
}
327+
328+
Application.Current.MainWindow.Hide();
329+
_ = InstallOrUpdate(plugin);
330+
return ShouldHideWindow;
331+
}
332+
};
333+
return new List<Result> { result };
334+
}
335+
305336
internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
306337
{
307338
if (!PluginsManifest.UserPlugins.Any())
@@ -337,6 +368,10 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
337368
ContextData = x
338369
});
339370

371+
if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute))
372+
{
373+
return InstallFromWeb(searchNameWithoutKeyword);
374+
}
340375
return Search(results, searchNameWithoutKeyword);
341376
}
342377

@@ -372,8 +407,8 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
372407
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"));
373408
return;
374409
}
375-
376-
string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}-{plugin.Version}");
410+
var directory = String.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}" : $"{plugin.Name}-{plugin.Version}";
411+
string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory);
377412

378413
FilesFolders.CopyAll(pluginFolderPath, newPluginPath);
379414

@@ -467,4 +502,4 @@ private List<Result> AutoCompleteReturnAllResults(string search, string hotkey,
467502
return new List<Result>();
468503
}
469504
}
470-
}
505+
}

0 commit comments

Comments
 (0)