mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
CmdPal: Make debugging extension load errors easier (#41251)
Turns out we didn't log all the HRESULTs for failing to load an extension. This adds more logging. It also adds a context command on the log command to make it easier to get to the log files
This commit is contained in:
@@ -32,17 +32,8 @@ namespace ManagedCommon
|
|||||||
/// <param name="isLocalLow">If the process using Logger is a low-privilege process.</param>
|
/// <param name="isLocalLow">If the process using Logger is a low-privilege process.</param>
|
||||||
public static void InitializeLogger(string applicationLogPath, bool isLocalLow = false)
|
public static void InitializeLogger(string applicationLogPath, bool isLocalLow = false)
|
||||||
{
|
{
|
||||||
string basePath;
|
string versionedPath = LogDirectoryPath(applicationLogPath, isLocalLow);
|
||||||
if (isLocalLow)
|
string basePath = Path.GetDirectoryName(versionedPath);
|
||||||
{
|
|
||||||
basePath = Environment.GetEnvironmentVariable("userprofile") + "\\appdata\\LocalLow\\Microsoft\\PowerToys" + applicationLogPath;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
basePath = Constants.AppDataPath() + applicationLogPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
string versionedPath = Path.Combine(basePath, Version);
|
|
||||||
|
|
||||||
if (!Directory.Exists(versionedPath))
|
if (!Directory.Exists(versionedPath))
|
||||||
{
|
{
|
||||||
@@ -59,6 +50,22 @@ namespace ManagedCommon
|
|||||||
Task.Run(() => DeleteOldVersionLogFolders(basePath, versionedPath));
|
Task.Run(() => DeleteOldVersionLogFolders(basePath, versionedPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string LogDirectoryPath(string applicationLogPath, bool isLocalLow = false)
|
||||||
|
{
|
||||||
|
string basePath;
|
||||||
|
if (isLocalLow)
|
||||||
|
{
|
||||||
|
basePath = Environment.GetEnvironmentVariable("userprofile") + "\\appdata\\LocalLow\\Microsoft\\PowerToys" + applicationLogPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
basePath = Constants.AppDataPath() + applicationLogPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
string versionedPath = Path.Combine(basePath, Version);
|
||||||
|
return versionedPath;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes old version log folders, keeping only the current version's folder.
|
/// Deletes old version log folders, keeping only the current version's folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using ManagedCommon;
|
||||||
using Microsoft.CmdPal.UI.ViewModels.Commands;
|
using Microsoft.CmdPal.UI.ViewModels.Commands;
|
||||||
using Microsoft.CmdPal.UI.ViewModels.Properties;
|
using Microsoft.CmdPal.UI.ViewModels.Properties;
|
||||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||||
@@ -19,6 +20,10 @@ internal sealed partial class FallbackLogItem : FallbackCommandItem
|
|||||||
Title = string.Empty;
|
Title = string.Empty;
|
||||||
_logMessagesPage.Name = string.Empty;
|
_logMessagesPage.Name = string.Empty;
|
||||||
Subtitle = Properties.Resources.builtin_log_subtitle;
|
Subtitle = Properties.Resources.builtin_log_subtitle;
|
||||||
|
|
||||||
|
var logPath = Logger.LogDirectoryPath("\\CmdPal\\Logs\\");
|
||||||
|
var openLogCommand = new OpenFileCommand(logPath) { Name = Resources.builtin_log_folder_command_name };
|
||||||
|
MoreCommands = [new CommandContextItem(openLogCommand)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateQuery(string query)
|
public override void UpdateQuery(string query)
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ public class ExtensionWrapper : IExtensionWrapper
|
|||||||
// We'll just return out nothing.
|
// We'll just return out nothing.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (hr.Value != 0)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Failed to find {ExtensionDisplayName}: {hr.Value}");
|
||||||
|
}
|
||||||
|
|
||||||
// Marshal.ThrowExceptionForHR(hr);
|
// Marshal.ThrowExceptionForHR(hr);
|
||||||
_extensionObject = MarshalInterface<IExtension>.FromAbi((nint)extensionPtr);
|
_extensionObject = MarshalInterface<IExtension>.FromAbi((nint)extensionPtr);
|
||||||
|
|||||||
@@ -285,6 +285,15 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to View log folder.
|
||||||
|
/// </summary>
|
||||||
|
public static string builtin_log_folder_command_name {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("builtin_log_folder_command_name", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to View log.
|
/// Looks up a localized string similar to View log.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -135,6 +135,9 @@
|
|||||||
<data name="builtin_log_title" xml:space="preserve">
|
<data name="builtin_log_title" xml:space="preserve">
|
||||||
<value>View log</value>
|
<value>View log</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="builtin_log_folder_command_name" xml:space="preserve">
|
||||||
|
<value>View log folder</value>
|
||||||
|
</data>
|
||||||
<data name="builtin_reload_subtitle" xml:space="preserve">
|
<data name="builtin_reload_subtitle" xml:space="preserve">
|
||||||
<value>Reload Command Palette extensions</value>
|
<value>Reload Command Palette extensions</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Reference in New Issue
Block a user