Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal List<Result> GetDefaultHotKeys()

internal async Task InstallOrUpdate(UserPlugin plugin)
{
if (PluginExists(plugin.ID))
if (PluginExists(plugin.ID) || Directory.Exists(Path.Combine(DataLocation.PluginsDirectory, plugin.Name)))
{
if (Context.API.GetAllPlugins()
.Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0))
Expand Down Expand Up @@ -302,6 +302,38 @@ internal List<Result> Search(IEnumerable<Result> results, string searchName)
.ToList();
}

internal List<Result> InstallFromWeb(string url)
{
var fileName = url.Split("/").Last();
var filePath = Path.Combine(DataLocation.PluginsDirectory, fileName);
var plugin = new UserPlugin
{
ID = "",
Name = fileName.Split(".").First(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to simply trim the last part (.zip). Also, it is possible that the link doesn't contain file name. Though, I think this won't be a large issue since this feature is mainly for debugging.

Author = "N/A",
UrlDownload = url
};
var result = new Result
{
Title = fileName,
SubTitle = $"Download and Install from URL",
IcoPath = icoPath,
Action = e =>
{
if (e.SpecialKeyState.CtrlPressed)
{
SearchWeb.NewTabInBrowser(url);
return ShouldHideWindow;
}

Application.Current.MainWindow.Hide();
_ = InstallOrUpdate(plugin);
return ShouldHideWindow;
}
};
return new List<Result> { result };
}

internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName, CancellationToken token)
{
if (!PluginsManifest.UserPlugins.Any())
Expand Down Expand Up @@ -337,6 +369,10 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
ContextData = x
});

if (Uri.IsWellFormedUriString(searchNameWithoutKeyword, UriKind.Absolute))
{
return InstallFromWeb(searchNameWithoutKeyword);
}
return Search(results, searchNameWithoutKeyword);
}

Expand Down Expand Up @@ -372,8 +408,8 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"));
return;
}

string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}-{plugin.Version}");
var directory = String.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}" : $"{plugin.Name}-{plugin.Version}";
string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory);

FilesFolders.CopyAll(pluginFolderPath, newPluginPath);

Expand Down Expand Up @@ -467,4 +503,4 @@ private List<Result> AutoCompleteReturnAllResults(string search, string hotkey,
return new List<Result>();
}
}
}
}