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");
|
App.Logger.WriteLine("[Bootstrapper::StartRoblox] Using Discord Rich Presence");
|
||||||
richPresence = new(activityWatcher);
|
richPresence = new(activityWatcher);
|
||||||
|
|
||||||
if (App.NotifyIcon is not null)
|
App.NotifyIcon?.SetRichPresenceHandler(richPresence);
|
||||||
App.NotifyIcon.RichPresenceIntegration = richPresence;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ namespace Bloxstrap.Integrations
|
|||||||
private readonly RobloxActivity _activityWatcher;
|
private readonly RobloxActivity _activityWatcher;
|
||||||
|
|
||||||
private RichPresence? _currentPresence;
|
private RichPresence? _currentPresence;
|
||||||
|
private bool _visible = true;
|
||||||
private string? _initialStatus;
|
private string? _initialStatus;
|
||||||
private long _currentUniverseId;
|
private long _currentUniverseId;
|
||||||
private DateTime? _timeStartedUniverse;
|
private DateTime? _timeStartedUniverse;
|
||||||
@ -89,6 +90,18 @@ namespace Bloxstrap.Integrations
|
|||||||
UpdatePresence();
|
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()
|
public async Task<bool> SetCurrentGame()
|
||||||
{
|
{
|
||||||
if (!_activityWatcher.ActivityInGame)
|
if (!_activityWatcher.ActivityInGame)
|
||||||
@ -195,7 +208,8 @@ namespace Bloxstrap.Integrations
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rpcClient.SetPresence(_currentPresence);
|
if (_visible)
|
||||||
|
_rpcClient.SetPresence(_currentPresence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -20,9 +20,8 @@
|
|||||||
<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" 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="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" />
|
||||||
<MenuItem x:Name="TestMenuItem" Header="Test" IsCheckable="True" Click="TestMenuItem_Click" />
|
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</ui:UiWindow.ContextMenu>
|
</ui:UiWindow.ContextMenu>
|
||||||
</ui:UiWindow>
|
</ui:UiWindow>
|
||||||
|
@ -42,15 +42,5 @@ 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 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 readonly System.Windows.Forms.NotifyIcon _notifyIcon;
|
||||||
private MenuContainer? _menuContainer;
|
private MenuContainer? _menuContainer;
|
||||||
|
|
||||||
private RobloxActivity? _activityWatcher;
|
private RobloxActivity? _activityWatcher;
|
||||||
|
private DiscordRichPresence? _richPresenceHandler;
|
||||||
|
|
||||||
private ServerInformation? _serverInformationWindow;
|
private ServerInformation? _serverInformationWindow;
|
||||||
|
|
||||||
public DiscordRichPresence? RichPresenceIntegration;
|
|
||||||
|
|
||||||
EventHandler? _alertClickHandler;
|
EventHandler? _alertClickHandler;
|
||||||
|
|
||||||
@ -35,15 +36,18 @@ namespace Bloxstrap.UI
|
|||||||
_notifyIcon.MouseClick += MouseClickEventHandler;
|
_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;
|
return;
|
||||||
|
|
||||||
_menuContainer = new();
|
_richPresenceHandler = richPresenceHandler;
|
||||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
|
||||||
_menuContainer.ServerDetailsMenuItem.Click += (_, _) => ShowServerInformationWindow();
|
if (_menuContainer is null)
|
||||||
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
return;
|
||||||
|
|
||||||
|
_menuContainer.Dispatcher.Invoke(() => _menuContainer.RichPresenceMenuItem.Visibility = Visibility.Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
public void SetActivityWatcher(RobloxActivity activityWatcher)
|
||||||
@ -55,6 +59,30 @@ namespace Bloxstrap.UI
|
|||||||
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
_activityWatcher.OnGameJoin += (_, _) => Task.Run(OnGameJoin);
|
||||||
_activityWatcher.OnGameLeave += OnGameLeave;
|
_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()
|
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()
|
public void ShowServerInformationWindow()
|
||||||
{
|
{
|
||||||
if (_serverInformationWindow is null)
|
if (_serverInformationWindow is null)
|
||||||
|
Loading…
Reference in New Issue
Block a user