Skip to content

Commit 48971d8

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into JsonRPCPluginSettingControl
2 parents 5ea8675 + 2855c6c commit 48971d8

File tree

188 files changed

+57122
-5424
lines changed

Some content is hidden

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

188 files changed

+57122
-5424
lines changed

Flow.Launcher.Core/Plugin/PluginConfig.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.IO;
@@ -45,8 +45,56 @@ public static List<PluginMetadata> Parse(string[] pluginDirectories)
4545
}
4646
}
4747
}
48-
49-
return allPluginMetadata;
48+
49+
(List<PluginMetadata> uniqueList, List<PluginMetadata> duplicateList) = GetUniqueLatestPluginMetadata(allPluginMetadata);
50+
51+
duplicateList
52+
.ForEach(
53+
x => Log.Warn("PluginConfig",
54+
string.Format("Duplicate plugin name: {0}, id: {1}, version: {2} " +
55+
"not loaded due to version not the highest of the duplicates",
56+
x.Name, x.ID, x.Version),
57+
"GetUniqueLatestPluginMetadata"));
58+
59+
return uniqueList;
60+
}
61+
62+
internal static (List<PluginMetadata>, List<PluginMetadata>) GetUniqueLatestPluginMetadata(List<PluginMetadata> allPluginMetadata)
63+
{
64+
var duplicate_list = new List<PluginMetadata>();
65+
var unique_list = new List<PluginMetadata>();
66+
67+
var duplicateGroups = allPluginMetadata.GroupBy(x => x.ID).Where(g => g.Count() > 1).Select(y => y).ToList();
68+
69+
foreach (var metadata in allPluginMetadata)
70+
{
71+
var duplicatesExist = false;
72+
foreach (var group in duplicateGroups)
73+
{
74+
if (metadata.ID == group.Key)
75+
{
76+
duplicatesExist = true;
77+
78+
// If metadata's version greater than each duplicate's version, CompareTo > 0
79+
var count = group.Where(x => metadata.Version.CompareTo(x.Version) > 0).Count();
80+
81+
// Only add if the meatadata's version is the highest of all duplicates in the group
82+
if (count == group.Count() - 1)
83+
{
84+
unique_list.Add(metadata);
85+
}
86+
else
87+
{
88+
duplicate_list.Add(metadata);
89+
}
90+
}
91+
}
92+
93+
if (!duplicatesExist)
94+
unique_list.Add(metadata);
95+
}
96+
97+
return (unique_list, duplicate_list);
5098
}
5199

52100
private static PluginMetadata GetPluginMetadata(string pluginDirectory)

Flow.Launcher.Core/Plugin/PythonPlugin.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics;
33
using System.IO;
44
using System.Threading;
@@ -28,6 +28,11 @@ public PythonPlugin(string filename)
2828
var path = Path.Combine(Constant.ProgramDirectory, JsonRPC);
2929
_startInfo.EnvironmentVariables["PYTHONPATH"] = path;
3030

31+
_startInfo.EnvironmentVariables["FLOW_VERSION"] = Constant.Version;
32+
_startInfo.EnvironmentVariables["FLOW_PROGRAM_DIRECTORY"] = Constant.ProgramDirectory;
33+
_startInfo.EnvironmentVariables["FLOW_APPLICATION_DIRECTORY"] = Constant.ApplicationDirectory;
34+
35+
3136
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
3237
_startInfo.ArgumentList.Add("-B");
3338
}
@@ -54,4 +59,4 @@ public override async Task InitAsync(PluginInitContext context)
5459
_startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory;
5560
}
5661
}
57-
}
62+
}

Flow.Launcher.Core/Resource/AvailableLanguages.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ internal static class AvailableLanguages
1717
public static Language German = new Language("de", "Deutsch");
1818
public static Language Korean = new Language("ko", "한국어");
1919
public static Language Serbian = new Language("sr", "Srpski");
20-
public static Language Portuguese_BR = new Language("pt-br", "Português (Brasil)");
20+
public static Language Portuguese_Portugal = new Language("pt-pt", "Português");
21+
public static Language Portuguese_Brazil = new Language("pt-br", "Português (Brasil)");
2122
public static Language Italian = new Language("it", "Italiano");
2223
public static Language Norwegian_Bokmal = new Language("nb-NO", "Norsk Bokmål");
2324
public static Language Slovak = new Language("sk", "Slovenský");
@@ -40,7 +41,8 @@ public static List<Language> GetAvailableLanguages()
4041
German,
4142
Korean,
4243
Serbian,
43-
Portuguese_BR,
44+
Portuguese_Portugal,
45+
Portuguese_Brazil,
4446
Italian,
4547
Norwegian_Bokmal,
4648
Slovak,

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Flow.Launcher.Infrastructure.UserSettings;
1111
using Flow.Launcher.Plugin;
1212
using System.Globalization;
13+
using System.Threading.Tasks;
1314

