mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11:27 -07:00
Add context menu option for toggling rich presence
This commit is contained in:
parent
b677ce5aea
commit
05185e9e9a
@ -259,8 +259,7 @@ namespace Bloxstrap
|
||||
App.Logger.WriteLine("[Bootstrapper::StartRoblox] Using Discord Rich Presence");
|
||||
richPresence = new(activityWatcher);
|
||||
|
||||
if (App.NotifyIcon is not null)
|
||||
App.NotifyIcon.RichPresenceIntegration = richPresence;
|
||||
App.NotifyIcon?.SetRichPresenceHandler(richPresence);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ namespace Bloxstrap.Integrations
|
||||
private readonly RobloxActivity _activityWatcher;
|
||||
|
||||
private RichPresence? _currentPresence;
|
||||
private bool _visible = true;
|
||||
private string? _initialStatus;
|
||||
private long _currentUniverseId;
|
||||
private DateTime? _timeStartedUniverse;
|
||||
@ -89,6 +90,18 @@ namespace Bloxstrap.Integrations
|
||||
UpdatePresence();
|
||||
}
|
||||
|
||||
public void SetVisibility(bool visible)
|
||||
{
|
||||
App.Logger.WriteLine($"[DiscordRichPresence::SetVisibility] Setting presence visibility ({visible})");
|
||||
|
||||
_visible = visible;
|
||||
|
||||
if (_visible)
|
||||
UpdatePresence();
|
||||
else
|
||||
_rpcClient.ClearPresence();
|
||||
}
|
||||
|
||||
public async Task<bool> SetCurrentGame()
|
||||
{
|
||||
if (!_activityWatcher.ActivityInGame)
|
||||
@ -195,6 +208,7 @@ namespace Bloxstrap.Integrations
|
||||
return;
|
||||
}
|
||||
|
||||
if (_visible)
|
||||
_rpcClient.SetPresence(_currentPresence);
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,8 @@
|
||||
<ContextMenu>
|
||||
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
||||
<Separator />
|
||||
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" Visibility="Collapsed" Click="RichPresenceMenuItem_Click" />
|
||||
<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="TestMenuItem" Header="Test" IsCheckable="True" Click="TestMenuItem_Click" />
|
||||
</ContextMenu>
|
||||
</ui:UiWindow.ContextMenu>
|
||||
</ui:UiWindow>
|
||||
|
@ -42,15 +42,5 @@ namespace Bloxstrap.UI.Elements.ContextMenu
|
||||
exStyle |= NativeMethods.WS_EX_TOOLWINDOW;
|
||||
NativeMethods.SetWindowLongPtr(wndHelper.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)exStyle);
|
||||
}
|
||||
|
||||
private void RichPresenceMenuItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Controls.ShowMessageBox($"hi how u doing i am {RichPresenceMenuItem.IsChecked}", MessageBoxImage.Warning);
|
||||
}
|
||||
|
||||
private void TestMenuItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Controls.ShowMessageBox($"hi how u doing i am {TestMenuItem.IsChecked}", MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,12 @@ namespace Bloxstrap.UI
|
||||
|
||||
private readonly System.Windows.Forms.NotifyIcon _notifyIcon;
|
||||
private MenuContainer? _menuContainer;
|
||||
|
||||
private RobloxActivity? _activityWatcher;
|
||||
private DiscordRichPresence? _richPresenceHandler;
|
||||
|
||||
private ServerInformation? _serverInformationWindow;
|
||||
|
||||
public DiscordRichPresence? RichPresenceIntegration;
|
||||
|
||||
EventHandler? _alertClickHandler;
|
||||
|
||||
@ -35,15 +36,18 @@ namespace Bloxstrap.UI
|
||||
_notifyIcon.MouseClick += MouseClickEventHandler;
|
||||
}
|
||||
|
||||
public void InitializeContextMenu()
|
||||
#region Handler registers
|
||||
public void SetRichPresenceHandler(DiscordRichPresence richPresenceHandler)
|
||||
{
|
||||
if (_menuContainer is not null)
|
||||
if (_richPresenceHandler is not null)
|
||||
return;
|
||||
|
||||
_menuContainer = new();
|
||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
||||
_menuContainer.ServerDetailsMenuItem.Click += (_, _) => ShowServerInformationWindow();
|
||||
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
||||
_richPresenceHandler = richPresenceHandler;
|
||||
|
||||
if (_menuContainer is null)
|
||||
return;
|
||||
|
||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.RichPresenceMenuItem.Visibility = Visibility.Visible);
|
||||
}
|
||||
|
||||
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
||||
@ -55,6 +59,30 @@ namespace Bloxstrap.UI
|
||||
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
||||
_activityWatcher.OnGameLeave += OnGameLeave;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Context menu
|
||||
public void InitializeContextMenu()
|
||||
{
|
||||
if (_menuContainer is not null)
|
||||
return;
|
||||
|
||||
_menuContainer = new();
|
||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
||||
_menuContainer.ServerDetailsMenuItem.Click += (_, _) => ShowServerInformationWindow();
|
||||
_menuContainer.RichPresenceMenuItem.Click += (_, _) => _richPresenceHandler?.SetVisibility(_menuContainer.RichPresenceMenuItem.IsChecked);
|
||||
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
||||
}
|
||||
|
||||
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
if (e.Button != System.Windows.Forms.MouseButtons.Right || _menuContainer is null)
|
||||
return;
|
||||
|
||||
_menuContainer.Activate();
|
||||
_menuContainer.ContextMenu.IsOpen = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async void OnGameJoin()
|
||||
{
|
||||
@ -78,15 +106,6 @@ namespace Bloxstrap.UI
|
||||
|
||||
}
|
||||
|
||||
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
if (e.Button != System.Windows.Forms.MouseButtons.Right || _menuContainer is null)
|
||||
return;
|
||||
|
||||
_menuContainer.Activate();
|
||||
_menuContainer.ContextMenu.IsOpen = true;
|
||||
}
|
||||
|
||||
public void ShowServerInformationWindow()
|
||||
{
|
||||
if (_serverInformationWindow is null)
|
||||
|
Loading…
Reference in New Issue
Block a user