import threading def send_toast(title: str, message: str, duration: int = 5) -> None: def _send(): try: from win10toast import ToastNotifier toaster = ToastNotifier() toaster.show_toast(title, message, duration=duration, threaded=True) except Exception: try: import subprocess ps_script = ( f"[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, " f"ContentType = WindowsRuntime] | Out-Null; " f"$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent(" f"[Windows.UI.Notifications.ToastTemplateType]::ToastText02); " f"$template.SelectSingleNode('//text[@id=1]').InnerText = '{title}'; " f"$template.SelectSingleNode('//text[@id=2]').InnerText = '{message}'; " f"$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('StockMind'); " f"$notifier.Show([Windows.UI.Notifications.ToastNotification]::new($template))" ) subprocess.Popen( ["powershell", "-WindowStyle", "Hidden", "-Command", ps_script], creationflags=0x08000000, ) except Exception: pass threading.Thread(target=_send, daemon=True).start()