From a724b290d441493486b7a0bb084c789e80a87deb Mon Sep 17 00:00:00 2001 From: natsurainko Date: Mon, 2 Dec 2024 15:54:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=92=8C=E6=B8=B8=E6=88=8F=E5=B4=A9=E6=BA=83=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Launch/QuickLaunchService.cs | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Natsurainko.FluentLauncher/Services/Launch/QuickLaunchService.cs b/Natsurainko.FluentLauncher/Services/Launch/QuickLaunchService.cs index 085adf12..8d79d962 100644 --- a/Natsurainko.FluentLauncher/Services/Launch/QuickLaunchService.cs +++ b/Natsurainko.FluentLauncher/Services/Launch/QuickLaunchService.cs @@ -1,6 +1,8 @@ using Microsoft.Windows.AppLifecycle; using Microsoft.Windows.AppNotifications; +using Microsoft.Windows.AppNotifications.Builder; using Natsurainko.FluentLauncher.Services.Settings; +using Natsurainko.FluentLauncher.Services.UI; using Natsurainko.FluentLauncher.Utils.Extensions; using Natsurainko.FluentLauncher.ViewModels.Common; using Nrk.FluentCore.GameManagement; @@ -10,12 +12,9 @@ using System.Collections.Generic; using System.CommandLine; using System.Linq; -using System.Threading; using System.Threading.Tasks; using System.Windows; -using Windows.UI.Popups; using Windows.UI.StartScreen; -using WinUIEx; namespace Natsurainko.FluentLauncher.Services.Launch; @@ -23,14 +22,16 @@ internal class QuickLaunchService { private readonly LaunchService _launchService; private readonly SettingsService _settingsService; + private readonly NotificationService _notificationService; public const string PinnedUri = "ms-resource:///Resources/JumpList__Pinned"; public const string LatestUri = "ms-resource:///Resources/JumpList__Latest"; - public QuickLaunchService(LaunchService launchService, SettingsService settingsService) + public QuickLaunchService(LaunchService launchService, SettingsService settingsService, NotificationService notificationService) { _launchService = launchService; _settingsService = settingsService; + _notificationService = notificationService; } public void LaunchFromActivatedEventArgs(string[] args) @@ -43,13 +44,19 @@ public void LaunchFromActivatedEventArgs(string[] args) if (minecraftFolder == null || instanceId == null) return; - MinecraftInstanceParser minecraftInstanceParser = new(minecraftFolder); - MinecraftInstance instance = minecraftInstanceParser.ParseAllInstances() - .FirstOrDefault(x => (x?.InstanceId.Equals(instanceId)).GetValueOrDefault(false), null) - ?? throw new Exception("The target Minecraft instance could not be found"); - + try + { + MinecraftInstanceParser minecraftInstanceParser = new(minecraftFolder); + MinecraftInstance instance = minecraftInstanceParser.ParseAllInstances() + .FirstOrDefault(x => (x?.InstanceId.Equals(instanceId)).GetValueOrDefault(false), null) + ?? throw new Exception("The target Minecraft instance could not be found"); - _launchService.LaunchFromUI(instance); + _launchService.LaunchFromUI(instance); + } + catch (Exception ex) + { + _notificationService.NotifyWithoutContent(ex.Message); + } } public async Task LaunchFromArguments(string minecraftFolder, string instanceId) @@ -80,7 +87,10 @@ public async Task LaunchFromArguments(string minecraftFolder, string instanceId) if (process.Process.ExitCode != 0) { - + AppNotificationManager.Default.Show(new AppNotificationBuilder() + .AddText($"Minecraft: {instance.GetDisplayName} Crashed") + .AddText("Quick Launch cannot provide further error information") + .BuildNotification()); } } catch (Exception ex)