From 8cd6690a335ceb79bd5b6e1963fcb3c1917a27eb Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 30 Apr 2023 21:38:54 +0100 Subject: [PATCH] Rework notification handling, make Job ID copyable --- Bloxstrap/App.xaml.cs | 14 ++++++++++++ Bloxstrap/Integrations/ServerNotifier.cs | 27 +++++++++--------------- Bloxstrap/Updater.cs | 21 +++++++----------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 3b11552..86d5c1a 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -52,6 +52,8 @@ namespace Bloxstrap public static readonly FastFlagManager FastFlags = new(); public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }); + public static System.Windows.Forms.NotifyIcon Notification { get; private set; } = null!; + // shorthand public static MessageBoxResult ShowMessageBox(string message, MessageBoxImage icon = MessageBoxImage.None, MessageBoxButton buttons = MessageBoxButton.OK) { @@ -155,6 +157,18 @@ namespace Bloxstrap } } + // so this needs to be here because winforms moment + // onclick events will not fire unless this is defined here in the main thread so uhhhhh + // we'll show the icon if we're launching roblox since we're likely gonna be showing a + // bunch of notifications, and always showing it just makes the most sense i guess since it + // indicates that bloxstrap is running, even in the background + Notification = new() + { + Icon = Bloxstrap.Properties.Resources.IconBloxstrap, + Text = ProjectName, + Visible = !IsMenuLaunch + }; + // todo: remove this once 32-bit support is fully gone if (!App.IsQuiet && !Environment.Is64BitOperatingSystem) { diff --git a/Bloxstrap/Integrations/ServerNotifier.cs b/Bloxstrap/Integrations/ServerNotifier.cs index cd04ef6..bdd1678 100644 --- a/Bloxstrap/Integrations/ServerNotifier.cs +++ b/Bloxstrap/Integrations/ServerNotifier.cs @@ -1,9 +1,6 @@ using System; -using System.Net.NetworkInformation; using System.Threading.Tasks; -using System.Windows.Forms; - -using Bloxstrap.Properties; +using System.Windows; namespace Bloxstrap.Integrations { @@ -42,23 +39,19 @@ namespace Bloxstrap.Integrations else message = $"Location: {locationCity}, {locationRegion}, {locationCountry}"; - if (_activityWatcher.ActivityMachineUDMUX) - message += "\nServer is UDMUX protected"; + message += "\nClick to copy Job ID"; App.Logger.WriteLine($"[ServerNotifier::Notify] {message.ReplaceLineEndings("\\n")}"); - NotifyIcon notification = new() - { - Icon = Resources.IconBloxstrap, - Text = "Bloxstrap", - Visible = true, - BalloonTipTitle = "Connected to server", - BalloonTipText = message - }; + EventHandler JobIDCopier = new((_, _) => Clipboard.SetText(_activityWatcher.ActivityJobId)); + + App.Notification.BalloonTipTitle = "Connected to server"; + App.Notification.BalloonTipText = message; + App.Notification.BalloonTipClicked += JobIDCopier; + App.Notification.ShowBalloonTip(10); - notification.ShowBalloonTip(10); await Task.Delay(10000); - notification.Dispose(); - } + App.Notification.BalloonTipClicked -= JobIDCopier; + } } } diff --git a/Bloxstrap/Updater.cs b/Bloxstrap/Updater.cs index 3d768e7..dbb25b6 100644 --- a/Bloxstrap/Updater.cs +++ b/Bloxstrap/Updater.cs @@ -80,22 +80,17 @@ namespace Bloxstrap if (isAutoUpgrade) { - NotifyIcon notification = new() - { - Icon = Resources.IconBloxstrap, - Text = "Bloxstrap", - Visible = true, - BalloonTipTitle = $"Bloxstrap has been upgraded to v{currentVersionInfo.ProductVersion}", - BalloonTipText = "Click here to see what's new in this version" - }; + EventHandler ReleaseNotesLauncher = new((_, _) => Utilities.OpenWebsite($"https://github.com/{App.ProjectRepository}/releases/tag/v{currentVersionInfo.ProductVersion}")); - notification.BalloonTipClicked += (_, _) => Utilities.OpenWebsite($"https://github.com/{App.ProjectRepository}/releases/tag/v{currentVersionInfo.ProductVersion}"); - notification.ShowBalloonTip(30); + App.Notification.BalloonTipTitle = "Bloxstrap has been upgraded to v{currentVersionInfo.ProductVersion}"; + App.Notification.BalloonTipText = "Click here to see what's new in this version"; + App.Notification.BalloonTipClicked += ReleaseNotesLauncher; + App.Notification.ShowBalloonTip(30); - Task.Run(() => + Task.Run(async () => { - Task.Delay(30000).Wait(); - notification.Dispose(); + await Task.Delay(30000); + App.Notification.BalloonTipClicked -= ReleaseNotesLauncher; }); } else if (!App.IsQuiet)