Skip to content

Commit 522ce80

Browse files
New app model
1 parent 21a10c1 commit 522ce80

File tree

5 files changed

+50
-33
lines changed

5 files changed

+50
-33
lines changed

VBAudioRouter.Host/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
using System;
33
using System.Runtime;
44
using System.Runtime.InteropServices;
5+
using System.Threading;
56

67
namespace VBAudioRouter.Host
78
{
89
static class Program
910
{
10-
[STAThread]
11+
[MTAThread]
1112
static void Main(string[] args)
1213
{
14+
GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
1315
using (SentrySdk.Init(o =>
1416
{
1517
o.Dsn = "https://[email protected]/6409713";
@@ -22,7 +24,6 @@ static void Main(string[] args)
2224
{
2325
try
2426
{
25-
GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
2627
VBAudioRouter.Program.WinMain(args);
2728
}
2829
catch (Exception ex)

VBAudioRouter.UWP/App.xaml.vb

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
Imports VBAudioRouter.Dialogs
1+
Imports ShortDev.Uwp.FullTrust.Xaml
2+
Imports VBAudioRouter.Dialogs
23
Imports VBAudioRouter.Utils
34
Imports Windows.UI
45
Imports Windows.UI.Core.Preview
56

67
Public NotInheritable Class App
78

89
Public Sub New()
9-
'Initialize()
1010
InitializeComponent()
11+
12+
Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.AboveNormal
13+
End Sub
14+
15+
Private Shared Async Sub Program_CloseRequested(ByVal sender As Object, ByVal e As Navigation.XamlWindowCloseRequestedEventArgs)
16+
Dim deferral = e.GetDeferral()
17+
e.Handled = Await HandleCloseRequest()
18+
deferral.Complete()
19+
End Sub
20+
21+
Protected Overrides Sub OnWindowCreated(args As WindowCreatedEventArgs)
22+
MyBase.OnWindowCreated(args)
1123
End Sub
1224

1325
Protected Overrides Async Sub OnLaunched(e As LaunchActivatedEventArgs)
@@ -42,14 +54,20 @@ Public NotInheritable Class App
4254
#End Region
4355

4456
#Region "Close confirm"
45-
AddHandler SystemNavigationManagerPreview.GetForCurrentView().CloseRequested, Async Sub(sender As Object, ev As SystemNavigationCloseRequestedPreviewEventArgs)
46-
Dim deferral As Deferral = ev.GetDeferral()
47-
Try
48-
ev.Handled = Await HandleCloseRequest()
49-
Finally
50-
deferral.Complete()
51-
End Try
52-
End Sub
57+
If Not WinUI.Interop.RuntimeInformation.IsAppContainer Then
58+
Dim subclass = XamlWindowSubclass.GetForCurrentView()
59+
subclass.UseDarkMode = True
60+
AddHandler Window.Current.GetSubclass().CloseRequested, AddressOf Program_CloseRequested
61+
Else
62+
AddHandler SystemNavigationManagerPreview.GetForCurrentView().CloseRequested, Async Sub(sender As Object, ev As SystemNavigationCloseRequestedPreviewEventArgs)
63+
Dim deferral As Deferral = ev.GetDeferral()
64+
Try
65+
ev.Handled = Await HandleCloseRequest()
66+
Finally
67+
deferral.Complete()
68+
End Try
69+
End Sub
70+
End If
5371
#End Region
5472

5573
#Region "Exception handling"
@@ -73,9 +91,9 @@ Public NotInheritable Class App
7391

7492
AddHandler rootFrame.NavigationFailed, AddressOf OnNavigationFailed
7593

76-
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
77-
' TODO: Zustand von zuvor angehaltener Anwendung laden
78-
End If
94+
'If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
95+
' ' TODO: Zustand von zuvor angehaltener Anwendung laden
96+
'End If
7997
Window.Current.Content = rootFrame
8098
End If
8199

VBAudioRouter.UWP/Program.vb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
Imports ShortDev.Uwp.FullTrust.Core.Xaml
1+
Partial Public Class Program
22

3-
Partial Public Class Program
4-
5-
Public Shared Sub WinMain(args As String())
6-
XamlApplicationWrapper.Run(Of App, WelcomePage)(Sub()
7-
Dim subclass = XamlWindowSubclass.ForCurrentWindow()
8-
subclass.UseDarkMode = True
9-
AddHandler Window.Current.GetSubclass().CloseRequested, AddressOf Program_CloseRequested
10-
End Sub)
3+
<MTAThread()>
4+
Shared Sub Main(ByVal args() As String)
5+
Application.Start(Function(p) New App())
116
End Sub
127

13-
Private Shared Async Sub Program_CloseRequested(ByVal sender As Object, ByVal e As Navigation.XamlWindowCloseRequestedEventArgs)
14-
Dim deferral = e.GetDeferral()
15-
e.Handled = Await App.HandleCloseRequest()
16-
deferral.Complete()
8+
Public Shared Sub WinMain(args As String())
9+
FullTrustApplication.Start(Function(p) New App())
1710
End Sub
1811

1912
End Class

VBAudioRouter.UWP/VBAudioRouter.UWP.vbproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<DefineDebug>true</DefineDebug>
6464
<DefineTrace>true</DefineTrace>
6565
<OutputPath>bin\x64\Debug\</OutputPath>
66-
<DefineConstants>NETFX_CORE,WINDOWS_UWP</DefineConstants>
66+
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,NETFX_CORE,WINDOWS_UWP,CODE_ANALYSIS</DefineConstants>
6767
<DebugType>full</DebugType>
6868
<PlatformTarget>x64</PlatformTarget>
6969
<UseVSHostingProcess>false</UseVSHostingProcess>
@@ -382,7 +382,7 @@
382382
<Version>7.1.2</Version>
383383
</PackageReference>
384384
<PackageReference Include="Microsoft.UI.Xaml">
385-
<Version>2.8.0-prerelease.220413001</Version>
385+
<Version>2.8.0-prerelease.220712001</Version>
386386
</PackageReference>
387387
<PackageReference Include="NAudio.Core">
388388
<Version>2.1.0</Version>
@@ -394,13 +394,13 @@
394394
<Version>13.0.1</Version>
395395
</PackageReference>
396396
<PackageReference Include="ShortDev.Uwp.FullTrust">
397-
<Version>0.1.3</Version>
397+
<Version>0.1.6</Version>
398398
</PackageReference>
399399
<PackageReference Include="UWPAudioVisualizer">
400400
<Version>1.0.38</Version>
401401
</PackageReference>
402402
<PackageReference Include="WinUI.Interop">
403-
<Version>0.2.4</Version>
403+
<Version>0.2.6</Version>
404404
</PackageReference>
405405
</ItemGroup>
406406
<ItemGroup>

VBAudioRouter.UWP/WelcomePage.xaml.vb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
Imports Windows.System
1+
Imports System.Runtime.InteropServices
2+
Imports Windows.System
23

34
Public NotInheritable Class WelcomePage
45
Inherits Page
56

7+
Public Sub New()
8+
InitializeComponent()
9+
End Sub
10+
611
Private Sub NavigationView_SelectionChanged(sender As Microsoft.UI.Xaml.Controls.NavigationView, args As Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs)
712
Dim navOptions As New FrameNavigationOptions()
813
navOptions.TransitionInfoOverride = args.RecommendedNavigationTransitionInfo

0 commit comments

Comments
 (0)