mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'dev' into theme_change_api
This commit is contained in:
commit
91b64275c1
14 changed files with 53 additions and 46 deletions
|
|
@ -284,7 +284,7 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
return ImageCache.TryGetValue(path, loadFullImage, out image);
|
||||
}
|
||||
|
||||
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false)
|
||||
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false, bool cacheImage = true)
|
||||
{
|
||||
var imageResult = await LoadInternalAsync(path, loadFullImage);
|
||||
|
||||
|
|
@ -300,16 +300,18 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
// image already exists
|
||||
img = ImageCache[key, loadFullImage] ?? img;
|
||||
}
|
||||
else
|
||||
else if (cacheImage)
|
||||
{
|
||||
// new guid
|
||||
|
||||
// save guid key
|
||||
GuidToKey[hash] = path;
|
||||
}
|
||||
}
|
||||
|
||||
// update cache
|
||||
ImageCache[path, loadFullImage] = img;
|
||||
if (cacheImage)
|
||||
{
|
||||
// update cache
|
||||
ImageCache[path, loadFullImage] = img;
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Flow.Launcher.Plugin.SharedModels;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
|
|
@ -364,6 +365,20 @@ namespace Flow.Launcher.Plugin
|
|||
/// <returns></returns>
|
||||
public void SetCurrentTheme(ThemeData theme);
|
||||
|
||||
/// Load image from path. Support local, remote and data:image url.
|
||||
/// If image path is missing, it will return a missing icon.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the image.</param>
|
||||
/// <param name="loadFullImage">
|
||||
/// Load full image or not.
|
||||
/// </param>
|
||||
/// <param name="cacheImage">
|
||||
/// Cache the image or not. Cached image will be stored in FL cache.
|
||||
/// If the image is just used one time, it's better to set this to false.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
ValueTask<ImageSource> LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true);
|
||||
|
||||
/// Update the plugin manifest
|
||||
/// </summary>
|
||||
/// <param name="usePrimaryUrlOnly">
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ namespace Flow.Launcher
|
|||
private async Task SetImageAsync(string imageName)
|
||||
{
|
||||
var imagePath = Path.Combine(Constant.ProgramDirectory, "Images", imageName);
|
||||
var imageSource = await ImageLoader.LoadAsync(imagePath);
|
||||
var imageSource = await App.API.LoadImageAsync(imagePath);
|
||||
Img.Source = imageSource;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Flow.Launcher
|
|||
|
||||
private async System.Threading.Tasks.Task LoadImageAsync()
|
||||
{
|
||||
imgClose.Source = await ImageLoader.LoadAsync(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png"));
|
||||
imgClose.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\close.png"));
|
||||
}
|
||||
|
||||
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
|
|
@ -71,11 +71,11 @@ namespace Flow.Launcher
|
|||
|
||||
if (!File.Exists(iconPath))
|
||||
{
|
||||
imgIco.Source = await ImageLoader.LoadAsync(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"));
|
||||
imgIco.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
imgIco.Source = await ImageLoader.LoadAsync(iconPath);
|
||||
imgIco.Source = await App.API.LoadImageAsync(iconPath);
|
||||
}
|
||||
|
||||
Show();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Squirrel;
|
||||
using Flow.Launcher.Core;
|
||||
|
|
@ -368,6 +369,9 @@ namespace Flow.Launcher
|
|||
_ = _theme.RefreshFrameAsync();
|
||||
}
|
||||
|
||||
public ValueTask<ImageSource> LoadImageAsync(string path, bool loadFullImage = false, bool cacheImage = true) =>
|
||||
ImageLoader.LoadAsync(path, loadFullImage, cacheImage);
|
||||
|
||||
public Task<bool> UpdatePluginManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default) =>
|
||||
PluginsManifest.UpdateManifestAsync(usePrimaryUrlOnly, token);
|
||||
|
||||
|
|
|
|||
|
|
@ -1168,7 +1168,7 @@ namespace Flow.Launcher.ViewModel
|
|||
else if (plugins.Count == 1)
|
||||
{
|
||||
PluginIconPath = plugins.Single().Metadata.IcoPath;
|
||||
PluginIconSource = await ImageLoader.LoadAsync(PluginIconPath);
|
||||
PluginIconSource = await App.API.LoadImageAsync(PluginIconPath);
|
||||
SearchIconVisibility = Visibility.Hidden;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private async Task LoadIconAsync()
|
||||
{
|
||||
Image = await ImageLoader.LoadAsync(PluginPair.Metadata.IcoPath);
|
||||
Image = await App.API.LoadImageAsync(PluginPair.Metadata.IcoPath);
|
||||
OnPropertyChanged(nameof(Image));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
return await ImageLoader.LoadAsync(imagePath, loadFullImage).ConfigureAwait(false);
|
||||
return await App.API.LoadImageAsync(imagePath, loadFullImage).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task LoadImageAsync()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Flow.Launcher.Infrastructure.Image;
|
||||
using Flow.Launcher.Plugin.Explorer.Search;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Explorer.Views;
|
||||
|
|
@ -89,7 +88,7 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
|
|||
|
||||
private async Task LoadImageAsync()
|
||||
{
|
||||
PreviewImage = await ImageLoader.LoadAsync(FilePath, true).ConfigureAwait(false);
|
||||
PreviewImage = await Main.Context.API.LoadImageAsync(FilePath, true).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using Flow.Launcher.Infrastructure.Image;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
#pragma warning disable IDE0005
|
||||
|
|
@ -41,8 +40,8 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
#if DEBUG
|
||||
throw;
|
||||
#else
|
||||
Main._context.API.ShowMsgBox(string.Format("Copying the selected image file to {0} has failed, changes will now be reverted", destinationFileNameFullPath));
|
||||
UpdateIconAttributes(selectedSearchSource, fullPathToOriginalImage);
|
||||
Main._context.API.ShowMsgBox(string.Format("Copying the selected image file to {0} has failed, changes will now be reverted", destinationFileNameFullPath));
|
||||
UpdateIconAttributes(selectedSearchSource, fullPathToOriginalImage);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +60,7 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
|
||||
internal async ValueTask<ImageSource> LoadPreviewIconAsync(string pathToPreviewIconImage)
|
||||
{
|
||||
return await ImageLoader.LoadAsync(pathToPreviewIconImage);
|
||||
return await Main._context.API.LoadImageAsync(pathToPreviewIconImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ using System.Linq;
|
|||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
|
||||
|
|
@ -22,11 +20,11 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
try
|
||||
{
|
||||
const string api = "http://suggestion.baidu.com/su?json=1&wd=";
|
||||
result = await Http.GetAsync(api + Uri.EscapeDataString(query), token).ConfigureAwait(false);
|
||||
result = await Main._context.API.HttpGetStringAsync(api + Uri.EscapeDataString(query), token).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException})
|
||||
{
|
||||
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
|
||||
Main._context.API.LogException(nameof(Baidu), "Can't get suggestion from Baidu", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +39,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log.Exception("|Baidu.Suggestions|can't parse suggestions", e);
|
||||
Main._context.API.LogException(nameof(Baidu), "Can't parse suggestions", e);
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -10,16 +8,15 @@ using System.Threading;
|
|||
|
||||
namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
class Bing : SuggestionSource
|
||||
public class Bing : SuggestionSource
|
||||
{
|
||||
public override async Task<List<string>> SuggestionsAsync(string query, CancellationToken token)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
const string api = "https://api.bing.com/qsonhs.aspx?q=";
|
||||
|
||||
await using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), token).ConfigureAwait(false);
|
||||
await using var resultStream = await Main._context.API.HttpGetStreamAsync(api + Uri.EscapeDataString(query), token).ConfigureAwait(false);
|
||||
|
||||
using var json = (await JsonDocument.ParseAsync(resultStream, cancellationToken: token));
|
||||
var root = json.RootElement.GetProperty("AS");
|
||||
|
|
@ -33,18 +30,15 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
.EnumerateArray()
|
||||
.Select(s => s.GetProperty("Txt").GetString()))
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e) when (e is HttpRequestException or { InnerException: TimeoutException })
|
||||
{
|
||||
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
|
||||
Main._context.API.LogException(nameof(Bing), "Can't get suggestion from Bing", e);
|
||||
return null;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log.Exception("|Bing.Suggestions|can't parse suggestions", e);
|
||||
Main._context.API.LogException(nameof(Bing), "Can't parse suggestions", e);
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Text.Json;
|
||||
|
|
@ -25,7 +23,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
{
|
||||
const string api = "https://duckduckgo.com/ac/?type=list&q=";
|
||||
|
||||
await using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false);
|
||||
await using var resultStream = await Main._context.API.HttpGetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false);
|
||||
|
||||
using var json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token);
|
||||
|
||||
|
|
@ -36,12 +34,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
}
|
||||
catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException})
|
||||
{
|
||||
Log.Exception("|DuckDuckGo.Suggestions|Can't get suggestion from DuckDuckGo", e);
|
||||
Main._context.API.LogException(nameof(DuckDuckGo), "Can't get suggestion from DuckDuckGo", e);
|
||||
return null;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log.Exception("|DuckDuckGo.Suggestions|can't parse suggestions", e);
|
||||
Main._context.API.LogException(nameof(DuckDuckGo), "Can't parse suggestions", e);
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Infrastructure.Http;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Text.Json;
|
||||
|
|
@ -18,7 +16,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
{
|
||||
const string api = "https://www.google.com/complete/search?output=chrome&q=";
|
||||
|
||||
await using var resultStream = await Http.GetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false);
|
||||
await using var resultStream = await Main._context.API.HttpGetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false);
|
||||
|
||||
using var json = await JsonDocument.ParseAsync(resultStream, cancellationToken: token);
|
||||
|
||||
|
|
@ -29,12 +27,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources
|
|||
}
|
||||
catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException})
|
||||
{
|
||||
Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e);
|
||||
Main._context.API.LogException(nameof(Google), "Can't get suggestion from Google", e);
|
||||
return null;
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Log.Exception("|Google.Suggestions|can't parse suggestions", e);
|
||||
Main._context.API.LogException(nameof(Google), "Can't parse suggestions", e);
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue