Skip to content

Commit 9133f2f

Browse files
authored
Merge branch 'dev' into 250412-SettingWindowFont
2 parents a28ee70 + f9e8139 commit 9133f2f

File tree

18 files changed

+318
-160
lines changed

18 files changed

+318
-160
lines changed

.github/workflows/dotnet.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: Build
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- dev
11+
- master
12+
pull_request:
13+
14+
jobs:
15+
build:
16+
17+
runs-on: windows-latest
18+
env:
19+
FlowVersion: 1.19.5
20+
NUGET_CERT_REVOCATION_MODE: offline
21+
BUILD_NUMBER: ${{ github.run_number }}
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set Flow.Launcher.csproj version
25+
id: update
26+
uses: vers-one/[email protected]
27+
with:
28+
file: |
29+
"**/SolutionAssemblyInfo.cs"
30+
version: ${{ env.FlowVersion }}.${{ env.BUILD_NUMBER }}
31+
- name: Setup .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: 7.0.x
35+
# cache: true
36+
# cache-dependency-path: |
37+
# Flow.Launcher/packages.lock.json
38+
# Flow.Launcher.Core/packages.lock.json
39+
# Flow.Launcher.Infrastructure/packages.lock.json
40+
# Flow.Launcher.Plugin/packages.lock.json
41+
- name: Install vpk
42+
run: dotnet tool install -g vpk
43+
- name: Restore dependencies
44+
run: nuget restore
45+
- name: Build
46+
run: dotnet build --no-restore -c Release
47+
- name: Initialize Service
48+
run: |
49+
sc config WSearch start= auto # Starts Windows Search service- Needed for running ExplorerTest
50+
net start WSearch
51+
- name: Test
52+
run: dotnet test --no-build --verbosity normal -c Release
53+
- name: Perform post_build tasks
54+
shell: powershell
55+
run: .\Scripts\post_build.ps1
56+
- name: Upload Plugin Nupkg
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: Plugin nupkg
60+
path: |
61+
Output\Release\Flow.Launcher.Plugin.*.nupkg
62+
compression-level: 0
63+
- name: Upload Setup
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: Flow Installer
67+
path: |
68+
Output\Packages\Flow-Launcher-*.exe
69+
compression-level: 0
70+
- name: Upload Portable Version
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: Portable Version
74+
path: |
75+
Output\Packages\Flow-Launcher-Portable.zip
76+
compression-level: 0
77+
- name: Upload Full Nupkg
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: Full nupkg
81+
path: |
82+
Output\Packages\FlowLauncher-*-full.nupkg
83+
84+
compression-level: 0
85+
- name: Upload Release Information
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: RELEASES
89+
path: |
90+
Output\Packages\RELEASES
91+
compression-level: 0

Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace Flow.Launcher.Core.ExternalPlugins
1616
{
1717
public record CommunityPluginSource(string ManifestFileUrl)
1818
{
19+
private static readonly string ClassName = nameof(CommunityPluginSource);
20+
1921
// We should not initialize API in static constructor because it will create another API instance
2022
private static IPublicAPI api = null;
2123
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
2224

23-
private static readonly string ClassName = nameof(CommunityPluginSource);
24-
2525
private string latestEtag = "";
2626

2727
private List<UserPlugin> plugins = new();
@@ -70,7 +70,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
7070
else
7171
{
7272
API.LogWarn(ClassName, $"Failed to load resource {ManifestFileUrl} with response {response.StatusCode}");
73-
return plugins;
73+
return null;
7474
}
7575
}
7676
catch (Exception e)
@@ -83,7 +83,7 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
8383
{
8484
API.LogException(ClassName, "Error Occurred", e);
8585
}
86-
return plugins;
86+
return null;
8787
}
8888
}
8989
}

Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token, bool onl
4040
var completedTask = await Task.WhenAny(tasks);
4141
if (completedTask.IsCompletedSuccessfully)
4242
{
43-
// one of the requests completed successfully; keep its results
44-
// and cancel the remaining http requests.
45-
pluginResults = await completedTask;
46-
cts.Cancel();
43+
var result = await completedTask;
44+
if (result != null)
45+
{
46+
// one of the requests completed successfully; keep its results
47+
// and cancel the remaining http requests.
48+
pluginResults = result;
49+
cts.Cancel();
50+
}
4751
}
4852
tasks.Remove(completedTask);
4953
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
3-
using System.Diagnostics;
4-
using System.Drawing;
5-
using System.Globalization;
6-
using System.Linq;
73
using System.Text.Json.Serialization;
84
using System.Windows;
9-
using System.Windows.Media;
105
using CommunityToolkit.Mvvm.DependencyInjection;
116
using Flow.Launcher.Infrastructure.Hotkey;
127
using Flow.Launcher.Infrastructure.Logger;
138
using Flow.Launcher.Infrastructure.Storage;
149
using Flow.Launcher.Plugin;
1510
using Flow.Launcher.Plugin.SharedModels;
1611
using Flow.Launcher.ViewModel;
17-
using SystemFonts = System.Windows.SystemFonts;
1812

