Skip to content

Commit

Permalink
Fix shutdown on older systems, acrylic support, OSC support
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Apr 2, 2023
1 parent 3c9b9bf commit d21b979
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Amethyst.Support/Amethyst.Support.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
Expand Down Expand Up @@ -160,14 +160,14 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Eigen3.3.3.9\build\native\Eigen3.targets" Condition="Exists('..\packages\Eigen3.3.3.9\build\native\Eigen3.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Eigen3.3.3.9\build\native\Eigen3.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Eigen3.3.3.9\build\native\Eigen3.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.221121.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>
5 changes: 2 additions & 3 deletions Amethyst.Support/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="Eigen3" version="3.3.9" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.221121.5" targetFramework="native" />
<package id="Eigen3" version="3.3.9" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230225.1" targetFramework="native" />
</packages>
8 changes: 4 additions & 4 deletions Amethyst/Amethyst.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230217.4" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25231-preview" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25330-preview" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="108.0.3" />
<PackageReference Include="System.ComponentModel.Composition" Version="7.0.0" />
<PackageReference Include="System.ComponentModel.Composition.Registration" Version="7.0.0" />
Expand Down
9 changes: 9 additions & 0 deletions Amethyst/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
<SolidColorBrush x:Key="NeutralBrush_Dark" Color="#8BFFFFFF" />
<SolidColorBrush x:Key="NeutralBrush_Light" Color="#72000000" />

<AcrylicBrush x:Key="AcrylicBrush_Dark" Opacity="0.5"
TintColor="#202020" TintOpacity="0.5" FallbackColor="#1C1C1C" />
<AcrylicBrush x:Key="AcrylicBrush_Darker" Opacity="0.7"
TintColor="#202020" TintOpacity="0.7" FallbackColor="#1C1C1C" />
<AcrylicBrush x:Key="AcrylicBrush_Light" Opacity="0.5"
TintColor="#F3F3F3" TintOpacity="0.0" FallbackColor="#EEEEEE" />
<AcrylicBrush x:Key="AcrylicBrush_Lighter" Opacity="0.3"
TintColor="#F3F3F3" TintOpacity="0.0" FallbackColor="#EEEEEE" />

<!--Resource overrides-->
<x:Double x:Key="TeachingTipMinHeight">20</x:Double>
<x:Double x:Key="TeachingTipMaxHeight">800</x:Double>
Expand Down
76 changes: 61 additions & 15 deletions Amethyst/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public sealed partial class MainWindow : Window, INotifyPropertyChanged
private readonly bool _mainPageInitFinished;

private SystemBackdropConfiguration _configurationSource;
private bool _mainPageLoadedOnce;
private MicaController _micaController;
private DesktopAcrylicController _acrylicController;

private bool _mainPageLoadedOnce;
private string _remoteVersionString = AppData.VersionString.Display;
private Shared.Events.RequestEvent _updateBrushesEvent;

private WindowsSystemDispatcherQueueHelper _wsdqHelper; // See separate sample below for implementation

Expand All @@ -74,6 +77,9 @@ public MainWindow()
InitializeComponent();
TrySetMicaBackdrop();

// Set up the shutdown handler
Closed += Window_Closed;

// Cache needed UI elements
Shared.TeachingTips.MainPage.InitializerTeachingTip = InitializerTeachingTip;
Shared.TeachingTips.MainPage.EndingTeachingTip = EndingTeachingTip;
Expand Down Expand Up @@ -1195,6 +1201,9 @@ private void MainWindow_ActualThemeChanged(FrameworkElement sender, object args)
Shared.Main.AppWindow.TitleBar.ButtonHoverBackgroundColor =
Shared.Main.AppWindow.TitleBar.ButtonPressedBackgroundColor;

// Refresh other stuff
_updateBrushesEvent?.Invoke(this, EventArgs.Empty);

// Request page reloads
Shared.Events.RequestInterfaceReload();

Expand Down Expand Up @@ -1838,12 +1847,12 @@ private void LicensesFlyout_Closed(object sender, object e)
Interfacing.IsNuxPending = false;
}

