From 80e7c0db0a783e2a121ce9d888d5f11a0aa24ca3 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 1/2] [MIRROR] Sends a toast notification when initializations complete. [MDB IGNORE] (#18623) * Sends a toast notification when initializations complete. (#72465) 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 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. No player-facing changes. * Sends a toast notification when initializations complete. Co-authored-by: Y0SH1M4S73R --- .../configuration/entries/general.dm | 2 ++ code/controllers/master.dm | 4 +++ icons/ui_icons/common/tg_16.png | Bin 0 -> 795 bytes tools/initToast/initToast.ps1 | 32 ++++++++++++++++++ 4 files changed, 38 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 f7c864a89f..64be4216ff 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -347,3 +347,5 @@ /datum/config_entry/str_list/randomizing_station_name_message default = list() + +/datum/config_entry/flag/toast_notification_on_init diff --git a/code/controllers/master.dm b/code/controllers/master.dm index de94b27e77..b6fb14a695 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -223,6 +223,10 @@ GLOBAL_REAL(Master, /datum/controller/master) = new // Sort subsystems by display setting for easy access. sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_display)) + + 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/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) From 50e2d911a6d774224a6cd945f3ba666fe0a8c42d Mon Sep 17 00:00:00 2001 From: Metis <100518708+sheepishgoat@users.noreply.github.com> Date: Tue, 15 Oct 2024 00:26:38 -0400 Subject: [PATCH 2/2] Update general.txt --- config/entries/general.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/entries/general.txt b/config/entries/general.txt index b118d65621..fab98d4441 100644 --- a/config/entries/general.txt +++ b/config/entries/general.txt @@ -515,3 +515,7 @@ RANDOMIZING_STATION_NAME_MESSAGE %NEW_STATION_NAME%? %NEW_STATION_NAME%! %NEW_ST RANDOMIZING_STATION_NAME_MESSAGE A popular social network application had already claimed the trademark of %CURRENT_STATION_NAME%, the station has been renamed to %NEW_STATION_NAME%. RANDOMIZING_STATION_NAME_MESSAGE We're pulling a prank on %RANDOM_CREWMEMBER%, so we've changed the station's name to %NEW_STATION_NAME%. RANDOMIZING_STATION_NAME_MESSAGE %RANDOM_NAME% made us change the station name, which is now %NEW_STATION_NAME%. + +## 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