1913
namespace Flow.Launcher.Infrastructure.UserSettings
2014
{
@@ -38,69 +32,6 @@ public void Save()
3832
_storage.Save();
3933
}
4034

41-
private string language = Constant.SystemLanguageCode;
42-
private static readonly Dictionary<string, string> LanguageToNotoSans = new()
43-
{
44-
{ "ko", "Noto Sans KR" },
45-
{ "ja", "Noto Sans JP" },
46-
{ "zh-CN", "Noto Sans SC" },
47-
{ "zh-SG", "Noto Sans SC" },
48-
{ "zh-Hans", "Noto Sans SC" },
49-
{ "zh-TW", "Noto Sans TC" },
50-
{ "zh-HK", "Noto Sans TC" },
51-
{ "zh-MO", "Noto Sans TC" },
52-
{ "zh-Hant", "Noto Sans TC" },
53-
{ "th", "Noto Sans Thai" },
54-
{ "ar", "Noto Sans Arabic" },
55-
{ "he", "Noto Sans Hebrew" },
56-
{ "hi", "Noto Sans Devanagari" },
57-
{ "bn", "Noto Sans Bengali" },
58-
{ "ta", "Noto Sans Tamil" },
59-
{ "el", "Noto Sans Greek" },
60-
{ "ru", "Noto Sans" },
61-
{ "en", "Noto Sans" },
62-
{ "fr", "Noto Sans" },
63-
{ "de", "Noto Sans" },
64-
{ "es", "Noto Sans" },
65-
{ "pt", "Noto Sans" }
66-
};
67-
68-
public static string GetSystemDefaultFont(bool? useNoto = null)
69-
{
70-
try
71-
{
72-
if (useNoto != false)
73-
{
74-
var culture = CultureInfo.CurrentCulture;
75-
var language = culture.Name; // e.g., "zh-TW"
76-
var langPrefix = language.Split('-')[0]; // e.g., "zh"
77-
78-
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
79-
{
80-
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
81-
return notoFont;
82-
}
83-
}
84-
85-
var font = SystemFonts.MessageFontFamily;
86-
if (font.FamilyNames.TryGetValue(System.Windows.Markup.XmlLanguage.GetLanguage("en-US"), out var englishName))
87-
{
88-
return englishName;
89-
}
90-
91-
return font.Source ?? "Segoe UI";
92-
}
93-
catch
94-
{
95-
return "Segoe UI";
96-
}
97-
}
98-
99-
private static bool TryGetNotoFont(string langKey, out string notoFont)
100-
{
101-
return LanguageToNotoSans.TryGetValue(langKey, out notoFont);
102-
}
103-
10435
private string _theme = Constant.DefaultTheme;
10536
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
10637
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
@@ -121,12 +52,13 @@ private static bool TryGetNotoFont(string langKey, out string notoFont)
12152
public string CycleHistoryUpHotkey { get; set; } = $"{KeyConstant.Alt} + Up";
12253
public string CycleHistoryDownHotkey { get; set; } = $"{KeyConstant.Alt} + Down";
12354

55+
private string _language = Constant.SystemLanguageCode;
12456
public string Language
12557
{
126-
get => language;
58+
get => _language;
12759
set
12860
{
129-
language = value;
61+
_language = value;
13062
OnPropertyChanged();
13163
}
13264
}
@@ -152,15 +84,15 @@ public string Theme
15284
public double QueryBoxFontSize { get; set; } = 16;
15385
public double ResultItemFontSize { get; set; } = 16;
15486
public double ResultSubItemFontSize { get; set; } = 13;
155-
public string QueryBoxFont { get; set; } = GetSystemDefaultFont();
87+
public string QueryBoxFont { get; set; } = Win32Helper.GetSystemDefaultFont();
15688
public string QueryBoxFontStyle { get; set; }
15789
public string QueryBoxFontWeight { get; set; }
15890
public string QueryBoxFontStretch { get; set; }
159-
public string ResultFont { get; set; } = GetSystemDefaultFont();
91+
public string ResultFont { get; set; } = Win32Helper.GetSystemDefaultFont();
16092
public string ResultFontStyle { get; set; }
16193
public string ResultFontWeight { get; set; }
16294
public string ResultFontStretch { get; set; }
163-
public string ResultSubFont { get; set; } = GetSystemDefaultFont();
95+
public string ResultSubFont { get; set; } = Win32Helper.GetSystemDefaultFont();
16496
public string ResultSubFontStyle { get; set; }
16597
public string ResultSubFontWeight { get; set; }
16698
public string ResultSubFontStretch { get; set; }
@@ -184,7 +116,7 @@ public string Theme
184116
public double? SettingWindowLeft { get; set; } = null;
185117
public WindowState SettingWindowState { get; set; } = WindowState.Normal;
186118

