mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-21 16:14:28 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
435b96c50c | ||
|
|
49b18d6af1 | ||
|
|
d6ec159af4 | ||
|
|
0d14675cc0 |
32
.github/workflows/release.yml
vendored
32
.github/workflows/release.yml
vendored
@@ -275,6 +275,8 @@ jobs:
|
||||
package_name="LanMountainDesktop"
|
||||
package_version="${version}"
|
||||
arch="amd64"
|
||||
desktop_template="LanMountainDesktop/packaging/linux/LanMountainDesktop.desktop"
|
||||
icon_source="LanMountainDesktop/packaging/linux/lanmountaindesktop.png"
|
||||
|
||||
# Verify source directory exists
|
||||
if [ ! -d "$source" ]; then
|
||||
@@ -288,6 +290,7 @@ jobs:
|
||||
mkdir -p "build-deb/usr/local/bin"
|
||||
mkdir -p "build-deb/usr/share/applications"
|
||||
mkdir -p "build-deb/usr/share/pixmaps"
|
||||
mkdir -p "build-deb/usr/share/icons/hicolor/256x256/apps"
|
||||
|
||||
# Copy application files
|
||||
cp -r "$source"/* "build-deb/usr/local/bin/"
|
||||
@@ -300,6 +303,31 @@ jobs:
|
||||
echo "Error: DEB package is empty after copy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$desktop_template" ] || [ ! -f "$icon_source" ]; then
|
||||
echo "Error: Linux desktop resources are missing"
|
||||
ls -la "LanMountainDesktop/packaging/linux" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed \
|
||||
-e "s|@@EXEC@@|/usr/local/bin/LanMountainDesktop|g" \
|
||||
-e "s|@@ICON@@|lanmountaindesktop|g" \
|
||||
"$desktop_template" > "build-deb/usr/share/applications/LanMountainDesktop.desktop"
|
||||
|
||||
cp "$icon_source" "build-deb/usr/share/pixmaps/lanmountaindesktop.png"
|
||||
cp "$icon_source" "build-deb/usr/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
|
||||
|
||||
{
|
||||
printf '%s\n' '#!/bin/sh'
|
||||
printf '%s\n' 'set -e'
|
||||
printf '%s\n' 'if command -v update-desktop-database >/dev/null 2>&1; then'
|
||||
printf '%s\n' ' update-desktop-database /usr/share/applications >/dev/null 2>&1 || true'
|
||||
printf '%s\n' 'fi'
|
||||
printf '%s\n' 'if command -v gtk-update-icon-cache >/dev/null 2>&1; then'
|
||||
printf '%s\n' ' gtk-update-icon-cache /usr/share/icons/hicolor >/dev/null 2>&1 || true'
|
||||
printf '%s\n' 'fi'
|
||||
} > "build-deb/DEBIAN/postinst"
|
||||
|
||||
# Create control file (NOTE: No leading spaces in control file)
|
||||
{
|
||||
@@ -313,6 +341,10 @@ jobs:
|
||||
|
||||
# Set proper permissions
|
||||
chmod 755 "build-deb/usr/local/bin/LanMountainDesktop" || chmod 755 "build-deb/usr/local/bin"/*
|
||||
chmod 644 "build-deb/usr/share/applications/LanMountainDesktop.desktop"
|
||||
chmod 644 "build-deb/usr/share/pixmaps/lanmountaindesktop.png"
|
||||
chmod 644 "build-deb/usr/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
|
||||
chmod 755 "build-deb/DEBIAN/postinst"
|
||||
|
||||
# Create DEB file
|
||||
if dpkg-deb --build "build-deb" "${package_name}_${package_version}_${arch}.deb"; then
|
||||
|
||||
@@ -24,6 +24,8 @@ public partial class App : Application
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
LinuxDesktopEntryInstaller.EnsureInstalled();
|
||||
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
|
||||
@@ -251,7 +251,9 @@
|
||||
"desktop.page_index_format": "Desktop {0}",
|
||||
"launcher.title": "App Launcher",
|
||||
"launcher.subtitle": "Apps and folders from Windows Start Menu",
|
||||
"launcher.subtitle_linux": "Installed apps discovered from Linux desktop entries",
|
||||
"launcher.empty": "No Start Menu entries found.",
|
||||
"launcher.empty_linux": "No Linux desktop entries were found.",
|
||||
"launcher.empty_folder": "This folder is empty.",
|
||||
"launcher.folder_items_format": "{0} apps",
|
||||
"launcher.context.hide_icon": "Hide Icon",
|
||||
|
||||
@@ -251,7 +251,9 @@
|
||||
"desktop.page_index_format": "桌面 {0}",
|
||||
"launcher.title": "应用启动台",
|
||||
"launcher.subtitle": "按 Windows 开始菜单结构显示所有应用与文件夹",
|
||||
"launcher.subtitle_linux": "显示从 Linux .desktop 条目扫描到的已安装应用",
|
||||
"launcher.empty": "未找到开始菜单条目。",
|
||||
"launcher.empty_linux": "未找到 Linux .desktop 应用条目。",
|
||||
"launcher.empty_folder": "此文件夹为空。",
|
||||
"launcher.folder_items_format": "{0} 个应用",
|
||||
"launcher.context.hide_icon": "隐藏图标",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace LanMountainDesktop.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LanMountainDesktop.Models;
|
||||
|
||||
public sealed class StartMenuAppEntry
|
||||
{
|
||||
@@ -9,4 +11,10 @@ public sealed class StartMenuAppEntry
|
||||
public required string RelativePath { get; init; }
|
||||
|
||||
public byte[]? IconPngBytes { get; init; }
|
||||
|
||||
public string? LaunchExecutable { get; init; }
|
||||
|
||||
public IReadOnlyList<string> LaunchArguments { get; init; } = [];
|
||||
|
||||
public string? WorkingDirectory { get; init; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -39,7 +39,7 @@ public sealed class ClassIslandScheduleDataService : IClassIslandScheduleDataSer
|
||||
};
|
||||
|
||||
private static readonly IDeserializer CsesDeserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
||||
.IgnoreUnmatchedProperties()
|
||||
.Build();
|
||||
|
||||
|
||||
192
LanMountainDesktop/Services/LinuxDesktopEntryInstaller.cs
Normal file
192
LanMountainDesktop/Services/LinuxDesktopEntryInstaller.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
internal static class LinuxDesktopEntryInstaller
|
||||
{
|
||||
private const string DesktopFileName = "LanMountainDesktop.desktop";
|
||||
private const string IconFileName = "lanmountaindesktop.png";
|
||||
private const string IconName = "lanmountaindesktop";
|
||||
|
||||
public static void EnsureInstalled()
|
||||
{
|
||||
if (!OperatingSystem.IsLinux())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var executablePath = ResolveExecutablePath();
|
||||
if (string.IsNullOrWhiteSpace(executablePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dataHome = ResolveDataHome();
|
||||
if (string.IsNullOrWhiteSpace(dataHome))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var applicationsDir = Path.Combine(dataHome, "applications");
|
||||
var iconDir = Path.Combine(dataHome, "icons", "hicolor", "256x256", "apps");
|
||||
|
||||
Directory.CreateDirectory(applicationsDir);
|
||||
Directory.CreateDirectory(iconDir);
|
||||
|
||||
var desktopTargetPath = Path.Combine(applicationsDir, DesktopFileName);
|
||||
var iconTargetPath = Path.Combine(iconDir, IconFileName);
|
||||
|
||||
TryCopyBundledIcon(iconTargetPath);
|
||||
|
||||
var desktopEntryContent = BuildDesktopEntryContent(executablePath);
|
||||
WriteFileIfChanged(desktopTargetPath, desktopEntryContent);
|
||||
|
||||
TryRunCommand("chmod", "+x", executablePath);
|
||||
TryRunCommand("chmod", "+x", desktopTargetPath);
|
||||
TryRunCommand("update-desktop-database", applicationsDir);
|
||||
TryRunCommand("gtk-update-icon-cache", Path.Combine(dataHome, "icons", "hicolor"));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep startup resilient if desktop integration fails.
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolveExecutablePath()
|
||||
{
|
||||
var processPath = Environment.ProcessPath;
|
||||
if (!string.IsNullOrWhiteSpace(processPath))
|
||||
{
|
||||
return processPath;
|
||||
}
|
||||
|
||||
var commandLineArgs = Environment.GetCommandLineArgs();
|
||||
if (commandLineArgs.Length > 0 && !string.IsNullOrWhiteSpace(commandLineArgs[0]))
|
||||
{
|
||||
return commandLineArgs[0];
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private static string ResolveDataHome()
|
||||
{
|
||||
var dataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (!string.IsNullOrWhiteSpace(dataHome))
|
||||
{
|
||||
return dataHome.Trim();
|
||||
}
|
||||
|
||||
var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
if (string.IsNullOrWhiteSpace(homePath))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return Path.Combine(homePath, ".local", "share");
|
||||
}
|
||||
|
||||
private static void TryCopyBundledIcon(string iconTargetPath)
|
||||
{
|
||||
foreach (var candidatePath in EnumerateIconSourceCandidates())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(candidatePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
File.Copy(candidatePath, iconTargetPath, overwrite: true);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore failures and continue trying fallbacks.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] EnumerateIconSourceCandidates()
|
||||
{
|
||||
var baseDirectory = AppContext.BaseDirectory;
|
||||
return
|
||||
[
|
||||
Path.Combine(baseDirectory, "share", "icons", "hicolor", "256x256", "apps", IconFileName),
|
||||
Path.Combine(baseDirectory, IconFileName)
|
||||
];
|
||||
}
|
||||
|
||||
private static string BuildDesktopEntryContent(string executablePath)
|
||||
{
|
||||
var escapedExecutablePath = executablePath.Replace("\"", "\\\"", StringComparison.Ordinal);
|
||||
return
|
||||
"[Desktop Entry]\n" +
|
||||
"Type=Application\n" +
|
||||
"Version=1.0\n" +
|
||||
"Name=LanMountainDesktop\n" +
|
||||
"Comment=LanMountainDesktop desktop shell\n" +
|
||||
$"Exec=\"{escapedExecutablePath}\" %U\n" +
|
||||
$"Icon={IconName}\n" +
|
||||
"Terminal=false\n" +
|
||||
"Categories=Utility;Education;\n" +
|
||||
"StartupWMClass=LanMountainDesktop\n";
|
||||
}
|
||||
|
||||
private static void WriteFileIfChanged(string filePath, string content)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
var existing = File.ReadAllText(filePath);
|
||||
if (string.Equals(existing, content, StringComparison.Ordinal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fall through to attempt writing the content.
|
||||
}
|
||||
|
||||
File.WriteAllText(filePath, content, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
||||
}
|
||||
|
||||
private static void TryRunCommand(string fileName, params string[] arguments)
|
||||
{
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true
|
||||
};
|
||||
|
||||
foreach (var argument in arguments)
|
||||
{
|
||||
startInfo.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
using var process = Process.Start(startInfo);
|
||||
if (process is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_ = process.WaitForExit(2_500);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore missing command or update failures.
|
||||
}
|
||||
}
|
||||
}
|
||||
371
LanMountainDesktop/Services/LinuxDesktopEntryService.cs
Normal file
371
LanMountainDesktop/Services/LinuxDesktopEntryService.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using LanMountainDesktop.Models;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
public sealed class LinuxDesktopEntryService
|
||||
{
|
||||
private static readonly Regex FieldCodeRegex =
|
||||
new(@"%[fFuUdDnNickvm]", RegexOptions.Compiled);
|
||||
|
||||
public StartMenuFolderNode Load()
|
||||
{
|
||||
var root = new StartMenuFolderNode("All Apps", string.Empty);
|
||||
if (!OperatingSystem.IsLinux())
|
||||
{
|
||||
return root;
|
||||
}
|
||||
|
||||
var seenDesktopIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var applicationsRoot in EnumerateApplicationsRoots())
|
||||
{
|
||||
foreach (var desktopFilePath in EnumerateDesktopFilesSafe(applicationsRoot))
|
||||
{
|
||||
if (!TryParseDesktopEntry(desktopFilePath, applicationsRoot, out var appEntry))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (seenDesktopIds.Add(appEntry.RelativePath))
|
||||
{
|
||||
root.Apps.Add(appEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
root.Apps.Sort((left, right) =>
|
||||
string.Compare(left.DisplayName, right.DisplayName, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase));
|
||||
return root;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateApplicationsRoots()
|
||||
{
|
||||
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var dataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (string.IsNullOrWhiteSpace(dataHome) && !string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
dataHome = Path.Combine(homeDirectory, ".local", "share");
|
||||
}
|
||||
|
||||
var dataDirs = (Environment.GetEnvironmentVariable("XDG_DATA_DIRS") ?? "/usr/local/share:/usr/share")
|
||||
.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var candidates = new List<string>();
|
||||
if (!string.IsNullOrWhiteSpace(dataHome))
|
||||
{
|
||||
candidates.Add(Path.Combine(dataHome, "applications"));
|
||||
}
|
||||
|
||||
foreach (var dataDir in dataDirs)
|
||||
{
|
||||
candidates.Add(Path.Combine(dataDir, "applications"));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
candidates.Add(Path.Combine(homeDirectory, ".local", "share", "flatpak", "exports", "share", "applications"));
|
||||
}
|
||||
|
||||
candidates.Add("/var/lib/flatpak/exports/share/applications");
|
||||
candidates.Add("/var/lib/snapd/desktop/applications");
|
||||
|
||||
return candidates
|
||||
.Where(path => !string.IsNullOrWhiteSpace(path) && Directory.Exists(path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateDesktopFilesSafe(string applicationsRoot)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(applicationsRoot, "*.desktop", SearchOption.AllDirectories);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryParseDesktopEntry(string desktopFilePath, string applicationsRoot, out StartMenuAppEntry appEntry)
|
||||
{
|
||||
appEntry = null!;
|
||||
|
||||
Dictionary<string, string> fields;
|
||||
try
|
||||
{
|
||||
fields = ReadDesktopEntryFields(desktopFilePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fields.TryGetValue("Type", out var entryType) ||
|
||||
!string.Equals(entryType, "Application", StringComparison.OrdinalIgnoreCase) ||
|
||||
GetBooleanField(fields, "NoDisplay") ||
|
||||
GetBooleanField(fields, "Hidden"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var displayName = GetPreferredName(fields);
|
||||
if (string.IsNullOrWhiteSpace(displayName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fields.TryGetValue("Exec", out var execValue) ||
|
||||
!TryParseExec(execValue, out var launchExecutable, out var launchArguments))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fields.TryGetValue("TryExec", out var tryExecValue) &&
|
||||
!string.IsNullOrWhiteSpace(tryExecValue) &&
|
||||
!CommandExists(tryExecValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var desktopFileId = BuildDesktopFileId(desktopFilePath, applicationsRoot);
|
||||
var iconValue = fields.TryGetValue("Icon", out var iconFieldValue)
|
||||
? iconFieldValue
|
||||
: string.Empty;
|
||||
var workingDirectory = Path.IsPathRooted(launchExecutable)
|
||||
? Path.GetDirectoryName(launchExecutable)
|
||||
: null;
|
||||
|
||||
appEntry = new StartMenuAppEntry
|
||||
{
|
||||
DisplayName = displayName.Trim(),
|
||||
FilePath = desktopFilePath,
|
||||
RelativePath = desktopFileId,
|
||||
IconPngBytes = LinuxIconService.TryGetIconPngBytes(iconValue, Path.GetDirectoryName(desktopFilePath)),
|
||||
LaunchExecutable = launchExecutable,
|
||||
LaunchArguments = launchArguments,
|
||||
WorkingDirectory = string.IsNullOrWhiteSpace(workingDirectory) ? null : workingDirectory
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ReadDesktopEntryFields(string desktopFilePath)
|
||||
{
|
||||
var fields = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
var inDesktopEntrySection = false;
|
||||
foreach (var rawLine in File.ReadLines(desktopFilePath))
|
||||
{
|
||||
var line = rawLine.Trim();
|
||||
if (string.IsNullOrWhiteSpace(line) || line.StartsWith('#'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.StartsWith('[') && line.EndsWith(']'))
|
||||
{
|
||||
inDesktopEntrySection = string.Equals(line, "[Desktop Entry]", StringComparison.OrdinalIgnoreCase);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inDesktopEntrySection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var separatorIndex = line.IndexOf('=');
|
||||
if (separatorIndex <= 0 || separatorIndex >= line.Length - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = line[..separatorIndex].Trim();
|
||||
var value = line[(separatorIndex + 1)..].Trim();
|
||||
fields[key] = value;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
private static bool GetBooleanField(IReadOnlyDictionary<string, string> fields, string key)
|
||||
{
|
||||
return fields.TryGetValue(key, out var value) &&
|
||||
bool.TryParse(value, out var result) &&
|
||||
result;
|
||||
}
|
||||
|
||||
private static string GetPreferredName(IReadOnlyDictionary<string, string> fields)
|
||||
{
|
||||
if (TryGetLocalizedField(fields, "Name", out var localizedName))
|
||||
{
|
||||
return localizedName;
|
||||
}
|
||||
|
||||
return fields.TryGetValue("Name", out var fallbackName)
|
||||
? fallbackName
|
||||
: string.Empty;
|
||||
}
|
||||
|
||||
private static bool TryGetLocalizedField(IReadOnlyDictionary<string, string> fields, string baseKey, out string value)
|
||||
{
|
||||
value = string.Empty;
|
||||
var uiCulture = CultureInfo.CurrentUICulture;
|
||||
var candidates = new[]
|
||||
{
|
||||
$"{baseKey}[{uiCulture.Name}]",
|
||||
$"{baseKey}[{uiCulture.TwoLetterISOLanguageName}]"
|
||||
};
|
||||
|
||||
foreach (var key in candidates)
|
||||
{
|
||||
if (fields.TryGetValue(key, out var localizedValue) &&
|
||||
!string.IsNullOrWhiteSpace(localizedValue))
|
||||
{
|
||||
value = localizedValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string BuildDesktopFileId(string desktopFilePath, string applicationsRoot)
|
||||
{
|
||||
var relativePath = Path.GetRelativePath(applicationsRoot, desktopFilePath)
|
||||
.Replace(Path.DirectorySeparatorChar, '-')
|
||||
.Replace(Path.AltDirectorySeparatorChar, '-');
|
||||
|
||||
return relativePath.Trim();
|
||||
}
|
||||
|
||||
private static bool TryParseExec(string execValue, out string launchExecutable, out List<string> launchArguments)
|
||||
{
|
||||
launchExecutable = string.Empty;
|
||||
launchArguments = [];
|
||||
|
||||
var tokens = TokenizeExec(execValue);
|
||||
if (tokens.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var cleanedTokens = new List<string>(tokens.Count);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var normalizedToken = token.Replace("%%", "%", StringComparison.Ordinal);
|
||||
if (normalizedToken.Length == 2 && normalizedToken[0] == '%')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
normalizedToken = FieldCodeRegex.Replace(normalizedToken, string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(normalizedToken))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
cleanedTokens.Add(normalizedToken);
|
||||
}
|
||||
|
||||
if (cleanedTokens.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
launchExecutable = cleanedTokens[0];
|
||||
launchArguments = cleanedTokens.Skip(1).ToList();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<string> TokenizeExec(string execValue)
|
||||
{
|
||||
var tokens = new List<string>();
|
||||
var current = new StringBuilder();
|
||||
var inQuotes = false;
|
||||
char quoteChar = '\0';
|
||||
|
||||
foreach (var c in execValue)
|
||||
{
|
||||
if ((c == '"' || c == '\'') &&
|
||||
(!inQuotes || quoteChar == c))
|
||||
{
|
||||
if (inQuotes)
|
||||
{
|
||||
inQuotes = false;
|
||||
quoteChar = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
inQuotes = true;
|
||||
quoteChar = c;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char.IsWhiteSpace(c) && !inQuotes)
|
||||
{
|
||||
if (current.Length > 0)
|
||||
{
|
||||
tokens.Add(current.ToString());
|
||||
current.Clear();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
current.Append(c);
|
||||
}
|
||||
|
||||
if (current.Length > 0)
|
||||
{
|
||||
tokens.Add(current.ToString());
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private static bool CommandExists(string command)
|
||||
{
|
||||
var trimmedCommand = command.Trim();
|
||||
if (string.IsNullOrWhiteSpace(trimmedCommand))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Path.IsPathRooted(trimmedCommand))
|
||||
{
|
||||
return File.Exists(trimmedCommand);
|
||||
}
|
||||
|
||||
var pathEntries = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty)
|
||||
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
foreach (var pathEntry in pathEntries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var candidate = Path.Combine(pathEntry, trimmedCommand);
|
||||
if (File.Exists(candidate))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore malformed PATH entries.
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
214
LanMountainDesktop/Services/LinuxIconService.cs
Normal file
214
LanMountainDesktop/Services/LinuxIconService.cs
Normal file
@@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
internal static class LinuxIconService
|
||||
{
|
||||
private static readonly string[] SupportedRasterExtensions =
|
||||
[
|
||||
".png",
|
||||
".ico"
|
||||
];
|
||||
|
||||
private static readonly Regex SizeDirectoryRegex =
|
||||
new(@"(?<size>\d{1,4})x\d{1,4}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
private static readonly ConcurrentDictionary<string, string?> IconPathCache = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static byte[]? TryGetIconPngBytes(string? iconKey, string? desktopFileDirectory = null)
|
||||
{
|
||||
if (!OperatingSystem.IsLinux() || string.IsNullOrWhiteSpace(iconKey))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var candidatePath in ResolveIconCandidates(iconKey.Trim(), desktopFileDirectory))
|
||||
{
|
||||
if (TryReadIconBytes(candidatePath, out var bytes))
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> ResolveIconCandidates(string iconKey, string? desktopFileDirectory)
|
||||
{
|
||||
if (Path.HasExtension(iconKey))
|
||||
{
|
||||
var directPath = ExpandHome(iconKey);
|
||||
if (Path.IsPathRooted(directPath))
|
||||
{
|
||||
yield return directPath;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(desktopFileDirectory))
|
||||
{
|
||||
yield return Path.GetFullPath(Path.Combine(desktopFileDirectory, directPath));
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
var resolvedThemePath = ResolveThemedIconPath(iconKey);
|
||||
if (!string.IsNullOrWhiteSpace(resolvedThemePath))
|
||||
{
|
||||
yield return resolvedThemePath;
|
||||
}
|
||||
}
|
||||
|
||||
private static string? ResolveThemedIconPath(string iconName)
|
||||
{
|
||||
return IconPathCache.GetOrAdd(iconName, static key => FindBestMatchingIconPath(key));
|
||||
}
|
||||
|
||||
private static string? FindBestMatchingIconPath(string iconName)
|
||||
{
|
||||
var candidates = new List<(string Path, int Score)>();
|
||||
foreach (var iconRoot in EnumerateIconRoots())
|
||||
{
|
||||
foreach (var extension in SupportedRasterExtensions)
|
||||
{
|
||||
foreach (var candidatePath in EnumerateFilesSafe(iconRoot, iconName + extension))
|
||||
{
|
||||
candidates.Add((candidatePath, ScoreIconPath(candidatePath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return candidates
|
||||
.OrderByDescending(candidate => candidate.Score)
|
||||
.ThenBy(candidate => candidate.Path.Length)
|
||||
.Select(candidate => candidate.Path)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateIconRoots()
|
||||
{
|
||||
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var dataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (string.IsNullOrWhiteSpace(dataHome) && !string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
dataHome = Path.Combine(homeDirectory, ".local", "share");
|
||||
}
|
||||
|
||||
var dataDirs = (Environment.GetEnvironmentVariable("XDG_DATA_DIRS") ?? "/usr/local/share:/usr/share")
|
||||
.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var candidates = new List<string>();
|
||||
if (!string.IsNullOrWhiteSpace(dataHome))
|
||||
{
|
||||
candidates.Add(Path.Combine(dataHome, "icons"));
|
||||
candidates.Add(Path.Combine(dataHome, "pixmaps"));
|
||||
}
|
||||
|
||||
foreach (var dataDir in dataDirs)
|
||||
{
|
||||
candidates.Add(Path.Combine(dataDir, "icons"));
|
||||
candidates.Add(Path.Combine(dataDir, "pixmaps"));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
candidates.Add(Path.Combine(homeDirectory, ".icons"));
|
||||
candidates.Add(Path.Combine(homeDirectory, ".local", "share", "flatpak", "exports", "share", "icons"));
|
||||
}
|
||||
|
||||
candidates.Add("/var/lib/flatpak/exports/share/icons");
|
||||
candidates.Add("/var/lib/snapd/desktop/icons");
|
||||
|
||||
return candidates
|
||||
.Where(path => !string.IsNullOrWhiteSpace(path) && Directory.Exists(path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateFilesSafe(string rootPath, string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(rootPath, fileName, SearchOption.AllDirectories);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadIconBytes(string filePath, out byte[] bytes)
|
||||
{
|
||||
bytes = [];
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(filePath);
|
||||
if (!SupportedRasterExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase) ||
|
||||
!File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bytes = File.ReadAllBytes(filePath);
|
||||
return bytes.Length > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ScoreIconPath(string filePath)
|
||||
{
|
||||
var score = 0;
|
||||
var extension = Path.GetExtension(filePath);
|
||||
if (extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 4_000;
|
||||
}
|
||||
else if (extension.Equals(".ico", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 2_000;
|
||||
}
|
||||
|
||||
if (filePath.Contains($"{Path.DirectorySeparatorChar}hicolor{Path.DirectorySeparatorChar}", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 8_000;
|
||||
}
|
||||
|
||||
if (filePath.Contains($"{Path.DirectorySeparatorChar}apps{Path.DirectorySeparatorChar}", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 1_000;
|
||||
}
|
||||
|
||||
var match = SizeDirectoryRegex.Match(filePath);
|
||||
if (match.Success &&
|
||||
int.TryParse(match.Groups["size"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var size))
|
||||
{
|
||||
score += Math.Min(size, 512);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private static string ExpandHome(string path)
|
||||
{
|
||||
if (!path.StartsWith("~", StringComparison.Ordinal))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
if (string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return path.Length == 1
|
||||
? homeDirectory
|
||||
: Path.Combine(homeDirectory, path[2..]);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -48,6 +49,7 @@ public partial class BaiduHotSearchWidget : UserControl, IDesktopComponentWidget
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private string _sourceType = BaiduHotSearchSourceTypes.Official;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
private sealed record HotItemVisual(
|
||||
Border Host,
|
||||
@@ -79,6 +81,7 @@ public partial class BaiduHotSearchWidget : UserControl, IDesktopComponentWidget
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -133,6 +136,67 @@ public partial class BaiduHotSearchWidget : UserControl, IDesktopComponentWidget
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFCFD"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#00000000"));
|
||||
|
||||
BrandTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#5D93FF") : Color.Parse("#2932E1"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#EFF1F5"));
|
||||
RefreshGlyphIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
foreach (var visual in _hotItemVisuals)
|
||||
{
|
||||
visual.IndexTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#5D93FF") : Color.Parse("#2932E1"));
|
||||
visual.TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
}
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
await RefreshHotSearchAsync(forceRefresh: true);
|
||||
@@ -375,6 +439,7 @@ public partial class BaiduHotSearchWidget : UserControl, IDesktopComponentWidget
|
||||
}
|
||||
|
||||
StatusTextBlock.FontSize = Math.Clamp(itemFont, 10, 20);
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private void UpdateInteractionState()
|
||||
|
||||
@@ -9,6 +9,7 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -46,6 +47,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
private sealed record HotItemVisual(
|
||||
Border Host,
|
||||
@@ -78,6 +80,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -129,6 +132,69 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFCFD"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#00000000"));
|
||||
|
||||
SearchBoxBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#ECF2FA"));
|
||||
SearchBoxBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#3FFFFFFF") : Color.Parse("#22000000"));
|
||||
SearchEntryTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
SearchGlyphIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
TopRightTitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#F472C4") : Color.Parse("#F44C9F"));
|
||||
|
||||
foreach (var visual in _hotItemVisuals)
|
||||
{
|
||||
visual.IndexTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#F472C4") : Color.Parse("#F44C9F"));
|
||||
visual.TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
}
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
await RefreshHotSearchAsync(forceRefresh: false);
|
||||
@@ -396,6 +462,7 @@ public partial class BilibiliHotSearchWidget : UserControl, IDesktopComponentWid
|
||||
}
|
||||
|
||||
StatusTextBlock.FontSize = Math.Clamp(itemFont, 10, 20);
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private void UpdateInteractionState()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
@@ -12,7 +12,7 @@ using WebViewCore.Events;
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class BrowserWidget : UserControl, IDesktopComponentWidget
|
||||
, IDesktopPageVisibilityAwareComponentWidget
|
||||
, IDesktopPageVisibilityAwareComponentWidget, IDisposable
|
||||
{
|
||||
private static readonly Uri DefaultHomeUri = new("https://www.bing.com");
|
||||
private double _currentCellSize = 48;
|
||||
@@ -22,6 +22,7 @@ public partial class BrowserWidget : UserControl, IDesktopComponentWidget
|
||||
private bool _isEditMode;
|
||||
private bool _isWebViewActive = true;
|
||||
private readonly WebView2RuntimeAvailability _runtimeAvailability;
|
||||
private bool _isDisposed;
|
||||
|
||||
public BrowserWidget()
|
||||
{
|
||||
@@ -48,6 +49,26 @@ public partial class BrowserWidget : UserControl, IDesktopComponentWidget
|
||||
NavigateTo(DefaultHomeUri);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
SizeChanged -= OnSizeChanged;
|
||||
ActualThemeVariantChanged -= OnActualThemeVariantChanged;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
|
||||
if (_runtimeAvailability.IsAvailable)
|
||||
{
|
||||
BrowserWebView.NavigationStarting -= OnBrowserWebViewNavigationStarting;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyCellSize(double cellSize)
|
||||
{
|
||||
_currentCellSize = Math.Max(1, cellSize);
|
||||
|
||||
@@ -14,6 +14,7 @@ using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -88,6 +89,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRotateEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
public CnrDailyNewsWidget()
|
||||
{
|
||||
@@ -105,6 +107,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -161,6 +164,66 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFCFD"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#00000000"));
|
||||
|
||||
BrandPrimaryTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
BrandSecondaryTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#6A6F77"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#EFF1F5"));
|
||||
RefreshGlyphIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
RefreshLabelTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
News1TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
News2TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRefreshing)
|
||||
@@ -354,9 +417,11 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
{
|
||||
var normalizedTitle = NormalizeCompactText(title);
|
||||
var hotLabel = L("cnrnews.widget.hot_label", "Hot");
|
||||
var primaryForeground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
if (News1TitleTextBlock.Inlines is null)
|
||||
{
|
||||
News1TitleTextBlock.Text = $"{hotLabel} | {normalizedTitle}";
|
||||
News1TitleTextBlock.Foreground = primaryForeground;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -368,7 +433,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
});
|
||||
News1TitleTextBlock.Inlines.Add(new Run(normalizedTitle)
|
||||
{
|
||||
Foreground = new SolidColorBrush(Color.Parse("#202327")),
|
||||
Foreground = primaryForeground,
|
||||
FontWeight = FontWeight.SemiBold
|
||||
});
|
||||
}
|
||||
@@ -401,7 +466,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
var textBlock = new TextBlock
|
||||
{
|
||||
Text = NormalizeCompactText(item.Title),
|
||||
Foreground = new SolidColorBrush(Color.Parse("#202327")),
|
||||
Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327")),
|
||||
FontFamily = MiSansFontFamily,
|
||||
FontWeight = FontWeight.SemiBold,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
@@ -556,6 +621,8 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
}
|
||||
|
||||
ExtraNewsItemsPanel.Spacing = Math.Clamp(6 * scale, 3, 10);
|
||||
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private void UpdateRefreshButtonState()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -14,9 +14,9 @@
|
||||
BorderThickness="0"
|
||||
Background="#C20A0A"
|
||||
Padding="20,16,20,14">
|
||||
<Grid RowDefinitions="Auto,*,Auto">
|
||||
<Grid RowDefinitions="*,Auto">
|
||||
<Canvas x:Name="DayDecorationCanvas"
|
||||
Grid.RowSpan="3"
|
||||
Grid.RowSpan="2"
|
||||
IsVisible="False"
|
||||
Width="212"
|
||||
Height="148"
|
||||
@@ -43,34 +43,32 @@
|
||||
Data="M8,54 L38,24 L64,52 L8,54 Z" />
|
||||
</Canvas>
|
||||
|
||||
<TextBlock x:Name="QuoteMarkTextBlock"
|
||||
Text="“"
|
||||
Foreground="#5CFAD0B7"
|
||||
FontSize="96"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Margin="1,0,0,0"
|
||||
LineHeight="86" />
|
||||
<Grid Grid.Row="0" RowDefinitions="Auto,*">
|
||||
<TextBlock x:Name="QuoteMarkTextBlock"
|
||||
Text="“"
|
||||
Foreground="#5CFAD0B7"
|
||||
FontSize="72"
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Margin="1,0,0,0"
|
||||
LineHeight="65" />
|
||||
|
||||
<TextBlock x:Name="PoetryContentTextBlock"
|
||||
Grid.Row="1"
|
||||
Text="芳草年年惹恨幽。想前事悠悠。"
|
||||
Foreground="#F8D8A8"
|
||||
FontSize="54"
|
||||
FontWeight="Medium"
|
||||
LineHeight="60"
|
||||
TextWrapping="Wrap"
|
||||
VerticalAlignment="Top"
|
||||
Margin="8,2,0,0" />
|
||||
<TextBlock x:Name="PoetryContentTextBlock"
|
||||
Grid.Row="1"
|
||||
Text="芳草年年惹恨幽。想前事悠悠。"
|
||||
Foreground="#F8D8A8"
|
||||
FontSize="54"
|
||||
FontWeight="Medium"
|
||||
LineHeight="60"
|
||||
TextWrapping="Wrap"
|
||||
MaxLines="2"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="8,2,0,0" />
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="AuthorPanel"
|
||||
Grid.Row="2"
|
||||
ColumnDefinitions="Auto,*"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,6,4,0"
|
||||
IsHitTestVisible="False">
|
||||
<Grid Grid.Row="1" ColumnDefinitions="Auto,*" VerticalAlignment="Bottom" Margin="0,6,0,0">
|
||||
<Border x:Name="AuthorAccent"
|
||||
Grid.Column="0"
|
||||
Width="6"
|
||||
@@ -92,6 +90,7 @@
|
||||
</Grid>
|
||||
|
||||
<TextBlock x:Name="StatusTextBlock"
|
||||
Grid.Row="0"
|
||||
Text="Loading..."
|
||||
IsVisible="False"
|
||||
Foreground="#D9FFFFFF"
|
||||
@@ -100,10 +99,10 @@
|
||||
VerticalAlignment="Top" />
|
||||
|
||||
<Button x:Name="RefreshButton"
|
||||
Grid.RowSpan="3"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,12,16,0"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0,8,4,0"
|
||||
Width="42"
|
||||
Height="42"
|
||||
CornerRadius="21"
|
||||
@@ -113,13 +112,12 @@
|
||||
Padding="0"
|
||||
Focusable="False">
|
||||
<TextBlock x:Name="RefreshGlyphTextBlock"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="↻"
|
||||
Text=""
|
||||
FontFamily="{StaticResource SymbolFontFamily}"
|
||||
FontSize="22"
|
||||
Foreground="#8C9097"
|
||||
FontSize="26"
|
||||
FontWeight="SemiLight"
|
||||
LineHeight="26" />
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -45,8 +45,8 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
private const double BaseCellSize = 48d;
|
||||
private const int BaseWidthCells = 4;
|
||||
private const int BaseHeightCells = 2;
|
||||
private const double MinPoetryFontSize = 12;
|
||||
private const double MinAuthorFontSize = 10.5;
|
||||
private const double MinPoetryFontSize = 8;
|
||||
private const double MinAuthorFontSize = 7;
|
||||
|
||||
private readonly record struct TextFitResult(double FontSize, FontWeight FontWeight, double LineHeight);
|
||||
|
||||
@@ -109,7 +109,6 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
0,
|
||||
0);
|
||||
|
||||
AuthorPanel.Margin = new Thickness(0, Math.Clamp(5 * scale, 2, 10), Math.Clamp(4 * scale, 2, 8), 0);
|
||||
AuthorAccent.Width = Math.Clamp(6 * scale, 3.2, 9.5);
|
||||
AuthorAccent.Height = Math.Clamp(24 * scale, 12, 34);
|
||||
AuthorAccent.Margin = new Thickness(0, 0, Math.Clamp(8 * scale, 4, 13), 0);
|
||||
@@ -351,11 +350,6 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
|
||||
AuthorTextBlock.Foreground = CreateBrush("#F4D7A7");
|
||||
AuthorAccent.Background = CreateBrush("#63F2AF90");
|
||||
AuthorPanel.Margin = new Thickness(
|
||||
0,
|
||||
Math.Clamp(6 * scale, 2, 10),
|
||||
Math.Clamp(6 * scale, 2, 10),
|
||||
Math.Clamp(1 * scale, 0, 3));
|
||||
|
||||
DayDecorationCanvas.IsVisible = false;
|
||||
RefreshButton.IsVisible = true;
|
||||
@@ -380,11 +374,6 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
|
||||
AuthorTextBlock.Foreground = CreateBrush("#272D38");
|
||||
AuthorAccent.Background = CreateBrush("#C8090D");
|
||||
AuthorPanel.Margin = new Thickness(
|
||||
0,
|
||||
Math.Clamp(6 * scale, 2, 10),
|
||||
Math.Clamp(6 * scale, 2, 10),
|
||||
Math.Clamp(2 * scale, 0, 4));
|
||||
|
||||
DayDecorationCanvas.IsVisible = true;
|
||||
RefreshButton.IsVisible = true;
|
||||
@@ -475,83 +464,19 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
DayDecorationCanvas.IsVisible = showDayDecorations;
|
||||
RefreshButton.IsVisible = true;
|
||||
|
||||
var refreshReservedWidth = RefreshButton.Width + Math.Clamp(8 * scale, 5, 14);
|
||||
var decorationReservedWidth = showDayDecorations
|
||||
? Math.Clamp(innerWidth * 0.24, 34, 96)
|
||||
: 0;
|
||||
var quoteReservedWidth = QuoteMarkTextBlock.IsVisible
|
||||
? Math.Clamp(10 * scale, 5, 16)
|
||||
: 0;
|
||||
var poemReservedRight = Math.Max(refreshReservedWidth, decorationReservedWidth);
|
||||
var poemWidth = innerWidth - poemReservedRight - quoteReservedWidth;
|
||||
var poemMinWidth = Math.Max(66, innerWidth * 0.56);
|
||||
if (poemWidth < poemMinWidth)
|
||||
{
|
||||
poemWidth = poemMinWidth;
|
||||
}
|
||||
poemWidth = Math.Min(Math.Max(64, poemWidth), innerWidth);
|
||||
var refreshButtonWidth = 42 + Math.Clamp(8 * scale, 5, 14);
|
||||
var quoteMarkWidth = QuoteMarkTextBlock.IsVisible ? Math.Clamp(10 * scale, 5, 16) : 0;
|
||||
|
||||
var poemWidth = innerWidth - quoteMarkWidth - Math.Clamp(12 * scale, 6, 20);
|
||||
poemWidth = Math.Min(Math.Max(64, poemWidth), innerWidth - Math.Clamp(16 * scale, 8, 24));
|
||||
|
||||
var authorMaxLines = innerWidth < Math.Max(_currentCellSize * 5.2, 252) ? 2 : 1;
|
||||
var authorUnitsTarget = authorMaxLines == 1 ? 20 : 12;
|
||||
var authorWidth = Math.Max(72, Math.Min(innerWidth * (isNightMode ? 0.5 : 0.56), innerWidth - 8));
|
||||
var authorPrepared = PrepareAuthorText(_authorRawText, authorUnitsTarget, authorMaxLines);
|
||||
var authorPreferredFontSize = Math.Clamp((isNightMode ? 25 : 23) * scale, 12, 34);
|
||||
var authorMinFontSize = Math.Clamp(authorPreferredFontSize * 0.72, MinAuthorFontSize, authorPreferredFontSize);
|
||||
var authorMinWeight = isNightMode ? 500 : 470;
|
||||
var authorMaxWeight = isNightMode ? 650 : 600;
|
||||
authorPrepared = EnsureTextFitsAtMinSize(
|
||||
preparedText: authorPrepared,
|
||||
sourceText: _authorRawText,
|
||||
targetUnits: authorUnitsTarget,
|
||||
maxLines: authorMaxLines,
|
||||
maxWidth: authorWidth,
|
||||
maxHeight: Math.Max(20, innerHeight * (authorMaxLines > 1 ? 0.38 : 0.28)),
|
||||
minFontSize: authorMinFontSize,
|
||||
minFontWeight: ToVariableWeight(authorMinWeight),
|
||||
lineHeightFactor: 1.12);
|
||||
|
||||
var authorFit = FitTextStable(
|
||||
authorPrepared,
|
||||
authorWidth,
|
||||
Math.Max(20, innerHeight * (authorMaxLines > 1 ? 0.38 : 0.28)),
|
||||
minFontSize: authorMinFontSize,
|
||||
maxFontSize: Math.Clamp(authorPreferredFontSize * 1.15, authorMinFontSize, 42),
|
||||
maxLines: authorMaxLines,
|
||||
lineHeightFactor: 1.12,
|
||||
minWeight: authorMinWeight,
|
||||
maxWeight: authorMaxWeight);
|
||||
|
||||
AuthorTextBlock.Text = authorPrepared;
|
||||
AuthorTextBlock.TextWrapping = authorMaxLines > 1 ? TextWrapping.Wrap : TextWrapping.NoWrap;
|
||||
AuthorTextBlock.MaxLines = authorMaxLines;
|
||||
AuthorTextBlock.MaxWidth = authorWidth;
|
||||
AuthorTextBlock.FontSize = authorFit.FontSize;
|
||||
AuthorTextBlock.LineHeight = authorFit.LineHeight;
|
||||
AuthorTextBlock.FontWeight = authorFit.FontWeight;
|
||||
AuthorPanel.MaxWidth = authorWidth + AuthorAccent.Width + AuthorAccent.Margin.Right + Math.Clamp(4 * scale, 2, 8);
|
||||
|
||||
var authorMeasured = MeasureTextSize(
|
||||
authorPrepared,
|
||||
authorFit.FontSize,
|
||||
authorFit.FontWeight,
|
||||
authorWidth,
|
||||
authorFit.LineHeight);
|
||||
var authorHeight = Math.Min(authorMeasured.Height, authorFit.LineHeight * authorMaxLines);
|
||||
var authorBlockHeight = Math.Max(authorHeight, AuthorAccent.Height) +
|
||||
AuthorPanel.Margin.Top +
|
||||
AuthorPanel.Margin.Bottom +
|
||||
Math.Clamp(4 * scale, 2, 8);
|
||||
|
||||
var poemMaxLines = innerHeight < _currentCellSize * 1.58
|
||||
? 4
|
||||
: innerHeight < _currentCellSize * 2.05
|
||||
? 3
|
||||
: 2;
|
||||
var poemMaxLines = 2;
|
||||
var poemUnitsTarget = EstimateTargetUnitsPerLine(poemWidth, scale, isNightMode);
|
||||
var poemPrepared = PreparePoetryText(_poetryRawText, poemUnitsTarget, poemMaxLines);
|
||||
var poemHeight = Math.Max(30, innerHeight - authorBlockHeight);
|
||||
var poemPreferredFontSize = Math.Clamp((isNightMode ? 34 : 32) * scale, 16, 56);
|
||||
var poemMinFontSize = Math.Clamp(poemPreferredFontSize * 0.72, MinPoetryFontSize, poemPreferredFontSize);
|
||||
|
||||
var availablePoemHeight = innerHeight * 0.72;
|
||||
var poemPreferredFontSize = Math.Clamp((isNightMode ? 34 : 32) * scale, 14, 56);
|
||||
var poemMinFontSize = Math.Clamp(poemPreferredFontSize * 0.65, MinPoetryFontSize, poemPreferredFontSize);
|
||||
var poemMinWeight = isNightMode ? 540 : 500;
|
||||
var poemMaxWeight = isNightMode ? 760 : 680;
|
||||
poemPrepared = EnsureTextFitsAtMinSize(
|
||||
@@ -560,19 +485,19 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
targetUnits: poemUnitsTarget,
|
||||
maxLines: poemMaxLines,
|
||||
maxWidth: poemWidth,
|
||||
maxHeight: poemHeight,
|
||||
maxHeight: availablePoemHeight,
|
||||
minFontSize: poemMinFontSize,
|
||||
minFontWeight: ToVariableWeight(poemMinWeight),
|
||||
lineHeightFactor: 1.1);
|
||||
lineHeightFactor: 1.12);
|
||||
|
||||
var poemFit = FitTextStable(
|
||||
poemPrepared,
|
||||
poemWidth,
|
||||
poemHeight,
|
||||
availablePoemHeight,
|
||||
minFontSize: poemMinFontSize,
|
||||
maxFontSize: Math.Clamp(poemPreferredFontSize * 1.20, poemMinFontSize, 62),
|
||||
maxLines: poemMaxLines,
|
||||
lineHeightFactor: 1.10,
|
||||
lineHeightFactor: 1.12,
|
||||
minWeight: poemMinWeight,
|
||||
maxWeight: poemMaxWeight);
|
||||
|
||||
@@ -582,6 +507,43 @@ public partial class DailyPoetryWidget : UserControl, IDesktopComponentWidget, I
|
||||
PoetryContentTextBlock.FontSize = poemFit.FontSize;
|
||||
PoetryContentTextBlock.LineHeight = poemFit.LineHeight;
|
||||
PoetryContentTextBlock.FontWeight = poemFit.FontWeight;
|
||||
|
||||
var authorWidth = Math.Max(72, Math.Min(innerWidth * (isNightMode ? 0.5 : 0.56), innerWidth - 8));
|
||||
var authorUnitsTarget = 20;
|
||||
var authorPrepared = PrepareAuthorText(_authorRawText, authorUnitsTarget, 1);
|
||||
var authorPreferredFontSize = Math.Clamp((isNightMode ? 25 : 23) * scale, 10, 34);
|
||||
var authorMinFontSize = Math.Clamp(authorPreferredFontSize * 0.65, MinAuthorFontSize, authorPreferredFontSize);
|
||||
var authorMinWeight = isNightMode ? 500 : 470;
|
||||
var authorMaxWeight = isNightMode ? 650 : 600;
|
||||
authorPrepared = EnsureTextFitsAtMinSize(
|
||||
preparedText: authorPrepared,
|
||||
sourceText: _authorRawText,
|
||||
targetUnits: authorUnitsTarget,
|
||||
maxLines: 1,
|
||||
maxWidth: authorWidth,
|
||||
maxHeight: AuthorAccent.Height,
|
||||
minFontSize: authorMinFontSize,
|
||||
minFontWeight: ToVariableWeight(authorMinWeight),
|
||||
lineHeightFactor: 1.12);
|
||||
|
||||
var authorFit = FitTextStable(
|
||||
authorPrepared,
|
||||
authorWidth,
|
||||
AuthorAccent.Height,
|
||||
minFontSize: authorMinFontSize,
|
||||
maxFontSize: Math.Clamp(authorPreferredFontSize * 1.15, authorMinFontSize, 42),
|
||||
maxLines: 1,
|
||||
lineHeightFactor: 1.12,
|
||||
minWeight: authorMinWeight,
|
||||
maxWeight: authorMaxWeight);
|
||||
|
||||
AuthorTextBlock.Text = authorPrepared;
|
||||
AuthorTextBlock.TextWrapping = TextWrapping.NoWrap;
|
||||
AuthorTextBlock.MaxLines = 1;
|
||||
AuthorTextBlock.MaxWidth = authorWidth;
|
||||
AuthorTextBlock.FontSize = authorFit.FontSize;
|
||||
AuthorTextBlock.LineHeight = authorFit.LineHeight;
|
||||
AuthorTextBlock.FontWeight = authorFit.FontWeight;
|
||||
}
|
||||
|
||||
private void UpdateRefreshButtonState()
|
||||
|
||||
@@ -9,6 +9,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.VisualTree;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
@@ -44,6 +45,7 @@ public partial class DailyWord2x2Widget : UserControl, IDesktopComponentWidget,
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
private bool _isMeaningVisible;
|
||||
|
||||
public DailyWord2x2Widget()
|
||||
@@ -59,6 +61,7 @@ public partial class DailyWord2x2Widget : UserControl, IDesktopComponentWidget,
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -113,6 +116,62 @@ public partial class DailyWord2x2Widget : UserControl, IDesktopComponentWidget,
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFBFA"));
|
||||
|
||||
WordTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#2B2F35"));
|
||||
MeaningTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5A6069"));
|
||||
HiddenHintTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#8A9099"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#EEF1F4"));
|
||||
RefreshIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRefreshing)
|
||||
|
||||
@@ -8,6 +8,7 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -41,6 +42,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
public DailyWordWidget()
|
||||
{
|
||||
@@ -58,6 +60,7 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -112,6 +115,64 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFBFA"));
|
||||
|
||||
WordTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#FF9D6C") : Color.Parse("#F07541"));
|
||||
PronunciationTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#6B7078"));
|
||||
MeaningTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#2B2F35"));
|
||||
ExampleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#2B2F35"));
|
||||
ExampleTranslationTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#7A8088"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#14A0A6AF"));
|
||||
RefreshIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#626870"));
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRefreshing)
|
||||
@@ -229,6 +290,14 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
var totalWidth = Bounds.Width > 1 ? Bounds.Width : _currentCellSize * BaseWidthCells;
|
||||
var totalHeight = Bounds.Height > 1 ? Bounds.Height : _currentCellSize * BaseHeightCells;
|
||||
|
||||
var isFourByThree = false;
|
||||
if (Bounds.Width > 1 && Bounds.Height > 1)
|
||||
{
|
||||
var widthRatio = Bounds.Width / (_currentCellSize * BaseWidthCells);
|
||||
var heightRatio = Bounds.Height / (_currentCellSize * BaseHeightCells);
|
||||
isFourByThree = widthRatio >= 0.9 && heightRatio >= 1.35;
|
||||
}
|
||||
|
||||
RootBorder.CornerRadius = new CornerRadius(Math.Clamp(34 * scale, 16, 52));
|
||||
RootBorder.Padding = new Thickness(0);
|
||||
|
||||
@@ -261,15 +330,15 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
ExampleTranslationTextBlock.MaxWidth = contentWidth;
|
||||
|
||||
var compactLayout = totalHeight < _currentCellSize * 1.72;
|
||||
MeaningTextBlock.MaxLines = compactLayout ? 1 : 2;
|
||||
ExampleTextBlock.MaxLines = compactLayout ? 1 : 2;
|
||||
ExampleTranslationTextBlock.IsVisible = !compactLayout;
|
||||
ExampleTranslationTextBlock.MaxLines = 1;
|
||||
MeaningTextBlock.MaxLines = compactLayout ? 1 : (isFourByThree ? 3 : 2);
|
||||
ExampleTextBlock.MaxLines = compactLayout ? 1 : (isFourByThree ? 4 : 2);
|
||||
ExampleTranslationTextBlock.IsVisible = !compactLayout || isFourByThree;
|
||||
ExampleTranslationTextBlock.MaxLines = isFourByThree ? 2 : 1;
|
||||
|
||||
var contentHeight = Math.Max(52, totalHeight - RootBorder.Padding.Top - RootBorder.Padding.Bottom - CardBorder.Padding.Top - CardBorder.Padding.Bottom);
|
||||
var wordHeightBudget = Math.Max(18, contentHeight * 0.24);
|
||||
var pronunciationHeightBudget = Math.Max(14, contentHeight * 0.16);
|
||||
var meaningHeightBudget = Math.Max(16, contentHeight * (compactLayout ? 0.26 : 0.30));
|
||||
var meaningHeightBudget = Math.Max(16, contentHeight * (compactLayout ? 0.26 : (isFourByThree ? 0.35 : 0.30)));
|
||||
var exampleHeightBudget = Math.Max(16, contentHeight - wordHeightBudget - pronunciationHeightBudget - meaningHeightBudget - Math.Clamp(16 * scale, 8, 24));
|
||||
if (!ExampleTranslationTextBlock.IsVisible)
|
||||
{
|
||||
@@ -433,11 +502,26 @@ public partial class DailyWordWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private double ResolveScale()
|
||||
{
|
||||
var cellScale = Math.Clamp(_currentCellSize / BaseCellSize, 0.56, 2.0);
|
||||
|
||||
var widthCells = BaseWidthCells;
|
||||
var heightCells = BaseHeightCells;
|
||||
|
||||
if (Bounds.Width > 1 && Bounds.Height > 1)
|
||||
{
|
||||
var widthRatio = Bounds.Width / (_currentCellSize * widthCells);
|
||||
var heightRatio = Bounds.Height / (_currentCellSize * heightCells);
|
||||
|
||||
if (widthRatio >= 0.9 && heightRatio >= 1.35)
|
||||
{
|
||||
heightCells = 3;
|
||||
}
|
||||
}
|
||||
|
||||
var widthScale = Bounds.Width > 1
|
||||
? Math.Clamp(Bounds.Width / Math.Max(1, _currentCellSize * BaseWidthCells), 0.56, 2.0)
|
||||
? Math.Clamp(Bounds.Width / Math.Max(1, _currentCellSize * widthCells), 0.56, 2.0)
|
||||
: 1;
|
||||
var heightScale = Bounds.Height > 1
|
||||
? Math.Clamp(Bounds.Height / Math.Max(1, _currentCellSize * BaseHeightCells), 0.56, 2.0)
|
||||
? Math.Clamp(Bounds.Height / Math.Max(1, _currentCellSize * heightCells), 0.56, 2.0)
|
||||
: 1;
|
||||
return Math.Clamp(Math.Min(cellScale, Math.Min(widthScale, heightScale)), 0.56, 2.0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -13,6 +13,7 @@ using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -58,6 +59,7 @@ public partial class IfengNewsWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
private sealed record NewsItemVisual(
|
||||
Border Host,
|
||||
@@ -86,6 +88,7 @@ public partial class IfengNewsWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -141,6 +144,67 @@ public partial class IfengNewsWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFCFD"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#00000000"));
|
||||
|
||||
BrandTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#EFF1F5"));
|
||||
RefreshGlyphIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
foreach (var visual in _itemVisuals)
|
||||
{
|
||||
visual.Host.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#F7F8FA"));
|
||||
visual.TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
}
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
await RefreshNewsAsync(forceRefresh: true);
|
||||
@@ -398,6 +462,7 @@ public partial class IfengNewsWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
}
|
||||
|
||||
StatusTextBlock.FontSize = Math.Clamp(titleFont, 10, 20);
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private void UpdateInteractionState()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -8,13 +8,14 @@ using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget
|
||||
public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget, IDisposable
|
||||
{
|
||||
private const int WaveBarCount = 22;
|
||||
|
||||
@@ -36,6 +37,8 @@ public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDe
|
||||
private bool _isAttached;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _pausedStudyMonitoringForRecording;
|
||||
private bool _isNightVisual = true;
|
||||
private bool _isDisposed;
|
||||
|
||||
public RecordingWidget()
|
||||
{
|
||||
@@ -45,6 +48,7 @@ public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDe
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
InitializeWaveBars();
|
||||
ReloadLanguageCode();
|
||||
@@ -146,6 +150,68 @@ public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDe
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
RootBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#ECEFF3"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#D9DEE7"));
|
||||
|
||||
TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#11151D"));
|
||||
TimerTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#A4A9B2"));
|
||||
FutureLine.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#A3A8B3"));
|
||||
|
||||
DiscardButtonBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#F8FAFD"));
|
||||
DiscardButtonBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4451") : Color.Parse("#E0E5EC"));
|
||||
DiscardIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#141922"));
|
||||
|
||||
SaveButtonBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#F8FAFD"));
|
||||
SaveButtonBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4451") : Color.Parse("#E0E5EC"));
|
||||
SaveIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#141922"));
|
||||
|
||||
HintTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#7A818E"));
|
||||
}
|
||||
|
||||
private void OnUiTick(object? sender, EventArgs e)
|
||||
{
|
||||
if (!_isAttached || !_isOnActivePage)
|
||||
@@ -291,11 +357,18 @@ public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDe
|
||||
SaveButtonBorder.Opacity = SaveButtonBorder.IsHitTestVisible ? 1 : 0.42;
|
||||
RecordToggleButtonBorder.Opacity = RecordToggleButtonBorder.IsHitTestVisible ? 1 : 0.54;
|
||||
|
||||
TimerTextBlock.Foreground = CreateBrush(!isSupported
|
||||
? "#B2B7C0"
|
||||
: isReady
|
||||
? "#A4A9B2"
|
||||
: "#151922");
|
||||
if (!isSupported)
|
||||
{
|
||||
TimerTextBlock.Foreground = CreateBrush(_isNightVisual ? "#A8B1C2" : "#B2B7C0");
|
||||
}
|
||||
else if (isReady)
|
||||
{
|
||||
TimerTextBlock.Foreground = CreateBrush(_isNightVisual ? "#A8B1C2" : "#A4A9B2");
|
||||
}
|
||||
else
|
||||
{
|
||||
TimerTextBlock.Foreground = CreateBrush(_isNightVisual ? "#E8EAED" : "#151922");
|
||||
}
|
||||
HintTextBlock.IsVisible = !isReady || !isSupported;
|
||||
|
||||
RecordDot.IsVisible = snapshot.State == AudioRecorderRuntimeState.Ready;
|
||||
@@ -540,4 +613,23 @@ public partial class RecordingWidget : UserControl, IDesktopComponentWidget, IDe
|
||||
|
||||
return (false, path.LocalPath);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_uiTimer.Stop();
|
||||
_uiTimer.Tick -= OnUiTick;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
SizeChanged -= OnSizeChanged;
|
||||
ActualThemeVariantChanged -= OnActualThemeVariantChanged;
|
||||
|
||||
_audioRecorderService.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -60,6 +61,7 @@ public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, I
|
||||
private bool _isAttached;
|
||||
private bool _isRefreshing;
|
||||
private bool _autoRefreshEnabled = true;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
private sealed record ForumItemVisual(
|
||||
Border Host,
|
||||
@@ -153,6 +155,7 @@ public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, I
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
ApplyCellSize(_currentCellSize);
|
||||
UpdateLanguageCode();
|
||||
@@ -208,6 +211,70 @@ public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, I
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightVisual = ResolveNightMode();
|
||||
UpdateAdaptiveLayout();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
CardBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#FCFCFD"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#00000000"));
|
||||
|
||||
HeaderTitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
HeaderDot.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#FF6B6B") : Color.Parse("#FF4D4F"));
|
||||
|
||||
RefreshButton.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#EFF1F5"));
|
||||
RefreshGlyphIcon.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#5E6671"));
|
||||
|
||||
foreach (var visual in _itemVisuals)
|
||||
{
|
||||
visual.Host.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#2D3440") : Color.Parse("#F7F8FA"));
|
||||
visual.AvatarHost.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4451") : Color.Parse("#E7EBF4"));
|
||||
visual.AvatarFallbackText.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#A8B1C2") : Color.Parse("#4A5466"));
|
||||
visual.TitleTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#E8EAED") : Color.Parse("#202327"));
|
||||
}
|
||||
|
||||
StatusTextBlock.Foreground = new SolidColorBrush(_isNightVisual ? Color.Parse("#8B95A5") : Color.Parse("#6A6F77"));
|
||||
}
|
||||
|
||||
private async void OnRefreshButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRefreshing)
|
||||
@@ -606,6 +673,8 @@ public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, I
|
||||
|
||||
StatusTextBlock.FontSize = Math.Clamp(14 * softScale, 10, 18);
|
||||
|
||||
ApplyNightModeVisual();
|
||||
|
||||
if (_visibleItemCount != previousVisibleItemCount &&
|
||||
_isAttached &&
|
||||
!_isRefreshing &&
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -9,7 +9,7 @@ using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget
|
||||
public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget, IDisposable
|
||||
{
|
||||
private readonly IStudyAnalyticsService _studyAnalyticsService = StudyAnalyticsServiceFactory.CreateDefault();
|
||||
private readonly StudyAnalyticsMonitoringLeaseCoordinator _monitoringLeaseCoordinator = StudyAnalyticsMonitoringLeaseCoordinatorFactory.CreateDefault();
|
||||
@@ -27,6 +27,7 @@ public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidg
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _isAttached;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _isDisposed;
|
||||
private IDisposable? _monitoringLease;
|
||||
|
||||
public StudyEnvironmentWidget()
|
||||
@@ -329,4 +330,23 @@ public partial class StudyEnvironmentWidget : UserControl, IDesktopComponentWidg
|
||||
|
||||
return CreateBrush(fallbackHex);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_uiTimer.Stop();
|
||||
_uiTimer.Tick -= OnUiTimerTick;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
SizeChanged -= OnSizeChanged;
|
||||
|
||||
_monitoringLease?.Dispose();
|
||||
_monitoringLease = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
private static readonly Pen GridPen = new(GridBrush, 1);
|
||||
private static readonly Pen AxisPen = new(AxisBrush, 1.1);
|
||||
|
||||
private static readonly IBrush QuietPointBrush = new SolidColorBrush(Color.Parse("#FF34D399"));
|
||||
private static readonly IBrush NormalPointBrush = new SolidColorBrush(Color.Parse("#FF60A5FA"));
|
||||
private static readonly IBrush NoisyPointBrush = new SolidColorBrush(Color.Parse("#FFF59E0B"));
|
||||
private static readonly IBrush ExtremePointBrush = new SolidColorBrush(Color.Parse("#FFEF4444"));
|
||||
private static readonly IBrush QuietBrush = new SolidColorBrush(Color.Parse("#FF34D399"));
|
||||
private static readonly IBrush NormalBrush = new SolidColorBrush(Color.Parse("#FF60A5FA"));
|
||||
private static readonly IBrush NoisyBrush = new SolidColorBrush(Color.Parse("#FFF59E0B"));
|
||||
private static readonly IBrush ExtremeBrush = new SolidColorBrush(Color.Parse("#FFEF4444"));
|
||||
|
||||
private IReadOnlyList<NoiseRealtimePoint> _points = Array.Empty<NoiseRealtimePoint>();
|
||||
private double _baselineDb = 45;
|
||||
@@ -47,34 +47,102 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
|
||||
DrawGrid(context, plot);
|
||||
|
||||
if (_points.Count == 0)
|
||||
if (_points.Count < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawElectronCloud(context, plot);
|
||||
}
|
||||
|
||||
private void DrawElectronCloud(DrawingContext context, Rect plot)
|
||||
{
|
||||
var start = _points[0].Timestamp;
|
||||
var end = _points[^1].Timestamp;
|
||||
var totalTicks = Math.Max(1, (end - start).Ticks);
|
||||
|
||||
var maxRenderPoints = Math.Clamp((int)Math.Floor(plot.Width * 1.5), 80, 520);
|
||||
var step = Math.Max(1, _points.Count / Math.Max(1, maxRenderPoints));
|
||||
var radius = Math.Clamp(Math.Min(plot.Width, plot.Height) / 88d, 1.4, 3.8);
|
||||
|
||||
for (var i = 0; i < _points.Count; i += step)
|
||||
var pointCount = _points.Count;
|
||||
var cloudLayers = 8;
|
||||
var baseRadius = Math.Clamp(Math.Min(plot.Width, plot.Height) / 45d, 3, 12);
|
||||
|
||||
var sortedPoints = new List<(double X, double Y, NoiseDistributionLevel Level)>();
|
||||
for (var i = 0; i < pointCount; i++)
|
||||
{
|
||||
var point = _points[i];
|
||||
var level = ResolveLevel(point.DisplayDb, _baselineDb);
|
||||
var x = MapX(plot, point.Timestamp, start, totalTicks);
|
||||
var y = MapY(plot, level, point.Timestamp);
|
||||
context.DrawEllipse(GetLevelBrush(level), pen: null, center: new Point(x, y), radiusX: radius, radiusY: radius);
|
||||
var y = MapYContinuous(plot, point.DisplayDb);
|
||||
var level = ResolveLevel(point.DisplayDb, _baselineDb);
|
||||
sortedPoints.Add((x, y, level));
|
||||
}
|
||||
|
||||
sortedPoints.Sort((a, b) => a.X.CompareTo(b.X));
|
||||
|
||||
for (var layer = cloudLayers - 1; layer >= 0; layer--)
|
||||
{
|
||||
var layerRatio = (double)layer / (cloudLayers - 1);
|
||||
var layerRadius = baseRadius * (1.2 + layerRatio * 0.8);
|
||||
var layerAlpha = (byte)(40 + layerRatio * 25);
|
||||
|
||||
foreach (var pt in sortedPoints)
|
||||
{
|
||||
var brush = GetLevelBrushWithAlpha(pt.Level, layerAlpha);
|
||||
var jitterX = ComputeJitter(pt.X * 1000 + layer) * layerRadius * 0.3;
|
||||
var jitterY = ComputeJitter(pt.Y * 1000 + layer) * layerRadius * 0.3;
|
||||
|
||||
context.DrawEllipse(
|
||||
brush,
|
||||
pen: null,
|
||||
center: new Point(pt.X + jitterX, pt.Y + jitterY),
|
||||
radiusX: layerRadius,
|
||||
radiusY: layerRadius * 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
var glowLayers = 5;
|
||||
for (var layer = glowLayers - 1; layer >= 0; layer--)
|
||||
{
|
||||
var layerRatio = (double)layer / (glowLayers - 1);
|
||||
var layerRadius = baseRadius * (0.8 + layerRatio * 0.6);
|
||||
var layerAlpha = (byte)(20 + layerRatio * 15);
|
||||
|
||||
foreach (var pt in sortedPoints)
|
||||
{
|
||||
var brush = GetLevelBrushWithAlpha(pt.Level, layerAlpha);
|
||||
context.DrawEllipse(
|
||||
brush,
|
||||
pen: null,
|
||||
center: new Point(pt.X, pt.Y),
|
||||
radiusX: layerRadius,
|
||||
radiusY: layerRadius * 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure latest point is always visible.
|
||||
var latest = _points[^1];
|
||||
var latestLevel = ResolveLevel(latest.DisplayDb, _baselineDb);
|
||||
var latestX = MapX(plot, latest.Timestamp, start, totalTicks);
|
||||
var latestY = MapY(plot, latestLevel, latest.Timestamp);
|
||||
context.DrawEllipse(GetLevelBrush(latestLevel), pen: new Pen(Brushes.White, 1), center: new Point(latestX, latestY), radiusX: radius + 0.8, radiusY: radius + 0.8);
|
||||
var latestY = MapYContinuous(plot, latest.DisplayDb);
|
||||
var latestLevel = ResolveLevel(latest.DisplayDb, _baselineDb);
|
||||
|
||||
for (var i = 3; i >= 0; i--)
|
||||
{
|
||||
var radius = baseRadius * (1.5 + i * 0.8);
|
||||
var alpha = (byte)(30 - i * 6);
|
||||
var glowBrush = GetLevelBrushWithAlpha(latestLevel, alpha);
|
||||
context.DrawEllipse(glowBrush, null, new Point(latestX, latestY), radius, radius * 0.6);
|
||||
}
|
||||
|
||||
context.DrawEllipse(
|
||||
GetLevelBrush(latestLevel),
|
||||
new Pen(Brushes.White, 1.5),
|
||||
new Point(latestX, latestY),
|
||||
baseRadius + 1,
|
||||
baseRadius * 0.7 + 1);
|
||||
|
||||
context.DrawEllipse(
|
||||
Brushes.White,
|
||||
null,
|
||||
new Point(latestX, latestY),
|
||||
2,
|
||||
2);
|
||||
}
|
||||
|
||||
private static void DrawGrid(DrawingContext context, Rect plot)
|
||||
@@ -103,34 +171,28 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
return plot.Left + plot.Width * (offsetTicks / (double)totalTicks);
|
||||
}
|
||||
|
||||
private static double MapY(Rect plot, NoiseDistributionLevel level, DateTimeOffset timestamp)
|
||||
private double MapYContinuous(Rect plot, double displayDb)
|
||||
{
|
||||
// 4 bands: quiet(bottom) -> extreme(top). Add deterministic jitter in each band.
|
||||
var bandHeight = plot.Height / 4d;
|
||||
var levelIndex = level switch
|
||||
{
|
||||
NoiseDistributionLevel.Quiet => 0,
|
||||
NoiseDistributionLevel.Normal => 1,
|
||||
NoiseDistributionLevel.Noisy => 2,
|
||||
NoiseDistributionLevel.Extreme => 3,
|
||||
_ => 1
|
||||
};
|
||||
var minDb = _baselineDb - 5;
|
||||
var maxDb = _baselineDb + 25;
|
||||
var dbRange = maxDb - minDb;
|
||||
if (dbRange <= 0) dbRange = 30;
|
||||
|
||||
var centerY = plot.Bottom - ((levelIndex + 0.5) * bandHeight);
|
||||
var jitter = ComputeJitter(timestamp.Ticks) * bandHeight * 0.26;
|
||||
return Math.Clamp(centerY + jitter, plot.Top + 1.5, plot.Bottom - 1.5);
|
||||
var normalizedDb = (displayDb - minDb) / dbRange;
|
||||
normalizedDb = Math.Clamp(normalizedDb, 0, 1);
|
||||
|
||||
return plot.Bottom - (normalizedDb * plot.Height);
|
||||
}
|
||||
|
||||
private static double ComputeJitter(long ticks)
|
||||
private static double ComputeJitter(double value)
|
||||
{
|
||||
// Deterministic pseudo-random value in [-1, 1] to avoid overlap without animation noise.
|
||||
var value = (ulong)ticks;
|
||||
value ^= value >> 33;
|
||||
value *= 0xff51afd7ed558ccdUL;
|
||||
value ^= value >> 33;
|
||||
value *= 0xc4ceb9fe1a85ec53UL;
|
||||
value ^= value >> 33;
|
||||
var normalized = (value & 0xFFFF) / 65535d;
|
||||
var hash = (ulong)(value * 1000000);
|
||||
hash ^= hash >> 33;
|
||||
hash *= 0xff51afd7ed558ccdUL;
|
||||
hash ^= hash >> 33;
|
||||
hash *= 0xc4ceb9fe1a85ec53UL;
|
||||
hash ^= hash >> 33;
|
||||
var normalized = (hash & 0xFFFF) / 65535d;
|
||||
return (normalized * 2d) - 1d;
|
||||
}
|
||||
|
||||
@@ -162,11 +224,23 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
NoiseDistributionLevel.Quiet => QuietPointBrush,
|
||||
NoiseDistributionLevel.Normal => NormalPointBrush,
|
||||
NoiseDistributionLevel.Noisy => NoisyPointBrush,
|
||||
NoiseDistributionLevel.Extreme => ExtremePointBrush,
|
||||
_ => NormalPointBrush
|
||||
NoiseDistributionLevel.Quiet => QuietBrush,
|
||||
NoiseDistributionLevel.Normal => NormalBrush,
|
||||
NoiseDistributionLevel.Noisy => NoisyBrush,
|
||||
NoiseDistributionLevel.Extreme => ExtremeBrush,
|
||||
_ => NormalBrush
|
||||
};
|
||||
}
|
||||
|
||||
private static IBrush GetLevelBrushWithAlpha(NoiseDistributionLevel level, byte alpha)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
NoiseDistributionLevel.Quiet => new SolidColorBrush(Color.FromArgb(alpha, 0x34, 0xD3, 0x99)),
|
||||
NoiseDistributionLevel.Normal => new SolidColorBrush(Color.FromArgb(alpha, 0x60, 0xA5, 0xFA)),
|
||||
NoiseDistributionLevel.Noisy => new SolidColorBrush(Color.FromArgb(alpha, 0xF5, 0x9E, 0x0B)),
|
||||
NoiseDistributionLevel.Extreme => new SolidColorBrush(Color.FromArgb(alpha, 0xEF, 0x44, 0x44)),
|
||||
_ => new SolidColorBrush(Color.FromArgb(alpha, 0x60, 0xA5, 0xFA))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -12,7 +12,7 @@ using LanMountainDesktop.Theme;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class StudyNoiseDistributionWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget
|
||||
public partial class StudyNoiseDistributionWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget, IDisposable
|
||||
{
|
||||
private static readonly Color[] ValueColorCandidates =
|
||||
{
|
||||
@@ -46,13 +46,14 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly DispatcherTimer _uiTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(250)
|
||||
Interval = TimeSpan.FromMilliseconds(100)
|
||||
};
|
||||
|
||||
private double _currentCellSize = 48;
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _isAttached;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _isDisposed;
|
||||
private bool _isCompactMode;
|
||||
private bool _isUltraCompactMode;
|
||||
private IDisposable? _monitoringLease;
|
||||
@@ -604,6 +605,25 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
{
|
||||
return _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_uiTimer.Stop();
|
||||
_uiTimer.Tick -= OnUiTimerTick;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
SizeChanged -= OnSizeChanged;
|
||||
|
||||
_monitoringLease?.Dispose();
|
||||
_monitoringLease = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ using Material.Icons;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class StudySessionControlWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget
|
||||
public partial class StudySessionControlWidget : UserControl, IDesktopComponentWidget, IDesktopPageVisibilityAwareComponentWidget, IDisposable
|
||||
{
|
||||
private static readonly Color[] PrimaryColorCandidates =
|
||||
{
|
||||
@@ -61,6 +61,7 @@ public partial class StudySessionControlWidget : UserControl, IDesktopComponentW
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _isAttached;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _isDisposed;
|
||||
private bool _isCompactMode;
|
||||
private bool _isUltraCompactMode;
|
||||
private IDisposable? _monitoringLease;
|
||||
@@ -468,4 +469,20 @@ public partial class StudySessionControlWidget : UserControl, IDesktopComponentW
|
||||
{
|
||||
return _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_uiTimer.Stop();
|
||||
_uiTimer.Tick -= OnUiTimerTick;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
SizeChanged -= OnSizeChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -69,6 +69,7 @@ public partial class WeatherClockWidget : UserControl, IDesktopComponentWidget,
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
|
||||
InitializeDialIfNeeded();
|
||||
InitializeHandsIfNeeded();
|
||||
@@ -238,6 +239,12 @@ public partial class WeatherClockWidget : UserControl, IDesktopComponentWidget,
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_isNightModeApplied = null;
|
||||
ApplyModeVisualIfNeeded();
|
||||
}
|
||||
|
||||
private void OnClockTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
UpdateClockVisual();
|
||||
|
||||
@@ -6,6 +6,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
@@ -81,6 +82,8 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
public required TextBlock OffsetTextBlock { get; init; }
|
||||
|
||||
public bool? IsNightApplied { get; set; }
|
||||
|
||||
public bool? IsSystemNightApplied { get; set; }
|
||||
}
|
||||
|
||||
private readonly DispatcherTimer _clockTimer = new()
|
||||
@@ -99,6 +102,7 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
private double _currentCellSize = BaseCellSize;
|
||||
private DateTime _nextLanguageProbeUtc = DateTime.MinValue;
|
||||
private string _secondHandMode = ClockSecondHandMode.Tick;
|
||||
private bool _isNightVisual = true;
|
||||
|
||||
public WorldClockWidget()
|
||||
{
|
||||
@@ -114,6 +118,7 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
ActualThemeVariantChanged += OnActualThemeVariantChanged;
|
||||
}
|
||||
|
||||
public void SetTimeZoneService(TimeZoneService timeZoneService)
|
||||
@@ -211,6 +216,79 @@ public partial class WorldClockWidget : UserControl, IDesktopComponentWidget, IT
|
||||
ApplyCellSize(_currentCellSize);
|
||||
}
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
_isNightVisual = ResolveNightMode();
|
||||
ApplyNightModeVisual();
|
||||
}
|
||||
|
||||
private bool ResolveNightMode()
|
||||
{
|
||||
if (ActualThemeVariant == ThemeVariant.Dark)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ActualThemeVariant == ThemeVariant.Light)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.TryFindResource("AdaptiveSurfaceBaseBrush", out var value) &&
|
||||
value is ISolidColorBrush brush)
|
||||
{
|
||||
return CalculateRelativeLuminance(brush.Color) < 0.45;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double CalculateRelativeLuminance(Color color)
|
||||
{
|
||||
static double ToLinear(double channel)
|
||||
{
|
||||
return channel <= 0.03928
|
||||
? channel / 12.92
|
||||
: Math.Pow((channel + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private void ApplyNightModeVisual()
|
||||
{
|
||||
RootBorder.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#1B2129") : Color.Parse("#F4F5F7"));
|
||||
RootBorder.BorderBrush = new SolidColorBrush(_isNightVisual ? Color.Parse("#33FFFFFF") : Color.Parse("#16000000"));
|
||||
|
||||
foreach (var entry in _entryVisuals)
|
||||
{
|
||||
ApplyTextThemeForSystemNight(entry, _isNightVisual);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyTextThemeForSystemNight(ClockEntryVisual entry, bool isSystemNight)
|
||||
{
|
||||
if (entry.IsSystemNightApplied.HasValue && entry.IsSystemNightApplied.Value == isSystemNight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
entry.IsSystemNightApplied = isSystemNight;
|
||||
|
||||
var cityForeground = isSystemNight ? "#E8EAED" : "#20232A";
|
||||
var dayForeground = isSystemNight ? "#A8B1C2" : "#646C79";
|
||||
var offsetForeground = isSystemNight ? "#A8B1C2" : "#7A7F89";
|
||||
|
||||
entry.CityTextBlock.Foreground = CreateBrush(cityForeground);
|
||||
entry.DayTextBlock.Foreground = CreateBrush(dayForeground);
|
||||
entry.OffsetTextBlock.Foreground = CreateBrush(offsetForeground);
|
||||
}
|
||||
|
||||
private void OnTimeZoneChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
|
||||
@@ -38,6 +38,7 @@ public partial class MainWindow
|
||||
Bitmap? IconBitmap);
|
||||
|
||||
private readonly WindowsStartMenuService _windowsStartMenuService = new();
|
||||
private readonly LinuxDesktopEntryService _linuxDesktopEntryService = new();
|
||||
private readonly Dictionary<string, Bitmap> _launcherIconCache = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Stack<StartMenuFolderNode> _launcherFolderStack = [];
|
||||
private readonly HashSet<string> _hiddenLauncherFolderPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -116,7 +117,9 @@ public partial class MainWindow
|
||||
{
|
||||
var loadResult = await Task.Run(() =>
|
||||
{
|
||||
var loadedRoot = _windowsStartMenuService.Load();
|
||||
var loadedRoot = OperatingSystem.IsLinux()
|
||||
? _linuxDesktopEntryService.Load()
|
||||
: _windowsStartMenuService.Load();
|
||||
var folderIconBytes = OperatingSystem.IsWindows()
|
||||
? WindowsIconService.TryGetSystemFolderIconPngBytes()
|
||||
: null;
|
||||
@@ -771,7 +774,7 @@ public partial class MainWindow
|
||||
if (LauncherRootTilePanel.Children.Count == 0)
|
||||
{
|
||||
LauncherRootTilePanel.Children.Add(CreateLauncherHintTile(
|
||||
L("launcher.empty", "No Start Menu entries found."),
|
||||
GetLauncherEmptyText(),
|
||||
string.Empty));
|
||||
}
|
||||
|
||||
@@ -1440,10 +1443,40 @@ public partial class MainWindow
|
||||
return new string(letters).ToUpperInvariant();
|
||||
}
|
||||
|
||||
private string GetLauncherEmptyText()
|
||||
{
|
||||
return OperatingSystem.IsLinux()
|
||||
? L("launcher.empty_linux", "No Linux desktop entries were found.")
|
||||
: L("launcher.empty", "No Start Menu entries found.");
|
||||
}
|
||||
|
||||
private static void LaunchStartMenuEntry(StartMenuAppEntry app)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (OperatingSystem.IsLinux() &&
|
||||
!string.IsNullOrWhiteSpace(app.LaunchExecutable))
|
||||
{
|
||||
var linuxStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = app.LaunchExecutable,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(app.WorkingDirectory))
|
||||
{
|
||||
linuxStartInfo.WorkingDirectory = app.WorkingDirectory;
|
||||
}
|
||||
|
||||
foreach (var argument in app.LaunchArguments)
|
||||
{
|
||||
linuxStartInfo.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
Process.Start(linuxStartInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = app.FilePath,
|
||||
|
||||
@@ -97,9 +97,13 @@ public partial class MainWindow
|
||||
"Swipe to pick a category, tap to open, then drag a widget onto the desktop.");
|
||||
|
||||
LauncherTitleTextBlock.Text = L("launcher.title", "App Launcher");
|
||||
LauncherSubtitleTextBlock.Text = L(
|
||||
"launcher.subtitle",
|
||||
"Displays all apps and folders based on the Windows Start menu structure.");
|
||||
LauncherSubtitleTextBlock.Text = OperatingSystem.IsLinux()
|
||||
? L(
|
||||
"launcher.subtitle_linux",
|
||||
"Displays installed apps discovered from Linux desktop entries.")
|
||||
: L(
|
||||
"launcher.subtitle",
|
||||
"Displays all apps and folders based on the Windows Start menu structure.");
|
||||
ToolTip.SetTip(LauncherFolderBackButton, L("common.back", "Back"));
|
||||
ToolTip.SetTip(LauncherFolderCloseButton, L("common.close", "Close"));
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Version=1.0
|
||||
Name=LanMountainDesktop
|
||||
Comment=LanMountainDesktop desktop shell
|
||||
Exec=@@EXEC@@ %U
|
||||
Icon=@@ICON@@
|
||||
Terminal=false
|
||||
Categories=Utility;Education;
|
||||
StartupWMClass=LanMountainDesktop
|
||||
101
LanMountainDesktop/packaging/linux/install.sh
Normal file
101
LanMountainDesktop/packaging/linux/install.sh
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
APP_BIN="$SCRIPT_DIR/LanMountainDesktop"
|
||||
DESKTOP_TEMPLATE="$SCRIPT_DIR/share/applications/LanMountainDesktop.desktop"
|
||||
ICON_SOURCE="$SCRIPT_DIR/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
|
||||
|
||||
APPLICATIONS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
|
||||
ICONS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/256x256/apps"
|
||||
DESKTOP_TARGET="$APPLICATIONS_DIR/LanMountainDesktop.desktop"
|
||||
ICON_TARGET="$ICONS_DIR/lanmountaindesktop.png"
|
||||
|
||||
check_audio_dependencies() {
|
||||
MISSING_DEPS=""
|
||||
|
||||
if command -v dpkg >/dev/null 2>&1; then
|
||||
if ! dpkg -s libportaudio2 >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS libportaudio2"
|
||||
fi
|
||||
if ! dpkg -s libasound2 >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS libasound2"
|
||||
fi
|
||||
elif command -v rpm >/dev/null 2>&1; then
|
||||
if ! rpm -q portaudio-libs >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS portaudio-libs"
|
||||
fi
|
||||
if ! rpm -q alsa-lib >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS alsa-lib"
|
||||
fi
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
if ! pacman -Q portaudio >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS portaudio"
|
||||
fi
|
||||
if ! pacman -Q alsa-lib >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS alsa-lib"
|
||||
fi
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
if ! apk -e info portaudio >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS portaudio"
|
||||
fi
|
||||
if ! apk -e info alsa-lib >/dev/null 2>&1; then
|
||||
MISSING_DEPS="$MISSING_DEPS alsa-lib"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$MISSING_DEPS" ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
install_audio_dependencies() {
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libportaudio2 libasound2
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
sudo dnf install -y portaudio-libs alsa-lib
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
sudo yum install -y portaudio-libs alsa-lib
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
sudo pacman -S --noconfirm portaudio alsa-lib
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
sudo apk add portaudio alsa-lib
|
||||
else
|
||||
printf '%s\n' "Warning: Could not detect package manager. Please install audio dependencies manually:"
|
||||
printf '%s\n' " - libportaudio2 (or portaudio-libs/portaudio)"
|
||||
printf '%s\n' " - libasound2 (or alsa-lib)"
|
||||
fi
|
||||
}
|
||||
|
||||
if ! check_audio_dependencies; then
|
||||
printf '%s\n' "Installing audio dependencies for recording features..."
|
||||
install_audio_dependencies
|
||||
|
||||
if ! check_audio_dependencies; then
|
||||
printf '%s\n' "Warning: Audio dependencies may not be installed correctly."
|
||||
printf '%s\n' "Recording and study monitoring features may not work properly."
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$APPLICATIONS_DIR" "$ICONS_DIR"
|
||||
|
||||
cp "$ICON_SOURCE" "$ICON_TARGET"
|
||||
sed \
|
||||
-e "s|@@EXEC@@|$APP_BIN|g" \
|
||||
-e "s|@@ICON@@|lanmountaindesktop|g" \
|
||||
"$DESKTOP_TEMPLATE" > "$DESKTOP_TARGET"
|
||||
|
||||
chmod +x "$APP_BIN" "$DESKTOP_TARGET"
|
||||
|
||||
if command -v update-desktop-database >/dev/null 2>&1; then
|
||||
update-desktop-database "$APPLICATIONS_DIR" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
|
||||
gtk-update-icon-cache "${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
printf '%s\n' "Installed desktop entry: $DESKTOP_TARGET"
|
||||
printf '%s\n' "Installed icon: $ICON_TARGET"
|
||||
BIN
LanMountainDesktop/packaging/linux/lanmountaindesktop.png
Normal file
BIN
LanMountainDesktop/packaging/linux/lanmountaindesktop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -141,6 +141,33 @@ function Create-PackageArchive {
|
||||
return $archivePath
|
||||
}
|
||||
|
||||
function Add-LinuxDesktopAssets {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$PublishedDirectory,
|
||||
[Parameter(Mandatory = $true)][string]$RepoRoot
|
||||
)
|
||||
|
||||
$resourcesRoot = Join-Path $RepoRoot "packaging/linux"
|
||||
$desktopTemplate = Join-Path $resourcesRoot "LanMountainDesktop.desktop"
|
||||
$iconSource = Join-Path $resourcesRoot "lanmountaindesktop.png"
|
||||
$installScriptSource = Join-Path $resourcesRoot "install.sh"
|
||||
|
||||
foreach ($requiredPath in @($desktopTemplate, $iconSource, $installScriptSource)) {
|
||||
if (-not (Test-Path -LiteralPath $requiredPath)) {
|
||||
throw "Linux packaging resource is missing: $requiredPath"
|
||||
}
|
||||
}
|
||||
|
||||
$applicationsDir = Join-Path $PublishedDirectory "share/applications"
|
||||
$iconsDir = Join-Path $PublishedDirectory "share/icons/hicolor/256x256/apps"
|
||||
[System.IO.Directory]::CreateDirectory($applicationsDir) | Out-Null
|
||||
[System.IO.Directory]::CreateDirectory($iconsDir) | Out-Null
|
||||
|
||||
Copy-Item -LiteralPath $desktopTemplate -Destination (Join-Path $applicationsDir "LanMountainDesktop.desktop") -Force
|
||||
Copy-Item -LiteralPath $iconSource -Destination (Join-Path $iconsDir "lanmountaindesktop.png") -Force
|
||||
Copy-Item -LiteralPath $installScriptSource -Destination (Join-Path $PublishedDirectory "install.sh") -Force
|
||||
}
|
||||
|
||||
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$repoRoot = Resolve-ExistingPath -PathValue (Join-Path $scriptRoot "..")
|
||||
|
||||
@@ -184,6 +211,10 @@ if ($LASTEXITCODE -ne 0) {
|
||||
|
||||
Remove-LibVlcForOtherArch -PublishedDirectory $PublishDir -Rid $RuntimeIdentifier
|
||||
|
||||
if ($RuntimeIdentifier -like "linux-*") {
|
||||
Add-LinuxDesktopAssets -PublishedDirectory $PublishDir -RepoRoot $repoRoot
|
||||
}
|
||||
|
||||
if (-not $KeepSymbols) {
|
||||
Get-ChildItem -Path $PublishDir -Recurse -File -Filter "*.pdb" | ForEach-Object {
|
||||
[System.IO.File]::Delete($_.FullName)
|
||||
|
||||
26
run.md
26
run.md
@@ -26,3 +26,29 @@ dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj
|
||||
- 启动失败提示 SDK 版本不匹配:确认 `dotnet --info` 中已安装 .NET 10 SDK。
|
||||
- 桌面端视频相关能力异常:优先在 Windows 环境下验证。
|
||||
- 配置重置:删除 `%LOCALAPPDATA%\LanMountainDesktop\settings.json` 后重启应用。
|
||||
|
||||
## 6. Linux 音频功能依赖
|
||||
|
||||
如果在 Linux 上使用录音机组件或自习监测组件,需要安装以下音频库:
|
||||
|
||||
### Debian/Ubuntu
|
||||
```bash
|
||||
sudo apt install libportaudio2 libasound2
|
||||
```
|
||||
|
||||
### Fedora/RHEL
|
||||
```bash
|
||||
sudo dnf install portaudio-libs alsa-lib
|
||||
```
|
||||
|
||||
### Arch Linux
|
||||
```bash
|
||||
sudo pacman -S portaudio alsa-lib
|
||||
```
|
||||
|
||||
### Alpine Linux
|
||||
```bash
|
||||
sudo apk add portaudio alsa-lib
|
||||
```
|
||||
|
||||
> 注:如果未安装这些依赖,录音和自习监测功能将不可用,但应用其他功能可以正常运行。
|
||||
|
||||
Reference in New Issue
Block a user