Skip to content

Commit 4526c7e

Browse files
committed
WebUI: update font size according to the system font size
1 parent a1146ca commit 4526c7e

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Source/Components/ImageGlass.Base/Types/Const.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static class Const
3434
public const string DATETIME_FORMAT = "yyyy/MM/dd HH:mm:ss";
3535
public const string DATE_FORMAT = "yyyy/MM/dd";
3636
public const string APP_PROTOCOL = "imageglass";
37-
public const string APP_CODE = "1️⃣5️⃣🎂";
37+
public const string APP_CODE = "2026";
3838
public const string MS_APPSTORE_ID = "9N33VZK3C7TH";
3939
public const int MAX_IMAGE_DIMENSION = 16_384;
4040

Source/Components/ImageGlass.Base/Webview2/Web2.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private async void Web2_NavigationCompleted(object? sender, CoreWebView2Navigati
562562
""");
563563
}
564564

565-
565+
// update border radius
566566
var borderRadiusTask = Task.CompletedTask;
567567
if (BHelper.IsOS(WindowsOS.Win10))
568568
{
@@ -571,10 +571,24 @@ private async void Web2_NavigationCompleted(object? sender, CoreWebView2Navigati
571571
""");
572572
}
573573

574+
// update font size
575+
const float defaultSystemFontSize = 9f;
576+
var fontSizeTask = Task.CompletedTask;
577+
if (Font.Size != defaultSystemFontSize)
578+
{
579+
const float defaultWebFontSize = 12.5f;
580+
var newWebFontSize = Math.Round(Font.Size / defaultSystemFontSize * defaultWebFontSize, 2);
581+
582+
fontSizeTask = this.ExecuteScriptAsync($"""
583+
document.documentElement.style.setProperty('--fontSize', '{newWebFontSize}');
584+
""");
585+
}
586+
587+
// update color mode
574588
var darkModeTask = SetWeb2DarkModeAsync(DarkMode);
575589
var accentColorTask = SetWeb2AccentColorAsync(AccentColor);
576590

577-
await Task.WhenAll(logTask, borderRadiusTask, darkModeTask, accentColorTask);
591+
await Task.WhenAll(logTask, borderRadiusTask, fontSizeTask, darkModeTask, accentColorTask);
578592
await OnWeb2NavigationCompleted();
579593
}
580594

0 commit comments

Comments
 (0)