add try catch
Some checks failed
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled

This commit is contained in:
Leilei Zhang 2025-06-04 17:07:31 +08:00
parent bf8f3ca3a5
commit 42c3768d94

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Utils;
using Microsoft.UI.Xaml.Controls;
using Windows.Win32;
@ -37,8 +38,11 @@ public static class AppxPackageHelper
break;
}
IAppxManifestApplication* manifestApp;
manifestApps->GetCurrent(&manifestApp);
IAppxManifestApplication* manifestApp = null;
try
{
manifestApps->GetCurrent(&manifestApp).ThrowOnFailure();
var hr = manifestApp->GetStringValue("AppListEntry", out var appListEntryPtr);
var appListEntry = ComFreeHelper.GetStringAndFree(hr, appListEntryPtr);
@ -51,6 +55,16 @@ public static class AppxPackageHelper
{
manifestApp->Release();
}
}
catch (Exception ex)
{
if (manifestApp != null)
{
manifestApp->Release();
}
Logger.LogError($"Failed to get current application from manifest: {ex.Message}");
}
manifestApps->MoveNext(out var hasNext);
if (hasNext == false)