Compare commits

...

17 Commits

Author SHA1 Message Date
Florian Rappl
5b0ab76d38 Disable Linux for now 2025-11-14 09:55:30 +01:00
Florian Rappl
349762bd5e Updated changelog 2025-11-14 09:46:01 +01:00
Florian Rappl
0b49467186 Merge pull request #924 from agracio/event-task-rework
ApiEventManager Rework and refactoring of task calls
2025-11-13 14:30:31 +01:00
agracio
6fa65aa149 adding block statements to if 2025-11-12 20:20:13 +00:00
agracio
816e9c0fe9 increasing test timeout times 2025-11-12 15:56:36 +00:00
agracio
c81b0e537f increasing test timeout times 2025-11-12 15:40:04 +00:00
agracio
b89e3caa17 Merge branch 'event-task-rework' of https://github.com/agracio/Electron.NET into event-task-rework 2025-11-12 15:32:33 +00:00
agracio
e8c5de63c9 reverting Linux CI changes, skipping printer test in CI 2025-11-12 15:32:17 +00:00
agracio
d7b9174853 Merge branch 'develop' into event-task-rework 2025-11-12 15:09:44 +00:00
agracio
5ba4ab24d5 adding virtual env instructions for Linux CI 2025-11-12 15:06:14 +00:00
agracio
c6ff957d9a rebase from develop, add timeouts to tests and attempt to skip NativeImageTests on Linux 2025-11-12 14:42:43 +00:00
Florian Rappl
c37f98dcd6 Added the test logger 2025-11-12 14:27:30 +01:00
Florian Rappl
0188051d6c Updated NUKE and integrated tests in CI/CD 2025-11-12 14:21:11 +01:00
Florian Rappl
3eb8507985 Updated to target .NET 10 as well 2025-11-12 13:48:03 +01:00
agracio
546668a2c0 refactoring events API, replacing task code with calls to ApiBase. 2025-11-12 10:43:32 +00:00
Florian Rappl
68feffba02 Merge pull request #922 from softworkz/submit_fix_ipc_params
Fix sendToIpcRenderer parameter handling
2025-11-12 01:30:35 +01:00
softworkz
12d2fcb484 Fix sendToIpcRenderer parameter handling 2025-11-11 23:46:56 +01:00
72 changed files with 1208 additions and 1239 deletions

View File

@@ -7,24 +7,27 @@ env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
jobs:
linux:
runs-on: ubuntu-latest
# linux:
# runs-on: ubuntu-latest
# timeout-minutes: 10
steps:
- uses: actions/checkout@v4
# steps:
# - uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
# - name: Setup dotnet
# uses: actions/setup-dotnet@v4
# with:
# dotnet-version: |
# 6.0.x
# 8.0.x
# 10.0.x
- name: Build
run: ./build.sh
# - name: Build
# run: ./build.sh
windows:
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
@@ -35,6 +38,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
10.0.x
- name: Build
run: |

View File

