Skip to content

Commit a6ddaf9

Browse files
committed
Merge branch 'dev' into JsonRPCShellRun
2 parents ae7de8d + 8f8636a commit a6ddaf9

File tree

104 files changed

+6471
-1521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+6471
-1521
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Flow.Launcher.Infrastructure.Http;
2+
using Flow.Launcher.Infrastructure.Logger;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text.Json;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Flow.Launcher.Core.ExternalPlugins
10+
{
11+
public static class PluginsManifest
12+
{
13+
static PluginsManifest()
14+
{
15+
UpdateTask = UpdateManifestAsync();
16+
}
17+
18+
public static List<UserPlugin> UserPlugins { get; private set; } = new List<UserPlugin>();
19+
20+
public static Task UpdateTask { get; private set; }
21+
22+
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
23+
24+
public static Task UpdateManifestAsync()
25+
{
26+
if (manifestUpdateLock.CurrentCount == 0)
27+
{
28+
return UpdateTask;
29+
}
30+
31+
return UpdateTask = DownloadManifestAsync();
32+
}
33+
34+
private async static Task DownloadManifestAsync()
35+
{
36+
try
37+
{
38+
await manifestUpdateLock.WaitAsync().ConfigureAwait(false);
39+
40+
await using var jsonStream = await Http.GetStreamAsync("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json")
41+
.ConfigureAwait(false);
42+
43+
UserPlugins = await JsonSerializer.DeserializeAsync<List<UserPlugin>>(jsonStream).ConfigureAwait(false);
44+
}
45+
catch (Exception e)
46+
{
47+
Log.Exception("|PluginManagement.GetManifest|Encountered error trying to download plugins manifest", e);
48+
49+
UserPlugins = new List<UserPlugin>();
50+
}
51+
finally
52+
{
53+
manifestUpdateLock.Release();
54+
}
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-

2-
namespace Flow.Launcher.Plugin.PluginsManager.Models
1+
namespace Flow.Launcher.Core.ExternalPlugins
32
{
4-
public class UserPlugin
3+
public record UserPlugin
54
{
65
public string ID { get; set; }
76
public string Name { get; set; }
@@ -12,5 +11,6 @@ public class UserPlugin
1211
public string Website { get; set; }
1312
public string UrlDownload { get; set; }
1413
public string UrlSourceCode { get; set; }
14+
public string IcoPath { get; set; }
1515
}
1616
}

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,31 @@ public static class QueryBuilder
1010
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
1111
{
1212
// replace multiple white spaces with one white space
13-
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
13+
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
1414
if (terms.Length == 0)
1515
{ // nothing was typed
1616
return null;
1717
}
1818

19-
var rawQuery = string.Join(Query.TermSeperater, terms);
19+
var rawQuery = string.Join(Query.TermSeparator, terms);
2020
string actionKeyword, search;
2121
string possibleActionKeyword = terms[0];
22-
List<string> actionParameters;
22+
string[] searchTerms;
23+
2324
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
2425
{ // use non global plugin for query
2526
actionKeyword = possibleActionKeyword;
26-
actionParameters = terms.Skip(1).ToList();
27-
search = actionParameters.Count > 0 ? rawQuery.Substring(actionKeyword.Length + 1) : string.Empty;
27+
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..] : string.Empty;
28+
searchTerms = terms[1..];
2829
}
2930
else
3031
{ // non action keyword
3132
actionKeyword = string.Empty;
3233
search = rawQuery;
34+
searchTerms = terms;
3335
}
3436

35-
var query = new Query
36-
{
37-
Terms = terms,
38-
RawQuery = rawQuery,
39-
ActionKeyword = actionKeyword,
40-
Search = search
41-
};
37+
var query = new Query(rawQuery, search,terms, searchTerms, actionKeyword);
4238

4339
return query;
4440
}

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Flow.Launcher.Infrastructure.Logger;
1010
using Flow.Launcher.Infrastructure.UserSettings;
1111
using Flow.Launcher.Plugin;
12+
using System.Globalization;
1213

1314
namespace Flow.Launcher.Core.Resource
1415
{
@@ -96,7 +97,8 @@ public void ChangeLanguage(Language language)
9697
}
9798
UpdatePluginMetadataTranslations();
9899
Settings.Language = language.LanguageCode;
99-
100+
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
101+
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
100102
}
101103

102104
public bool PromptShouldUsePinyin(string languageCodeToSet)

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,11 @@ public ResourceDictionary GetResourceDictionary()
189189
new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
190190
=> Array.ForEach(setters, p => o.Setters.Add(p)));
191191
}
192-
192+
/* Ignore Theme Window Width and use setting */
193193
var windowStyle = dict["WindowStyle"] as Style;
194-
195-
var width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
196-
.Select(x => x.Value).FirstOrDefault();
197-
198-
if (width == null)
199-
{
200-
windowStyle = dict["BaseWindowStyle"] as Style;
201-
202-
width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
203-
.Select(x => x.Value).FirstOrDefault();
204-
}
205-
194+
var width = Settings.WindowSize;
195+
windowStyle.Setters.Add(new Setter(Window.WidthProperty, width));
206196
mainWindowWidth = (double)width;
207-
208197
return dict;
209198
}
210199

