From 3bf3f4e02d4dfd077a71435c9121e8e02777a3c9 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 10 Jan 2023 16:38:08 +0100 Subject: [PATCH] [MIRROR] Sends a toast notification when initializations complete. [MDB IGNORE] (#18623) * Sends a toast notification when initializations complete. (#72465) ## About The Pull Request Initialization is significantly slowed down by the presence of clients, though when testing features, you need to join the server. I've been told that some devs (particularly Mothblocks) are alt-tabbed out of Dream Daemon while doing dev work, meaning that they are liable to miss initializations completing, causing an effective slowdown in the dev cycle. Mothblocks said it would be nice if there was a way to produce a desktop notification when initialization completes. I originally intended to add a function to rust_g that would produce a Windows toast notification with a button allowing you to immediately launch Dream Seeker. However, I couldn't find a reliable way to detect if the OS version was Windows 7 or earlier, so running this function on such an OS would cause a rust panic (which I was told is only a problem because MSO probably still uses Windows 7). Fortunately, PowerShell scripts can access the necessary .NET APIs to produce toast notifications on Windows 10, while also failing more gracefully than crashing the host process. So I recreated the functionality I intended in PowerShell. Toast notifications will only be sent on Windows, if the TOAST_NOTIFICATION_ON_INIT config flag is enabled, AND there are no clients on the server. **Note for downstreams:** If you want the toast notification to have your downstream's icon, copy it, scale the copy down to 16x16, and either rename it "tg_16.png" or change that path in the call to `world.shelleo` to the name of the new file. Video Demo: https://user-images.githubusercontent.com/12720844/210492033-963923d7-a1de-4326-9c9f-4f0c0b71d1a5.mp4 ## Why It's Good For The Game This isn't really a line item in the Dev Cycles Initiative, but even if Mothblocks was exaggerating the benefits, it would still be a significant speedup in the dev cycles. ## Changelog No player-facing changes. * Sends a toast notification when initializations complete. Co-authored-by: Y0SH1M4S73R --- .../configuration/entries/general.dm | 2 ++ code/controllers/master.dm | 3 ++ config/config.txt | 4 +++ icons/ui_icons/common/tg_16.png | Bin 0 -> 795 bytes tools/initToast/initToast.ps1 | 32 ++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 icons/ui_icons/common/tg_16.png create mode 100644 tools/initToast/initToast.ps1 diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index 263201b6846..7bfbe268b6d 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -649,3 +649,5 @@ default = 50 /datum/config_entry/string/morgue_cadaver_override_species + +/datum/config_entry/flag/toast_notification_on_init diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 99060e9ae96..5000aa07e30 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -267,6 +267,9 @@ GLOBAL_REAL(Master, /datum/controller/master) = new log_world(msg) + if(world.system_type == MS_WINDOWS && CONFIG_GET(flag/toast_notification_on_init) && !length(GLOB.clients)) + world.shelleo("start /min powershell -ExecutionPolicy Bypass -File tools/initToast/initToast.ps1 -name \"[world.name]\" -icon %CD%\\icons\\ui_icons\\common\\tg_16.png -port [world.port]") + // Set world options. world.change_fps(CONFIG_GET(number/fps)) var/initialized_tod = REALTIMEOFDAY diff --git a/config/config.txt b/config/config.txt index 2f57ba97810..3ac807188ae 100644 --- a/config/config.txt +++ b/config/config.txt @@ -648,3 +648,7 @@ PR_ANNOUNCEMENTS_PER_ROUND 5 ## Uncomment to block granting profiling privileges to users with R_DEBUG, for performance purposes #FORBID_ADMIN_PROFILING + +## Comment to disable sending a toast notification on the host server when initializations complete. +## Even if this is enabled, a notification will only be sent if there are no clients connected. +TOAST_NOTIFICATION_ON_INIT diff --git a/icons/ui_icons/common/tg_16.png b/icons/ui_icons/common/tg_16.png new file mode 100644 index 0000000000000000000000000000000000000000..2b08bdd29cd524802105981590e28a82d8167c5c GIT binary patch literal 795 zcmV+$1LXXPP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0yD(zy7TKwZ}-sTT0Yy6{ZwItT2!Xm~p zEX9OaN;gS0GUcLI-K3X$f9Lw0({F9JHS_uBc{|TJ=Q+=LFdI&5qI+cWAmSaB+-&C+ zI!^VXvPvH@Y=N~Xapz&JN54^)*U!%_|1&l|-(=!3G(6&DG#Z69R(MeJB4ee}U!zIW zN*n5G>cuo6B0^6J@%NP~+}+?Qcf-E4&G^vq8H2xu(bU?G-hm+)48KuWdK)(ia^y+z zQC(sx@VcqRQL@6H#A^=_Dm59$h}mo=^^H10ufND=9dTS8L8NYhBp^{s6cI^p#Z+*) z#buG<$$R^$k$p51nLD*oY2*+SGlNS^mGj;)V7N% z`DagHtx`eNX=1{Ha4j!Ow5BM%m<_3P4u%XP&eZ0@gZwI}BC+PE_$S0nU@No1l9d=x|{)d7P0+qKXbIxR$ zP;*sD9`dt~y?XN= zi?!C=^5qJ1PUTYLOAmWg3wWNlsF$Mq*a?oa!r^qSmfF)V$I6IJ6|E^Ms;c20szzf= z8=k$IYW?-QkC^n5yS}56ZE*SgX{AhNGy1;$6DEyD)~2!X2_(fu(J&&nrDNlsgV+=o ziKq1q5IT2ByCtEO#-_hA#Wgswb7EqWwWCk?x+&^dJgIvF`bKm%28M?5ys~& $null +$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Tgstation.Tgstation') + +[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom, ContentType = WindowsRuntime] > $null +$xml = New-Object Windows.Data.Xml.Dom.XmlDocument + +$xml.LoadXml(@" + + + + Initialization Complete + + + + + + +"@) + +[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null +$toast = New-Object Windows.UI.Notifications.ToastNotification $xml + +$notifier.Show($toast)