Skip to content

Commit

Permalink
Create an IExtensionHost class, to enable logging (#137)
Browse files Browse the repository at this point in the history
Allow extensions to send status messages to the host app.

As an example, you can now:

```cs
ExtensionHost.LogMessage(new LogMessage() { Message = "This is a test, from the HackerNews sample" });
```

And have that appear in the host apps debug console. 

Closes #134 
Closes #118 

Should also make resolving #87 and #135 easier. 

We don't have the design of these status messages totally planned out yet. But this should at least make it possible. For those in the back, **this does not actually display these messages anywhere in the host UX currently**. 

-----

Other information that's currently included:
* The host app's HWND. Way too many times does the Windows API need an HWND, which extensions won't have, but the host app does. 
* The `LanguageOverride`. This is in case we ever want to support `PrimaryLanguageOverride` in the host app.
  • Loading branch information
zadjii-msft authored Nov 5, 2024
1 parent 6ee3ad6 commit c319a74
Show file tree
Hide file tree
Showing 30 changed files with 430 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

namespace EverythingExtension;

public partial class EverythingExtensionActionsProvider : ICommandProvider
public partial class EverythingExtensionActionsProvider : CommandProvider
{
public string DisplayName => $"Everything extension for cmdpal";

public IconDataType Icon => new(string.Empty);
public EverythingExtensionActionsProvider()
{
DisplayName = "Everything extension for cmdpal";
}

private readonly IListItem[] _commands = [
new ListItem(new EverythingExtensionPage())
Expand All @@ -26,11 +27,7 @@ public partial class EverythingExtensionActionsProvider : ICommandProvider
},
];

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return _commands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public EverythingExtensionPage()
Everything_SetMax(20);
}

public override ISection[] GetItems(string query)
public override IListItem[] GetItems(string query)
{
Everything_SetSearchW(query);

Expand Down Expand Up @@ -60,19 +60,11 @@ public override ISection[] GetItems(string query)
items.Add(new ListItem(new NoOpCommand() { Name = "(Are you sure Everything is running?)" }));
}

return [
new ListSection()
{
Items = items.ToArray(),
}
];
return items.ToArray();
}

var resultCount = Everything_GetNumResults();

// Create a new ListSections
var section = new ListSection();

// Create a List to store ListItems
var itemList = new List<ListItem>();

Expand Down Expand Up @@ -101,9 +93,6 @@ public override ISection[] GetItems(string query)
}

// Convert the List to an array and assign it to the Items property
section.Items = itemList.ToArray();

// Return the ListSection with the items
return [section];
return itemList.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

namespace HackerNewsExtension;

