Merge fix: Support DI and Mocking better + Support launching app with file for win and linux #656

This commit is contained in:
Gregor Biswanger
2022-04-06 18:58:02 +02:00
3 changed files with 95 additions and 18 deletions

View File

@@ -0,0 +1,76 @@
using System.Threading.Tasks;
namespace ElectronNET.API.Interfaces
{
/// <summary>
/// Electron's process object is extended from the Node.js process object. It adds the
/// events, properties, and methods.
/// </summary>
public interface IProcess
{
/// <summary>
/// The process.execPath property returns the absolute pathname of the executable that
/// started the Node.js process. Symbolic links, if any, are resolved.
/// </summary>
Task<string> ExecPathAsync { get; }
/// <summary>
/// The process.argv property returns an array containing the command-line arguments passed
/// when the Node.js process was launched. The first element will be process.execPath. See
/// process.argv0 if access to the original value of argv[0] is needed. The second element
/// will be the path to the JavaScript file being executed. The remaining elements will be
/// any additional command-line arguments
/// </summary>
Task<string[]> ArgvAsync { get; }
/// <summary>
/// The process.execPath property returns the absolute pathname of the executable that
/// started the Node.js process. Symbolic links, if any, are resolved.
/// </summary>
Task<string> TypeAsync { get; }
/// <summary>
/// The process.versions property returns an object listing the version strings of
/// chrome and electron.
/// </summary>
Task<ProcessVersions> VersionsAsync { get; }
/// <summary>
/// A Boolean. When app is started by being passed as parameter to the default app, this
/// property is true in the main process, otherwise it is false.
/// </summary>
Task<bool> DefaultAppAsync { get; }
/// <summary>
/// A Boolean, true when the current renderer context is the "main" renderer frame. If you
/// want the ID of the current frame you should use webFrame.routingId
/// </summary>
Task<bool> IsMainFrameAsync { get; }
/// <summary>
/// A String representing the path to the resources directory.
/// </summary>
Task<string> ResourcesPathAsync { get; }
/// <summary>
/// The number of seconds the current Node.js process has been running. The return value
/// includes fractions of a second. Use Math.floor() to get whole seconds.
/// </summary>
Task<double> UpTimeAsync { get; }
/// <summary>
/// The PID of the electron process
/// </summary>
Task<int> PidAsync { get; }
/// <summary>
/// The operating system CPU architecture for which the Node.js binary was compiled
/// </summary>
Task<string> ArchAsync { get; }
/// <summary>
/// A string identifying the operating system platform on which the Node.js process is running
/// </summary>
Task<string> PlatformAsync { get; }
}
}

View File

@@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using ElectronNET.API.Interfaces;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -9,7 +10,7 @@ namespace ElectronNET.API
/// Electron's process object is extended from the Node.js process object. It adds the
/// events, properties, and methods.
/// </summary>
public sealed class Process
public sealed class Process : IProcess
{
internal Process() { }

View File

@@ -33,23 +33,23 @@ namespace ElectronNET.API
.AddSingleton(provider => Dock.Instance)
.AddSingleton(provider => new ApplicationSocket { Socket = BridgeConnector.Socket, })
// this set for proper dependency injection
.AddSingleton<IIpcMain>(provider => IpcMain.Instance)
.AddSingleton<IApp>(provider => App.Instance)
.AddSingleton<IAutoUpdater>(provider => AutoUpdater.Instance)
.AddSingleton<IWindowManager>(provider => WindowManager.Instance)
.AddSingleton<IMenu>(provider => Menu.Instance)
.AddSingleton<IDialog>(provider => Dialog.Instance)
.AddSingleton<INotification>(provider => Notification.Instance)
.AddSingleton<ITray>(provider => Tray.Instance)
.AddSingleton<IGlobalShortcut>(provider => GlobalShortcut.Instance)
.AddSingleton<IShell>(provider => Shell.Instance)
.AddSingleton<IScreen>(provider => Screen.Instance)
.AddSingleton<IClipboard>(provider => Clipboard.Instance)
.AddSingleton<IHostHook>(provider => HostHook.Instance)
.AddSingleton<IPowerMonitor>(provider => PowerMonitor.Instance)
.AddSingleton<INativeTheme>(provider => NativeTheme.Instance)
.AddSingleton<IDock>(provider => Dock.Instance)
.AddSingleton<IIpcMain>(_ => IpcMain.Instance)
.AddSingleton<IApp>(_ => App.Instance)
.AddSingleton<IAutoUpdater>(_ => AutoUpdater.Instance)
.AddSingleton<IWindowManager>(_ => WindowManager.Instance)
.AddSingleton<IMenu>(_ => Menu.Instance)
.AddSingleton<IDialog>(_ => Dialog.Instance)
.AddSingleton<INotification>(_ => Notification.Instance)
.AddSingleton<ITray>(_ => Tray.Instance)
.AddSingleton<IGlobalShortcut>(_ => GlobalShortcut.Instance)
.AddSingleton<IShell>(_ => Shell.Instance)
.AddSingleton<IScreen>(_ => Screen.Instance)
.AddSingleton<IClipboard>(_ => Clipboard.Instance)
.AddSingleton<IHostHook>(_ => HostHook.Instance)
.AddSingleton<IPowerMonitor>(_ => PowerMonitor.Instance)
.AddSingleton<INativeTheme>(_ => NativeTheme.Instance)
.AddSingleton<IDock>(_ => Dock.Instance)
.AddSingleton<IProcess>(_ => Process.Instance)
.AddSingleton<IApplicationSocket>(provider => provider.GetService<ApplicationSocket>());
.AddSingleton(provider => Process.Instance);
}
}