Skip to content

Commit

Permalink
增加错误提示和游戏崩溃提示
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Dec 2, 2024
1 parent 7e58d59 commit a724b29
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions Natsurainko.FluentLauncher/Services/Launch/QuickLaunchService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,27 +12,26 @@
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;

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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a724b29

Please sign in to comment.