1415
namespace Flow.Launcher.Core.Resource
1516
{
@@ -95,10 +96,13 @@ public void ChangeLanguage(Language language)
9596
{
9697
LoadLanguage(language);
9798
}
98-
UpdatePluginMetadataTranslations();
9999
Settings.Language = language.LanguageCode;
100100
CultureInfo.CurrentCulture = new CultureInfo(language.LanguageCode);
101101
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
102+
Task.Run(() =>
103+
{
104+
UpdatePluginMetadataTranslations();
105+
});
102106
}
103107

104108
public bool PromptShouldUsePinyin(string languageCodeToSet)

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ public static class Constant
3535

3636
public const string DefaultTheme = "Win11Light";
3737

38+
public const string Light = "Light";
39+
public const string Dark = "Dark";
40+
public const string System = "System";
41+
3842
public const string Themes = "Themes";
43+
public const string Settings = "Settings";
44+
public const string Logs = "Logs";
3945

4046
public const string Website = "https://flow-launcher.github.io";
47+
public const string GitHub = "https://github.com/Flow-Launcher/Flow.Launcher";
48+
public const string Docs = "https://flow-launcher.github.io/docs";
4149
}
4250
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1212
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
1313
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
14+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1415
</PropertyGroup>
1516

1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -21,7 +22,6 @@
2122
<DefineConstants>DEBUG;TRACE</DefineConstants>
2223
<ErrorReport>prompt</ErrorReport>
2324
<WarningLevel>4</WarningLevel>
24-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2525
<Prefer32Bit>false</Prefer32Bit>
2626
</PropertyGroup>
2727

@@ -32,7 +32,6 @@
3232
<DefineConstants>TRACE</DefineConstants>
3333
<ErrorReport>prompt</ErrorReport>
3434
<WarningLevel>4</WarningLevel>
35-
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
3635
<Prefer32Bit>false</Prefer32Bit>
3736
</PropertyGroup>
3837

Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,28 @@ namespace Flow.Launcher.Infrastructure.Hotkey
99
/// Listens keyboard globally.
1010
/// <remarks>Uses WH_KEYBOARD_LL.</remarks>
1111
/// </summary>
12-
public class GlobalHotkey : IDisposable
12+
public unsafe class GlobalHotkey : IDisposable
1313
{
14-
private static GlobalHotkey instance;
15-
private InterceptKeys.LowLevelKeyboardProc hookedLowLevelKeyboardProc;
16-
private IntPtr hookId = IntPtr.Zero;
14+
private static readonly IntPtr hookId;
15+
16+
17+
1718
public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state);
18-
public event KeyboardCallback hookedKeyboardCallback;
19+
internal static Func<KeyEvent, int, SpecialKeyState, bool> hookedKeyboardCallback;
1920

2021
//Modifier key constants
2122
private const int VK_SHIFT = 0x10;
2223
private const int VK_CONTROL = 0x11;
2324
private const int VK_ALT = 0x12;
2425
private const int VK_WIN = 91;
2526

26-
public static GlobalHotkey Instance
27+
static GlobalHotkey()
2728
{
28-
get
29-
{
30-
if (instance == null)
31-
{
32-
instance = new GlobalHotkey();
33-
}
34-
return instance;
35-
}
36-
}
37-
38-
private GlobalHotkey()
39-
{
40-
// We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime
41-
hookedLowLevelKeyboardProc = LowLevelKeyboardProc;
4229
// Set the hook
43-
hookId = InterceptKeys.SetHook(hookedLowLevelKeyboardProc);
30+
hookId = InterceptKeys.SetHook(& LowLevelKeyboardProc);
4431
}
4532

46-
public SpecialKeyState CheckModifiers()
33+
public static SpecialKeyState CheckModifiers()
4734
{
4835
SpecialKeyState state = new SpecialKeyState();
4936
if ((InterceptKeys.GetKeyState(VK_SHIFT) & 0x8000) != 0)
@@ -70,8 +57,8 @@ public SpecialKeyState CheckModifiers()
7057
return state;
7158
}
7259

