mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
continue dev
This commit is contained in:
@@ -4,11 +4,8 @@
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Shmuelie.WinRTServer;
|
||||
using Shmuelie.WinRTServer.CsWinRT;
|
||||
|
||||
namespace PowerToysExtension;
|
||||
|
||||
@@ -21,31 +18,42 @@ public class Program
|
||||
{
|
||||
// Initialize per-extension log under CmdPal/PowerToysExtension.
|
||||
Logger.InitializeLogger("\\CmdPal\\PowerToysExtension\\Logs");
|
||||
Logger.LogInfo("PowerToysExtension starting (args: " + string.Join(' ', args) + ")");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Continue even if logging fails.
|
||||
}
|
||||
|
||||
if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
|
||||
try
|
||||
{
|
||||
using ExtensionServer server = new();
|
||||
if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
|
||||
{
|
||||
Logger.LogInfo("RegisterProcessAsComServer mode detected.");
|
||||
using ExtensionServer server = new();
|
||||
|
||||
ManualResetEvent extensionDisposedEvent = new(false);
|
||||
ManualResetEvent extensionDisposedEvent = new(false);
|
||||
|
||||
// We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
|
||||
// This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
|
||||
// If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate.
|
||||
PowerToysExtension extensionInstance = new(extensionDisposedEvent);
|
||||
server.RegisterExtension(() => extensionInstance);
|
||||
// We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
|
||||
// This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
|
||||
// If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate.
|
||||
PowerToysExtension extensionInstance = new(extensionDisposedEvent);
|
||||
server.RegisterExtension(() => extensionInstance);
|
||||
Logger.LogInfo("Extension instance registered; waiting for disposal signal.");
|
||||
|
||||
// This will make the main thread wait until the event is signalled by the extension class.
|
||||
// Since we have single instance of the extension object, we exit as soon as it is disposed.
|
||||
extensionDisposedEvent.WaitOne();
|
||||
// This will make the main thread wait until the event is signalled by the extension class.
|
||||
// Since we have single instance of the extension object, we exit as soon as it is disposed.
|
||||
extensionDisposedEvent.WaitOne();
|
||||
Logger.LogInfo("Extension disposed signal received; exiting server loop.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not being launched as a Extension... exiting.");
|
||||
Logger.LogInfo("Exited: not launched with -RegisterProcessAsComServer.");
|
||||
}
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
Console.WriteLine("Not being launched as a Extension... exiting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user