Compare commits

...

3 commits

Author SHA1 Message Date
2dust
c2ef3a4a8c Add Design.IsDesignMode to the desktop version
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release Linux / rpm (push) Blocked by required conditions
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run
2025-10-29 20:21:41 +08:00
2dust
86eb8297dd Update JsonUtils.cs 2025-10-29 20:20:44 +08:00
2dust
c63d4e83f9 Use OperatingSystem replace RuntimeInformation 2025-10-29 20:20:40 +08:00
4 changed files with 32 additions and 19 deletions

View file

@ -35,9 +35,13 @@ public class JsonUtils
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
public static T DeepCopy<T>(T obj) public static T? DeepCopy<T>(T? obj)
{ {
return Deserialize<T>(Serialize(obj, false))!; if (obj is null)
{
return default;
}
return Deserialize<T>(Serialize(obj, false));
} }
/// <summary> /// <summary>
@ -67,7 +71,7 @@ public class JsonUtils
/// </summary> /// </summary>
/// <param name="strJson"></param> /// <param name="strJson"></param>
/// <returns></returns> /// <returns></returns>
public static JsonNode? ParseJson(string strJson) public static JsonNode? ParseJson(string? strJson)
{ {
try try
{ {
@ -116,7 +120,7 @@ public class JsonUtils
/// <param name="obj"></param> /// <param name="obj"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns></returns> /// <returns></returns>
public static string Serialize(object? obj, JsonSerializerOptions options) public static string Serialize(object? obj, JsonSerializerOptions? options)
{ {
var result = string.Empty; var result = string.Empty;
try try
@ -125,7 +129,7 @@ public class JsonUtils
{ {
return result; return result;
} }
result = JsonSerializer.Serialize(obj, options); result = JsonSerializer.Serialize(obj, options ?? _defaultSerializeOptions);
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -963,13 +963,13 @@ public class Utils
#region Platform #region Platform
public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public static bool IsWindows() => OperatingSystem.IsWindows();
public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); public static bool IsLinux() => OperatingSystem.IsLinux();
public static bool IsOSX() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); public static bool IsOSX() => OperatingSystem.IsMacOS();
public static bool IsNonWindows() => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public static bool IsNonWindows() => !OperatingSystem.IsWindows();
public static string GetExeName(string name) public static string GetExeName(string name)
{ {

View file

@ -10,15 +10,17 @@ public partial class App : Application
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
DataContext = StatusBarViewModel.Instance;
} }
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted()
{ {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (!Design.IsDesignMode)
{ {
AppManager.Instance.InitComponents(); AppManager.Instance.InitComponents();
DataContext = StatusBarViewModel.Instance;
}
desktop.Exit += OnExit; desktop.Exit += OnExit;
desktop.MainWindow = new MainWindow(); desktop.MainWindow = new MainWindow();

View file

@ -54,12 +54,19 @@ internal class Program
// Avalonia configuration, don't remove; also used by visual designer. // Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp() public static AppBuilder BuildAvaloniaApp()
{ {
return AppBuilder.Configure<App>() var builder = AppBuilder.Configure<App>()
.UsePlatformDetect() .UsePlatformDetect()
//.WithInterFont() //.WithInterFont()
.WithFontByDefault() .WithFontByDefault()
.LogToTrace() .LogToTrace()
.UseReactiveUI() .UseReactiveUI();
.With(new MacOSPlatformOptions { ShowInDock = AppManager.Instance.Config.UiItem.MacOSShowInDock });
if (OperatingSystem.IsMacOS())
{
var showInDock = Design.IsDesignMode || AppManager.Instance.Config.UiItem.MacOSShowInDock;
builder = builder.With(new MacOSPlatformOptions { ShowInDock = showInDock });
}
return builder;
} }
} }