73-
[MethodImpl(MethodImplOptions.NoInlining)]
74-
private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
60+
[UnmanagedCallersOnly]
61+
private static IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
7562
{
7663
bool continues = true;
7764

@@ -91,17 +78,17 @@ private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
9178
{
9279
return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
9380
}
94-
return (IntPtr)1;
81+
return (IntPtr)(-1);
9582
}
9683

97-
~GlobalHotkey()
84+
public void Dispose()
9885
{
99-
Dispose();
86+
InterceptKeys.UnhookWindowsHookEx(hookId);
10087
}
10188

102-
public void Dispose()
89+
~GlobalHotkey()
10390
{
104-
InterceptKeys.UnhookWindowsHookEx(hookId);
91+
Dispose();
10592
}
10693
}
10794
}

Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Flow.Launcher.Infrastructure.Hotkey
66
{
7-
internal static class InterceptKeys
7+
internal static unsafe class InterceptKeys
88
{
99
public delegate IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam);
1010

1111
private const int WH_KEYBOARD_LL = 13;
1212

13-
public static IntPtr SetHook(LowLevelKeyboardProc proc)
13+
public static IntPtr SetHook(delegate* unmanaged<int, UIntPtr, IntPtr, IntPtr> proc)
1414
{
1515
using (Process curProcess = Process.GetCurrentProcess())
1616
using (ProcessModule curModule = curProcess.MainModule)
@@ -20,7 +20,7 @@ public static IntPtr SetHook(LowLevelKeyboardProc proc)
2020
}
2121

2222
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
23-
public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
23+
public static extern IntPtr SetWindowsHookEx(int idHook, delegate* unmanaged<int, UIntPtr, IntPtr, IntPtr> lpfn, IntPtr hMod, uint dwThreadId);
2424

2525
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
2626
[return: MarshalAs(UnmanagedType.Bool)]

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Settings : BaseModel
1515
private string language = "en";
1616
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
1717
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
18+
public string ColorScheme { get; set; } = "System";
1819
public bool ShowOpenResultHotkey { get; set; } = true;
1920
public double WindowSize { get; set; } = 580;
2021

@@ -38,6 +39,7 @@ public string Language
3839
public string ResultFontWeight { get; set; }
3940
public string ResultFontStretch { get; set; }
4041
public bool UseGlyphIcons { get; set; } = true;
42+
public bool FirstLaunch { get; set; } = true;
4143

4244
public int CustomExplorerIndex { get; set; } = 0;
4345

@@ -82,6 +84,8 @@ public CustomExplorerViewModel CustomExplorer
8284
}
8385
};
8486

87+
public bool UseAnimation { get; set; } = true;
88+
public bool UseSound { get; set; } = true;
8589

8690
/// <summary>
8791
/// when false Alphabet static service will always return empty results
@@ -130,8 +134,8 @@ public string QuerySearchPrecisionString
130134
public bool DontPromptUpdateMsg { get; set; }
131135
public bool EnableUpdateLog { get; set; }
132136

133-
public bool StartFlowLauncherOnSystemStartup { get; set; } = true;
134-
public bool HideOnStartup { get; set; }
137+
public bool StartFlowLauncherOnSystemStartup { get; set; } = false;
138+
public bool HideOnStartup { get; set; } = true;
135139
bool _hideNotifyIcon { get; set; }
136140
public bool HideNotifyIcon
137141
{
@@ -163,4 +167,11 @@ public enum LastQueryMode
163167
Empty,
164168
Preserved
165169
}
170+
171+
public enum ColorSchemes
172+
{
173+
System,
174+
Light,
175+
Dark
176+
}
166177
}

Flow.Launcher.Plugin/Interfaces/IPluginI18n.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Flow.Launcher.Plugin
1+
using System.Globalization;
2+
3+
namespace Flow.Launcher.Plugin
24
{
35
/// <summary>
46
/// Represent plugins that support internationalization
@@ -8,5 +10,13 @@ public interface IPluginI18n : IFeatures
810
string GetTranslatedPluginTitle();
911

1012
string GetTranslatedPluginDescription();
13+
14+
/// <summary>
15+
/// The method will be invoked when language of flow changed
16+
/// </summary>
17+
void OnCultureInfoChanged(CultureInfo newCulture)
18+
{
19+
20+
}
1121
}
1222
}

0 commit comments

Comments
 (0)