Skip to content

Commit 38f02a3

Browse files
committed
main view host
1 parent c0fe889 commit 38f02a3

16 files changed

+1225
-5
lines changed

src/Starward/AppSetting.cs

Lines changed: 557 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl x:Class="Starward.Features.Main.MainView"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:Starward.Features.Main"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<Grid>
11+
<Image HorizontalAlignment="Center"
12+
VerticalAlignment="Center"
13+
Source="ms-appx:///Assets/Image/UI_CutScene_1130320101A.png"
14+
Stretch="UniformToFill" />
15+
</Grid>
16+
17+
</UserControl>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
3+
4+
namespace Starward.Features.Main
5+
{
6+
public sealed partial class MainView : UserControl
7+
{
8+
public MainView()
9+
{
10+
this.InitializeComponent();
11+
}
12+
}
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<sf:WindowEx x:Class="Starward.Features.Main.MainWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:Starward.Features.Main"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:mxi="using:Microsoft.Xaml.Interactivity"
9+
xmlns:sf="using:Starward.Frameworks"
10+
xmlns:sh="using:Starward.Helpers"
11+
x:DefaultBindMode="OneWay"
12+
mc:Ignorable="d">
13+
14+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
15+
16+
<ContentControl x:Name="MainContentHost"
17+
HorizontalContentAlignment="Stretch"
18+
VerticalContentAlignment="Stretch" />
19+
20+
<StackPanel MaxWidth="600"
21+
Margin="24,72,24,72"
22+
VerticalAlignment="Bottom">
23+
<StackPanel.Transitions>
24+
<TransitionCollection>
25+
<AddDeleteThemeTransition />
26+
</TransitionCollection>
27+
</StackPanel.Transitions>
28+
<mxi:Interaction.Behaviors>
29+
<sh:InAppToast Tag="MainWindow" />
30+
</mxi:Interaction.Behaviors>
31+
</StackPanel>
32+
33+
</Grid>
34+
35+
</sf:WindowEx>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using Microsoft.UI.Windowing;
3+
using Microsoft.UI.Xaml.Controls;
4+
using Starward.Frameworks;
5+
using System;
6+
using System.ComponentModel;
7+
using System.Runtime.InteropServices;
8+
using Vanara.PInvoke;
9+
using Windows.Graphics;
10+
11+
12+
namespace Starward.Features.Main;
13+
14+
/// <summary>
15+
/// An empty window that can be used on its own or navigated to within a Frame.
16+
/// </summary>
17+
[INotifyPropertyChanged]
18+
public sealed partial class MainWindow : WindowEx
19+
{
20+
21+
22+
public static new MainWindow Current { get; private set; }
23+
24+
25+
26+
public MainWindow()
27+
{
28+
Current = this;
29+
this.InitializeComponent();
30+
InitializeMainWindow();
31+
if (string.IsNullOrWhiteSpace(AppSetting.UserDataFolder))
32+
{
33+
MainContentHost.Content = new WelcomeView();
34+
}
35+
else
36+
{
37+
MainContentHost.Content = new MainView();
38+
App.Current.InitializeSystemTray();
39+
}
40+
}
41+
42+
43+
44+
private void InitializeMainWindow()
45+
{
46+
Title = "Starward";
47+
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
48+
AppWindow.TitleBar.IconShowOptions = IconShowOptions.ShowIconAndSystemMenu;
49+
AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
50+
AppWindow.Closing += AppWindow_Closing;
51+
CenterInScreen(1200, 676);
52+
AdaptTitleBarButtonColorToActuallTheme();
53+
SetDragRectangles(new RectInt32(0, 0, 100000, (int)(48 * UIScale)));
54+
SetIcon();
55+
WTSRegisterSessionNotification(WindowHandle, 0);
56+
if (AppWindow.Presenter is OverlappedPresenter presenter)
57+
{
58+
presenter.IsMaximizable = false;
59+
presenter.IsResizable = false;
60+
}
61+
}
62+
63+
64+
private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
65+
{
66+
try
67+
{
68+
if (string.IsNullOrWhiteSpace(AppSetting.UserDataFolder))
69+
{
70+
App.Current.Exit();
71+
return;
72+
}
73+
args.Cancel = true;
74+
MainWindowCloseOption option = AppSetting.CloseWindowOption;
75+
if (option is not MainWindowCloseOption.Hide and not MainWindowCloseOption.Exit)
76+
{
77+
var dialog = new MainWindowCloseDialog
78+
{
79+
Title = Lang.ExperienceSettingPage_CloseWindowOption,
80+
PrimaryButtonText = Lang.Common_Confirm,
81+
CloseButtonText = Lang.Common_Cancel,
82+
DefaultButton = ContentDialogButton.Primary,
83+
XamlRoot = Content.XamlRoot,
84+
};
85+
var result = await dialog.ShowAsync();
86+
if (result is not ContentDialogResult.Primary)
87+
{
88+
return;
89+
}
90+
option = dialog.MainWindowCloseOption.Value;
91+
AppSetting.CloseWindowOption = option;
92+
}
93+
if (option is MainWindowCloseOption.Hide)
94+
{
95+
Hide();
96+
}
97+
if (option is MainWindowCloseOption.Exit)
98+
{
99+
App.Current.Exit();
100+
}
101+
}
102+
catch { }
103+
}
104+
105+
106+
protected override nint WindowSubclassProc(HWND hWnd, uint uMsg, nint wParam, nint lParam, nuint uIdSubclass, nint dwRefData)
107+
{
108+
if (uMsg == (uint)User32.WindowMessage.WM_SYSCOMMAND)
109+
{
110+
// SC_MAXIMIZE
111+
if (wParam == 0xF030)
112+
{
113+
return IntPtr.Zero;
114+
}
115+
}
116+
if (uMsg == (uint)User32.WindowMessage.WM_WTSSESSION_CHANGE)
117+
{
118+
// WTS_SESSION_LOCK
119+
if (wParam == 0x7)
120+
{
121+
122+
}
123+
// WTS_SESSION_UNLOCK
124+
if (wParam == 0x8)
125+
{
126+
127+
}
128+
}
129+
return base.WindowSubclassProc(hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData);
130+
}
131+
132+
133+
134+
[LibraryImport("wtsapi32.dll")]
135+
[return: MarshalAs(UnmanagedType.Bool)]
136+
private static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);
137+
138+
139+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentDialog x:Class="Starward.Features.Main.MainWindowCloseDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:lang="using:Starward.Language"
7+
xmlns:local="using:Starward.Features.Main"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Background="{ThemeResource CustomAcrylicBrush}"
10+
BorderThickness="0"
11+
Style="{ThemeResource DefaultContentDialogStyle}"
12+
mc:Ignorable="d">
13+
14+
15+
<StackPanel Spacing="4">
16+
17+
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}"
18+
Text="{x:Bind lang:Lang.CloseWindowDialog_YouCouldChangeTheOptionAgainInSettingPage}"
19+
TextWrapping="Wrap" />
20+
<RadioButtons ItemsSource="{x:Bind MainWindowCloseOption.Items}" SelectedItem="{x:Bind MainWindowCloseOption.SelectedItem, Mode=TwoWay}" />
21+
22+
</StackPanel>
23+
24+
</ContentDialog>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Starward.Helpers.Enumeration;
4+
using System.ComponentModel;
5+
6+
7+
namespace Starward.Features.Main;
8+
9+
[INotifyPropertyChanged]
10+
public sealed partial class MainWindowCloseDialog : ContentDialog
11+
{
12+
13+
14+
public MainWindowCloseDialog()
15+
{
16+
this.InitializeComponent();
17+
}
18+
19+
20+
21+
public EnumItemsSource<MainWindowCloseOption> MainWindowCloseOption
22+
{
23+
get;
24+
set => SetProperty(ref field, value);
25+
} = new(Main.MainWindowCloseOption.Hide);
26+
27+
28+
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Starward.Helpers.Enumeration;
2+
3+
namespace Starward.Features.Main;
4+
5+
/// <summary>
6+
/// 关闭主窗口的选项
7+
/// </summary>
8+
public enum MainWindowCloseOption
9+
{
10+
11+
/// <summary>
12+
/// 隐藏窗口
13+
/// </summary>
14+
[LocalizationKey(nameof(Lang.ExperienceSettingPage_MinimizeToSystemTray))]
15+
Hide = 1,
16+
17+
/// <summary>
18+
/// 退出进程
19+
/// </summary>
20+
[LocalizationKey(nameof(Lang.ExperienceSettingPage_ExitCompletely))]
21+
Exit = 2,
22+
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl x:Class="Starward.Features.Main.WelcomeView"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:Starward.Features.Main"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<Grid>
11+
<Image HorizontalAlignment="Center"
12+
VerticalAlignment="Center"
13+
Source="ms-appx:///Assets/Image/UI_CutScene_1130320101A.png"
14+
Stretch="UniformToFill" />
15+
</Grid>
16+
</UserControl>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
3+
4+
namespace Starward.Features.Main;
5+
6+
public sealed partial class WelcomeView : UserControl
7+
{
8+
public WelcomeView()
9+
{
10+
this.InitializeComponent();
11+
}
12+
}

0 commit comments

Comments
 (0)