mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Fix dialog modal blocking, reorganize UI code
This commit is contained in:
parent
53a64881cd
commit
9d7f9f7ba3
@ -314,9 +314,9 @@ namespace Bloxstrap
|
||||
FinalizeExceptionHandling(exception);
|
||||
});
|
||||
|
||||
NotifyIcon?.InitializeContextMenu();
|
||||
|
||||
// this ordering is very important as all wpf windows are shown as modal dialogs, mess it up and you'll end up blocking input to one of them
|
||||
dialog?.ShowBootstrapper();
|
||||
NotifyIcon?.InitializeContextMenu();
|
||||
|
||||
bootstrapperTask.Wait();
|
||||
|
||||
|
@ -15,14 +15,15 @@
|
||||
ShowInTaskbar="False"
|
||||
WindowStyle="None"
|
||||
ResizeMode="NoResize"
|
||||
Loaded="Window_Loaded">
|
||||
Loaded="Window_Loaded"
|
||||
Closed="Window_Closed">
|
||||
<ui:UiWindow.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
||||
<Separator />
|
||||
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" IsChecked="True" Visibility="Collapsed" />
|
||||
<MenuItem x:Name="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" />
|
||||
<MenuItem x:Name="LogTracerMenuItem" Header="Open log tracer" Visibility="Collapsed" />
|
||||
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" IsChecked="True" Visibility="Collapsed" Click="RichPresenceMenuItem_Click" />
|
||||
<MenuItem x:Name="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" Click="ServerDetailsMenuItem_Click" />
|
||||
<MenuItem x:Name="LogTracerMenuItem" Header="Open log tracer" Visibility="Collapsed" Click="LogTracerMenuItem_Click" />
|
||||
</ContextMenu>
|
||||
</ui:UiWindow.ContextMenu>
|
||||
</ui:UiWindow>
|
||||
|
@ -13,7 +13,7 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using Bloxstrap.UI.ViewModels;
|
||||
using Bloxstrap.Integrations;
|
||||
|
||||
namespace Bloxstrap.UI.Elements.ContextMenu
|
||||
{
|
||||
@ -24,13 +24,47 @@ namespace Bloxstrap.UI.Elements.ContextMenu
|
||||
{
|
||||
// i wouldve gladly done this as mvvm but turns out that data binding just does not work with menuitems for some reason so idk this sucks
|
||||
|
||||
public MenuContainer()
|
||||
private readonly RobloxActivity? _activityWatcher;
|
||||
private readonly DiscordRichPresence? _richPresenceHandler;
|
||||
|
||||
private LogTracer? _logTracerWindow;
|
||||
private ServerInformation? _serverInformationWindow;
|
||||
|
||||
public MenuContainer(RobloxActivity? activityWatcher, DiscordRichPresence? richPresenceHandler)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_activityWatcher = activityWatcher;
|
||||
_richPresenceHandler = richPresenceHandler;
|
||||
|
||||
if (_activityWatcher is not null)
|
||||
{
|
||||
LogTracerMenuItem.Visibility = Visibility.Visible;
|
||||
|
||||
_activityWatcher.OnGameJoin += ActivityWatcher_OnGameJoin;
|
||||
_activityWatcher.OnGameLeave += ActivityWatcher_OnGameLeave;
|
||||
}
|
||||
|
||||
if (_richPresenceHandler is not null)
|
||||
RichPresenceMenuItem.Visibility = Visibility.Visible;
|
||||
|
||||
VersionMenuItem.Header = $"{App.ProjectName} v{App.Version}";
|
||||
}
|
||||
|
||||
public void ShowServerInformationWindow()
|
||||
{
|
||||
if (_serverInformationWindow is null)
|
||||
{
|
||||
_serverInformationWindow = new ServerInformation(_activityWatcher!);
|
||||
_serverInformationWindow.Closed += (_, _) => _serverInformationWindow = null;
|
||||
}
|
||||
|
||||
if (!_serverInformationWindow.IsVisible)
|
||||
_serverInformationWindow.Show();
|
||||
|
||||
_serverInformationWindow.Activate();
|
||||
}
|
||||
|
||||
private void Window_Loaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// this is an awful hack lmao im so sorry to anyone who reads this
|
||||
@ -42,5 +76,35 @@ namespace Bloxstrap.UI.Elements.ContextMenu
|
||||
exStyle |= NativeMethods.WS_EX_TOOLWINDOW;
|
||||
NativeMethods.SetWindowLongPtr(wndHelper.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)exStyle);
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, EventArgs e) => App.Logger.WriteLine("[MenuContainer::Window_Closed] Context menu container closed");
|
||||
|
||||
private void RichPresenceMenuItem_Click(object sender, RoutedEventArgs e) => _richPresenceHandler?.SetVisibility(((MenuItem)sender).IsChecked);
|
||||
|
||||
private void ServerDetailsMenuItem_Click(object sender, RoutedEventArgs e) => ShowServerInformationWindow();
|
||||
|
||||
private void LogTracerMenuItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_logTracerWindow is null)
|
||||
{
|
||||
_logTracerWindow = new LogTracer(_activityWatcher!);
|
||||
_logTracerWindow.Closed += (_, _) => _logTracerWindow = null;;
|
||||
}
|
||||
|
||||
if (!_logTracerWindow.IsVisible)
|
||||
_logTracerWindow.Show();
|
||||
|
||||
_logTracerWindow.Activate();
|
||||
}
|
||||
|
||||
private void ActivityWatcher_OnGameJoin(object? sender, EventArgs e) => Dispatcher.Invoke(() => ServerDetailsMenuItem.Visibility = Visibility.Visible);
|
||||
|
||||
private void ActivityWatcher_OnGameLeave(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.Invoke(() => {
|
||||
ServerDetailsMenuItem.Visibility = Visibility.Collapsed;
|
||||
_serverInformationWindow?.Close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,6 @@ namespace Bloxstrap.UI
|
||||
private RobloxActivity? _activityWatcher;
|
||||
private DiscordRichPresence? _richPresenceHandler;
|
||||
|
||||
private ServerInformation? _serverInformationWindow;
|
||||
private LogTracer? _logTracerWindow;
|
||||
|
||||
EventHandler? _alertClickHandler;
|
||||
|
||||
public NotifyIconWrapper()
|
||||
@ -43,11 +40,6 @@ namespace Bloxstrap.UI
|
||||
return;
|
||||
|
||||
_richPresenceHandler = richPresenceHandler;
|
||||
|
||||
if (_menuContainer is null)
|
||||
return;
|
||||
|
||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.RichPresenceMenuItem.Visibility = Visibility.Visible);
|
||||
}
|
||||
|
||||
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
||||
@ -56,11 +48,9 @@ namespace Bloxstrap.UI
|
||||
return;
|
||||
|
||||
_activityWatcher = activityWatcher;
|
||||
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
||||
_activityWatcher.OnGameLeave += OnGameLeave;
|
||||
|
||||
if (App.Settings.Prop.OhHeyYouFoundMe && _menuContainer is not null)
|
||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.LogTracerMenuItem.Visibility = Visibility.Visible);
|
||||
if (App.Settings.Prop.ShowServerDetails)
|
||||
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -70,12 +60,8 @@ namespace Bloxstrap.UI
|
||||
if (_menuContainer is not null)
|
||||
return;
|
||||
|
||||
_menuContainer = new();
|
||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
||||
_menuContainer.RichPresenceMenuItem.Click += (_, _) => _richPresenceHandler?.SetVisibility(_menuContainer.RichPresenceMenuItem.IsChecked);
|
||||
_menuContainer.ServerDetailsMenuItem.Click += (_, _) => ShowServerInformationWindow();
|
||||
_menuContainer.LogTracerMenuItem.Click += (_, _) => ShowLogTracerWindow();
|
||||
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
||||
_menuContainer = new(_activityWatcher, _richPresenceHandler);
|
||||
_menuContainer.ShowDialog();
|
||||
}
|
||||
|
||||
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
||||
@ -91,52 +77,8 @@ namespace Bloxstrap.UI
|
||||
#region Activity handlers
|
||||
public async void OnGameJoin()
|
||||
{
|
||||
if (_menuContainer is not null)
|
||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Visible);
|
||||
|
||||
if (App.Settings.Prop.ShowServerDetails)
|
||||
{
|
||||
string serverLocation = await _activityWatcher!.GetServerLocation();
|
||||
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => ShowServerInformationWindow());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGameLeave(object? sender, EventArgs e)
|
||||
{
|
||||
_menuContainer?.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Collapsed);
|
||||
|
||||
if (_serverInformationWindow is not null && _serverInformationWindow.IsVisible)
|
||||
_serverInformationWindow.Dispatcher.Invoke(_serverInformationWindow.Close);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Window handlers
|
||||
public void ShowServerInformationWindow()
|
||||
{
|
||||
if (_serverInformationWindow is null)
|
||||
{
|
||||
_serverInformationWindow = new ServerInformation(_activityWatcher!);
|
||||
_serverInformationWindow.Closed += (_, _) => _serverInformationWindow = null;
|
||||
}
|
||||
|
||||
if (!_serverInformationWindow.IsVisible)
|
||||
_serverInformationWindow.Show();
|
||||
|
||||
_serverInformationWindow.Activate();
|
||||
}
|
||||
|
||||
public void ShowLogTracerWindow()
|
||||
{
|
||||
if (_logTracerWindow is null)
|
||||
{
|
||||
_logTracerWindow = new LogTracer(_activityWatcher!);
|
||||
_logTracerWindow.Closed += (_, _) => _logTracerWindow = null;
|
||||
}
|
||||
|
||||
if (!_logTracerWindow.IsVisible)
|
||||
_logTracerWindow.Show();
|
||||
|
||||
_logTracerWindow.Activate();
|
||||
string serverLocation = await _activityWatcher!.GetServerLocation();
|
||||
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => _menuContainer?.ShowServerInformationWindow());
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -183,9 +125,7 @@ namespace Bloxstrap.UI
|
||||
|
||||
App.Logger.WriteLine($"[NotifyIconWrapper::Dispose] Disposing NotifyIcon");
|
||||
|
||||
if (_menuContainer is not null)
|
||||
_menuContainer.Dispatcher.Invoke(_menuContainer.Close);
|
||||
|
||||
_menuContainer?.Dispatcher.Invoke(_menuContainer.Close);
|
||||
_notifyIcon.Dispose();
|
||||
|
||||
_disposed = true;
|
||||
|
Loading…
Reference in New Issue
Block a user