187-
bool _showPlaceholder { get; set; } = true;
119+
private bool _showPlaceholder { get; set; } = true;
188120
public bool ShowPlaceholder
189121
{
190122
get => _showPlaceholder;
@@ -197,7 +129,7 @@ public bool ShowPlaceholder
197129
}
198130
}
199131
}
200-
string _placeholderText { get; set; } = string.Empty;
132+
private string _placeholderText { get; set; } = string.Empty;
201133
public string PlaceholderText
202134
{
203135
get => _placeholderText;
@@ -376,7 +308,7 @@ public bool KeepMaxResults
376308
public bool StartFlowLauncherOnSystemStartup { get; set; } = false;
377309
public bool UseLogonTaskForStartup { get; set; } = false;
378310
public bool HideOnStartup { get; set; } = true;
379-
bool _hideNotifyIcon { get; set; }
311+
private bool _hideNotifyIcon;
380312
public bool HideNotifyIcon
381313
{
382314
get => _hideNotifyIcon;
@@ -554,5 +486,4 @@ public enum BackdropTypes
554486
Mica,
555487
MicaAlt
556488
}
557-
558489
}

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Globalization;
6+
using System.Linq;
57
using System.Runtime.InteropServices;
68
using System.Windows;
79
using System.Windows.Interop;
10+
using System.Windows.Markup;
811
using System.Windows.Media;
912
using Flow.Launcher.Infrastructure.UserSettings;
1013
using Microsoft.Win32;
@@ -14,6 +17,7 @@
1417
using Windows.Win32.UI.Input.KeyboardAndMouse;
1518
using Windows.Win32.UI.WindowsAndMessaging;
1619
using Point = System.Windows.Point;
20+
using SystemFonts = System.Windows.SystemFonts;
1721

1822
namespace Flow.Launcher.Infrastructure
1923
{
@@ -595,5 +599,73 @@ public static void OpenImeSettings()
595599
}
596600

597601
#endregion
602+
603+
#region System Font
604+
605+
private static readonly Dictionary<string, string> _languageToNotoSans = new()
606+
{
607+
{ "ko", "Noto Sans KR" },
608+
{ "ja", "Noto Sans JP" },
609+
{ "zh-CN", "Noto Sans SC" },
610+
{ "zh-SG", "Noto Sans SC" },
611+
{ "zh-Hans", "Noto Sans SC" },
612+
{ "zh-TW", "Noto Sans TC" },
613+
{ "zh-HK", "Noto Sans TC" },
614+
{ "zh-MO", "Noto Sans TC" },
615+
{ "zh-Hant", "Noto Sans TC" },
616+
{ "th", "Noto Sans Thai" },
617+
{ "ar", "Noto Sans Arabic" },
618+
{ "he", "Noto Sans Hebrew" },
619+
{ "hi", "Noto Sans Devanagari" },
620+
{ "bn", "Noto Sans Bengali" },
621+
{ "ta", "Noto Sans Tamil" },
622+
{ "el", "Noto Sans Greek" },
623+
{ "ru", "Noto Sans" },
624+
{ "en", "Noto Sans" },
625+
{ "fr", "Noto Sans" },
626+
{ "de", "Noto Sans" },
627+
{ "es", "Noto Sans" },
628+
{ "pt", "Noto Sans" }
629+
};
630+
631+
public static string GetSystemDefaultFont()
632+
{
633+
try
634+
{
635+
var culture = CultureInfo.CurrentCulture;
636+
var language = culture.Name; // e.g., "zh-TW"
637+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
638+
639+
// First, try to find by full name, and if not found, fallback to prefix
640+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
641+
{
642+
// If the font is installed, return it
643+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
644+
{
645+
return notoFont;
646+
}
647+
}
648+
649+
// If Noto font is not found, fallback to the system default font
650+
var font = SystemFonts.MessageFontFamily;
651+
if (font.FamilyNames.TryGetValue(XmlLanguage.GetLanguage("en-US"), out var englishName))
652+
{
653+
return englishName;
654+
}
655+
656+
return font.Source ?? "Segoe UI";
657+
}
658+
catch
659+
{
660+
return "Segoe UI";
661+
}
662+
}
663+
664+
private static bool TryGetNotoFont(string langKey, out string notoFont)
665+
{
666+
return _languageToNotoSans.TryGetValue(langKey, out notoFont);
667+
}
668+
669+
#endregion
598670
}
599671
}

0 commit comments

Comments
 (0)