@@ -375,8 +364,6 @@ private void SetWindowAccent(Window w, AccentState state)
375364
{
376365
var windowHelper = new WindowInteropHelper(w);
377366

378-
// this determines the width of the main query window
379-
w.Width = mainWindowWidth;
380367
windowHelper.EnsureHandle();
381368

382369
var accent = new AccentPolicy { AccentState = state };

Flow.Launcher.Core/Updater.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Flow.Launcher.Infrastructure.UserSettings;
1717
using Flow.Launcher.Plugin;
1818
using System.Text.Json.Serialization;
19+
using System.Threading;
1920

2021
namespace Flow.Launcher.Core
2122
{
@@ -28,21 +29,21 @@ public Updater(string gitHubRepository)
2829
GitHubRepository = gitHubRepository;
2930
}
3031

31-
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
32+
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
33+
34+
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
3235
{
36+
await UpdateLock.WaitAsync();
3337
try
3438
{
35-
UpdateInfo newUpdateInfo;
36-
3739
if (!silentUpdate)
3840
api.ShowMsg(api.GetTranslation("pleaseWait"),
39-
api.GetTranslation("update_flowlauncher_update_check"));
41+
api.GetTranslation("update_flowlauncher_update_check"));
4042

4143
using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
4244

43-
4445
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
45-
newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
46+
var newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
4647

4748
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
4849
var currentVersion = Version.Parse(Constant.Version);
@@ -58,7 +59,7 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
5859

5960
if (!silentUpdate)
6061
api.ShowMsg(api.GetTranslation("update_flowlauncher_update_found"),
61-
api.GetTranslation("update_flowlauncher_updating"));
62+
api.GetTranslation("update_flowlauncher_updating"));
6263

6364
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false);
6465

@@ -70,8 +71,8 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
7071
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
7172
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
7273
MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
73-
DataLocation.PortableDataPath,
74-
targetDestination));
74+
DataLocation.PortableDataPath,
75+
targetDestination));
7576
}
7677
else
7778
{
@@ -87,12 +88,15 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
8788
UpdateManager.RestartApp(Constant.ApplicationFileName);
8889
}
8990
}
90-
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException || e.InnerException is TimeoutException)
91+
catch (Exception e) when (e is HttpRequestException or WebException or SocketException || e.InnerException is TimeoutException)
9192
{
9293
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
9394
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
94-
api.GetTranslation("update_flowlauncher_check_connection"));
95-
return;
95+
api.GetTranslation("update_flowlauncher_check_connection"));
96+
}
97+
finally
98+
{
99+
UpdateLock.Release();
96100
}
97101
}
98102

@@ -115,13 +119,16 @@ private async Task<UpdateManager> GitHubUpdateManager(string repository)
115119
var uri = new Uri(repository);
116120
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
117121

118-
var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);
122+
await using var jsonStream = await Http.GetStreamAsync(api).ConfigureAwait(false);
119123

120124
var releases = await System.Text.Json.JsonSerializer.DeserializeAsync<List<GithubRelease>>(jsonStream).ConfigureAwait(false);
121125
var latest = releases.Where(r => !r.Prerelease).OrderByDescending(r => r.PublishedAt).First();
122126
var latestUrl = latest.HtmlUrl.Replace("/tag/", "/download/");
123-
124-
var client = new WebClient { Proxy = Http.WebProxy };
127+
128+
var client = new WebClient
129+
{
130+
Proxy = Http.WebProxy
131+
};
125132
var downloader = new FileDownloader(client);
126133

127134
var manager = new UpdateManager(latestUrl, urlDownloader: downloader);

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class Constant
3333

3434
public static readonly string QueryTextBoxIconImagePath = $"{ProgramDirectory}\\Images\\mainsearch.svg";
3535

36-
public const string DefaultTheme = "Darker";
36+
public const string DefaultTheme = "Win11Light";
3737

3838
public const string Themes = "Themes";
3939

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@
5050

5151
<ItemGroup>
5252
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
53+
<PackageReference Include="Fody" Version="6.5.5">
54+
<PrivateAssets>all</PrivateAssets>
55+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
56+
</PackageReference>
5357
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56" />
5458
<PackageReference Include="NLog" Version="4.7.10" />
5559
<PackageReference Include="NLog.Schema" Version="4.7.10" />
5660
<PackageReference Include="NLog.Web.AspNetCore" Version="4.13.0" />
61+
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
5762
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
5863
<!--ToolGood.Words.Pinyin v3.0.2.6 results in high memory usage when search with pinyin is enabled-->
5964
<!--Bumping to it or higher needs to test and ensure this is no longer a problem-->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Flow.Launcher.Plugin;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Flow.Launcher.ViewModel
9+
{
10+
public class CustomExplorerViewModel : BaseModel
11+
{
12+
public string Name { get; set; }
13+
public string Path { get; set; }
14+
public string FileArgument { get; set; } = "\"%d\"";
15+
public string DirectoryArgument { get; set; } = "\"%d\"";
16+
public bool Editable { get; init; } = true;
17+
18+
public CustomExplorerViewModel Copy()
19+
{
20+
return new CustomExplorerViewModel
21+
{
22+
Name = Name,
23+
Path = Path,
24+
FileArgument = FileArgument,
25+
DirectoryArgument = DirectoryArgument,
26+
Editable = Editable
27+
};
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)