@@ -1,23 +1,54 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Clean",
"Compile",
"Default",
"Package",
"PrePublish",
"Publish",
"PublishPackages",
"PublishPreRelease",
"PublishRelease",
"Restore",
"RunUnitTests"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"CommonPropsFilePath": {
"type": "string",
"description": "common.props file path - to determine the configured version"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
@@ -27,25 +58,8 @@
"description": "Shows the help text for this build assembly"
},
"Host": {
"type": "string",
"description": "Host for execution. Default is 'automatic'",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
@@ -66,10 +80,6 @@
"type": "string"
}
},
"ReleaseNotesFilePath": {
"type": "string",
"description": "ReleaseNotesFilePath - To determine the lates changelog version"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
@@ -78,59 +88,50 @@
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"CreatePackages",
"Default",
"Package",
"PrePublish",
"Publish",
"PublishPackages",
"PublishPreRelease",
"PublishRelease",
"Restore",
"RunUnitTests"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"CreatePackages",
"Default",
"Package",
"PrePublish",
"Publish",
"PublishPackages",
"PublishPreRelease",
"PublishRelease",
"Restore",
"RunUnitTests"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
]
"$ref": "#/definitions/Verbosity"
}
}
}
}
},
"allOf": [
{
"properties": {
"CommonPropsFilePath": {
"type": "string",
"description": "common.props file path - to determine the configured version"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"ReleaseNotesFilePath": {
"type": "string",
"description": "ReleaseNotesFilePath - To determine the lates changelog version"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}

View File

@@ -5,13 +5,20 @@
- Updated `PrintToPDFOptions` to also allow specifying the `PageSize` with an object (#769)
- Updated splashscreen image to have 0 margin (#622)
- Updated the IPC API w.r.t. naming and consistency (#905) @agracio
- Updated the IPC bridge w.r.t. synchronization and thread-safety (#918) @agracio
- Updated serialization to use `System.Text.Json` replacing `Newtonsoft.Json` (#917) @Denny09310
- Fixed parameter handling for the `sendToIpcRenderer` function (#922) @softworkz
- Fixed synchronization on removing event handlers (#921) @softworkz
- Fixed creation of windows with `contextIsolation` enabled (#906) @NimbusFox
- Fixed single instance behavior using the `ElectronSingleInstance` property (#901)
- Fixed potential race conditions (#908) @softworkz
- Added option to use `ElectronSplashScreen` with an HTML file (#799)
- Added option to provide floating point value as aspect ratios with `SetAspectRatio` (#793)
- Added option to provide `TitleBarOverlay` as an object (#911) @Denny09310
- Added `TitleBarOverlay` property to `BrowserWindowOptions` (#909)
- Added `RoundedCorners` property to `BrowserWindowOptions`
- Added integration tests and robustness checks (#913) @softworkz
- Added .NET 10 as an explicit target
# 0.0.18

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2024 Gregor Biswanger, Robert Mühsig
Copyright (c) 2017-2025 Gregor Biswanger, Robert Mühsig, Florian Rappl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -49,12 +49,12 @@ Add the Electron.NET configuration to your `.csproj` file:
```xml
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ElectronNET.Core" Version="1.0.0" />
<PackageReference Include="ElectronNET.Core" Version="0.1.0" />
</ItemGroup>
```

View File

@@ -28,7 +28,7 @@ Add publish profiles to `Properties/PublishProfiles/`:
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
@@ -48,7 +48,7 @@ Add publish profiles to `Properties/PublishProfiles/`:
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
@@ -68,7 +68,7 @@ Add publish profiles to `Properties/PublishProfiles/`:
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
@@ -89,7 +89,7 @@ Add publish profiles to `Properties/PublishProfiles/`:
<Platform>Any CPU</Platform>
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>

View File

@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.305",
"version": "10.0.100",
"rollForward": "feature",
"allowPrerelease": false
}

View File

@@ -3,6 +3,7 @@ using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Tools.NuGet;
@@ -15,7 +16,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
// ReSharper disable ArrangeThisQualifier
@@ -116,7 +116,7 @@ class Build : NukeBuild
Target Restore => _ => _
.Executes(() =>
{
DotNetRestore(s => s.SetProjectFile(Solution.Path));
DotNetRestore(s => s.SetProjectFile(Solution));
});
Target Compile => _ => _
@@ -124,7 +124,7 @@ class Build : NukeBuild
.Executes(() =>
{
DotNetBuild(s => s
.SetProjectFile(Solution.Path)
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetProperty("GeneratePackageOnBuild", "True")
.SetProperty("VersionPostFix", VersionPostFix ?? string.Empty));
@@ -134,18 +134,17 @@ class Build : NukeBuild
.DependsOn(Compile)
.Executes(() =>
{
// There aren't any yet
});
var TestProject = SourceDirectory / "ElectronNET.IntegrationTests" / "ElectronNET.IntegrationTests.csproj";
Target CreatePackages => _ => _
.DependsOn(Compile)
.Executes(() =>
{
// Packages are created on build
DotNetTest(s => s
.SetProjectFile(TestProject)
.SetConfiguration(Configuration)
.When(_ => GitHubActions.Instance is not null, x => x.SetLoggers("GitHubActions"))
);
});
Target PublishPackages => _ => _
.DependsOn(CreatePackages)
.DependsOn(Compile)
.DependsOn(RunUnitTests)
.Executes(() =>
{
@@ -240,7 +239,7 @@ class Build : NukeBuild
Target Package => _ => _
.DependsOn(RunUnitTests)
.DependsOn(CreatePackages);
.DependsOn(Compile);
Target Default => _ => _
.DependsOn(Package);

View File

@@ -11,11 +11,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nuke.Common" Version="8.0.0" />
<PackageReference Include="Nuke.Common" Version="9.0.4" />
</ItemGroup>
<ItemGroup>
<PackageDownload Include="NuGet.CommandLine" Version="[6.3.1]" />
<PackageDownload Include="NuGet.CommandLine" Version="[6.12.2]" />
</ItemGroup>
</Project>

View File

@@ -1,37 +1,49 @@
namespace ElectronNET.API
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
{
using ElectronNET.API.Serialization;
using ElectronNET.Common;
using Common;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading.Tasks;
public abstract class ApiBase
{
protected enum SocketEventNameTypes
protected enum SocketTaskEventNameTypes
{
DashesLowerFirst,
NoDashUpperFirst,
NoDashUpperFirst
}
protected enum SocketTaskMessageNameTypes
{
DashesLowerFirst,
NoDashUpperFirst
}
internal const int PropertyTimeout = 1000;
protected enum SocketEventNameTypes
{
DashedLower,
CamelCase,
}
private const int PropertyTimeout = 1000;
private readonly string objectName;
private readonly ConcurrentDictionary<string, PropertyGetter> propertyGetters = new ConcurrentDictionary<string, PropertyGetter>();
private readonly ConcurrentDictionary<string, string> propertyEventNames = new ConcurrentDictionary<string, string>();
private readonly ConcurrentDictionary<string, string> propertyMessageNames = new ConcurrentDictionary<string, string>();
private readonly ConcurrentDictionary<string, string> methodMessageNames = new ConcurrentDictionary<string, string>();
private readonly ConcurrentDictionary<string, PropertyGetter> propertyGetters;
private readonly ConcurrentDictionary<string, string> propertyEventNames = new();
private readonly ConcurrentDictionary<string, string> propertyMessageNames = new();
private readonly ConcurrentDictionary<string, string> methodMessageNames = new();
private static readonly ConcurrentDictionary<string, EventContainer> eventContainers = new();
private static readonly ConcurrentDictionary<string, ConcurrentDictionary<string, PropertyGetter>> AllPropertyGetters = new();
private readonly object objLock = new object();
public virtual int Id
{
get
{
return -1;
}
get => -1;
// ReSharper disable once ValueParameterNotUsed
protected set
@@ -39,11 +51,14 @@
}
}
protected abstract SocketEventNameTypes SocketEventNameType { get; }
protected abstract SocketTaskEventNameTypes SocketTaskEventNameType { get; }
protected virtual SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.NoDashUpperFirst;
protected virtual SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
protected ApiBase()
{
this.objectName = this.GetType().Name.LowerFirst();
propertyGetters = AllPropertyGetters.GetOrAdd(objectName, _ => new ConcurrentDictionary<string, PropertyGetter>());
}
protected void CallMethod0([CallerMemberName] string callerName = null)
@@ -98,7 +113,7 @@
}
}
protected Task<T> GetPropertyAsync<T>([CallerMemberName] string callerName = null)
protected Task<T> GetPropertyAsync<T>(object arg = null, [CallerMemberName] string callerName = null)
{
Debug.Assert(callerName != null, nameof(callerName) + " != null");
@@ -106,7 +121,7 @@
{
return this.propertyGetters.GetOrAdd(callerName, _ =>
{
var getter = new PropertyGetter<T>(this, callerName, PropertyTimeout);
var getter = new PropertyGetter<T>(this, callerName, PropertyTimeout, arg);
getter.Task<T>().ContinueWith(_ =>
{
@@ -120,6 +135,98 @@
}).Task<T>();
}
}
protected void AddEvent(Action value, int? id = null, [CallerMemberName] string callerName = null)
{
Debug.Assert(callerName != null, nameof(callerName) + " != null");
var eventName = EventName(callerName);
var eventKey = EventKey(eventName, id);
lock (objLock)
{
var container = eventContainers.GetOrAdd(eventKey, _ =>
{
var container = new EventContainer();
BridgeConnector.Socket.On(eventKey, container.OnEventAction);
BridgeConnector.Socket.Emit($"register-{eventName}", id);
return container;
});
container.Register(value);
}
}
protected void RemoveEvent(Action value, int? id = null, [CallerMemberName] string callerName = null)
{
Debug.Assert(callerName != null, nameof(callerName) + " != null");
var eventName = EventName(callerName);
var eventKey = EventKey(eventName, id);
lock (objLock)
{
if (eventContainers.TryGetValue(eventKey, out var container) && !container.Unregister(value))
{
BridgeConnector.Socket.Off(eventKey);
eventContainers.TryRemove(eventKey, out _);
}
}
}
protected void AddEvent<T>(Action<T> value, int? id = null, [CallerMemberName] string callerName = null)
{
Debug.Assert(callerName != null, nameof(callerName) + " != null");
var eventName = EventName(callerName);
var eventKey = EventKey(eventName, id);
lock (objLock)
{
var container = eventContainers.GetOrAdd(eventKey, _ =>
{
var container = new EventContainer();
BridgeConnector.Socket.On<T>(eventKey, container.OnEventActionT);
BridgeConnector.Socket.Emit($"register-{eventName}", id);
return container;
});
container.Register(value);
}
}
protected void RemoveEvent<T>(Action<T> value, int? id = null, [CallerMemberName] string callerName = null)
{
Debug.Assert(callerName != null, nameof(callerName) + " != null");
var eventName = EventName(callerName);
var eventKey = EventKey(eventName, id);
lock (objLock)
{
if (eventContainers.TryGetValue(eventKey, out var container) && !container.Unregister(value))
{
BridgeConnector.Socket.Off(eventKey);
eventContainers.TryRemove(eventKey, out _);
}
}
}
private string EventName(string callerName)
{
switch (SocketEventNameType)
{
case SocketEventNameTypes.DashedLower:
return $"{objectName}-{callerName.ToDashedEventName()}";
case SocketEventNameTypes.CamelCase:
return $"{objectName}-{callerName.ToCamelCaseEventName()}";
default:
throw new ArgumentOutOfRangeException();
}
}
private string EventKey(string eventName, int? id)
{
return string.Format(CultureInfo.InvariantCulture, "{0}{1:D}", eventName, id);
}
internal abstract class PropertyGetter
{
@@ -131,26 +238,37 @@
private readonly Task<T> tcsTask;
private TaskCompletionSource<T> tcs;
public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs)
public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs, object arg = null)
{
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
this.tcsTask = this.tcs.Task;
string eventName;
string messageName;
switch (apiBase.SocketEventNameType)
switch (apiBase.SocketTaskEventNameType)
{
case SocketEventNameTypes.DashesLowerFirst:
case SocketTaskEventNameTypes.DashesLowerFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
break;
case SocketEventNameTypes.NoDashUpperFirst:
case SocketTaskEventNameTypes.NoDashUpperFirst:
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
break;
default:
throw new ArgumentOutOfRangeException();
}
var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
switch (apiBase.SocketTaskMessageNameType)
{
case SocketTaskMessageNameTypes.DashesLowerFirst:
messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}");
break;
case SocketTaskMessageNameTypes.NoDashUpperFirst:
messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
break;
default:
throw new ArgumentOutOfRangeException();
}
BridgeConnector.Socket.Once<T>(eventName, (result) =>
{
@@ -171,14 +289,14 @@
}
}
});
if (apiBase.Id >= 0)
if (arg != null)
{
BridgeConnector.Socket.Emit(messageName, apiBase.Id);
_ = apiBase.Id >= 0 ? BridgeConnector.Socket.Emit(messageName, apiBase.Id, arg) : BridgeConnector.Socket.Emit(messageName, arg);
}
else
{
BridgeConnector.Socket.Emit(messageName);
_ = apiBase.Id >= 0 ? BridgeConnector.Socket.Emit(messageName, apiBase.Id) : BridgeConnector.Socket.Emit(messageName);
}
System.Threading.Tasks.Task.Delay(PropertyTimeout).ContinueWith(_ =>
@@ -203,5 +321,53 @@
return this.tcsTask as Task<T1>;
}
}
[SuppressMessage("ReSharper", "InconsistentlySynchronizedField")]
private class EventContainer
{
private Action eventAction;
private Delegate eventActionT;
private Action<T> GetEventActionT<T>()
{
return (Action<T>)eventActionT;
}
private void SetEventActionT<T>(Action<T> actionT)
{
eventActionT = actionT;
}
public void OnEventAction() => eventAction?.Invoke();
public void OnEventActionT<T>(T p) => GetEventActionT<T>()?.Invoke(p);
public void Register(Action receiver)
{
eventAction += receiver;
}
public void Register<T>(Action<T> receiver)
{
var actionT = GetEventActionT<T>();
actionT += receiver;
SetEventActionT(actionT);
}
public bool Unregister(Action receiver)
{
eventAction -= receiver;
return this.eventAction != null;
}
public bool Unregister<T>(Action<T> receiver)
{
var actionT = GetEventActionT<T>();
actionT -= receiver;
SetEventActionT(actionT);
return actionT != null;
}
}
}
}

View File

@@ -1,7 +1,5 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
using ElectronNET.API.Serialization;
using ElectronNET.Common;
using System;
using System.Runtime.InteropServices;
using System.Text.Json;
@@ -17,7 +15,8 @@ namespace ElectronNET.API
/// </summary>
public sealed class App : ApiBase
{
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.NoDashUpperFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Emitted when all windows have been closed.
@@ -224,45 +223,37 @@ namespace ElectronNET.API
/// </summary>
public event Action BrowserWindowBlur
{
add => ApiEventManager.AddEvent("app-browser-window-blur", GetHashCode(), _browserWindowBlur, value);
remove => ApiEventManager.RemoveEvent("app-browser-window-blur", GetHashCode(), _browserWindowBlur, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _browserWindowBlur;
/// <summary>
/// Emitted when a <see cref="BrowserWindow"/> gets focused.
/// </summary>
public event Action BrowserWindowFocus
{
add => ApiEventManager.AddEvent("app-browser-window-focus", GetHashCode(), _browserWindowFocus, value);
remove => ApiEventManager.RemoveEvent("app-browser-window-focus", GetHashCode(), _browserWindowFocus, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _browserWindowFocus;
/// <summary>
/// Emitted when a new <see cref="BrowserWindow"/> is created.
/// </summary>
public event Action BrowserWindowCreated
{
add => ApiEventManager.AddEvent("app-browser-window-created", GetHashCode(), _browserWindowCreated, value);
remove => ApiEventManager.RemoveEvent("app-browser-window-created", GetHashCode(), _browserWindowCreated, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _browserWindowCreated;
/// <summary>
/// Emitted when a new <see cref="WebContents"/> is created.
/// </summary>
public event Action WebContentsCreated
{
add => ApiEventManager.AddEvent("app-web-contents-created", GetHashCode(), _webContentsCreated, value);
remove => ApiEventManager.RemoveEvent("app-web-contents-created", GetHashCode(), _webContentsCreated, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _webContentsCreated;
/// <summary>
/// Emitted when Chromes accessibility support changes. This event fires when assistive technologies, such as
/// screen readers, are enabled or disabled. See https://www.chromium.org/developers/design-documents/accessibility for more details.
@@ -270,12 +261,10 @@ namespace ElectronNET.API
/// <returns><see langword="true"/> when Chrome's accessibility support is enabled, <see langword="false"/> otherwise.</returns>
public event Action<bool> AccessibilitySupportChanged
{
add => ApiEventManager.AddEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value, (args) => args.GetBoolean());
remove => ApiEventManager.RemoveEvent("app-accessibility-support-changed", GetHashCode(), _accessibilitySupportChanged, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<bool> _accessibilitySupportChanged;
/// <summary>
/// Emitted when the application has finished basic startup.
/// </summary>
@@ -329,12 +318,10 @@ namespace ElectronNET.API
/// </summary>
public event Action<string> OpenFile
{
add => ApiEventManager.AddEvent("app-open-file", GetHashCode(), _openFile, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("app-open-file", GetHashCode(), _openFile, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<string> _openFile;
/// <summary>
/// Emitted when a MacOS user wants to open a URL with the application. Your application's Info.plist file must
@@ -342,12 +329,10 @@ namespace ElectronNET.API
/// </summary>
public event Action<string> OpenUrl
{
add => ApiEventManager.AddEvent("app-open-url", GetHashCode(), _openUrl, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("app-open-url", GetHashCode(), _openUrl, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<string> _openUrl;
/// <summary>
/// A <see cref="string"/> property that indicates the current application's name, which is the name in the
/// application's package.json file.

View File

@@ -1,9 +1,6 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using ElectronNET.Common;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
// ReSharper disable InconsistentNaming
@@ -13,8 +10,12 @@ namespace ElectronNET.API
/// <summary>
/// Enable apps to automatically update themselves. Based on electron-updater.
/// </summary>
public sealed class AutoUpdater
public sealed class AutoUpdater: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Whether to automatically download an update when it is found. (Default is true)
/// </summary>
@@ -22,15 +23,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("autoUpdater-autoDownload-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-autoDownload-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<bool>()).Result;
}
set
{
@@ -47,15 +40,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("autoUpdater-autoInstallOnAppQuit-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-autoInstallOnAppQuit-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<bool>()).Result;
}
set
{
@@ -73,15 +58,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("autoUpdater-allowPrerelease-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-allowPrerelease-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<bool>()).Result;
}
set
{
@@ -97,15 +74,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("autoUpdater-fullChangelog-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-fullChangelog-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<bool>()).Result;
}
set
{
@@ -122,15 +91,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("autoUpdater-allowDowngrade-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-allowDowngrade-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<bool>()).Result;
}
set
{
@@ -145,15 +106,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("autoUpdater-updateConfigPath-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-updateConfigPath-get");
return tcs.Task;
}).Result;
return Task.Run(() => GetPropertyAsync<string>()).Result;
}
}
@@ -164,15 +117,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<SemVer>();
BridgeConnector.Socket.Once<SemVer>("autoUpdater-currentVersion-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-currentVersion-get");
return tcs.Task;
});
return Task.Run(() => GetPropertyAsync<SemVer>());
}
}
@@ -197,15 +142,18 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<string>();
return Task.Run(() => GetPropertyAsync<string>());
}
}
BridgeConnector.Socket.Once<string>("autoUpdater-channel-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-channel-get");
return tcs.Task;
});
/// <summary>
/// Set the update channel. Not applicable for GitHub.
/// </summary>
public string SetChannel
{
set
{
BridgeConnector.Socket.Emit("autoUpdater-channel-set", value);
}
}
@@ -217,15 +165,7 @@ namespace ElectronNET.API
{
get
{
return Task.Run(() =>
{
var tcs = new TaskCompletionSource<Dictionary<string, string>>();
BridgeConnector.Socket.Once<Dictionary<string, string>>("autoUpdater-requestHeaders-get-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-get");
return tcs.Task;
});
return Task.Run(() => GetPropertyAsync<Dictionary<string, string>>());
}
}
@@ -245,68 +185,56 @@ namespace ElectronNET.API
/// </summary>
public event Action<string> OnError
{
add => ApiEventManager.AddEvent("autoUpdater-error", GetHashCode(), _error, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("autoUpdater-error", GetHashCode(), _error, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<string> _error;
/// <summary>
/// Emitted when checking if an update has started.
/// </summary>
public event Action OnCheckingForUpdate
{
add => ApiEventManager.AddEvent("autoUpdater-checking-for-update", GetHashCode(), _checkingForUpdate, value);
remove => ApiEventManager.RemoveEvent("autoUpdater-checking-for-update", GetHashCode(), _checkingForUpdate, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _checkingForUpdate;
/// <summary>
/// Emitted when there is an available update.
/// The update is downloaded automatically if AutoDownload is true.
/// </summary>
public event Action<UpdateInfo> OnUpdateAvailable
{
add => ApiEventManager.AddEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-available", GetHashCode(), _updateAvailable, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<UpdateInfo> _updateAvailable;
/// <summary>
/// Emitted when there is no available update.
/// </summary>
public event Action<UpdateInfo> OnUpdateNotAvailable
{
add => ApiEventManager.AddEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-not-available", GetHashCode(), _updateNotAvailable, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<UpdateInfo> _updateNotAvailable;
/// <summary>
/// Emitted on download progress.
/// </summary>
public event Action<ProgressInfo> OnDownloadProgress
{
add => ApiEventManager.AddEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value, (args) => args.Deserialize(ElectronJsonContext.Default.ProgressInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-download-progress", GetHashCode(), _downloadProgress, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<ProgressInfo> _downloadProgress;
/// <summary>
/// Emitted on download complete.
/// </summary>
public event Action<UpdateInfo> OnUpdateDownloaded
{
add => ApiEventManager.AddEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value, (args) => args.Deserialize(ElectronJsonContext.Default.UpdateInfo));
remove => ApiEventManager.RemoveEvent("autoUpdater-update-downloaded", GetHashCode(), _updateDownloaded, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<UpdateInfo> _updateDownloaded;
private static AutoUpdater _autoUpdater;
private static object _syncRoot = new object();
@@ -342,11 +270,11 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>();
string guid = Guid.NewGuid().ToString();
BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdaterCheckForUpdatesComplete" + guid, (result) =>
BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdater-checkForUpdates-completed" + guid, (result) =>
{
try
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesError" + guid);
taskCompletionSource.SetResult(result);
}
catch (Exception ex)
@@ -354,15 +282,15 @@ namespace ElectronNET.API
taskCompletionSource.SetException(ex);
}
});
BridgeConnector.Socket.Once<string>("autoUpdaterCheckForUpdatesError" + guid, (result) =>
BridgeConnector.Socket.Once<string>("autoUpdater-checkForUpdatesError" + guid, (result) =>
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
BridgeConnector.Socket.Off("autoUpdater-checkForUpdates-completed" + guid);
string message = "An error occurred in CheckForUpdatesAsync";
if (!string.IsNullOrEmpty(result)) message = result;
taskCompletionSource.SetException(new Exception(message));
});
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdates", guid);
BridgeConnector.Socket.Emit("autoUpdater-checkForUpdates", guid);
return taskCompletionSource.Task;
}
@@ -378,11 +306,11 @@ namespace ElectronNET.API
var taskCompletionSource = new TaskCompletionSource<UpdateCheckResult>();
string guid = Guid.NewGuid().ToString();
BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (result) =>
BridgeConnector.Socket.Once<UpdateCheckResult>("autoUpdater-checkForUpdatesAndNotify-completed" + guid, (result) =>
{
try
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesAndNotifyError" + guid);
taskCompletionSource.SetResult(result);
}
catch (Exception ex)
@@ -390,15 +318,15 @@ namespace ElectronNET.API
taskCompletionSource.SetException(ex);
}
});
BridgeConnector.Socket.Once<string>("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (result) =>
BridgeConnector.Socket.Once<string>("autoUpdater-checkForUpdatesAndNotifyError" + guid, (result) =>
{
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
BridgeConnector.Socket.Off("autoUpdater-checkForUpdatesAndNotify-completed" + guid);
string message = "An error occurred in CheckForUpdatesAndNotifyAsync";
if (!string.IsNullOrEmpty(result)) message = result;
taskCompletionSource.SetException(new Exception(message));
});
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdatesAndNotify", guid);
BridgeConnector.Socket.Emit("autoUpdater-checkForUpdatesAndNotify", guid);
return taskCompletionSource.Task;
}
@@ -414,7 +342,7 @@ namespace ElectronNET.API
/// <param name="isForceRunAfter">Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.</param>
public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false)
{
BridgeConnector.Socket.Emit("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter);
BridgeConnector.Socket.Emit("autoUpdater-quitAndInstall", isSilent, isForceRunAfter);
}
/// <summary>
@@ -426,8 +354,8 @@ namespace ElectronNET.API
var tcs = new TaskCompletionSource<string>();
string guid = Guid.NewGuid().ToString();
BridgeConnector.Socket.Once<string>("autoUpdaterDownloadUpdateComplete" + guid, tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdaterDownloadUpdate", guid);
BridgeConnector.Socket.Once<string>("autoUpdater-downloadUpdate-completed" + guid, tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-downloadUpdate", guid);
return tcs.Task;
}
@@ -441,8 +369,8 @@ namespace ElectronNET.API
var tcs = new TaskCompletionSource<string>();
string guid = Guid.NewGuid().ToString();
BridgeConnector.Socket.Once<string>("autoUpdaterGetFeedURLComplete" + guid, tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdaterGetFeedURL", guid);
BridgeConnector.Socket.Once<string>("autoUpdater-getFeedURL-completed" + guid, tcs.SetResult);
BridgeConnector.Socket.Emit("autoUpdater-getFeedURL", guid);
return tcs.Task;
}

View File

@@ -1,6 +1,4 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -10,12 +8,14 @@ namespace ElectronNET.API
/// It is like a child window, except that it is positioned relative to its owning window.
/// It is meant to be an alternative to the webview tag.
/// </summary>
public class BrowserView
public class BrowserView: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
/// <summary>
/// Gets the identifier.
/// </summary>
public int Id { get; internal set; }
public override int Id { get; protected set; }
/// <summary>
/// Render and control web pages.
@@ -30,19 +30,11 @@ namespace ElectronNET.API
{
get
{
var tcs = new TaskCompletionSource<Rectangle>();
Task.Run(() =>
{
BridgeConnector.Socket.Once<Rectangle>("browserView-getBounds-reply", tcs.SetResult);
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
});
return tcs.Task.GetAwaiter().GetResult();
return Task.Run(() => GetPropertyAsync<Rectangle>()).Result;
}
set
{
BridgeConnector.Socket.Emit("browserView-setBounds", Id, value);
BridgeConnector.Socket.Emit("browserView-bounds-set", Id, value);
}
}

View File

@@ -10,15 +10,13 @@ using System.Threading.Tasks;
namespace ElectronNET.API;
using ElectronNET.Common;
using System.Text.Json;
/// <summary>
/// Create and control browser windows.
/// </summary>
public class BrowserWindow : ApiBase
{
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Gets the identifier.
@@ -34,34 +32,28 @@ public class BrowserWindow : ApiBase
/// </summary>
public event Action OnReadyToShow
{
add => ApiEventManager.AddEvent("browserWindow-ready-to-show", Id, _readyToShow, value);
remove => ApiEventManager.RemoveEvent("browserWindow-ready-to-show", Id, _readyToShow, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _readyToShow;
/// <summary>
/// Emitted when the document changed its title.
/// </summary>
public event Action<string> OnPageTitleUpdated
{
add => ApiEventManager.AddEvent("browserWindow-page-title-updated", Id, _pageTitleUpdated, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("browserWindow-page-title-updated", Id, _pageTitleUpdated, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _pageTitleUpdated;
/// <summary>
/// Emitted when the window is going to be closed.
/// </summary>
public event Action OnClose
{
add => ApiEventManager.AddEvent("browserWindow-close", Id, _close, value);
remove => ApiEventManager.RemoveEvent("browserWindow-close", Id, _close, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _close;
/// <summary>
/// Emitted when the window is closed.
/// After you have received this event you should remove the
@@ -69,144 +61,118 @@ public class BrowserWindow : ApiBase
/// </summary>
public event Action OnClosed
{
add => ApiEventManager.AddEvent("browserWindow-closed", Id, _closed, value);
remove => ApiEventManager.RemoveEvent("browserWindow-closed", Id, _closed, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _closed;
/// <summary>
/// Emitted when window session is going to end due to force shutdown or machine restart or session log off.
/// </summary>
public event Action OnSessionEnd
{
add => ApiEventManager.AddEvent("browserWindow-session-end", Id, _sessionEnd, value);
remove => ApiEventManager.RemoveEvent("browserWindow-session-end", Id, _sessionEnd, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _sessionEnd;
/// <summary>
/// Emitted when the web page becomes unresponsive.
/// </summary>
public event Action OnUnresponsive
{
add => ApiEventManager.AddEvent("browserWindow-unresponsive", Id, _unresponsive, value);
remove => ApiEventManager.RemoveEvent("browserWindow-unresponsive", Id, _unresponsive, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _unresponsive;
/// <summary>
/// Emitted when the unresponsive web page becomes responsive again.
/// </summary>
public event Action OnResponsive
{
add => ApiEventManager.AddEvent("browserWindow-responsive", Id, _responsive, value);
remove => ApiEventManager.RemoveEvent("browserWindow-responsive", Id, _responsive, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _responsive;
/// <summary>
/// Emitted when the window loses focus.
/// </summary>
public event Action OnBlur
{
add => ApiEventManager.AddEvent("browserWindow-blur", Id, _blur, value);
remove => ApiEventManager.RemoveEvent("browserWindow-blur", Id, _blur, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _blur;
/// <summary>
/// Emitted when the window gains focus.
/// </summary>
public event Action OnFocus
{
add => ApiEventManager.AddEvent("browserWindow-focus", Id, _focus, value);
remove => ApiEventManager.RemoveEvent("browserWindow-focus", Id, _focus, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _focus;
/// <summary>
/// Emitted when the window is shown.
/// </summary>
public event Action OnShow
{
add => ApiEventManager.AddEvent("browserWindow-show", Id, _show, value);
remove => ApiEventManager.RemoveEvent("browserWindow-show", Id, _show, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _show;
/// <summary>
/// Emitted when the window is hidden.
/// </summary>
public event Action OnHide
{
add => ApiEventManager.AddEvent("browserWindow-hide", Id, _hide, value);
remove => ApiEventManager.RemoveEvent("browserWindow-hide", Id, _hide, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _hide;
/// <summary>
/// Emitted when window is maximized.
/// </summary>
public event Action OnMaximize
{
add => ApiEventManager.AddEvent("browserWindow-maximize", Id, _maximize, value);
remove => ApiEventManager.RemoveEvent("browserWindow-maximize", Id, _maximize, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _maximize;
/// <summary>
/// Emitted when the window exits from a maximized state.
/// </summary>
public event Action OnUnmaximize
{
add => ApiEventManager.AddEvent("browserWindow-unmaximize", Id, _unmaximize, value);
remove => ApiEventManager.RemoveEvent("browserWindow-unmaximize", Id, _unmaximize, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _unmaximize;
/// <summary>
/// Emitted when the window is minimized.
/// </summary>
public event Action OnMinimize
{
add => ApiEventManager.AddEvent("browserWindow-minimize", Id, _minimize, value);
remove => ApiEventManager.RemoveEvent("browserWindow-minimize", Id, _minimize, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _minimize;
/// <summary>
/// Emitted when the window is restored from a minimized state.
/// </summary>
public event Action OnRestore
{
add => ApiEventManager.AddEvent("browserWindow-restore", Id, _restore, value);
remove => ApiEventManager.RemoveEvent("browserWindow-restore", Id, _restore, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _restore;
/// <summary>
/// Emitted when the window is being resized.
/// </summary>
public event Action OnResize
{
add => ApiEventManager.AddEvent("browserWindow-resize", Id, _resize, value);
remove => ApiEventManager.RemoveEvent("browserWindow-resize", Id, _resize, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _resize;
/// <summary>
/// Emitted when the window is being moved to a new position.
///
@@ -214,67 +180,55 @@ public class BrowserWindow : ApiBase
/// </summary>
public event Action OnMove
{
add => ApiEventManager.AddEvent("browserWindow-move", Id, _move, value);
remove => ApiEventManager.RemoveEvent("browserWindow-move", Id, _move, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _move;
/// <summary>
/// macOS: Emitted once when the window is moved to a new position.
/// </summary>
public event Action OnMoved
{
add => ApiEventManager.AddEvent("browserWindow-moved", Id, _moved, value);
remove => ApiEventManager.RemoveEvent("browserWindow-moved", Id, _moved, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _moved;
/// <summary>
/// Emitted when the window enters a full-screen state.
/// </summary>
public event Action OnEnterFullScreen
{
add => ApiEventManager.AddEvent("browserWindow-enter-full-screen", Id, _enterFullScreen, value);
remove => ApiEventManager.RemoveEvent("browserWindow-enter-full-screen", Id, _enterFullScreen, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _enterFullScreen;
/// <summary>
/// Emitted when the window leaves a full-screen state.
/// </summary>
public event Action OnLeaveFullScreen
{
add => ApiEventManager.AddEvent("browserWindow-leave-full-screen", Id, _leaveFullScreen, value);
remove => ApiEventManager.RemoveEvent("browserWindow-leave-full-screen", Id, _leaveFullScreen, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _leaveFullScreen;
/// <summary>
/// Emitted when the window enters a full-screen state triggered by HTML API.
/// </summary>
public event Action OnEnterHtmlFullScreen
{
add => ApiEventManager.AddEvent("browserWindow-enter-html-full-screen", Id, _enterHtmlFullScreen, value);
remove => ApiEventManager.RemoveEvent("browserWindow-enter-html-full-screen", Id, _enterHtmlFullScreen, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _enterHtmlFullScreen;
/// <summary>
/// Emitted when the window leaves a full-screen state triggered by HTML API.
/// </summary>
public event Action OnLeaveHtmlFullScreen
{
add => ApiEventManager.AddEvent("browserWindow-leave-html-full-screen", Id, _leaveHtmlFullScreen, value);
remove => ApiEventManager.RemoveEvent("browserWindow-leave-html-full-screen", Id, _leaveHtmlFullScreen, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _leaveHtmlFullScreen;
/// <summary>
/// Emitted when an App Command is invoked. These are typically related to
/// keyboard media keys or browser commands, as well as the “Back” button
@@ -286,56 +240,46 @@ public class BrowserWindow : ApiBase
/// </summary>
public event Action<string> OnAppCommand
{
add => ApiEventManager.AddEvent("browserWindow-app-command", Id, _appCommand, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("browserWindow-app-command", Id, _appCommand, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _appCommand;
/// <summary>
/// Emitted on 3-finger swipe. Possible directions are up, right, down, left.
/// </summary>
public event Action<string> OnSwipe
{
add => ApiEventManager.AddEvent("browserWindow-swipe", Id, _swipe, value, (args) => args.ToString());
remove => ApiEventManager.RemoveEvent("browserWindow-swipe", Id, _swipe, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _swipe;
/// <summary>
/// Emitted when the window opens a sheet.
/// </summary>
public event Action OnSheetBegin
{
add => ApiEventManager.AddEvent("browserWindow-sheet-begin", Id, _sheetBegin, value);
remove => ApiEventManager.RemoveEvent("browserWindow-sheet-begin", Id, _sheetBegin, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _sheetBegin;
/// <summary>
/// Emitted when the window has closed a sheet.
/// </summary>
public event Action OnSheetEnd
{
add => ApiEventManager.AddEvent("browserWindow-sheet-end", Id, _sheetEnd, value);
remove => ApiEventManager.RemoveEvent("browserWindow-sheet-end", Id, _sheetEnd, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _sheetEnd;
/// <summary>
/// Emitted when the native new tab button is clicked.
/// </summary>
public event Action OnNewWindowForTab
{
add => ApiEventManager.AddEvent("browserWindow-new-window-for-tab", Id, _newWindowForTab, value);
remove => ApiEventManager.RemoveEvent("browserWindow-new-window-for-tab", Id, _newWindowForTab, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _newWindowForTab;
internal BrowserWindow(int id)
{
Id = id;

View File

@@ -2,14 +2,18 @@ using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
{
/// <summary>
/// Perform copy and paste operations on the system clipboard.
/// </summary>
public sealed class Clipboard
public sealed class Clipboard: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
private static Clipboard _clipboard;
private static object _syncRoot = new object();
@@ -41,15 +45,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type"></param>
/// <returns>The content in the clipboard as plain text.</returns>
public Task<string> ReadTextAsync(string type = "")
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("clipboard-readText-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readText", type);
return tcs.Task;
}
public Task<string> ReadTextAsync(string type = "") => GetPropertyAsync<string>(type);
/// <summary>
/// Writes the text into the clipboard as plain text.
@@ -66,15 +62,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string> ReadHTMLAsync(string type = "")
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("clipboard-readHTML-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readHTML", type);
return tcs.Task;
}
public Task<string> ReadHTMLAsync(string type = "") => GetPropertyAsync<string>(type);
/// <summary>
/// Writes markup to the clipboard.
@@ -91,15 +79,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string> ReadRTFAsync(string type = "")
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("clipboard-readRTF-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readRTF", type);
return tcs.Task;
}
public Task<string> ReadRTFAsync(string type = "") => GetPropertyAsync<string>(type);
/// <summary>
/// Writes the text into the clipboard in RTF.
@@ -108,7 +88,7 @@ namespace ElectronNET.API
/// <param name="type"></param>
public void WriteRTF(string text, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-writeHTML", text, type);
BridgeConnector.Socket.Emit("clipboard-writeRTF", text, type);
}
/// <summary>
@@ -117,15 +97,7 @@ namespace ElectronNET.API
/// be empty strings when the bookmark is unavailable.
/// </summary>
/// <returns></returns>
public Task<ReadBookmark> ReadBookmarkAsync()
{
var tcs = new TaskCompletionSource<ReadBookmark>();
BridgeConnector.Socket.Once<ReadBookmark>("clipboard-readBookmark-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readBookmark");
return tcs.Task;
}
public Task<ReadBookmark> ReadBookmarkAsync() => GetPropertyAsync<ReadBookmark>();
/// <summary>
/// Writes the title and url into the clipboard as a bookmark.
@@ -148,15 +120,7 @@ namespace ElectronNET.API
/// find pasteboard whenever the application is activated.
/// </summary>
/// <returns></returns>
public Task<string> ReadFindTextAsync()
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("clipboard-readFindText-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readFindText");
return tcs.Task;
}
public Task<string> ReadFindTextAsync() => GetPropertyAsync<string>();
/// <summary>
/// macOS: Writes the text into the find pasteboard as plain text. This method uses
@@ -182,15 +146,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string[]> AvailableFormatsAsync(string type = "")
{
var tcs = new TaskCompletionSource<string[]>();
BridgeConnector.Socket.Once<string[]>("clipboard-availableFormats-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-availableFormats", type);
return tcs.Task;
}
public Task<string[]> AvailableFormatsAsync(string type = "") => GetPropertyAsync<string[]>(type);
/// <summary>
/// Writes data to the clipboard.
@@ -207,15 +163,7 @@ namespace ElectronNET.API
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<NativeImage> ReadImageAsync(string type = "")
{
var tcs = new TaskCompletionSource<NativeImage>();
BridgeConnector.Socket.Once<NativeImage>("clipboard-readImage-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("clipboard-readImage", type);
return tcs.Task;
}
public Task<NativeImage> ReadImageAsync(string type = "") => GetPropertyAsync<NativeImage>(type);
/// <summary>
/// Writes an image to the clipboard.

View File

@@ -1,5 +1,4 @@
using System.Text.Json;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
namespace ElectronNET.API

View File

@@ -1,5 +1,4 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System;
using System.Text.Json;
using System.Threading.Tasks;

View File

@@ -1,17 +1,19 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
using ElectronNET.Common;
using System;
using System.Text.Json;
using System;
using System.Threading.Tasks;
using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
namespace ElectronNET.API
{
/// <summary>
/// Read and respond to changes in Chromium's native color theme.
/// </summary>
public sealed class NativeTheme
public sealed class NativeTheme: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
private static NativeTheme _nativeTheme;
private static object _syncRoot = new object();
@@ -105,58 +107,26 @@ namespace ElectronNET.API
/// A <see cref="ThemeSourceMode"/> property that can be <see cref="ThemeSourceMode.System"/>, <see cref="ThemeSourceMode.Light"/> or <see cref="ThemeSourceMode.Dark"/>. It is used to override (<seealso cref="SetThemeSource"/>) and
/// supercede the value that Chromium has chosen to use internally.
/// </summary>
public Task<ThemeSourceMode> GetThemeSourceAsync()
{
var tcs = new TaskCompletionSource<ThemeSourceMode>();
BridgeConnector.Socket.Once<ThemeSourceMode>("nativeTheme-themeSource-getCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("nativeTheme-themeSource-get");
return tcs.Task;
}
public Task<ThemeSourceMode> GetThemeSourceAsync() => GetPropertyAsync<ThemeSourceMode>();
/// <summary>
/// A <see cref="bool"/> for if the OS / Chromium currently has a dark mode enabled or is
/// being instructed to show a dark-style UI. If you want to modify this value you
/// should use <see cref="SetThemeSource"/>.
/// </summary>
public Task<bool> ShouldUseDarkColorsAsync()
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("nativeTheme-shouldUseDarkColors-completed", tcs.SetResult);
BridgeConnector.Socket.Emit("nativeTheme-shouldUseDarkColors");
return tcs.Task;
}
public Task<bool> ShouldUseDarkColorsAsync() => GetPropertyAsync<bool>();
/// <summary>
/// A <see cref="bool"/> for if the OS / Chromium currently has high-contrast mode enabled or is
/// being instructed to show a high-contrast UI.
/// </summary>
public Task<bool> ShouldUseHighContrastColorsAsync()
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("nativeTheme-shouldUseHighContrastColors-completed", tcs.SetResult);
BridgeConnector.Socket.Emit("nativeTheme-shouldUseHighContrastColors");
return tcs.Task;
}
public Task<bool> ShouldUseHighContrastColorsAsync() => GetPropertyAsync<bool>();
/// <summary>
/// A <see cref="bool"/> for if the OS / Chromium currently has an inverted color scheme or is
/// being instructed to use an inverted color scheme.
/// </summary>
public Task<bool> ShouldUseInvertedColorSchemeAsync()
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("nativeTheme-shouldUseInvertedColorScheme-completed", tcs.SetResult);
BridgeConnector.Socket.Emit("nativeTheme-shouldUseInvertedColorScheme");
return tcs.Task;
}
public Task<bool> ShouldUseInvertedColorSchemeAsync() => GetPropertyAsync<bool>();
/// <summary>
/// Emitted when something in the underlying NativeTheme has changed. This normally means that either the value of <see cref="ShouldUseDarkColorsAsync"/>,
@@ -164,10 +134,8 @@ namespace ElectronNET.API
/// </summary>
public event Action Updated
{
add => ApiEventManager.AddEvent("nativeTheme-updated", GetHashCode(), _updated, value);
remove => ApiEventManager.RemoveEvent("nativeTheme-updated", GetHashCode(), _updated, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _updated;
}
}

View File

@@ -1,9 +1,7 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -11,8 +9,9 @@ namespace ElectronNET.API
/// <summary>
/// Create OS desktop notifications
/// </summary>
public sealed class Notification
public sealed class Notification: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.NoDashUpperFirst;
private static Notification _notification;
private static object _syncRoot = new object();
@@ -117,16 +116,6 @@ namespace ElectronNET.API
/// Whether or not desktop notifications are supported on the current system.
/// </summary>
/// <returns></returns>
public Task<bool> IsSupportedAsync()
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("notificationIsSupportedComplete", tcs.SetResult);
BridgeConnector.Socket.Emit("notificationIsSupported");
return tcs.Task;
}
public Task<bool> IsSupportedAsync() => GetPropertyAsync<bool>();
}
}

View File

@@ -1,5 +1,4 @@
using ElectronNET.Common;
using System;
using System;
// ReSharper disable InconsistentNaming
@@ -8,74 +7,65 @@ namespace ElectronNET.API
/// <summary>
/// Monitor power state changes..
/// </summary>
public sealed class PowerMonitor
public sealed class PowerMonitor: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Emitted when the system is about to lock the screen.
/// </summary>
public event Action OnLockScreen
{
add => ApiEventManager.AddEvent("pm-lock-screen", string.Empty, _lockScreen, value);
remove => ApiEventManager.RemoveEvent("pm-lock-screen", string.Empty, _lockScreen, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _lockScreen;
/// <summary>
/// Emitted when the system is about to unlock the screen.
/// </summary>
public event Action OnUnLockScreen
{
add => ApiEventManager.AddEvent("pm-unlock-screen", string.Empty, _unlockScreen, value);
remove => ApiEventManager.RemoveEvent("pm-unlock-screen", string.Empty, _unlockScreen, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _unlockScreen;
/// <summary>
/// Emitted when the system is suspending.
/// </summary>
public event Action OnSuspend
{
add => ApiEventManager.AddEvent("pm-suspend", string.Empty, _suspend, value);
remove => ApiEventManager.RemoveEvent("pm-suspend", string.Empty, _suspend, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _suspend;
/// <summary>
/// Emitted when system is resuming.
/// </summary>
public event Action OnResume
{
add => ApiEventManager.AddEvent("pm-resume", string.Empty, _resume, value);
remove => ApiEventManager.RemoveEvent("pm-resume", string.Empty, _resume, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _resume;
/// <summary>
/// Emitted when the system changes to AC power.
/// </summary>
public event Action OnAC
{
add => ApiEventManager.AddEvent("pm-on-ac", string.Empty, _onAC, value);
remove => ApiEventManager.RemoveEvent("pm-on-ac", string.Empty, _onAC, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _onAC;
/// <summary>
/// Emitted when system changes to battery power.
/// </summary>
public event Action OnBattery
{
add => ApiEventManager.AddEvent("pm-on-battery", string.Empty, _onBattery, value);
remove => ApiEventManager.RemoveEvent("pm-on-battery", string.Empty, _onBattery, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _onBattery;
/// <summary>
/// Emitted when the system is about to reboot or shut down. If the event handler
/// invokes `e.preventDefault()`, Electron will attempt to delay system shutdown in
@@ -84,12 +74,10 @@ namespace ElectronNET.API
/// </summary>
public event Action OnShutdown
{
add => ApiEventManager.AddEvent("pm-shutdown", string.Empty, _shutdown, value);
remove => ApiEventManager.RemoveEvent("pm-shutdown", string.Empty, _shutdown, value);
add => AddEvent(value);
remove => RemoveEvent(value);
}
private event Action _shutdown;
private static PowerMonitor _powerMonitor;
private static object _syncRoot = new object();

View File

@@ -9,8 +9,10 @@ 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: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
internal Process()
{
}
@@ -42,18 +44,7 @@ namespace ElectronNET.API
/// The process.execPath property returns the absolute pathname of the executable that
/// started the Node.js process. Symbolic links, if any, are resolved.
/// </summary>
public Task<string> ExecPathAsync
{
get
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("process-execPath-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-execPath");
return tcs.Task;
}
}
public Task<string> ExecPathAsync => GetPropertyAsync<string>();
/// <summary>
/// The process.argv property returns an array containing the command-line arguments passed
@@ -62,169 +53,56 @@ namespace ElectronNET.API
/// will be the path to the JavaScript file being executed. The remaining elements will be
/// any additional command-line arguments
/// </summary>
public Task<string[]> ArgvAsync
{
get
{
var tcs = new TaskCompletionSource<string[]>();
BridgeConnector.Socket.Once<string[]>("process-argv-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-argv");
return tcs.Task;
}
}
public Task<string[]> ArgvAsync => GetPropertyAsync<string[]>();
/// <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>
public Task<string> TypeAsync
{
get
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("process-type-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-type");
return tcs.Task;
}
}
public Task<string> TypeAsync => GetPropertyAsync<string>();
/// <summary>
/// The process.versions property returns an object listing the version strings of
/// chrome and electron.
/// </summary>
public Task<ProcessVersions> VersionsAsync
{
get
{
var tcs = new TaskCompletionSource<ProcessVersions>();
BridgeConnector.Socket.Once<ProcessVersions>("process-versions-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-versions");
return tcs.Task;
}
}
public Task<ProcessVersions> VersionsAsync => GetPropertyAsync<ProcessVersions>();
/// <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>
public Task<bool> DefaultAppAsync
{
get
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("process-defaultApp-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-defaultApp");
return tcs.Task;
}
}
public Task<bool> DefaultAppAsync => GetPropertyAsync<bool>();
/// <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>
public Task<bool> IsMainFrameAsync
{
get
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("process-isMainFrame-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-isMainFrame");
return tcs.Task;
}
}
public Task<bool> IsMainFrameAsync => GetPropertyAsync<bool>();
/// <summary>
/// A String representing the path to the resources directory.
/// </summary>
public Task<string> ResourcesPathAsync
{
get
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("process-resourcesPath-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-resourcesPath");
return tcs.Task;
}
}
public Task<string> ResourcesPathAsync => GetPropertyAsync<string>();
/// <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>
public Task<double> UpTimeAsync
{
get
{
var tcs = new TaskCompletionSource<double>();
BridgeConnector.Socket.Once<double>("process-uptime-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-uptime");
return tcs.Task;
}
}
public Task<double> UpTimeAsync => GetPropertyAsync<double>();
/// <summary>
/// The PID of the electron process
/// </summary>
public Task<int> PidAsync
{
get
{
var tcs = new TaskCompletionSource<int>();
BridgeConnector.Socket.Once<int>("process-pid-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-pid");
return tcs.Task;
}
}
public Task<int> PidAsync => GetPropertyAsync<int>();
/// <summary>
/// The operating system CPU architecture for which the Node.js binary was compiled
/// </summary>
public Task<string> ArchAsync
{
get
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("process-arch-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-arch");
return tcs.Task;
}
}
public Task<string> ArchAsync => GetPropertyAsync<string>();
/// <summary>
/// A string identifying the operating system platform on which the Node.js process is running
/// </summary>
public Task<string> PlatformAsync
{
get
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("process-platform-Completed", tcs.SetResult);
BridgeConnector.Socket.Emit("process-platform");
return tcs.Task;
}
}
public Task<string> PlatformAsync => GetPropertyAsync<string>();
}
}

View File

@@ -1,39 +1,39 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using ElectronNET.Common;
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using ElectronNET.API.Serialization;
namespace ElectronNET.API
{
/// <summary>
/// Retrieve information about screen size, displays, cursor position, etc.
/// </summary>
public sealed class Screen
public sealed class Screen: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Emitted when an new Display has been added.
/// </summary>
public event Action<Display> OnDisplayAdded
{
add => ApiEventManager.AddEvent("screen-display-added", GetHashCode(), _onDisplayAdded, value, (args) => args.Deserialize(ElectronJsonContext.Default.Display));
remove => ApiEventManager.RemoveEvent("screen-display-added", GetHashCode(), _onDisplayAdded, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<Display> _onDisplayAdded;
/// <summary>
/// Emitted when oldDisplay has been removed.
/// </summary>
public event Action<Display> OnDisplayRemoved
{
add => ApiEventManager.AddEvent("screen-display-removed", GetHashCode(), _onDisplayRemoved, value, (args) => args.Deserialize(ElectronJsonContext.Default.Display));
remove => ApiEventManager.RemoveEvent("screen-display-removed", GetHashCode(), _onDisplayRemoved, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action<Display> _onDisplayRemoved;
/// <summary>
/// Emitted when one or more metrics change in a display.
/// The changedMetrics is an array of strings that describe the changes.
@@ -41,8 +41,32 @@ namespace ElectronNET.API
/// </summary>
public event Action<Display, string[]> OnDisplayMetricsChanged
{
add => ApiEventManager.AddScreenEvent("screen-display-metrics-changed", GetHashCode(), _onDisplayMetricsChanged, value);
remove => ApiEventManager.RemoveScreenEvent("screen-display-metrics-changed", GetHashCode(), _onDisplayMetricsChanged, value);
add
{
if (_onDisplayMetricsChanged == null)
{
BridgeConnector.Socket.On<JsonElement>("screen-display-metrics-changed" + GetHashCode(), (args) =>
{
var arr = args.EnumerateArray().ToArray();
var display = arr[0].Deserialize(ElectronJsonContext.Default.Display);
var metrics = arr[1].Deserialize<string[]>(ElectronJson.Options);
_onDisplayMetricsChanged(display, metrics);
});
BridgeConnector.Socket.Emit("register-screen-display-metrics-changed", GetHashCode());
}
_onDisplayMetricsChanged += value;
}
remove
{
_onDisplayMetricsChanged -= value;
if (_onDisplayMetricsChanged == null)
{
BridgeConnector.Socket.Off("screen-display-metrics-changed" + GetHashCode());
}
}
}
private event Action<Display, string[]> _onDisplayMetricsChanged;
@@ -77,87 +101,37 @@ namespace ElectronNET.API
/// The current absolute position of the mouse pointer.
/// </summary>
/// <returns></returns>
public Task<Point> GetCursorScreenPointAsync()
{
var tcs = new TaskCompletionSource<Point>();
BridgeConnector.Socket.Once<Point>("screen-getCursorScreenPointCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getCursorScreenPoint");
return tcs.Task;
}
public Task<Point> GetCursorScreenPointAsync() => GetPropertyAsync<Point>();
/// <summary>
/// macOS: The height of the menu bar in pixels.
/// </summary>
/// <returns>The height of the menu bar in pixels.</returns>
public Task<int> GetMenuBarHeightAsync()
{
var tcs = new TaskCompletionSource<int>();
BridgeConnector.Socket.Once<int>("screen-getMenuBarHeightCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getMenuBarHeight");
return tcs.Task;
}
public Task<Rectangle> GetMenuBarWorkAreaAsync() => GetPropertyAsync<Rectangle>();
/// <summary>
/// The primary display.
/// </summary>
/// <returns></returns>
public Task<Display> GetPrimaryDisplayAsync()
{
var tcs = new TaskCompletionSource<Display>();
BridgeConnector.Socket.Once<Display>("screen-getPrimaryDisplayCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getPrimaryDisplay");
return tcs.Task;
}
public Task<Display> GetPrimaryDisplayAsync() => GetPropertyAsync<Display>();
/// <summary>
/// An array of displays that are currently available.
/// </summary>
/// <returns>An array of displays that are currently available.</returns>
public Task<Display[]> GetAllDisplaysAsync()
{
var tcs = new TaskCompletionSource<Display[]>();
BridgeConnector.Socket.Once<Display[]>("screen-getAllDisplaysCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getAllDisplays");
return tcs.Task;
}
public Task<Display[]> GetAllDisplaysAsync() => GetPropertyAsync<Display[]>();
/// <summary>
/// The display nearest the specified point.
/// </summary>
/// <returns>The display nearest the specified point.</returns>
public Task<Display> GetDisplayNearestPointAsync(Point point)
{
var tcs = new TaskCompletionSource<Display>();
BridgeConnector.Socket.Once<Display>("screen-getDisplayNearestPointCompleted", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getDisplayNearestPoint", point);
return tcs.Task;
}
public Task<Display> GetDisplayNearestPointAsync(Point point) => GetPropertyAsync<Display>(point);
/// <summary>
/// The display that most closely intersects the provided bounds.
/// </summary>
/// <param name="rectangle"></param>
/// <returns>The display that most closely intersects the provided bounds.</returns>
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle)
{
var tcs = new TaskCompletionSource<Display>();
BridgeConnector.Socket.Once<Display>("screen-getDisplayMatching", tcs.SetResult);
BridgeConnector.Socket.Emit("screen-getDisplayMatching", rectangle);
return tcs.Task;
}
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle) => GetPropertyAsync<Display>(rectangle);
}
}

View File

@@ -1,7 +1,5 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System;
using System.Text.Json;
using System.Threading.Tasks;
namespace ElectronNET.API

View File

@@ -1,9 +1,11 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Extensions;
using ElectronNET.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using ElectronNET.API.Serialization;
// ReSharper disable InconsistentNaming
@@ -12,15 +14,41 @@ namespace ElectronNET.API
/// <summary>
/// Add icons and context menus to the system's notification area.
/// </summary>
public sealed class Tray
public sealed class Tray: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashedLower;
/// <summary>
/// Emitted when the tray icon is clicked.
/// </summary>
public event Action<TrayClickEventArgs, Rectangle> OnClick
{
add => ApiEventManager.AddTrayEvent("tray-click", GetHashCode(), _click, value);
remove => ApiEventManager.RemoveTrayEvent("tray-click", GetHashCode(), _click, value);
add
{
if (_click == null)
{
BridgeConnector.Socket.On<JsonElement>("tray-click" + GetHashCode(), (result) =>
{
var array = result.EnumerateArray().ToArray();
var trayClickEventArgs = array[0].Deserialize(ElectronJsonContext.Default.TrayClickEventArgs);
var bounds = array[1].Deserialize(ElectronJsonContext.Default.Rectangle);
_click(trayClickEventArgs, bounds);
});
BridgeConnector.Socket.Emit("register-tray-click", GetHashCode());
}
_click += value;
}
remove
{
_click -= value;
if (_click == null)
{
BridgeConnector.Socket.Off("tray-click" + GetHashCode());
}
}
}
private event Action<TrayClickEventArgs, Rectangle> _click;
@@ -30,8 +58,31 @@ namespace ElectronNET.API
/// </summary>
public event Action<TrayClickEventArgs, Rectangle> OnRightClick
{
add => ApiEventManager.AddTrayEvent("tray-right-click", GetHashCode(), _rightClick, value);
remove => ApiEventManager.RemoveTrayEvent("tray-right-click", GetHashCode(), _rightClick, value);
add
{
if (_rightClick == null)
{
BridgeConnector.Socket.On<JsonElement>("tray-right-click" + GetHashCode(), (result) =>
{
var array = result.EnumerateArray().ToArray();
var trayClickEventArgs = array[0].Deserialize(ElectronJsonContext.Default.TrayClickEventArgs);
var bounds = array[1].Deserialize(ElectronJsonContext.Default.Rectangle);
_rightClick(trayClickEventArgs, bounds);
});
BridgeConnector.Socket.Emit("register-tray-right-click", GetHashCode());
}
_rightClick += value;
}
remove
{
_rightClick -= value;
if (_rightClick == null)
{
BridgeConnector.Socket.Off("tray-right-click" + GetHashCode());
}
}
}
private event Action<TrayClickEventArgs, Rectangle> _rightClick;
@@ -41,8 +92,31 @@ namespace ElectronNET.API
/// </summary>
public event Action<TrayClickEventArgs, Rectangle> OnDoubleClick
{
add => ApiEventManager.AddTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value);
remove => ApiEventManager.RemoveTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value);
add
{
if (_doubleClick == null)
{
BridgeConnector.Socket.On<JsonElement>("tray-double-click" + GetHashCode(), (result) =>
{
var array = result.EnumerateArray().ToArray();
var trayClickEventArgs = array[0].Deserialize(ElectronJsonContext.Default.TrayClickEventArgs);
var bounds = array[1].Deserialize(ElectronJsonContext.Default.Rectangle);
_doubleClick(trayClickEventArgs, bounds);
});
BridgeConnector.Socket.Emit("register-tray-double-click", GetHashCode());
}
_doubleClick += value;
}
remove
{
_doubleClick -= value;
if (_doubleClick == null)
{
BridgeConnector.Socket.Off("tray-double-click" + GetHashCode());
}
}
}
private event Action<TrayClickEventArgs, Rectangle> _doubleClick;
@@ -52,35 +126,29 @@ namespace ElectronNET.API
/// </summary>
public event Action OnBalloonShow
{
add => ApiEventManager.AddEvent("tray-balloon-show", GetHashCode(), _balloonShow, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-show", GetHashCode(), _balloonShow, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _balloonShow;
/// <summary>
/// Windows: Emitted when the tray balloon is clicked.
/// </summary>
public event Action OnBalloonClick
{
add => ApiEventManager.AddEvent("tray-balloon-click", GetHashCode(), _balloonClick, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-click", GetHashCode(), _balloonClick, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _balloonClick;
/// <summary>
/// Windows: Emitted when the tray balloon is closed
/// because of timeout or user manually closes it.
/// </summary>
public event Action OnBalloonClosed
{
add => ApiEventManager.AddEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value);
add => AddEvent(value, GetHashCode());
remove => RemoveEvent(value, GetHashCode());
}
private event Action _balloonClosed;
// TODO: Implement macOS Events
private static Tray _tray;

View File

@@ -1,8 +1,5 @@
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using ElectronNET.Common;
using System;
using System.Text.Json;
using System.Threading.Tasks;
// ReSharper disable InconsistentNaming
@@ -12,15 +9,19 @@ namespace ElectronNET.API;
/// <summary>
/// Render and control web pages.
/// </summary>
public class WebContents
public class WebContents: ApiBase
{
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.CamelCase;
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public int Id { get; private set; }
public override int Id { get; protected set; }
/// <summary>
/// Manage browser sessions, cookies, cache, proxy settings, etc.
@@ -32,103 +33,85 @@ public class WebContents
/// </summary>
public event Action<bool> OnCrashed
{
add => ApiEventManager.AddEvent("webContents-crashed", Id, _crashed, value, (args) => args.GetBoolean());
remove => ApiEventManager.RemoveEvent("webContents-crashed", Id, _crashed, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<bool> _crashed;
/// <summary>
/// Emitted when the navigation is done, i.e. the spinner of the tab has
/// stopped spinning, and the onload event was dispatched.
/// </summary>
public event Action OnDidFinishLoad
{
add => ApiEventManager.AddEvent("webContents-didFinishLoad", Id, _didFinishLoad, value);
remove => ApiEventManager.RemoveEvent("webContents-didFinishLoad", Id, _didFinishLoad, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _didFinishLoad;
/// <summary>
/// Emitted when any frame (including main) starts navigating.
/// </summary>
public event Action<string> OnDidStartNavigation
{
add => ApiEventManager.AddEvent("webContents-didStartNavigation", Id, _didStartNavigation, value);
remove => ApiEventManager.RemoveEvent("webContents-didStartNavigation", Id, _didStartNavigation, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _didStartNavigation;
/// <summary>
/// Emitted when a main frame navigation is done.
/// This event is not emitted for in-page navigations, such as clicking anchor links or updating the window.location.hash. Use did-navigate-in-page event for this purpose.
/// </summary>
public event Action<OnDidNavigateInfo> OnDidNavigate
{
add => ApiEventManager.AddEvent("webContents-didNavigate", Id, _didNavigate, value);
remove => ApiEventManager.RemoveEvent("webContents-didNavigate", Id, _didNavigate, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<OnDidNavigateInfo> _didNavigate;
/// <summary>
/// Emitted when a server side redirect occurs during navigation. For example a 302 redirect.
/// This event will be emitted after OnDidStartNavigation and always before the OnDidRedirectNavigation event for the same navigation.
/// </summary>
public event Action<string> OnWillRedirect
{
add => ApiEventManager.AddEvent("webContents-willRedirect", Id, _willRedirect, value);
remove => ApiEventManager.RemoveEvent("webContents-willRedirect", Id, _willRedirect, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _willRedirect;
/// <summary>
/// Emitted after a server side redirect occurs during navigation. For example a 302 redirect.
/// </summary>
public event Action<string> OnDidRedirectNavigation
{
add => ApiEventManager.AddEvent("webContents-didRedirectNavigation", Id, _didRedirectNavigation, value);
remove => ApiEventManager.RemoveEvent("webContents-didRedirectNavigation", Id, _didRedirectNavigation, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<string> _didRedirectNavigation;
/// <summary>
/// This event is like OnDidFinishLoad but emitted when the load failed.
/// </summary>
public event Action<OnDidFailLoadInfo> OnDidFailLoad
{
add => ApiEventManager.AddEvent("webContents-didFailLoad", Id, _didFailLoad, value, (args) => args.Deserialize<OnDidFailLoadInfo>(ElectronJson.Options));
remove => ApiEventManager.RemoveEvent("webContents-didFailLoad", Id, _didFailLoad, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<OnDidFailLoadInfo> _didFailLoad;
/// <summary>
/// Emitted when an input event is sent to the WebContents.
/// </summary>
public event Action<InputEvent> InputEvent
{
add => ApiEventManager.AddEvent("webContents-input-event", Id, _inputEvent, value, (args) => args.Deserialize<InputEvent>(ElectronJson.Options));
remove => ApiEventManager.RemoveEvent("webContents-input-event", Id, _inputEvent, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action<InputEvent> _inputEvent;
/// <summary>
/// Emitted when the document in the top-level frame is loaded.
/// </summary>
public event Action OnDomReady
{
add => ApiEventManager.AddEvent("webContents-domReady", Id, _domReady, value);
remove => ApiEventManager.RemoveEvent("webContents-domReady", Id, _domReady, value);
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
private event Action _domReady;
internal WebContents(int id)
{
Id = id;
@@ -156,38 +139,19 @@ public class WebContents
/// Get system printers.
/// </summary>
/// <returns>printers</returns>
public Task<PrinterInfo[]> GetPrintersAsync()
{
var tcs = new TaskCompletionSource<PrinterInfo[]>();
BridgeConnector.Socket.Once<PrinterInfo[]>("webContents-getPrinters-completed", tcs.SetResult);
BridgeConnector.Socket.Emit("webContents-getPrinters", Id);
return tcs.Task;
}
public Task<PrinterInfo[]> GetPrintersAsync() => GetPropertyAsync<PrinterInfo[]>();
/// <summary>
/// Prints window's web page.
/// </summary>
/// <param name="options"></param>
/// <returns>success</returns>
public Task<bool> PrintAsync(PrintOptions options = null)
{
var tcs = new TaskCompletionSource<bool>();
BridgeConnector.Socket.Once<bool>("webContents-print-completed", tcs.SetResult);
if (options == null)
{
BridgeConnector.Socket.Emit("webContents-print", Id, "");
}
else
{
BridgeConnector.Socket.Emit("webContents-print", Id, options);
}
return tcs.Task;
}
public Task<bool> PrintAsync(PrintOptions options) => GetPropertyAsync<bool>(options);
/// <summary>
/// Prints window's web page.
/// </summary>
/// <returns>success</returns>
public Task<bool> PrintAsync() => GetPropertyAsync<bool>(string.Empty);
/// <summary>
/// Prints window's web page as PDF with Chromium's preview printing custom
@@ -251,7 +215,7 @@ public class WebContents
{
var tcs = new TaskCompletionSource<string>();
BridgeConnector.Socket.Once<string>("webContents-getUrl", tcs.SetResult);
BridgeConnector.Socket.Once<string>("webContents-getUrl" + Id, tcs.SetResult);
BridgeConnector.Socket.Emit("webContents-getUrl", Id);
return tcs.Task;

View File

@@ -1,105 +0,0 @@
using ElectronNET.API;
using ElectronNET.API.Entities;
using ElectronNET.API.Serialization;
using System;
using System.Linq;
using System.Text.Json;
namespace ElectronNET.Common;
internal static class ApiEventManager
{
internal static void AddEvent(string eventName, object id, Action callback, Action value, string suffix = "")
{
if (callback == null)
{
BridgeConnector.Socket.On(eventName + id, () => { callback(); });
BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id);
}
callback += value;
}
internal static void RemoveEvent(string eventName, object id, Action callback, Action value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
internal static void AddEvent<T>(string eventName, object id, Action<T> callback, Action<T> value, Func<JsonElement, T> converter, string suffix = "")
{
if (callback == null)
{
BridgeConnector.Socket.On<JsonElement>(eventName + id, (args) =>
{
var converted = converter.Invoke(args);
callback(converted);
});
BridgeConnector.Socket.Emit($"register-{eventName}{suffix}", id);
}
callback += value;
}
internal static void AddEvent<T>(string eventName, object id, Action<T> callback, Action<T> value)
{
if (callback == null)
{
BridgeConnector.Socket.On<T>(eventName + id, (args) => callback(args));
BridgeConnector.Socket.Emit($"register-{eventName}", id);
}
callback += value;
}
internal static void RemoveEvent<T>(string eventName, object id, Action<T> callback, Action<T> value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
internal static void AddTrayEvent(string eventName, object id, Action<TrayClickEventArgs, Rectangle> callback, Action<TrayClickEventArgs, Rectangle> value)
{
if (callback == null)
{
BridgeConnector.Socket.On<JsonElement>(eventName + id, (result) =>
{
var array = result.EnumerateArray().ToArray();
var trayClickEventArgs = array[0].Deserialize(ElectronJsonContext.Default.TrayClickEventArgs);
var bounds = array[1].Deserialize(ElectronJsonContext.Default.Rectangle);
callback(trayClickEventArgs, bounds);
});
BridgeConnector.Socket.Emit($"register-{eventName}", id);
callback += value;
}
}
internal static void RemoveTrayEvent(string eventName, object id, Action<TrayClickEventArgs, Rectangle> callback, Action<TrayClickEventArgs, Rectangle> value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
internal static void AddScreenEvent(string eventName, object id, Action<Display, string[]> callback, Action<Display, string[]> value)
{
if (callback == null)
{
BridgeConnector.Socket.On<JsonElement>(eventName + id, (args) =>
{
var arr = args.EnumerateArray().ToArray();
var display = arr[0].Deserialize(ElectronJsonContext.Default.Display);
var metrics = arr[1].Deserialize<string[]>(ElectronJson.Options);
callback(display, metrics);
});
BridgeConnector.Socket.Emit($"register-{eventName}", id);
callback += value;
}
}
internal static void RemoveScreenEvent(string eventName, object id, Action<Display, string[]> callback, Action<Display, string[]> value)
{
callback -= value;
if (callback == null) BridgeConnector.Socket.Off(eventName + id);
}
}

View File

@@ -1,9 +1,11 @@
namespace ElectronNET.Common
{
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Services;
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System;
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Services;
namespace ElectronNET.Common
{
internal static class Extensions
{
public static bool IsUnpackaged(this StartupMethod method)
@@ -49,6 +51,26 @@
return str;
}
public static string StripOn(this string str)
{
if (string.IsNullOrWhiteSpace(str) || !str.StartsWith("On", StringComparison.Ordinal))
{
return str;
}
return str.Substring(2);
}
public static string ToDashedEventName(this string str)
{
return string.Join("-", Regex.Split(str.StripOn(), "(?<!^)(?=[A-Z])")).ToLower(CultureInfo.InvariantCulture);
}
public static string ToCamelCaseEventName(this string str)
{
return str.StripOn().LowerFirst();
}
public static bool IsReady(this LifetimeServiceBase service)
{

View File

@@ -3,7 +3,7 @@
<Import Project="..\common.props" />
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net10.0</TargetFrameworks>
<PackageOutputPath>..\..\artifacts</PackageOutputPath>
<PackageId>$(PackageNamePrefix).API</PackageId>
<Title>$(PackageId)</Title>

View File

@@ -1,13 +1,13 @@
namespace ElectronNET.Runtime
{
using ElectronNET.Runtime.Controllers;
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Helpers;
using System;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Reflection;
using ElectronNET.Runtime.Controllers;
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Helpers;
internal class StartupManager
{
@@ -135,7 +135,7 @@
return buildInfo;
}
if (electronAssembly.GetName().Name == "testhost")
if (electronAssembly.GetName().Name == "testhost" || electronAssembly.GetName().Name == "ReSharperTestRunner")
{
electronAssembly = AppDomain.CurrentDomain.GetData("ElectronTestAssembly") as Assembly ?? electronAssembly;
}

View File

@@ -3,7 +3,7 @@
<Import Project="..\common.props" />
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net10.0</TargetFrameworks>
<PackageOutputPath>..\..\artifacts</PackageOutputPath>
<PackageId>$(PackageNamePrefix).AspNet</PackageId>
<Title>$(PackageId)</Title>
@@ -20,12 +20,18 @@
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
<NoWarn>1701;1702;4014;CS4014;CA1416;CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0|AnyCPU'">
<NoWarn>1701;1702;4014;CS4014;CA1416;CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
<NoWarn>1701;1702;4014;CS4014;CA1416;CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
<NoWarn>1701;1702;4014;CS4014;CA1416;CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net10.0|AnyCPU'">
<NoWarn>1701;1702;4014;CS4014;CA1416;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

View File

@@ -34,81 +34,81 @@ module.exports = (socket) => {
});
});
// Properties *****
socket.on('autoUpdater-autoDownload-get', () => {
electronSocket.emit('autoUpdater-autoDownload-get-reply', electron_updater_1.autoUpdater.autoDownload);
socket.on('autoUpdater-autoDownload', () => {
electronSocket.emit('autoUpdater-autoDownload-completed', electron_updater_1.autoUpdater.autoDownload);
});
socket.on('autoUpdater-autoDownload-set', (value) => {
electron_updater_1.autoUpdater.autoDownload = value;
});
socket.on('autoUpdater-autoInstallOnAppQuit-get', () => {
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-get-reply', electron_updater_1.autoUpdater.autoInstallOnAppQuit);
socket.on('autoUpdater-autoInstallOnAppQuit', () => {
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', electron_updater_1.autoUpdater.autoInstallOnAppQuit);
});
socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => {
electron_updater_1.autoUpdater.autoInstallOnAppQuit = value;
});
socket.on('autoUpdater-allowPrerelease-get', () => {
electronSocket.emit('autoUpdater-allowPrerelease-get-reply', electron_updater_1.autoUpdater.allowPrerelease);
socket.on('autoUpdater-allowPrerelease', () => {
electronSocket.emit('autoUpdater-allowPrerelease-completed', electron_updater_1.autoUpdater.allowPrerelease);
});
socket.on('autoUpdater-allowPrerelease-set', (value) => {
electron_updater_1.autoUpdater.allowPrerelease = value;
});
socket.on('autoUpdater-fullChangelog-get', () => {
electronSocket.emit('autoUpdater-fullChangelog-get-reply', electron_updater_1.autoUpdater.fullChangelog);
socket.on('autoUpdater-fullChangelog', () => {
electronSocket.emit('autoUpdater-fullChangelog-completed', electron_updater_1.autoUpdater.fullChangelog);
});
socket.on('autoUpdater-fullChangelog-set', (value) => {
electron_updater_1.autoUpdater.fullChangelog = value;
});
socket.on('autoUpdater-allowDowngrade-get', () => {
electronSocket.emit('autoUpdater-allowDowngrade-get-reply', electron_updater_1.autoUpdater.allowDowngrade);
socket.on('autoUpdater-allowDowngrade', () => {
electronSocket.emit('autoUpdater-allowDowngrade-completed', electron_updater_1.autoUpdater.allowDowngrade);
});
socket.on('autoUpdater-allowDowngrade-set', (value) => {
electron_updater_1.autoUpdater.allowDowngrade = value;
});
socket.on('autoUpdater-updateConfigPath-get', () => {
electronSocket.emit('autoUpdater-updateConfigPath-get-reply', electron_updater_1.autoUpdater.updateConfigPath || '');
socket.on('autoUpdater-updateConfigPath', () => {
electronSocket.emit('autoUpdater-updateConfigPath-completed', electron_updater_1.autoUpdater.updateConfigPath || '');
});
socket.on('autoUpdater-updateConfigPath-set', (value) => {
electron_updater_1.autoUpdater.updateConfigPath = value;
});
socket.on('autoUpdater-currentVersion-get', () => {
electronSocket.emit('autoUpdater-currentVersion-get-reply', electron_updater_1.autoUpdater.currentVersion);
socket.on('autoUpdater-currentVersion', () => {
electronSocket.emit('autoUpdater-currentVersion-completed', electron_updater_1.autoUpdater.currentVersion);
});
socket.on('autoUpdater-channel-get', () => {
electronSocket.emit('autoUpdater-channel-get-reply', electron_updater_1.autoUpdater.channel || '');
socket.on('autoUpdater-channel', () => {
electronSocket.emit('autoUpdater-channel-completed', electron_updater_1.autoUpdater.channel || '');
});
socket.on('autoUpdater-channel-set', (value) => {
electron_updater_1.autoUpdater.channel = value;
});
socket.on('autoUpdater-requestHeaders-get', () => {
electronSocket.emit('autoUpdater-requestHeaders-get-reply', electron_updater_1.autoUpdater.requestHeaders);
socket.on('autoUpdater-requestHeaders', () => {
electronSocket.emit('autoUpdater-requestHeaders-completed', electron_updater_1.autoUpdater.requestHeaders);
});
socket.on('autoUpdater-requestHeaders-set', (value) => {
electron_updater_1.autoUpdater.requestHeaders = value;
});
socket.on('autoUpdaterCheckForUpdatesAndNotify', async (guid) => {
socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => {
electron_updater_1.autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => {
electronSocket.emit('autoUpdaterCheckForUpdatesAndNotifyComplete' + guid, updateCheckResult);
electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult);
}).catch((error) => {
electronSocket.emit('autoUpdaterCheckForUpdatesAndNotifyError' + guid, error);
electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error);
});
});
socket.on('autoUpdaterCheckForUpdates', async (guid) => {
socket.on('autoUpdater-checkForUpdates', async (guid) => {
electron_updater_1.autoUpdater.checkForUpdates().then((updateCheckResult) => {
electronSocket.emit('autoUpdaterCheckForUpdatesComplete' + guid, updateCheckResult);
electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult);
}).catch((error) => {
electronSocket.emit('autoUpdaterCheckForUpdatesError' + guid, error);
electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error);
});
});
socket.on('autoUpdaterQuitAndInstall', async (isSilent, isForceRunAfter) => {
socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => {
electron_updater_1.autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
});
socket.on('autoUpdaterDownloadUpdate', async (guid) => {
socket.on('autoUpdater-downloadUpdate', async (guid) => {
const downloadedPath = await electron_updater_1.autoUpdater.downloadUpdate();
electronSocket.emit('autoUpdaterDownloadUpdateComplete' + guid, downloadedPath);
electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath);
});
socket.on('autoUpdaterGetFeedURL', async (guid) => {
socket.on('autoUpdater-getFeedURL', async (guid) => {
const feedUrl = await electron_updater_1.autoUpdater.getFeedURL();
electronSocket.emit('autoUpdaterGetFeedURLComplete' + guid, feedUrl || '');
electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || '');
});
};
//# sourceMappingURL=autoUpdater.js.map

View File

@@ -43,101 +43,101 @@ export = (socket: Socket) => {
// Properties *****
socket.on('autoUpdater-autoDownload-get', () => {
electronSocket.emit('autoUpdater-autoDownload-get-reply', autoUpdater.autoDownload);
socket.on('autoUpdater-autoDownload', () => {
electronSocket.emit('autoUpdater-autoDownload-completed', autoUpdater.autoDownload);
});
socket.on('autoUpdater-autoDownload-set', (value) => {
autoUpdater.autoDownload = value;
});
socket.on('autoUpdater-autoInstallOnAppQuit-get', () => {
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-get-reply', autoUpdater.autoInstallOnAppQuit);
socket.on('autoUpdater-autoInstallOnAppQuit', () => {
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', autoUpdater.autoInstallOnAppQuit);
});
socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => {
autoUpdater.autoInstallOnAppQuit = value;
});
socket.on('autoUpdater-allowPrerelease-get', () => {
electronSocket.emit('autoUpdater-allowPrerelease-get-reply', autoUpdater.allowPrerelease);
socket.on('autoUpdater-allowPrerelease', () => {
electronSocket.emit('autoUpdater-allowPrerelease-completed', autoUpdater.allowPrerelease);
});
socket.on('autoUpdater-allowPrerelease-set', (value) => {
autoUpdater.allowPrerelease = value;
});
socket.on('autoUpdater-fullChangelog-get', () => {
electronSocket.emit('autoUpdater-fullChangelog-get-reply', autoUpdater.fullChangelog);
socket.on('autoUpdater-fullChangelog', () => {
electronSocket.emit('autoUpdater-fullChangelog-completed', autoUpdater.fullChangelog);
});
socket.on('autoUpdater-fullChangelog-set', (value) => {
autoUpdater.fullChangelog = value;
});
socket.on('autoUpdater-allowDowngrade-get', () => {
electronSocket.emit('autoUpdater-allowDowngrade-get-reply', autoUpdater.allowDowngrade);
socket.on('autoUpdater-allowDowngrade', () => {
electronSocket.emit('autoUpdater-allowDowngrade-completed', autoUpdater.allowDowngrade);
});
socket.on('autoUpdater-allowDowngrade-set', (value) => {
autoUpdater.allowDowngrade = value;
});
socket.on('autoUpdater-updateConfigPath-get', () => {
electronSocket.emit('autoUpdater-updateConfigPath-get-reply', autoUpdater.updateConfigPath || '');
socket.on('autoUpdater-updateConfigPath', () => {
electronSocket.emit('autoUpdater-updateConfigPath-completed', autoUpdater.updateConfigPath || '');
});
socket.on('autoUpdater-updateConfigPath-set', (value) => {
autoUpdater.updateConfigPath = value;
});
socket.on('autoUpdater-currentVersion-get', () => {
electronSocket.emit('autoUpdater-currentVersion-get-reply', autoUpdater.currentVersion);
socket.on('autoUpdater-currentVersion', () => {
electronSocket.emit('autoUpdater-currentVersion-completed', autoUpdater.currentVersion);
});
socket.on('autoUpdater-channel-get', () => {
electronSocket.emit('autoUpdater-channel-get-reply', autoUpdater.channel || '');
socket.on('autoUpdater-channel', () => {
electronSocket.emit('autoUpdater-channel-completed', autoUpdater.channel || '');
});
socket.on('autoUpdater-channel-set', (value) => {
autoUpdater.channel = value;
});
socket.on('autoUpdater-requestHeaders-get', () => {
electronSocket.emit('autoUpdater-requestHeaders-get-reply', autoUpdater.requestHeaders);
socket.on('autoUpdater-requestHeaders', () => {
electronSocket.emit('autoUpdater-requestHeaders-completed', autoUpdater.requestHeaders);
});
socket.on('autoUpdater-requestHeaders-set', (value) => {
autoUpdater.requestHeaders = value;
});
socket.on('autoUpdaterCheckForUpdatesAndNotify', async (guid) => {
socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => {
autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => {
electronSocket.emit('autoUpdaterCheckForUpdatesAndNotifyComplete' + guid, updateCheckResult);
electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult);
}).catch((error) => {
electronSocket.emit('autoUpdaterCheckForUpdatesAndNotifyError' + guid, error);
electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error);
});
});
socket.on('autoUpdaterCheckForUpdates', async (guid) => {
socket.on('autoUpdater-checkForUpdates', async (guid) => {
autoUpdater.checkForUpdates().then((updateCheckResult) => {
electronSocket.emit('autoUpdaterCheckForUpdatesComplete' + guid, updateCheckResult);
electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult);
}).catch((error) => {
electronSocket.emit('autoUpdaterCheckForUpdatesError' + guid, error);
electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error);
});
});
socket.on('autoUpdaterQuitAndInstall', async (isSilent, isForceRunAfter) => {
socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => {
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
});
socket.on('autoUpdaterDownloadUpdate', async (guid) => {
socket.on('autoUpdater-downloadUpdate', async (guid) => {
const downloadedPath = await autoUpdater.downloadUpdate();
electronSocket.emit('autoUpdaterDownloadUpdateComplete' + guid, downloadedPath);
electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath);
});
socket.on('autoUpdaterGetFeedURL', async (guid) => {
socket.on('autoUpdater-getFeedURL', async (guid) => {
const feedUrl = await autoUpdater.getFeedURL();
electronSocket.emit('autoUpdaterGetFeedURLComplete' + guid, feedUrl || '');
electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || '');
});
};

View File

@@ -22,11 +22,11 @@ const browserViewApi = (socket) => {
browserViews.push(browserView);
electronSocket.emit('BrowserViewCreated', browserView['id']);
});
socket.on('browserView-getBounds', (id) => {
socket.on('browserView-bounds', (id) => {
const bounds = getBrowserViewById(id).getBounds();
electronSocket.emit('browserView-getBounds-reply', bounds);
electronSocket.emit('browserView-bounds-completed', bounds);
});
socket.on('browserView-setBounds', (id, bounds) => {
socket.on('browserView-bounds-set', (id, bounds) => {
getBrowserViewById(id).setBounds(bounds);
});
socket.on('browserView-setAutoResize', (id, options) => {

View File

@@ -28,13 +28,13 @@ const browserViewApi = (socket: Socket) => {
electronSocket.emit('BrowserViewCreated', browserView['id']);
});
socket.on('browserView-getBounds', (id) => {
socket.on('browserView-bounds', (id) => {
const bounds = getBrowserViewById(id).getBounds();
electronSocket.emit('browserView-getBounds-reply', bounds);
electronSocket.emit('browserView-bounds-completed', bounds);
});
socket.on('browserView-setBounds', (id, bounds) => {
socket.on('browserView-bounds-set', (id, bounds) => {
getBrowserViewById(id).setBounds(bounds);
});

View File

@@ -5,35 +5,35 @@ module.exports = (socket) => {
electronSocket = socket;
socket.on('clipboard-readText', (type) => {
const text = electron_1.clipboard.readText(type);
electronSocket.emit('clipboard-readText-Completed', text);
electronSocket.emit('clipboard-readText-completed', text);
});
socket.on('clipboard-writeText', (text, type) => {
electron_1.clipboard.writeText(text, type);
});
socket.on('clipboard-readHTML', (type) => {
const content = electron_1.clipboard.readHTML(type);
electronSocket.emit('clipboard-readHTML-Completed', content);
electronSocket.emit('clipboard-readHTML-completed', content);
});
socket.on('clipboard-writeHTML', (markup, type) => {
electron_1.clipboard.writeHTML(markup, type);
});
socket.on('clipboard-readRTF', (type) => {
const content = electron_1.clipboard.readRTF(type);
electronSocket.emit('clipboard-readRTF-Completed', content);
electronSocket.emit('clipboard-readRTF-completed', content);
});
socket.on('clipboard-writeRTF', (text, type) => {
electron_1.clipboard.writeHTML(text, type);
});
socket.on('clipboard-readBookmark', () => {
const bookmark = electron_1.clipboard.readBookmark();
electronSocket.emit('clipboard-readBookmark-Completed', bookmark);
electronSocket.emit('clipboard-readBookmark-completed', bookmark);
});
socket.on('clipboard-writeBookmark', (title, url, type) => {
electron_1.clipboard.writeBookmark(title, url, type);
});
socket.on('clipboard-readFindText', () => {
const content = electron_1.clipboard.readFindText();
electronSocket.emit('clipboard-readFindText-Completed', content);
electronSocket.emit('clipboard-readFindText-completed', content);
});
socket.on('clipboard-writeFindText', (text) => {
electron_1.clipboard.writeFindText(text);
@@ -43,14 +43,14 @@ module.exports = (socket) => {
});
socket.on('clipboard-availableFormats', (type) => {
const formats = electron_1.clipboard.availableFormats(type);
electronSocket.emit('clipboard-availableFormats-Completed', formats);
electronSocket.emit('clipboard-availableFormats-completed', formats);
});
socket.on('clipboard-write', (data, type) => {
electron_1.clipboard.write(data, type);
});
socket.on('clipboard-readImage', (type) => {
const image = electron_1.clipboard.readImage(type);
electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
electronSocket.emit('clipboard-readImage-completed', { 1: image.toPNG().toString('base64') });
});
socket.on('clipboard-writeImage', (data, type) => {
const dataContent = JSON.parse(data);

View File

@@ -6,7 +6,7 @@ export = (socket: Socket) => {
electronSocket = socket;
socket.on('clipboard-readText', (type) => {
const text = clipboard.readText(type);
electronSocket.emit('clipboard-readText-Completed', text);
electronSocket.emit('clipboard-readText-completed', text);
});
socket.on('clipboard-writeText', (text, type) => {
@@ -15,7 +15,7 @@ export = (socket: Socket) => {
socket.on('clipboard-readHTML', (type) => {
const content = clipboard.readHTML(type);
electronSocket.emit('clipboard-readHTML-Completed', content);
electronSocket.emit('clipboard-readHTML-completed', content);
});
socket.on('clipboard-writeHTML', (markup, type) => {
@@ -24,7 +24,7 @@ export = (socket: Socket) => {
socket.on('clipboard-readRTF', (type) => {
const content = clipboard.readRTF(type);
electronSocket.emit('clipboard-readRTF-Completed', content);
electronSocket.emit('clipboard-readRTF-completed', content);
});
socket.on('clipboard-writeRTF', (text, type) => {
@@ -33,7 +33,7 @@ export = (socket: Socket) => {
socket.on('clipboard-readBookmark', () => {
const bookmark = clipboard.readBookmark();
electronSocket.emit('clipboard-readBookmark-Completed', bookmark);
electronSocket.emit('clipboard-readBookmark-completed', bookmark);
});
socket.on('clipboard-writeBookmark', (title, url, type) => {
@@ -42,7 +42,7 @@ export = (socket: Socket) => {
socket.on('clipboard-readFindText', () => {
const content = clipboard.readFindText();
electronSocket.emit('clipboard-readFindText-Completed', content);
electronSocket.emit('clipboard-readFindText-completed', content);
});
socket.on('clipboard-writeFindText', (text) => {
@@ -55,7 +55,7 @@ export = (socket: Socket) => {
socket.on('clipboard-availableFormats', (type) => {
const formats = clipboard.availableFormats(type);
electronSocket.emit('clipboard-availableFormats-Completed', formats);
electronSocket.emit('clipboard-availableFormats-completed', formats);
});
socket.on('clipboard-write', (data, type) => {
@@ -64,7 +64,7 @@ export = (socket: Socket) => {
socket.on('clipboard-readImage', (type) => {
const image = clipboard.readImage(type);
electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
electronSocket.emit('clipboard-readImage-completed', { 1: image.toPNG().toString('base64') });
});
socket.on('clipboard-writeImage', (data, type) => {

View File

@@ -26,13 +26,13 @@ module.exports = (socket) => {
socket.on('removeAllListenersIpcMainChannel', (channel) => {
electron_1.ipcMain.removeAllListeners(channel);
});
socket.on('sendToIpcRenderer', (browserWindow, channel, ...data) => {
socket.on('sendToIpcRenderer', (browserWindow, channel, data) => {
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
if (window) {
window.webContents.send(channel, ...data);
}
});
socket.on('sendToIpcRendererBrowserView', (id, channel, ...data) => {
socket.on('sendToIpcRendererBrowserView', (id, channel, data) => {
const browserViews = (global['browserViews'] = global['browserViews'] || []);
let view = null;
for (let i = 0; i < browserViews.length; i++) {

View File

@@ -1 +1 @@
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["ipc.ts"],"names":[],"mappings":";AAAA,uCAAqE;AAErE,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;QAC5C,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,OAAO,EAAE,EAAE;QAChD,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChC,MAAM,CAAC,GAAQ,MAAM,CAAC;YACtB,CAAC,CAAC,kBAAkB,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;YACvC,MAAM,CAAC,EAAE,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;gBACnC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,CAAC;YAEH,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,OAAO,EAAE,EAAE;QAChD,kBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAClC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,kCAAkC,EAAE,CAAC,OAAO,EAAE,EAAE;QACtD,kBAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE;QAC/D,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAEtD,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE;QAC/D,MAAM,YAAY,GAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAkB,CAAC;QAC7G,IAAI,IAAI,GAAgB,IAAI,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;gBAC/B,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBACvB,MAAM;YACV,CAAC;QACL,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,6EAA6E;IAC7E,kBAAO,CAAC,EAAE,CAAC,oCAAoC,EAAE,CAAC,KAAK,EAAE,EAAU,EAAE,EAAE;QACnE,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,eAAI,CAAC,kBAAkB,EAAE,CAAC;YACvC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,IAAI,EAAE,IAAI,OAAQ,EAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChD,MAAM,EAAE,GAAG,wBAAa,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtD,EAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YAChD,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,kBAAO,CAAC,EAAE,CAAC,gCAAgC,EAAE,CAAC,KAAK,EAAE,QAAgB,EAAE,EAAU,EAAE,EAAE;;QACjF,IAAI,CAAC;YACD,MAAM,OAAO,GAAI,MAAc,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC;YACvE,MAAM,EAAE,GAAG,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,0CAAE,KAAK,0CAAE,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7D,IAAI,EAAE,IAAI,OAAQ,EAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChD,MAAM,EAAE,GAAG,wBAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACzC,EAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YAChD,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["ipc.ts"],"names":[],"mappings":";AAAA,uCAAqE;AAErE,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;QAC5C,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,OAAO,EAAE,EAAE;QAChD,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChC,MAAM,CAAC,GAAQ,MAAM,CAAC;YACtB,CAAC,CAAC,kBAAkB,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;YACvC,MAAM,CAAC,EAAE,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;gBACnC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,CAAC;YAEH,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,OAAO,EAAE,EAAE;QAChD,kBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAClC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,kCAAkC,EAAE,CAAC,OAAO,EAAE,EAAE;QACtD,kBAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC5D,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAEtD,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC5D,MAAM,YAAY,GAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAkB,CAAC;QAC7G,IAAI,IAAI,GAAgB,IAAI,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;gBAC/B,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBACvB,MAAM;YACV,CAAC;QACL,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,6EAA6E;IAC7E,kBAAO,CAAC,EAAE,CAAC,oCAAoC,EAAE,CAAC,KAAK,EAAE,EAAU,EAAE,EAAE;QACnE,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,eAAI,CAAC,kBAAkB,EAAE,CAAC;YACvC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClD,IAAI,EAAE,IAAI,OAAQ,EAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChD,MAAM,EAAE,GAAG,wBAAa,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtD,EAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YAChD,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,kBAAO,CAAC,EAAE,CAAC,gCAAgC,EAAE,CAAC,KAAK,EAAE,QAAgB,EAAE,EAAU,EAAE,EAAE;;QACjF,IAAI,CAAC;YACD,MAAM,OAAO,GAAI,MAAc,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC;YACvE,MAAM,EAAE,GAAG,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,0CAAE,KAAK,0CAAE,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7D,IAAI,EAAE,IAAI,OAAQ,EAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChD,MAAM,EAAE,GAAG,wBAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACzC,EAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YAChD,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}

View File

@@ -32,7 +32,7 @@ export = (socket: Socket) => {
ipcMain.removeAllListeners(channel);
});
socket.on('sendToIpcRenderer', (browserWindow, channel, ...data) => {
socket.on('sendToIpcRenderer', (browserWindow, channel, data) => {
const window = BrowserWindow.fromId(browserWindow.id);
if (window) {
@@ -40,7 +40,7 @@ export = (socket: Socket) => {
}
});
socket.on('sendToIpcRendererBrowserView', (id, channel, ...data) => {
socket.on('sendToIpcRendererBrowserView', (id, channel, data) => {
const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[];
let view: BrowserView = null;
for (let i = 0; i < browserViews.length; i++) {

View File

@@ -15,9 +15,9 @@ module.exports = (socket) => {
const shouldUseInvertedColorScheme = electron_1.nativeTheme.shouldUseInvertedColorScheme;
electronSocket.emit('nativeTheme-shouldUseInvertedColorScheme-completed', shouldUseInvertedColorScheme);
});
socket.on('nativeTheme-themeSource-get', () => {
socket.on('nativeTheme-getThemeSource', () => {
const themeSource = electron_1.nativeTheme.themeSource;
electronSocket.emit('nativeTheme-themeSource-getCompleted', themeSource);
electronSocket.emit('nativeTheme-getThemeSource-completed', themeSource);
});
socket.on('nativeTheme-themeSource', (themeSource) => {
electron_1.nativeTheme.themeSource = themeSource;

View File

@@ -23,10 +23,10 @@ export = (socket: Socket) => {
electronSocket.emit('nativeTheme-shouldUseInvertedColorScheme-completed', shouldUseInvertedColorScheme);
});
socket.on('nativeTheme-themeSource-get', () => {
socket.on('nativeTheme-getThemeSource', () => {
const themeSource = nativeTheme.themeSource;
electronSocket.emit('nativeTheme-themeSource-getCompleted', themeSource);
electronSocket.emit('nativeTheme-getThemeSource-completed', themeSource);
});
socket.on('nativeTheme-themeSource', (themeSource) => {

View File

@@ -44,7 +44,7 @@ module.exports = (socket) => {
});
socket.on('notificationIsSupported', () => {
const isSupported = electron_1.Notification.isSupported();
electronSocket.emit('notificationIsSupportedComplete', isSupported);
electronSocket.emit('notificationIsSupportedCompleted', isSupported);
});
};
//# sourceMappingURL=notification.js.map

View File

@@ -53,6 +53,6 @@ export = (socket: Socket) => {
socket.on('notificationIsSupported', () => {
const isSupported = Notification.isSupported();
electronSocket.emit('notificationIsSupportedComplete', isSupported);
electronSocket.emit('notificationIsSupportedCompleted', isSupported);
});
};

View File

@@ -3,39 +3,39 @@ const electron_1 = require("electron");
let electronSocket;
module.exports = (socket) => {
electronSocket = socket;
socket.on('register-pm-lock-screen', () => {
socket.on('register-powerMonitor-lock-screen', () => {
electron_1.powerMonitor.on('lock-screen', () => {
electronSocket.emit('pm-lock-screen');
electronSocket.emit('powerMonitor-lock-screen');
});
});
socket.on('register-pm-unlock-screen', () => {
socket.on('register-powerMonitor-unlock-screen', () => {
electron_1.powerMonitor.on('unlock-screen', () => {
electronSocket.emit('pm-unlock-screen');
electronSocket.emit('powerMonitor-unlock-screen');
});
});
socket.on('register-pm-suspend', () => {
socket.on('register-powerMonitor-suspend', () => {
electron_1.powerMonitor.on('suspend', () => {
electronSocket.emit('pm-suspend');
electronSocket.emit('powerMonitor-suspend');
});
});
socket.on('register-pm-resume', () => {
socket.on('register-powerMonitor-resume', () => {
electron_1.powerMonitor.on('resume', () => {
electronSocket.emit('pm-resume');
electronSocket.emit('powerMonitor-resume');
});
});
socket.on('register-pm-on-ac', () => {
socket.on('register-powerMonitor-ac', () => {
electron_1.powerMonitor.on('on-ac', () => {
electronSocket.emit('pm-on-ac');
electronSocket.emit('powerMonitor-ac');
});
});
socket.on('register-pm-on-battery', () => {
socket.on('register-powerMonitor-battery', () => {
electron_1.powerMonitor.on('on-battery', () => {
electronSocket.emit('pm-on-battery');
electronSocket.emit('powerMonitor-battery');
});
});
socket.on('register-pm-shutdown', () => {
socket.on('register-powerMonitor-shutdown', () => {
electron_1.powerMonitor.on('shutdown', () => {
electronSocket.emit('pm-shutdown');
electronSocket.emit('powerMonitor-shutdown');
});
});
};

View File

@@ -4,39 +4,39 @@ let electronSocket;
export = (socket: Socket) => {
electronSocket = socket;
socket.on('register-pm-lock-screen', () => {
socket.on('register-powerMonitor-lock-screen', () => {
powerMonitor.on('lock-screen', () => {
electronSocket.emit('pm-lock-screen');
electronSocket.emit('powerMonitor-lock-screen');
});
});
socket.on('register-pm-unlock-screen', () => {
socket.on('register-powerMonitor-unlock-screen', () => {
powerMonitor.on('unlock-screen', () => {
electronSocket.emit('pm-unlock-screen');
electronSocket.emit('powerMonitor-unlock-screen');
});
});
socket.on('register-pm-suspend', () => {
socket.on('register-powerMonitor-suspend', () => {
powerMonitor.on('suspend', () => {
electronSocket.emit('pm-suspend');
electronSocket.emit('powerMonitor-suspend');
});
});
socket.on('register-pm-resume', () => {
socket.on('register-powerMonitor-resume', () => {
powerMonitor.on('resume', () => {
electronSocket.emit('pm-resume');
electronSocket.emit('powerMonitor-resume');
});
});
socket.on('register-pm-on-ac', () => {
socket.on('register-powerMonitor-ac', () => {
powerMonitor.on('on-ac', () => {
electronSocket.emit('pm-on-ac');
electronSocket.emit('powerMonitor-ac');
});
});
socket.on('register-pm-on-battery', () => {
socket.on('register-powerMonitor-battery', () => {
powerMonitor.on('on-battery', () => {
electronSocket.emit('pm-on-battery');
electronSocket.emit('powerMonitor-battery');
});
});
socket.on('register-pm-shutdown', () => {
socket.on('register-powerMonitor-shutdown', () => {
powerMonitor.on('shutdown', () => {
electronSocket.emit('pm-shutdown');
electronSocket.emit('powerMonitor-shutdown');
});
});
};

View File

@@ -4,59 +4,59 @@ module.exports = (socket) => {
electronSocket = socket;
socket.on('process-execPath', () => {
const value = process.execPath;
electronSocket.emit('process-execPath-Completed', value);
electronSocket.emit('process-execPath-completed', value);
});
socket.on('process-argv', () => {
const value = process.argv;
electronSocket.emit('process-argv-Completed', value);
electronSocket.emit('process-argv-completed', value);
});
socket.on('process-type', () => {
const value = process.type;
electronSocket.emit('process-type-Completed', value);
electronSocket.emit('process-type-completed', value);
});
socket.on('process-versions', () => {
const value = process.versions;
electronSocket.emit('process-versions-Completed', value);
electronSocket.emit('process-versions-completed', value);
});
socket.on('process-defaultApp', () => {
if (process.defaultApp === undefined) {
electronSocket.emit('process-defaultApp-Completed', false);
electronSocket.emit('process-defaultApp-completed', false);
return;
}
electronSocket.emit('process-defaultApp-Completed', process.defaultApp);
electronSocket.emit('process-defaultApp-completed', process.defaultApp);
});
socket.on('process-isMainFrame', () => {
if (process.isMainFrame === undefined) {
electronSocket.emit('process-isMainFrame-Completed', false);
electronSocket.emit('process-isMainFrame-completed', false);
return;
}
electronSocket.emit('process-isMainFrame-Completed', process.isMainFrame);
electronSocket.emit('process-isMainFrame-completed', process.isMainFrame);
});
socket.on('process-resourcesPath', () => {
const value = process.resourcesPath;
electronSocket.emit('process-resourcesPath-Completed', value);
electronSocket.emit('process-resourcesPath-completed', value);
});
socket.on('process-uptime', () => {
socket.on('process-upTime', () => {
let value = process.uptime();
if (value === undefined) {
value = -1;
}
electronSocket.emit('process-uptime-Completed', value);
electronSocket.emit('process-upTime-completed', value);
});
socket.on('process-pid', () => {
if (process.pid === undefined) {
electronSocket.emit('process-pid-Completed', -1);
electronSocket.emit('process-pid-completed', -1);
return;
}
electronSocket.emit('process-pid-Completed', process.pid);
electronSocket.emit('process-pid-completed', process.pid);
});
socket.on('process-arch', () => {
const value = process.arch;
electronSocket.emit('process-arch-Completed', value);
electronSocket.emit('process-arch-completed', value);
});
socket.on('process-platform', () => {
const value = process.platform;
electronSocket.emit('process-platform-Completed', value);
electronSocket.emit('process-platform-completed', value);
});
};
//# sourceMappingURL=process.js.map

View File

@@ -6,68 +6,68 @@ export = (socket: Socket) => {
socket.on('process-execPath', () => {
const value = process.execPath;
electronSocket.emit('process-execPath-Completed', value);
electronSocket.emit('process-execPath-completed', value);
});
socket.on('process-argv', () => {
const value = process.argv;
electronSocket.emit('process-argv-Completed', value);
electronSocket.emit('process-argv-completed', value);
});
socket.on('process-type', () => {
const value = process.type;
electronSocket.emit('process-type-Completed', value);
electronSocket.emit('process-type-completed', value);
});
socket.on('process-versions', () => {
const value = process.versions;
electronSocket.emit('process-versions-Completed', value);
electronSocket.emit('process-versions-completed', value);
});
socket.on('process-defaultApp', () => {
if (process.defaultApp === undefined) {
electronSocket.emit('process-defaultApp-Completed', false);
electronSocket.emit('process-defaultApp-completed', false);
return;
}
electronSocket.emit('process-defaultApp-Completed', process.defaultApp);
electronSocket.emit('process-defaultApp-completed', process.defaultApp);
});
socket.on('process-isMainFrame', () => {
if (process.isMainFrame === undefined) {
electronSocket.emit('process-isMainFrame-Completed', false);
electronSocket.emit('process-isMainFrame-completed', false);
return;
}
electronSocket.emit('process-isMainFrame-Completed', process.isMainFrame);
electronSocket.emit('process-isMainFrame-completed', process.isMainFrame);
});
socket.on('process-resourcesPath', () => {
const value = process.resourcesPath;
electronSocket.emit('process-resourcesPath-Completed', value);
electronSocket.emit('process-resourcesPath-completed', value);
});
socket.on('process-uptime', () => {
socket.on('process-upTime', () => {
let value = process.uptime();
if (value === undefined) {
value = -1;
}
electronSocket.emit('process-uptime-Completed', value);
electronSocket.emit('process-upTime-completed', value);
});
socket.on('process-pid', () => {
if (process.pid === undefined) {
electronSocket.emit('process-pid-Completed', -1);
electronSocket.emit('process-pid-completed', -1);
return;
}
electronSocket.emit('process-pid-Completed', process.pid);
electronSocket.emit('process-pid-completed', process.pid);
});
socket.on('process-arch', () => {
const value = process.arch;
electronSocket.emit('process-arch-Completed', value);
electronSocket.emit('process-arch-completed', value);
});
socket.on('process-platform', () => {
const value = process.platform;
electronSocket.emit('process-platform-Completed', value);
electronSocket.emit('process-platform-completed', value);
})
};

View File

@@ -20,27 +20,27 @@ module.exports = (socket) => {
});
socket.on('screen-getCursorScreenPoint', () => {
const point = electron_1.screen.getCursorScreenPoint();
electronSocket.emit('screen-getCursorScreenPointCompleted', point);
electronSocket.emit('screen-getCursorScreenPoint-completed', point);
});
socket.on('screen-getMenuBarHeight', () => {
socket.on('screen-getMenuBarWorkArea', () => {
const height = electron_1.screen.getPrimaryDisplay().workArea;
electronSocket.emit('screen-getMenuBarHeightCompleted', height);
electronSocket.emit('screen-getMenuBarWorkArea-completed', height);
});
socket.on('screen-getPrimaryDisplay', () => {
const display = electron_1.screen.getPrimaryDisplay();
electronSocket.emit('screen-getPrimaryDisplayCompleted', display);
electronSocket.emit('screen-getPrimaryDisplay-completed', display);
});
socket.on('screen-getAllDisplays', () => {
const display = electron_1.screen.getAllDisplays();
electronSocket.emit('screen-getAllDisplaysCompleted', display);
electronSocket.emit('screen-getAllDisplays-completed', display);
});
socket.on('screen-getDisplayNearestPoint', (point) => {
const display = electron_1.screen.getDisplayNearestPoint(point);
electronSocket.emit('screen-getDisplayNearestPointCompleted', display);
electronSocket.emit('screen-getDisplayNearestPoint-completed', display);
});
socket.on('screen-getDisplayMatching', (rectangle) => {
const display = electron_1.screen.getDisplayMatching(rectangle);
electronSocket.emit('screen-getDisplayMatchingCompleted', display);
electronSocket.emit('screen-getDisplayMatching-completed', display);
});
};
//# sourceMappingURL=screen.js.map

View File

@@ -25,31 +25,31 @@ export = (socket: Socket) => {
socket.on('screen-getCursorScreenPoint', () => {
const point = screen.getCursorScreenPoint();
electronSocket.emit('screen-getCursorScreenPointCompleted', point);
electronSocket.emit('screen-getCursorScreenPoint-completed', point);
});
socket.on('screen-getMenuBarHeight', () => {
socket.on('screen-getMenuBarWorkArea', () => {
const height = screen.getPrimaryDisplay().workArea;
electronSocket.emit('screen-getMenuBarHeightCompleted', height);
electronSocket.emit('screen-getMenuBarWorkArea-completed', height);
});
socket.on('screen-getPrimaryDisplay', () => {
const display = screen.getPrimaryDisplay();
electronSocket.emit('screen-getPrimaryDisplayCompleted', display);
electronSocket.emit('screen-getPrimaryDisplay-completed', display);
});
socket.on('screen-getAllDisplays', () => {
const display = screen.getAllDisplays();
electronSocket.emit('screen-getAllDisplaysCompleted', display);
electronSocket.emit('screen-getAllDisplays-completed', display);
});
socket.on('screen-getDisplayNearestPoint', (point) => {
const display = screen.getDisplayNearestPoint(point);
electronSocket.emit('screen-getDisplayNearestPointCompleted', display);
electronSocket.emit('screen-getDisplayNearestPoint-completed', display);
});
socket.on('screen-getDisplayMatching', (rectangle) => {
const display = screen.getDisplayMatching(rectangle);
electronSocket.emit('screen-getDisplayMatchingCompleted', display);
electronSocket.emit('screen-getDisplayMatching-completed', display);
});
};

View File

@@ -12,16 +12,19 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- https://github.com/Tyrrrz/GitHubActionsTestLogger/issues/5 -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" />
</ItemGroup>
<ItemGroup>

View File

@@ -17,7 +17,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_app_path()
{
var path = await Electron.App.GetAppPathAsync();
@@ -25,7 +25,7 @@ namespace ElectronNET.IntegrationTests.Tests
Directory.Exists(path).Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_version_and_locale()
{
var version = await Electron.App.GetVersionAsync();
@@ -34,7 +34,7 @@ namespace ElectronNET.IntegrationTests.Tests
locale.Should().NotBeNullOrWhiteSpace();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_special_paths()
{
var userData = await Electron.App.GetPathAsync(PathName.UserData);
@@ -47,7 +47,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Badge_count_roundtrip_where_supported()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
@@ -68,7 +68,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_app_metrics()
{
var metrics = await Electron.App.GetAppMetricsAsync();
@@ -76,29 +76,29 @@ namespace ElectronNET.IntegrationTests.Tests
metrics.Length.Should().BeGreaterThan(0);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_gpu_feature_status()
{
var status = await Electron.App.GetGpuFeatureStatusAsync();
status.Should().NotBeNull();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_login_item_settings()
{
var settings = await Electron.App.GetLoginItemSettingsAsync();
settings.Should().NotBeNull();
}
[Fact]
public void Can_set_app_logs_path()
[Fact(Timeout = 20000)]
public async Task Can_set_app_logs_path()
{
var tempDir = Path.Combine(Path.GetTempPath(), "ElectronLogsTest" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempDir);
Electron.App.SetAppLogsPath(tempDir);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task CommandLine_append_and_query_switch()
{
var switchName = "integration-switch";
@@ -107,7 +107,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await Electron.App.CommandLine.GetSwitchValueAsync(switchName)).Should().Be("value123");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Accessibility_support_toggle()
{
Electron.App.SetAccessibilitySupportEnabled(true);
@@ -116,7 +116,7 @@ namespace ElectronNET.IntegrationTests.Tests
Electron.App.SetAccessibilitySupportEnabled(false);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task UserAgentFallback_roundtrip()
{
var original = await Electron.App.UserAgentFallbackAsync;
@@ -126,7 +126,7 @@ namespace ElectronNET.IntegrationTests.Tests
Electron.App.UserAgentFallback = original; // restore
}
[Fact]
[Fact(Timeout = 20000)]
public async Task BadgeCount_set_and_reset_where_supported()
{
await Electron.App.SetBadgeCountAsync(2);
@@ -136,14 +136,14 @@ namespace ElectronNET.IntegrationTests.Tests
await Electron.App.SetBadgeCountAsync(0);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task App_metrics_have_cpu_info()
{
var metrics = await Electron.App.GetAppMetricsAsync();
metrics[0].Cpu.Should().NotBeNull();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task App_badge_count_roundtrip()
{
// Set then get (non-mac platforms treat as no-op but should return0 or set value)
@@ -154,7 +154,7 @@ namespace ElectronNET.IntegrationTests.Tests
(count ==3 || count ==0).Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task App_gpu_feature_status_has_some_fields()
{
var status = await Electron.App.GetGpuFeatureStatusAsync();

View File

@@ -0,0 +1,132 @@
namespace ElectronNET.IntegrationTests.Tests
{
using API;
using System.Threading.Tasks;
[Collection("ElectronCollection")]
public class AutoUpdaterTests
{
private readonly ElectronFixture fx;
public AutoUpdaterTests(ElectronFixture fx)
{
this.fx = fx;
}
[Fact(Timeout = 20000)]
public async Task AutoDownload_check()
{
Electron.AutoUpdater.AutoDownload = false;
var test1 = Electron.AutoUpdater.AutoDownload;
Electron.AutoUpdater.AutoDownload = true;
var test2 = Electron.AutoUpdater.AutoDownload;
test1.Should().BeFalse();
test2.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task AutoInstallOnAppQuit_check()
{
Electron.AutoUpdater.AutoInstallOnAppQuit = false;
var test1 = Electron.AutoUpdater.AutoInstallOnAppQuit;
Electron.AutoUpdater.AutoInstallOnAppQuit = true;
var test2 = Electron.AutoUpdater.AutoInstallOnAppQuit;
test1.Should().BeFalse();
test2.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task AllowPrerelease_check()
{
Electron.AutoUpdater.AllowPrerelease = false;
var test1 = Electron.AutoUpdater.AllowPrerelease;
Electron.AutoUpdater.AllowPrerelease = true;
var test2 = Electron.AutoUpdater.AllowPrerelease;
test1.Should().BeFalse();
test2.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task FullChangelog_check()
{
Electron.AutoUpdater.FullChangelog = false;
var test1 = Electron.AutoUpdater.FullChangelog;
Electron.AutoUpdater.FullChangelog = true;
var test2 = Electron.AutoUpdater.FullChangelog;
test1.Should().BeFalse();
test2.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task AllowDowngrade_check()
{
Electron.AutoUpdater.AllowDowngrade = false;
var test1 = Electron.AutoUpdater.AllowDowngrade;
Electron.AutoUpdater.AllowDowngrade = true;
var test2 = Electron.AutoUpdater.AllowDowngrade;
test1.Should().BeFalse();
test2.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task UpdateConfigPath_check()
{
var test1 = Electron.AutoUpdater.UpdateConfigPath;
test1.Should().Be(string.Empty);
}
[Fact(Timeout = 20000)]
public async Task CurrentVersionAsync_check()
{
var semver = await Electron.AutoUpdater.CurrentVersionAsync;
semver.Should().NotBeNull();
semver.Major.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
public async Task ChannelAsync_check()
{
var test = await Electron.AutoUpdater.ChannelAsync;
test.Should().Be(string.Empty);
Electron.AutoUpdater.SetChannel = "beta";
test = await Electron.AutoUpdater.ChannelAsync;
test.Should().Be("beta");
}
[Fact(Timeout = 20000)]
public async Task RequestHeadersAsync_check()
{
var headers = new Dictionary<string, string>
{
{ "key1", "value1" },
};
var test = await Electron.AutoUpdater.RequestHeadersAsync;
test.Should().BeNull();
Electron.AutoUpdater.RequestHeaders = headers;
test = await Electron.AutoUpdater.RequestHeadersAsync;
test.Should().NotBeNull();
test.Count.Should().Be(1);
test["key1"].Should().Be("value1");
}
[Fact(Timeout = 20000)]
public async Task CheckForUpdatesAsync_check()
{
var test = await Electron.AutoUpdater.CheckForUpdatesAsync();
test.Should().BeNull();
}
[Fact(Timeout = 20000)]
public async Task CheckForUpdatesAndNotifyAsync_check()
{
var test = await Electron.AutoUpdater.CheckForUpdatesAsync();
test.Should().BeNull();
}
[Fact(Timeout = 20000)]
public async Task GetFeedURLAsync_check()
{
var test = await Electron.AutoUpdater.GetFeedURLAsync();
test.Should().Contain("Deprecated");
}
}
}

View File

@@ -12,7 +12,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Create_browser_view_and_adjust_bounds()
{
var view = await Electron.WindowManager.CreateBrowserViewAsync(new BrowserViewConstructorOptions());

View File

@@ -14,7 +14,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_set_and_get_title()
{
const string title = "Integration Test Title";
@@ -23,7 +23,7 @@ namespace ElectronNET.IntegrationTests.Tests
roundTrip.Should().Be(title);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_resize_and_get_size()
{
this.fx.MainWindow.SetSize(643, 482);
@@ -33,7 +33,7 @@ namespace ElectronNET.IntegrationTests.Tests
size[1].Should().Be(482);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_set_progress_bar_and_clear()
{
this.fx.MainWindow.SetProgressBar(0.5);
@@ -42,7 +42,7 @@ namespace ElectronNET.IntegrationTests.Tests
await Task.Delay(50);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_set_and_get_position()
{
this.fx.MainWindow.SetPosition(134, 246);
@@ -51,7 +51,7 @@ namespace ElectronNET.IntegrationTests.Tests
pos.Should().BeEquivalentTo([134, 246]);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_set_and_get_bounds()
{
var bounds = new Rectangle { X = 10, Y = 20, Width = 400, Height = 300 };
@@ -63,7 +63,7 @@ namespace ElectronNET.IntegrationTests.Tests
round.Height.Should().Be(300);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_set_and_get_content_bounds()
{
var bounds = new Rectangle { X = 0, Y = 0, Width = 300, Height = 200 };
@@ -73,7 +73,7 @@ namespace ElectronNET.IntegrationTests.Tests
round.Height.Should().BeGreaterThan(0);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Show_hide_visibility_roundtrip()
{
this.fx.MainWindow.Show();
@@ -82,7 +82,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await this.fx.MainWindow.IsVisibleAsync()).Should().BeFalse();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task AlwaysOnTop_toggle_and_query()
{
this.fx.MainWindow.SetAlwaysOnTop(true);
@@ -91,7 +91,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task MenuBar_auto_hide_and_visibility()
{
this.fx.MainWindow.SetAutoHideMenuBar(true);
@@ -102,7 +102,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await this.fx.MainWindow.IsMenuBarVisibleAsync()).Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task ReadyToShow_event_fires_after_content_ready()
{
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false });
@@ -122,7 +122,7 @@ namespace ElectronNET.IntegrationTests.Tests
window.Show();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task PageTitleUpdated_event_fires_on_title_change()
{
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = true });
@@ -142,7 +142,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await tcs.Task).Should().Be("NewTitle");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Resize_event_fires_on_size_change()
{
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false });
@@ -153,7 +153,7 @@ namespace ElectronNET.IntegrationTests.Tests
resized.Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Progress_bar_and_always_on_top_toggle()
{
var win = this.fx.MainWindow;
@@ -165,7 +165,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await win.IsAlwaysOnTopAsync()).Should().BeFalse();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Menu_bar_visibility_and_auto_hide()
{
var win = this.fx.MainWindow;
@@ -175,7 +175,7 @@ namespace ElectronNET.IntegrationTests.Tests
(await win.IsMenuBarVisibleAsync()).Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Parent_child_relationship_roundtrip()
{
var child = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false, Width = 300, Height = 200 });
@@ -188,7 +188,7 @@ namespace ElectronNET.IntegrationTests.Tests
child.Destroy();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Represented_filename_and_edited_flags()
{
var win = this.fx.MainWindow;

View File

@@ -13,7 +13,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Clipboard_text_roundtrip()
{
var text = $"Hello Electron {Guid.NewGuid()}";
@@ -22,7 +22,7 @@ namespace ElectronNET.IntegrationTests.Tests
read.Should().Be(text);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Available_formats_contains_text_after_write()
{
var text = "FormatsTest";
@@ -31,7 +31,7 @@ namespace ElectronNET.IntegrationTests.Tests
formats.Should().Contain(f => f.Contains("text") || f.Contains("TEXT") || f.Contains("plain"));
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Bookmark_write_and_read()
{
var url = "https://electron-test.com";

View File

@@ -6,7 +6,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class GlobalShortcutTests
{
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_register_and_unregister()
{
var accel = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "Cmd+Alt+G" : "Ctrl+Alt+G";

View File

@@ -11,7 +11,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Ipc_On_receives_message_from_renderer()
{
var tcs = new TaskCompletionSource<string>();
@@ -21,7 +21,7 @@ namespace ElectronNET.IntegrationTests.Tests
result.Should().Be("payload123");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Ipc_Once_only_fires_once()
{
var count = 0;
@@ -31,7 +31,7 @@ namespace ElectronNET.IntegrationTests.Tests
count.Should().Be(1);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Ipc_RemoveAllListeners_stops_receiving()
{
var fired = false;
@@ -42,7 +42,7 @@ namespace ElectronNET.IntegrationTests.Tests
fired.Should().BeFalse();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Ipc_OnSync_returns_value()
{
Electron.IpcMain.OnSync("ipc-sync-test", (obj) =>
@@ -54,7 +54,7 @@ namespace ElectronNET.IntegrationTests.Tests
ret.Should().Be("pong");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Ipc_Send_from_main_reaches_renderer()
{
// Listener: store raw arg; if Electron packs differently we will normalize later

View File

@@ -12,7 +12,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task ApplicationMenu_click_invokes_handler()
{
var clicked = false;
@@ -38,7 +38,7 @@ namespace ElectronNET.IntegrationTests.Tests
clicked.Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task ContextMenu_popup_registers_items()
{
var win = this.fx.MainWindow;

View File

@@ -17,7 +17,7 @@ namespace ElectronNET.IntegrationTests.Tests
return ReferenceEquals(completed, all) && all.IsCompletedSuccessfully;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task BrowserWindow_OnResize_multiple_handlers_called()
{
var win = this.fx.MainWindow;
@@ -41,7 +41,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
}
[Fact]
[Fact(Timeout = 20000)]
public async Task WebContents_OnDomReady_multiple_handlers_called()
{
var wc = this.fx.MainWindow.WebContents;

View File

@@ -1,14 +1,16 @@
using System.Runtime.Versioning;
using RectangleEntity = ElectronNET.API.Entities.Rectangle;
namespace ElectronNET.IntegrationTests.Tests
{
using System.Drawing;
using ElectronNET.API.Entities;
[SupportedOSPlatform("Windows")]
public class NativeImageTests
{
[Fact]
public void Create_from_bitmap_and_to_png()
[SkippableFact(Timeout = 20000)]
public async Task Create_from_bitmap_and_to_png()
{
using var bmp = new Bitmap(10, 10);
using (var g = Graphics.FromImage(bmp))
@@ -25,8 +27,8 @@ namespace ElectronNET.IntegrationTests.Tests
png!.Length.Should().BeGreaterThan(0);
}
[Fact]
public void Create_from_buffer_and_to_data_url()
[SkippableFact(Timeout = 20000)]
public async Task Create_from_buffer_and_to_data_url()
{
// Prepare PNG bytes
using var bmp = new Bitmap(8, 8);
@@ -44,8 +46,8 @@ namespace ElectronNET.IntegrationTests.Tests
dataUrl!.StartsWith("data:image/", StringComparison.Ordinal).Should().BeTrue();
}
[Fact]
public void Resize_and_crop_produce_expected_sizes()
[SkippableFact(Timeout = 20000)]
public async Task Resize_and_crop_produce_expected_sizes()
{
using var bmp = new Bitmap(12, 10);
using (var g = Graphics.FromImage(bmp))
@@ -64,8 +66,8 @@ namespace ElectronNET.IntegrationTests.Tests
csize.Height.Should().Be(3);
}
[Fact]
public void Add_representation_for_scale_factor()
[SkippableFact(Timeout = 20000)]
public async Task Add_representation_for_scale_factor()
{
using var bmp = new Bitmap(5, 5);
using (var g = Graphics.FromImage(bmp))

View File

@@ -6,7 +6,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class NativeThemeTests
{
[Fact]
[Fact(Timeout = 20000)]
public async Task ThemeSource_roundtrip()
{
// Capture initial
@@ -14,17 +14,23 @@ namespace ElectronNET.IntegrationTests.Tests
// Force light
Electron.NativeTheme.SetThemeSource(ThemeSourceMode.Light);
var useDarkAfterLight = await Electron.NativeTheme.ShouldUseDarkColorsAsync();
var themeSourceLight = await Electron.NativeTheme.GetThemeSourceAsync();
// Force dark
Electron.NativeTheme.SetThemeSource(ThemeSourceMode.Dark);
var useDarkAfterDark = await Electron.NativeTheme.ShouldUseDarkColorsAsync();
var themeSourceDark = await Electron.NativeTheme.GetThemeSourceAsync();
// Restore system
Electron.NativeTheme.SetThemeSource(ThemeSourceMode.System);
var themeSourceSystem = await Electron.NativeTheme.GetThemeSourceAsync();
// Assertions are tolerant (platform dependent)
useDarkAfterLight.Should().BeFalse("forcing Light should result in light colors");
useDarkAfterDark.Should().BeTrue("forcing Dark should result in dark colors");
themeSourceLight.Should().Be(ThemeSourceMode.Light);
themeSourceDark.Should().Be(ThemeSourceMode.Dark);
themeSourceSystem.Should().Be(ThemeSourceMode.System);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Updated_event_fires_on_change()
{
var fired = false;
@@ -39,5 +45,19 @@ namespace ElectronNET.IntegrationTests.Tests
fired.Should().BeTrue();
}
[Fact(Timeout = 20000)]
public async Task Should_use_high_contrast_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseHighContrastColorsAsync();
metrics.Should().Be(false);
}
[Fact(Timeout = 20000)]
public async Task Should_use_inverted_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseInvertedColorSchemeAsync();
metrics.Should().Be(false);
}
}
}

View File

@@ -6,7 +6,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class NotificationTests
{
[Fact]
[Fact(Timeout = 20000)]
public async Task Notification_create_check()
{
var tcs = new TaskCompletionSource();
@@ -21,7 +21,7 @@ namespace ElectronNET.IntegrationTests.Tests
tcs.Task.IsCompletedSuccessfully.Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Notification_is_supported_check()
{
var supported = await Electron.Notification.IsSupportedAsync();

View File

@@ -5,7 +5,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class ProcessTests
{
[Fact]
[Fact(Timeout = 20000)]
public async Task Process_info_is_accessible()
{
// Use renderer to fetch process info and round-trip
@@ -14,15 +14,45 @@ namespace ElectronNET.IntegrationTests.Tests
result.Should().Be("ok");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Process_properties_are_populated()
{
var execPath = await Electron.Process.ExecPathAsync;
execPath.Should().NotBeNullOrWhiteSpace();
var pid = await Electron.Process.PidAsync;
pid.Should().BeGreaterThan(0);
var platform = await Electron.Process.PlatformAsync;
platform.Should().NotBeNullOrWhiteSpace();
var argv = await Electron.Process.ArgvAsync;
argv.Should().NotBeNull();
argv.Length.Should().BeGreaterThan(0);
var type = await Electron.Process.TypeAsync;
type.Should().NotBeNullOrWhiteSpace();
var version = await Electron.Process.VersionsAsync;
version.Should().NotBeNull();
version.Chrome.Should().NotBeNullOrWhiteSpace();
version.Electron.Should().NotBeNullOrWhiteSpace();
var defaultApp = await Electron.Process.DefaultAppAsync;
defaultApp.Should().BeTrue();
var isMainFrame = await Electron.Process.IsMainFrameAsync;
isMainFrame.Should().BeFalse();
var resourcePath = await Electron.Process.ResourcesPathAsync;
resourcePath.Should().NotBeNullOrWhiteSpace();
var upTime = await Electron.Process.UpTimeAsync;
upTime.Should().BeGreaterThan(0);
var arch = await Electron.Process.ArchAsync;
arch.Should().NotBeNullOrWhiteSpace();
}
}

View File

@@ -1,3 +1,5 @@
using ElectronNET.API.Entities;
namespace ElectronNET.IntegrationTests.Tests
{
using ElectronNET.API;
@@ -13,7 +15,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Primary_display_has_positive_dimensions()
{
var display = await Electron.Screen.GetPrimaryDisplayAsync();
@@ -21,12 +23,62 @@ namespace ElectronNET.IntegrationTests.Tests
display.Size.Height.Should().BeGreaterThan(0);
}
[Fact]
[Fact(Timeout = 20000)]
public async Task GetAllDisplays_returns_at_least_one()
{
var displays = await Electron.Screen.GetAllDisplaysAsync();
displays.Should().NotBeNull();
displays.Length.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
public async Task GetCursorScreenPoint_check()
{
var point = await Electron.Screen.GetCursorScreenPointAsync();
point.Should().NotBeNull();
point.X.Should().BeGreaterThanOrEqualTo(0);
point.Y.Should().BeGreaterThanOrEqualTo(0);
}
[Fact(Timeout = 20000)]
public async Task GetMenuBarWorkArea_check()
{
var area = await Electron.Screen.GetMenuBarWorkAreaAsync();
area.Should().NotBeNull();
area.X.Should().BeGreaterThanOrEqualTo(0);
area.Y.Should().BeGreaterThanOrEqualTo(0);
area.Height.Should().BeGreaterThan(0);
area.Width.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
public async Task GetDisplayNearestPoint_check()
{
var point = new Point
{
X = 100,
Y = 100
};
var display = await Electron.Screen.GetDisplayNearestPointAsync(point);
display.Should().NotBeNull();
display.Size.Width.Should().BeGreaterThan(0);
display.Size.Height.Should().BeGreaterThan(0);
}
[Fact(Timeout = 20000)]
public async Task GetDisplayMatching_check()
{
var rectangle = new Rectangle
{
X = 100,
Y = 100,
Width = 100,
Height = 100
};
var display = await Electron.Screen.GetDisplayMatchingAsync(rectangle);
display.Should().NotBeNull();
display.Size.Width.Should().BeGreaterThan(0);
display.Size.Height.Should().BeGreaterThan(0);
}
}
}

View File

@@ -12,7 +12,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Session_preloads_roundtrip()
{
var session = this.fx.MainWindow.WebContents.Session;
@@ -23,7 +23,7 @@ namespace ElectronNET.IntegrationTests.Tests
preloadsAfter.Should().Contain("/tmp/preload_dummy.js");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Session_proxy_set_and_resolve()
{
var session = this.fx.MainWindow.WebContents.Session;
@@ -34,7 +34,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Session_clear_cache_and_storage_completes()
{
var session = this.fx.MainWindow.WebContents.Session;
@@ -46,7 +46,7 @@ namespace ElectronNET.IntegrationTests.Tests
ua.Should().NotBeNullOrWhiteSpace();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Session_preloads_set_multiple_and_clear()
{
var session = this.fx.MainWindow.WebContents.Session;
@@ -59,7 +59,7 @@ namespace ElectronNET.IntegrationTests.Tests
empty.Should().NotContain("/tmp/a.js");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Clear_auth_cache_overloads()
{
var session = this.fx.MainWindow.WebContents.Session;
@@ -67,29 +67,29 @@ namespace ElectronNET.IntegrationTests.Tests
await session.ClearAuthCacheAsync(new RemovePassword("password") { Origin = "https://example.com", Username = "user", Password = "pw", Realm = "realm", Scheme = Scheme.basic });
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Clear_storage_with_options()
{
var session = this.fx.MainWindow.WebContents.Session;
await session.ClearStorageDataAsync(new ClearStorageDataOptions { Storages = new[] { "cookies" }, Quotas = new[] { "temporary" } });
}
[Fact]
public void Enable_disable_network_emulation()
[Fact(Timeout = 20000)]
public async Task Enable_disable_network_emulation()
{
var session = this.fx.MainWindow.WebContents.Session;
session.EnableNetworkEmulation(new EnableNetworkEmulationOptions { Offline = false, Latency = 10, DownloadThroughput = 50000, UploadThroughput = 20000 });
session.DisableNetworkEmulation();
}
[Fact]
public void Flush_storage_data_does_not_throw()
[Fact(Timeout = 20000)]
public async Task Flush_storage_data_does_not_throw()
{
var session = this.fx.MainWindow.WebContents.Session;
session.FlushStorageData();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Set_user_agent_affects_new_navigation()
{
var session = this.fx.MainWindow.WebContents.Session;

View File

@@ -5,7 +5,7 @@ namespace ElectronNET.IntegrationTests.Tests
[Collection("ElectronCollection")]
public class ShellTests
{
[Fact]
[Fact(Timeout = 20000)]
public async Task OpenExternal_invalid_scheme_returns_error_or_empty()
{
var error = await Electron.Shell.OpenExternalAsync("mailto:test@example.com");

View File

@@ -13,7 +13,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task SetThumbarButtons_returns_success()
{
var btn = new ThumbarButton("icon.png") { Tooltip = "Test" };
@@ -21,7 +21,7 @@ namespace ElectronNET.IntegrationTests.Tests
success.Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Thumbar_button_click_invokes_callback()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

View File

@@ -12,7 +12,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_create_tray_and_destroy()
{
//await Electron.Tray.Show("assets/icon.png");

View File

@@ -12,7 +12,7 @@ namespace ElectronNET.IntegrationTests.Tests
this.fx = fx;
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_get_url_after_navigation()
{
var wc = this.fx.MainWindow.WebContents;
@@ -21,7 +21,7 @@ namespace ElectronNET.IntegrationTests.Tests
url.Should().Contain("example.com");
}
[Fact]
[Fact(Timeout = 20000)]
public async Task ExecuteJavaScript_returns_title()
{
var wc = this.fx.MainWindow.WebContents;
@@ -30,7 +30,7 @@ namespace ElectronNET.IntegrationTests.Tests
title.Should().NotBeNull();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task DomReady_event_fires()
{
var wc = this.fx.MainWindow.WebContents;
@@ -41,7 +41,7 @@ namespace ElectronNET.IntegrationTests.Tests
fired.Should().BeTrue();
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_print_to_pdf()
{
var html = "data:text/html,<html><body><h1>PDF Test</h1><p>Electron.NET</p></body></html>";
@@ -63,7 +63,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
}
[Fact]
[Fact(Timeout = 20000)]
public async Task Can_basic_print()
{
var html = "data:text/html,<html><body><h2>Print Test</h2></body></html>";
@@ -71,5 +71,13 @@ namespace ElectronNET.IntegrationTests.Tests
var ok = await this.fx.MainWindow.WebContents.PrintAsync(new PrintOptions { Silent = true, PrintBackground = true });
ok.Should().BeTrue();
}
[SkippableFact(Timeout = 20000)]
public async Task GetPrintersAsync_check()
{
Skip.If(Environment.GetEnvironmentVariable("GITHUB_TOKEN") != null, "Skipping printer test in CI environment.");
var info = await fx.MainWindow.WebContents.GetPrintersAsync();
info.Should().NotBeNull();
}
}
}

View File

@@ -3,7 +3,7 @@
<Import Project="..\common.props" />
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net10.0</TargetFrameworks>
<PackageOutputPath>..\..\artifacts</PackageOutputPath>
<PackageId>$(PackageNamePrefix)</PackageId>
<Title>$(PackageId)</Title>

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.1.0.0</Version>
<Version>0.1.0</Version>
<PackageNamePrefix>ElectronNET.Core</PackageNamePrefix>
<Authors>Gregor Biswanger, Florian Rappl, softworkz</Authors>
<Product>Electron.NET</Product>