Skip to content

Commit

Permalink
close window option #509
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 30, 2023
1 parent c2d4859 commit 35f4fc1
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 5 deletions.
54 changes: 54 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1204,4 +1204,23 @@ Do you accept the risk and continue to use it?</value>
<data name="LauncherPage_ThisDay" xml:space="preserve">
<value>This Day</value>
</data>
<data name="ExperienceSettingPage_CloseWindowOption" xml:space="preserve">
<value>Close Window Option</value>
</data>
<data name="ExperienceSettingPage_MinimizeToSystemTray" xml:space="preserve">
<value>Minimize to system tray</value>
</data>
<data name="ExperienceSettingPage_ExitCompletely" xml:space="preserve">
<value>Exit completely</value>
</data>
<data name="ExperienceSettingPage_CloseWindowButKeepSystemTray" xml:space="preserve">
<value>Close window but keep system tray</value>
</data>
<data name="SettingPage_Experience" xml:space="preserve">
<value>Experience</value>
<comment>means user experience</comment>
</data>
<data name="CloseWindowDialog_YouCouldChangeTheOptionAgainInSettingPage" xml:space="preserve">
<value>You could change the option again in setting page.</value>
</data>
</root>
18 changes: 18 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1204,4 +1204,22 @@
<data name="LauncherPage_ThisDay" xml:space="preserve">
<value>本日</value>
</data>
<data name="CloseWindowDialog_YouCouldChangeTheOptionAgainInSettingPage" xml:space="preserve">
<value>你可以在设置页面再次更改此选项。</value>
</data>
<data name="SettingPage_Experience" xml:space="preserve">
<value>体验</value>
</data>
<data name="ExperienceSettingPage_CloseWindowButKeepSystemTray" xml:space="preserve">
<value>关闭窗口但保留系统托盘</value>
</data>
<data name="ExperienceSettingPage_ExitCompletely" xml:space="preserve">
<value>完全退出</value>
</data>
<data name="ExperienceSettingPage_MinimizeToSystemTray" xml:space="preserve">
<value>最小化到系统托盘</value>
</data>
<data name="ExperienceSettingPage_CloseWindowOption" xml:space="preserve">
<value>关闭窗口选项</value>
</data>
</root>
8 changes: 8 additions & 0 deletions src/Starward/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Starward.Core.Launcher;
using Starward.Core.Metadata;
using Starward.Core.SelfQuery;
using Starward.Models;
using Starward.Services;
using Starward.Services.Gacha;
using System;
Expand Down Expand Up @@ -413,6 +414,13 @@ public static bool ExitWhenClosing
}


public static CloseWindowOption CloseWindowOption
{
get => GetValue<CloseWindowOption>();
set => SetValue(value);
}


#endregion


Expand Down
32 changes: 32 additions & 0 deletions src/Starward/Controls/CloseWindowDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<UserControl x:Class="Starward.Controls.CloseWindowDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<StackPanel Spacing="4">

<TextBlock Margin="0,0,0,8"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind lang:Lang.CloseWindowDialog_YouCouldChangeTheOptionAgainInSettingPage}"
TextWrapping="Wrap" />
<RadioButton Click="RadioButton_Click"
Content="{x:Bind lang:Lang.ExperienceSettingPage_MinimizeToSystemTray}"
GroupName="CloseWindowOption"
IsChecked="True"
Tag="Hide" />
<RadioButton Click="RadioButton_Click"
Content="{x:Bind lang:Lang.ExperienceSettingPage_ExitCompletely}"
GroupName="CloseWindowOption"
Tag="Exit" />
<RadioButton Click="RadioButton_Click"
Content="{x:Bind lang:Lang.ExperienceSettingPage_CloseWindowButKeepSystemTray}"
GroupName="CloseWindowOption"
Tag="Close" />
</StackPanel>

</UserControl>
43 changes: 43 additions & 0 deletions src/Starward/Controls/CloseWindowDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Starward.Models;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Starward.Controls;

public sealed partial class CloseWindowDialog : UserControl
{


public CloseWindowOption CloseWindowOption { get; private set; } = CloseWindowOption.Hide;


public CloseWindowDialog()
{
this.InitializeComponent();
}


private void RadioButton_Click(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement element)
{
if (element.Tag is "Hide")
{
CloseWindowOption = CloseWindowOption.Hide;
}
else if (element.Tag is "Exit")
{
CloseWindowOption = CloseWindowOption.Exit;
}
else if (element.Tag is "Close")
{
CloseWindowOption = CloseWindowOption.Close;
}
}
}


}
13 changes: 13 additions & 0 deletions src/Starward/Models/CloseWindowOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Starward.Models;

public enum CloseWindowOption
{

Undefined = 0,

Hide = 1,

Exit = 2,

Close = 3,
}
46 changes: 42 additions & 4 deletions src/Starward/MyWindows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Starward.Controls;
using Starward.Models;
using Starward.Pages;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -102,11 +105,46 @@ public void ChangeWindowSize(int width = 0, int height = 0)
}


private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
{
args.Cancel = true;
// todo
App.Current.Exit();
try
{
args.Cancel = true;
CloseWindowOption option = AppConfig.CloseWindowOption;
if (option is not CloseWindowOption.Hide and not CloseWindowOption.Exit and not CloseWindowOption.Close)
{
var content = new CloseWindowDialog();
var dialog = new ContentDialog
{
Content = content,
Title = Lang.ExperienceSettingPage_CloseWindowOption,
PrimaryButtonText = Lang.Common_Confirm,
CloseButtonText = Lang.Common_Cancel,
DefaultButton = ContentDialogButton.Primary,
XamlRoot = Content.XamlRoot,
};
var result = await dialog.ShowAsync();
if (result is not ContentDialogResult.Primary)
{
return;
}
option = content.CloseWindowOption;
AppConfig.CloseWindowOption = option;
}
if (option is CloseWindowOption.Hide)
{
Hide();
}
if (option is CloseWindowOption.Exit)
{
App.Current.Exit();
}
if (option is CloseWindowOption.Close)
{
App.Current.CloseMainWindow();
}
}
catch { }
}


Expand Down
38 changes: 38 additions & 0 deletions src/Starward/Pages/Setting/ExperienceSettingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<sp:PageBase x:Class="Starward.Pages.Setting.ExperienceSettingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.Pages.Setting"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sp="using:Starward.Pages"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<ScrollViewer>
<StackPanel>

<!-- close window option -->
<TextBlock FontSize="20"
FontWeight="SemiBold"
Text="{x:Bind lang:Lang.ExperienceSettingPage_CloseWindowOption}" />
<Border Height="36"
Margin="0,12,0,0"
HorizontalAlignment="Left"
Background="{ThemeResource CustomOverlayAcrylicBrush}"
CornerRadius="8,18,18,8">
<ComboBox Name="ComboBox_CloseWindowOption"
Height="36"
MinWidth="280"
Padding="18.5,0,0,0"
BorderThickness="0"
CornerRadius="8,18,18,8"
SelectionChanged="ComboBox_CloseWindowOption_SelectionChanged" />
</Border>



</StackPanel>
</ScrollViewer>

</sp:PageBase>
Loading

0 comments on commit 35f4fc1

Please sign in to comment.