Skip to content

Commit f71ad0e

Browse files
committed
Mac
1 parent d754f7d commit f71ad0e

5 files changed

Lines changed: 40 additions & 19 deletions

File tree

Amethyst.Desktop/Program.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,34 @@ public static AppBuilder BuildAvaloniaApp()
3030

3131
public static class AppBuilderExtensions
3232
{
33-
private static ISystemShell Shell { get; } = new SystemShell();
33+
private static ISystemShell Shell { get; set; }
3434

3535
public static AppBuilder SetupDesktopNotifications(this AppBuilder builder, out INotificationManager manager)
3636
{
37-
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
38-
{
39-
var context = WindowsApplicationContext.FromCurrentProcess();
40-
manager = new WindowsNotificationManager(context);
41-
}
42-
else if (Environment.OSVersion.Platform == PlatformID.Unix)
43-
{
44-
var context = FreeDesktopApplicationContext.FromCurrentProcess();
45-
manager = new FreeDesktopNotificationManager(context);
46-
}
47-
else
37+
if (OperatingSystem.IsWindows()) Shell = new SystemShell();
38+
39+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
40+
switch (Environment.OSVersion.Platform)
4841
{
49-
// TODO: OSX once implemented/stable
50-
manager = null;
51-
return builder;
42+
case PlatformID.Win32NT:
43+
{
44+
var context = WindowsApplicationContext.FromCurrentProcess();
45+
manager = new WindowsNotificationManager(context);
46+
break;
47+
}
48+
case PlatformID.Unix:
49+
{
50+
var context = FreeDesktopApplicationContext.FromCurrentProcess();
51+
manager = new FreeDesktopNotificationManager(context);
52+
break;
53+
}
54+
default:
55+
// TODO: OSX once implemented/stable
56+
manager = null;
57+
return builder;
5258
}
5359

54-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
60+
if (!OperatingSystem.IsMacCatalyst() && !OperatingSystem.IsMacOS())
5561
manager.Initialize().GetAwaiter().GetResult();
5662

5763
var notificationManager = manager;

Amethyst/Amethyst.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<NoWarn>$(NoWarn);NU1507</NoWarn>
77
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9-
<LangVersion>latest</LangVersion>
9+
<LangVersion>preview</LangVersion>
1010
<Version>2.0.0.0</Version>
1111
</PropertyGroup>
1212

Amethyst/MainWindow.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
xmlns:utils="clr-namespace:Amethyst.Utils"
99
xmlns:avalonia="clr-namespace:FluentIcons.Avalonia;assembly=FluentIcons.Avalonia"
1010
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
11-
Background="Transparent" TransparencyLevelHint="Mica,Transparent" x:Name="Root">
11+
Background="{DynamicResource SolidBackgroundFillColorTertiaryBrush}"
12+
TransparencyLevelHint="Mica,Transparent"
13+
x:Name="Root">
1214

1315
<Grid RowDefinitions="Auto,*">
1416
<Grid Name="TitleBarHost" ZIndex="1"

Amethyst/MainWindow.axaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ private void OnActualThemeVariantChanged(object sender, EventArgs e)
8787

8888
private void TryEnableMicaEffect()
8989
{
90+
if (OperatingSystem.IsWindows())
91+
Background = new SolidColorBrush(Colors.Transparent);
92+
9093
return;
9194
// TransparencyBackgroundFallback = Brushes.Transparent;
9295
// TransparencyLevelHint = WindowTransparencyLevel.Mica;

Amethyst/Utils/SystemShell.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public interface ISystemShell
55
{
6-
public static ISystemShell Instance => Locator.Current.GetService<ISystemShell>();
6+
public static ISystemShell Instance => Locator.Current.GetService<ISystemShell>() ?? StubShell.Instance;
77

88
uint TimeBeginPeriod(uint uMilliseconds);
99
uint TimeEndPeriod(uint uMilliseconds);
@@ -12,6 +12,16 @@ public interface ISystemShell
1212
Bitmap GetFileIcon(string path);
1313
}
1414

15+
public class StubShell : ISystemShell
16+
{
17+
public static StubShell Instance { get; } = new();
18+
public uint TimeBeginPeriod(uint uMilliseconds) => 0;
19+
public uint TimeEndPeriod(uint uMilliseconds) => 0;
20+
public void OpenFolderAndSelectItem(string path) { }
21+
public void OpenFolderAndSelectItem(Uri path) { }
22+
public Bitmap GetFileIcon(string path) => null;
23+
}
24+
1525
#if FALSE
1626
using System;
1727
using System.ComponentModel;

0 commit comments

Comments
 (0)