mirror of
https://github.com/SPLURT-Station/S.P.L.U.R.T-Station-13.git
synced 2025-12-09 16:07:40 +00:00
[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 <legoboyo@earthlink.net>
This commit is contained in:
@@ -347,3 +347,5 @@
|
||||
|
||||
/datum/config_entry/str_list/randomizing_station_name_message
|
||||
default = list()
|
||||
|
||||
/datum/config_entry/flag/toast_notification_on_init
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
icons/ui_icons/common/tg_16.png
Normal file
BIN
icons/ui_icons/common/tg_16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 795 B |
32
tools/initToast/initToast.ps1
Normal file
32
tools/initToast/initToast.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
param([string]$name, [string]$icon, [Int32]$port=80)
|
||||
|
||||
$hkcu = [Microsoft.Win32.RegistryKey]::OpenBaseKey('CurrentUser','default')
|
||||
|
||||
$amuid_hkey = $hkcu.CreateSubKey('SOFTWARE\Classes\AppUserModelId\Tgstation.Tgstation', $true, [Microsoft.Win32.RegistryOptions]::Volatile)
|
||||
|
||||
if ($name) { $amuid_hkey.SetValue('DisplayName', $name) }
|
||||
if ($icon) { $amuid_hkey.SetValue('IconUri', $icon) }
|
||||
|
||||
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $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(@"
|
||||
<toast>
|
||||
<visual>
|
||||
<binding template="ToastGeneric">
|
||||
<text>Initialization Complete</text>
|
||||
</binding>
|
||||
</visual>
|
||||
<actions>
|
||||
<action content="Launch Dream Seeker" activationType="protocol" arguments="byond://127.0.0.1:$port"/>
|
||||
</actions>
|
||||
</toast>
|
||||
"@)
|
||||
|
||||
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
||||
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
||||
|
||||
$notifier.Show($toast)
|
||||
Reference in New Issue
Block a user