public partial class HackerNewsCommandsProvider : ICommandProvider
public partial class HackerNewsCommandsProvider : CommandProvider
{
public string DisplayName => $"Hacker News Commands";

public IconDataType Icon => new(string.Empty);
public HackerNewsCommandsProvider()
{
DisplayName = "Hacker News Commands";
}

private readonly IListItem[] _actions = [
new ListItem(new HackerNewsPage()),
];

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return _actions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"profiles": {
"HackerNewsExtension (Package)": {
"commandName": "MsixPackage"
"commandName": "MsixPackage",
"doNotLaunchApp": true
},
"HackerNewsExtension (Unpackaged)": {
"commandName": "Project"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,18 @@ public async Task<List<MastodonStatus>> FetchExplorePage()
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")]
public partial class MastodonExtensionActionsProvider : ICommandProvider
public partial class MastodonExtensionActionsProvider : CommandProvider
{
public string DisplayName => $"Mastodon extension for cmdpal Commands";

public IconDataType Icon => new(string.Empty);
public MastodonExtensionActionsProvider()
{
DisplayName = "Mastodon extension for cmdpal Commands";
}

private readonly IListItem[] _actions = [
new ListItem(new MastodonExtensionPage()) { Subtitle = "Explore top posts on mastodon.social" },
];

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return _actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

using System;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;

namespace MediaControlsExtension;

public partial class MediaActionsProvider : ICommandProvider
public partial class MediaActionsProvider : CommandProvider
{
public string DisplayName => $"Media controls actions";

public IconDataType Icon => new(string.Empty);
public MediaActionsProvider()
{
DisplayName = "Media controls actions";
}

private readonly IListItem[] _actions = [
new MediaListItem()
];

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return _actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@

namespace Microsoft.CmdPal.Ext.Bookmarks;

public partial class BookmarksCommandProvider : ICommandProvider
public partial class BookmarksCommandProvider : CommandProvider
{
public string DisplayName => $"Bookmarks";

public IconDataType Icon => new(string.Empty);

private readonly List<ICommand> _commands = [];
private readonly AddBookmarkPage _addNewCommand = new();

public BookmarksCommandProvider()
{
DisplayName = "Bookmarks";

_addNewCommand.AddedAction += AddNewCommand_AddedAction;
}

Expand All @@ -31,10 +29,6 @@ private void AddNewCommand_AddedAction(object sender, object? args)
_commands.Clear();
}

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

private void LoadCommands()
{
List<ICommand> collected = [];
Expand Down Expand Up @@ -84,7 +78,7 @@ private void LoadCommands()
_commands.AddRange(collected);
}

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
if (_commands.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@

using System;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;

namespace Microsoft.CmdPal.Ext.Calc;

public partial class CalculatorCommandProvider : ICommandProvider
public partial class CalculatorCommandProvider : CommandProvider
{
public string DisplayName => $"Calculator";

private readonly CalculatorTopLevelListItem calculatorCommand = new();

public CalculatorCommandProvider()
{
DisplayName = "Calculator";
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [calculatorCommand];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@

namespace Microsoft.CmdPal.Ext.Settings;

public partial class SettingsCommandProvider : ICommandProvider
public partial class SettingsCommandProvider : CommandProvider
{
public string DisplayName => $"Settings";

private readonly SettingsPage settingsPage = new();

public SettingsCommandProvider()
{
DisplayName = $"Settings";
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [new ListItem(settingsPage) { Subtitle = "CmdPal settings" }];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@

namespace Microsoft.CmdPal.Ext.Registry;

public partial class RegistryCommandsProvider : ICommandProvider
public partial class RegistryCommandsProvider : CommandProvider
{
public string DisplayName => $"Windows Services";

public RegistryCommandsProvider()
{
DisplayName = $"Windows Registry";
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [
new ListItem(new RegistryListPage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@

namespace Microsoft.CmdPal.Ext.WindowsServices;

public partial class WindowsServicesCommandsProvider : ICommandProvider
public partial class WindowsServicesCommandsProvider : CommandProvider
{
public string DisplayName => $"Windows Services";

public WindowsServicesCommandsProvider()
{
DisplayName = $"Windows Services";
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [
new ListItem(new ServicesListPage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

namespace Microsoft.CmdPal.Ext.WindowsSettings;

public partial class WindowsSettingsCommandsProvider : ICommandProvider
public partial class WindowsSettingsCommandsProvider : CommandProvider
{
public string DisplayName => $"Windows Services";

private readonly ListItem _searchSettingsListItem;

#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Expand All @@ -22,6 +20,8 @@ public partial class WindowsSettingsCommandsProvider : ICommandProvider

public WindowsSettingsCommandsProvider()
{
DisplayName = $"Windows Services";

_windowsSettings = JsonSettingsListHelper.ReadAllPossibleSettings();
_searchSettingsListItem = new ListItem(new WindowsSettingsListPage(_windowsSettings))
{
Expand All @@ -35,13 +35,7 @@ public WindowsSettingsCommandsProvider()
WindowsSettingsPathHelper.GenerateSettingsPathValues(_windowsSettings);
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [
_searchSettingsListItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@

using System;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;

namespace Microsoft.CmdPal.Ext.WindowsTerminal;

public partial class WindowsTerminalCommandsProvider : ICommandProvider
public partial class WindowsTerminalCommandsProvider : CommandProvider
{
public string DisplayName => $"Windows Terminal";

private readonly TerminalTopLevelListItem terminalCommand = new();

public WindowsTerminalCommandsProvider()
{
DisplayName = $"Windows Terminal";
}

public IconDataType Icon => new(string.Empty);

#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
public void Dispose() => throw new NotImplementedException();
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize

public IListItem[] TopLevelCommands()
public override IListItem[] TopLevelCommands()
{
return [terminalCommand];
}
Expand Down
Loading

0 comments on commit c319a74

Please sign in to comment.