diff --git a/RustTools/App.xaml.cs b/RustTools/App.xaml.cs index 28b3ab3..4105107 100644 --- a/RustTools/App.xaml.cs +++ b/RustTools/App.xaml.cs @@ -1,8 +1,7 @@ -using System.Threading; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; - using RustTools.Contracts.Services; using RustTools.Models; using RustTools.Services; @@ -10,14 +9,10 @@ using RustTools.ViewModels; using RustTools.Views; using RustTools.muqing; using RustTools.Activation; -using System.Diagnostics; using RustTools.WindowUI; using Windows.ApplicationModel.Activation; -using Windows.Storage; -using Microsoft.UI.Xaml.Controls; using Microsoft.Windows.AppLifecycle; -using Windows.ApplicationModel; -using Windows.Management.Core; +using WinUIEx; namespace RustTools; @@ -47,7 +42,7 @@ public partial class App : Microsoft.UI.Xaml.Application public static UIElement? AppTitlebar { get; set; } - public static WindowEx MainWindow { get; } = new MainWindow(); + public static WindowEx? MainWindow; public App() { @@ -116,7 +111,6 @@ public partial class App : Microsoft.UI.Xaml.Application protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { base.OnLaunched(args); - var activatedEventArgs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs(); if (activatedEventArgs.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File) { @@ -158,7 +152,10 @@ public partial class App : Microsoft.UI.Xaml.Application else { //MainWindow.Activate(); - await App.GetService().ActivateAsync(args); + //MainWindow = new MainWindow(); + var editor=new Editor.EditorWin(); + editor.Activate(); + //await App.GetService().ActivateAsync(args); } } } diff --git a/RustTools/Editor/EditorWin.xaml b/RustTools/Editor/EditorWin.xaml new file mode 100644 index 0000000..84577a7 --- /dev/null +++ b/RustTools/Editor/EditorWin.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/RustTools/Editor/EditorWin.xaml.cs b/RustTools/Editor/EditorWin.xaml.cs new file mode 100644 index 0000000..e7ea4c2 --- /dev/null +++ b/RustTools/Editor/EditorWin.xaml.cs @@ -0,0 +1,99 @@ +using System.ComponentModel; +using System.Runtime.InteropServices; +using Microsoft.UI; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using RustTools.muqing; +using Windows.ApplicationModel.Core; +using Windows.Foundation; +using Windows.UI.Core.Preview; +using Windows.UI.Popups; +using Windows.UI.WindowManagement; +using WinRT.Interop; +namespace RustTools.Editor; +/// +/// ༭ +/// +public sealed partial class EditorWin : WindowEx +{ + + private Microsoft.UI.Windowing.AppWindow? app; + public EditorWin() + { + InitializeComponent(); + gj.SetBackTheme(this); + ExtendsContentIntoTitleBar = true; + var frame = App.AppTitlebar as FrameworkElement; + if (frame != null) + { + gj.UpdateTitleBar(this, frame.ActualTheme); + grid.RequestedTheme = frame.ActualTheme; + } + + //WindowManager.Get(this).IsMinimizable = false; + //WindowManager.Get(this).IsMaximizable = false; + //WindowManager.Get(this).IsResizable = false; + //WindowManager.Get(this).IsAlwaysOnTop = false; + //WindowManager.Get(this).IsTitleBarVisible = false; + + + //app = GetAppWindowForCurrentWindow(); + //app.Closing += OnClosing; + //Closed += EditorWin_Closed; + + Closed += EditorWin_Closed; + } + + private async Task SaveDataAsync() + { + + } + //ûûб + private bool IsSave = false; + private ContentDialog? ClosedDialog; + private async void EditorWin_Closed(object sender, WindowEventArgs e) + { + if (IsSave == false) + { + // ֹڹر + e.Handled = true; + } + if (ClosedDialog != null) { + return; + } + // ʾһԻ򣬸֪ûڲܹر + ClosedDialog = new ContentDialog + { + XamlRoot = grid.XamlRoot, + Title = "", + Content = "㻹δļڱС", + PrimaryButtonText = "ر", + PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style, + SecondaryButtonText = "ֱӹر", + CloseButtonText = "ȡ" + }; + var result = await ClosedDialog.ShowAsync(); + if (result == ContentDialogResult.Primary) + { + IsSave = true; + Application.Current.Exit(); + return; + } + else if (result == ContentDialogResult.Secondary) + { + + IsSave = true; + Application.Current.Exit(); + return; + } + ClosedDialog = null; + } + + private Microsoft.UI.Windowing.AppWindow GetAppWindowForCurrentWindow() + { + var hWnd = WindowNative.GetWindowHandle(this); + var myWndId = Win32Interop.GetWindowIdFromWindow(hWnd); + return Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId); + } +} diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index 3a33ce2..66ddfe7 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using Microsoft.UI.Xaml; using RustTools.Helpers; using RustTools.muqing; +using RustTools.WindowUI; using Windows.Storage; using Windows.UI.ViewManagement; @@ -26,6 +27,7 @@ public sealed partial class MainWindow : WindowEx dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event + //var editorWin = new Editor.EditorWin(); } // this handles updating the caption button colors correctly when indows system theme is changed diff --git a/RustTools/WindowUI/ModuleInfoWin.xaml.cs b/RustTools/WindowUI/ModuleInfoWin.xaml.cs index 3b97492..26e65af 100644 --- a/RustTools/WindowUI/ModuleInfoWin.xaml.cs +++ b/RustTools/WindowUI/ModuleInfoWin.xaml.cs @@ -31,13 +31,16 @@ public sealed partial class ModuleInfoWin : WindowEx InitializeComponent(); ExtendsContentIntoTitleBar = true; gj.SetBackTheme(this); - init(v); var frame = App.AppTitlebar as FrameworkElement; if (frame != null) { gj.UpdateTitleBar(this, frame.ActualTheme); grid.RequestedTheme = frame.ActualTheme; } + if (v != string.Empty) + { + init(v); + } // ôڱɫ } private async void init(string v) @@ -185,7 +188,6 @@ public sealed partial class ModuleInfoWin : WindowEx private void DownloadDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) { - // Prevent the dialog from closing if (args.Result != ContentDialogResult.Secondary) { diff --git a/RustTools/muqing/gj.cs b/RustTools/muqing/gj.cs index 8109580..c8216f0 100644 --- a/RustTools/muqing/gj.cs +++ b/RustTools/muqing/gj.cs @@ -85,31 +85,6 @@ public class gj } } - public static void SetBackColor(WindowEx windowEx) - { - var uISettings = new UISettings(); - // 获取当前的背景颜色 - var backgroundColor = uISettings.GetColorValue(UIColorType.Background); - - // 判断主题模式 - if (backgroundColor == Colors.Black) - { - // 设置背景色为黑色 - //uISettings.SetColorValue(UIColorType.Background, Colors.Black); - //uISettings.SetColorValue(UIColorType.Foreground, Colors.White); - } - else if (backgroundColor == Colors.White) - { - // 设置背景色为白色 - //uISettings.SetColorValue(UIColorType.Background, Colors.White); - //uISettings.SetColorValue(UIColorType.Foreground, Colors.Black); - } - else - { - Console.WriteLine("Current theme mode is unknown."); - } - } - private const int WAINACTIVE = 0x00; private const int WAACTIVE = 0x01;