bloxstrap/Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs
pizzaboxer fd290f9ff7
Move activity watcher to separate process (#810)
this was done to:
- ensure robloxplayerbeta launches as an orphaned process
- help alleviate problems with multiple instances
- alleviate problems with the notifyicon causing blocking conflicts on the bootstrapper ui thread
- help reduce functional dependency on the bootstrapper, makes it less monolithic and more maintainable

ive always wanted to do this for a long while, but have always put it off because of how painful it would be

this may genuinely be the most painful refactoring i've ever had to do, but after 2 days, i managed to do it, and it works great!
2024-08-28 22:47:04 +01:00

75 lines
2.1 KiB
C#

using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Wpf.Ui.Controls.Interfaces;
using Wpf.Ui.Mvvm.Contracts;
using Bloxstrap.UI.ViewModels.Settings;
namespace Bloxstrap.UI.Elements.Settings
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : INavigationWindow
{
public MainWindow(bool showAlreadyRunningWarning)
{
var viewModel = new MainWindowViewModel();
viewModel.RequestSaveNoticeEvent += (_, _) => SettingsSavedSnackbar.Show();
viewModel.RequestCloseWindowEvent += (_, _) => Close();
DataContext = viewModel;
InitializeComponent();
App.Logger.WriteLine("MainWindow::MainWindow", "Initializing menu");
#if DEBUG // easier access
EditorWarningNavItem.Visibility = Visibility.Visible;
#endif
if (showAlreadyRunningWarning)
ShowAlreadyRunningSnackbar();
}
private async void ShowAlreadyRunningSnackbar()
{
await Task.Delay(500); // wait for everything to finish loading
AlreadyRunningSnackbar.Show();
}
#region INavigationWindow methods
public Frame GetFrame() => RootFrame;
public INavigation GetNavigation() => RootNavigation;
public bool Navigate(Type pageType) => RootNavigation.Navigate(pageType);
public void SetPageService(IPageService pageService) => RootNavigation.PageService = pageService;
public void ShowWindow() => Show();
public void CloseWindow() => Close();
#endregion INavigationWindow methods
private void WpfUiWindow_Closing(object sender, CancelEventArgs e)
{
if (App.FastFlags.Changed || App.PendingSettingTasks.Any())
{
var result = Frontend.ShowMessageBox(Strings.Menu_UnsavedChanges, MessageBoxImage.Warning, MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes)
e.Cancel = true;
}
if (!e.Cancel)
App.Terminate();
}
}
}