private bool TrySetMicaBackdrop()
private void TrySetMicaBackdrop()
{
if (!MicaController.IsSupported())
if (!MicaController.IsSupported() && !DesktopAcrylicController.IsSupported())
{
Logger.Info("Mica is not supported! Time to update Windows, man!");
return false; // Mica is not supported on this system
Logger.Info("Mica and acrylic are not supported! Time to update Windows, man!");
return; // Mica/acrylic is not supported on this system
}

_wsdqHelper = new WindowsSystemDispatcherQueueHelper();
Expand All @@ -1852,24 +1861,55 @@ private bool TrySetMicaBackdrop()
// Hooking up the policy object
_configurationSource = new SystemBackdropConfiguration();
Activated += Window_Activated;
Closed += Window_Closed;
((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged;

// Initial configuration state.
_configurationSource.IsInputActive = true;
SetConfigurationSourceTheme();

_micaController = new MicaController();
if (MicaController.IsSupported())
{
_micaController = new MicaController();

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
_micaController.AddSystemBackdropTarget(this
.As<ICompositionSupportsSystemBackdrop>());
_micaController.SetSystemBackdropConfiguration(_configurationSource);
// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
_micaController.AddSystemBackdropTarget(this
.As<ICompositionSupportsSystemBackdrop>());
_micaController.SetSystemBackdropConfiguration(_configurationSource);

// Change the window background to support mica
MainGrid.Background = new SolidColorBrush(Colors.Transparent);
return true; // succeeded
// Change the window background to support mica
MainGrid.Background = new SolidColorBrush(Colors.Transparent);
}
else if (DesktopAcrylicController.IsSupported())
{
_acrylicController = new DesktopAcrylicController();

// Enable the system backdrop.
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
_acrylicController.AddSystemBackdropTarget(this
.As<ICompositionSupportsSystemBackdrop>());
_acrylicController.SetSystemBackdropConfiguration(_configurationSource);

// Change the window background to support acrylic
MainGrid.Background = Application.Current.RequestedTheme == ApplicationTheme.Dark
? Application.Current.Resources["AcrylicBrush_Dark"].As<AcrylicBrush>()
: Application.Current.Resources["AcrylicBrush_Light"].As<AcrylicBrush>();
ContentFrame.Background = Application.Current.RequestedTheme == ApplicationTheme.Dark
? Application.Current.Resources["AcrylicBrush_Darker"].As<AcrylicBrush>()
: Application.Current.Resources["AcrylicBrush_Lighter"].As<AcrylicBrush>();

_updateBrushesEvent += (_, _) =>
{
// Change the window background to support acrylic
MainGrid.Background = Interfacing.ActualTheme == ElementTheme.Dark
? Application.Current.Resources["AcrylicBrush_Dark"].As<AcrylicBrush>()
: Application.Current.Resources["AcrylicBrush_Light"].As<AcrylicBrush>();
ContentFrame.Background = Interfacing.ActualTheme == ElementTheme.Dark
? Application.Current.Resources["AcrylicBrush_Darker"].As<AcrylicBrush>()
: Application.Current.Resources["AcrylicBrush_Lighter"].As<AcrylicBrush>();
return Task.CompletedTask;
};
}
}

private void Window_Activated(object sender, WindowActivatedEventArgs args)
Expand Down Expand Up @@ -1925,6 +1965,12 @@ private async void Window_Closed(object sender, WindowEventArgs args)
_micaController = null;
}

if (_acrylicController is not null)
{
_acrylicController.Dispose();
_acrylicController = null;
}

Activated -= Window_Activated;
_configurationSource = null;
break;
Expand Down
11 changes: 5 additions & 6 deletions K2CrashHandler/K2CrashHandler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="6.0.0-preview.5.21301.5" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230118.102" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25231-preview" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25330-preview" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!-- Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored -->
<ItemGroup
Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ parameters:
- "plugin_PSMoveService"
- "plugin_owoTrackVR"
- "plugin_OpenVR"
- "plugin_OSC"

steps:
- checkout: self
Expand Down

0 comments on commit d21b979

Please sign in to comment.