From 8d6ab22fa59d9b6fe6f8fa88b3f70199cd0b4bfc Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 11 Jul 2022 10:20:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=89=88=E6=9C=AC=E5=8F=B7=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAsstGui/Helper/ToastNotification.cs | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/MeoAsstGui/Helper/ToastNotification.cs b/src/MeoAsstGui/Helper/ToastNotification.cs index 8e9f6e45b6..f67dc394fd 100644 --- a/src/MeoAsstGui/Helper/ToastNotification.cs +++ b/src/MeoAsstGui/Helper/ToastNotification.cs @@ -15,6 +15,7 @@ using System.Drawing; using System.Media; using System.Runtime.InteropServices; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Interop; @@ -39,10 +40,32 @@ namespace MeoAsstGui } } + private static bool _systemToastChecked = false; + private static bool _systemToastCheckInited = false; + public bool CheckToastSystem() { - var os = RuntimeInformation.OSDescription.ToString(); - return os.ToString().CompareTo("Microsoft Windows 10.0.10240") >= 0; + if (!_systemToastCheckInited) + { + _systemToastCheckInited = true; + + // like "Microsoft Windows 10.0.10240 " + var osDesc = RuntimeInformation.OSDescription; + Regex versionRegex = new Regex(@"\d+\.\d+\.\d+"); + var matched = versionRegex.Match(osDesc); + if (!matched.Success) + { + _systemToastChecked = false; + return _systemToastChecked; + } + var osVersion = matched.Groups[0].Value; + Semver.SemVersion curVersionObj; + bool verParsed = Semver.SemVersion.TryParse(osVersion, Semver.SemVersionStyles.Strict, out curVersionObj); + + var minimumVersionObj = new Semver.SemVersion(10, 0, 10240); + _systemToastChecked = verParsed && curVersionObj.CompareSortOrderTo(minimumVersionObj) >= 0; + } + return _systemToastChecked; } private NotificationManager _notificationManager = new NotificationManager();