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);
|
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();
|
dialog?.ShowBootstrapper();
|
||||||
|
NotifyIcon?.InitializeContextMenu();
|
||||||
|
|
||||||
bootstrapperTask.Wait();
|
bootstrapperTask.Wait();
|
||||||
|
|
||||||
|
@ -15,14 +15,15 @@
|
|||||||
ShowInTaskbar="False"
|
ShowInTaskbar="False"
|
||||||
WindowStyle="None"
|
WindowStyle="None"
|
||||||
ResizeMode="NoResize"
|
ResizeMode="NoResize"
|
||||||
Loaded="Window_Loaded">
|
Loaded="Window_Loaded"
|
||||||
|
Closed="Window_Closed">
|
||||||
<ui:UiWindow.ContextMenu>
|
<ui:UiWindow.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
||||||
<Separator />
|
<Separator />
|
||||||
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" IsChecked="True" 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" />
|
<MenuItem x:Name="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" Click="ServerDetailsMenuItem_Click" />
|
||||||
<MenuItem x:Name="LogTracerMenuItem" Header="Open log tracer" Visibility="Collapsed" />
|
<MenuItem x:Name="LogTracerMenuItem" Header="Open log tracer" Visibility="Collapsed" Click="LogTracerMenuItem_Click" />
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</ui:UiWindow.ContextMenu>
|
</ui:UiWindow.ContextMenu>
|
||||||
</ui:UiWindow>
|
</ui:UiWindow>
|
||||||
|
@ -13,7 +13,7 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
using Bloxstrap.UI.ViewModels;
|
using Bloxstrap.Integrations;
|
||||||
|
|
||||||
namespace Bloxstrap.UI.Elements.ContextMenu
|
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
|
// 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();
|
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}";
|
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)
|
private void Window_Loaded(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// this is an awful hack lmao im so sorry to anyone who reads this
|
// 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;
|
exStyle |= NativeMethods.WS_EX_TOOLWINDOW;
|
||||||
NativeMethods.SetWindowLongPtr(wndHelper.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)exStyle);
|
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 RobloxActivity? _activityWatcher;
|
||||||
private DiscordRichPresence? _richPresenceHandler;
|
private DiscordRichPresence? _richPresenceHandler;
|
||||||
|
|
||||||
private ServerInformation? _serverInformationWindow;
|
|
||||||
private LogTracer? _logTracerWindow;
|
|
||||||
|
|
||||||
EventHandler? _alertClickHandler;
|
EventHandler? _alertClickHandler;
|
||||||
|
|
||||||
public NotifyIconWrapper()
|
public NotifyIconWrapper()
|
||||||
@ -43,11 +40,6 @@ namespace Bloxstrap.UI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_richPresenceHandler = richPresenceHandler;
|
_richPresenceHandler = richPresenceHandler;
|
||||||
|
|
||||||
if (_menuContainer is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.RichPresenceMenuItem.Visibility = Visibility.Visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
||||||
@ -56,11 +48,9 @@ namespace Bloxstrap.UI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_activityWatcher = activityWatcher;
|
_activityWatcher = activityWatcher;
|
||||||
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
|
||||||
_activityWatcher.OnGameLeave += OnGameLeave;
|
|
||||||
|
|
||||||
if (App.Settings.Prop.OhHeyYouFoundMe && _menuContainer is not null)
|
if (App.Settings.Prop.ShowServerDetails)
|
||||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.LogTracerMenuItem.Visibility = Visibility.Visible);
|
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -70,12 +60,8 @@ namespace Bloxstrap.UI
|
|||||||
if (_menuContainer is not null)
|
if (_menuContainer is not null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_menuContainer = new();
|
_menuContainer = new(_activityWatcher, _richPresenceHandler);
|
||||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
_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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
||||||
@ -90,53 +76,9 @@ namespace Bloxstrap.UI
|
|||||||
|
|
||||||
#region Activity handlers
|
#region Activity handlers
|
||||||
public async void OnGameJoin()
|
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();
|
string serverLocation = await _activityWatcher!.GetServerLocation();
|
||||||
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => ShowServerInformationWindow());
|
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => _menuContainer?.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();
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -183,9 +125,7 @@ namespace Bloxstrap.UI
|
|||||||
|
|
||||||
App.Logger.WriteLine($"[NotifyIconWrapper::Dispose] Disposing NotifyIcon");
|
App.Logger.WriteLine($"[NotifyIconWrapper::Dispose] Disposing NotifyIcon");
|
||||||
|
|
||||||
if (_menuContainer is not null)
|
_menuContainer?.Dispatcher.Invoke(_menuContainer.Close);
|
||||||
_menuContainer.Dispatcher.Invoke(_menuContainer.Close);
|
|
||||||
|
|
||||||
_notifyIcon.Dispose();
|
_notifyIcon.Dispose();
|
||||||
|
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user