mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 21:25:09 +00:00
Compare commits
169 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dea16798b | ||
|
|
bf8c7c8fa1 | ||
|
|
06724f6eae | ||
|
|
83e579d44b | ||
|
|
ed67aa8072 | ||
|
|
5e005499ef | ||
|
|
975e4020dc | ||
|
|
15ce35a7d9 | ||
|
|
de1637672a | ||
|
|
8f92d3986f | ||
|
|
ca7414b8e6 | ||
|
|
37ae869dcb | ||
|
|
3420ee2de4 | ||
|
|
0a76e951eb | ||
|
|
4db316eb15 | ||
|
|
a867f23220 | ||
|
|
490440c23a | ||
|
|
519fb53c00 | ||
|
|
12388541ab | ||
|
|
8c8115f3bd | ||
|
|
4286bc4f45 | ||
|
|
886f839482 | ||
|
|
96abbd161c | ||
|
|
9baf1528ac | ||
|
|
380441c2c8 | ||
|
|
a66375e37c | ||
|
|
606d00de5a | ||
|
|
b3266cd93f | ||
|
|
cb36e34dc3 | ||
|
|
db7a5ff868 | ||
|
|
a030e3cbe7 | ||
|
|
b98c570b9d | ||
|
|
d106c6b193 | ||
|
|
c95bbe7ab2 | ||
|
|
258710bc52 | ||
|
|
9ddb1b195e | ||
|
|
eee84d214e | ||
|
|
1ab48350e1 | ||
|
|
874bc8eb94 | ||
|
|
7aa2268a81 | ||
|
|
b08222bddc | ||
|
|
c5c822a028 | ||
|
|
ce4ef03636 | ||
|
|
641864b946 | ||
|
|
c6d67a9145 | ||
|
|
fabd25a89e | ||
|
|
029b077602 | ||
|
|
0329530815 | ||
|
|
58ab180c94 | ||
|
|
a03dc1d195 | ||
|
|
76dcdc4137 | ||
|
|
2b415e5b59 | ||
|
|
94055b985f | ||
|
|
596aa68c70 | ||
|
|
485bce08d7 | ||
|
|
2ba49dbd6a | ||
|
|
39c3e92128 | ||
|
|
c552a04347 | ||
|
|
1541553ed1 | ||
|
|
52b850092c | ||
|
|
cac9cfcec8 | ||
|
|
4ad39ba4c1 | ||
|
|
95acbd5dea | ||
|
|
95f9a59431 | ||
|
|
d409c3a0f9 | ||
|
|
6d0fbde5ad | ||
|
|
b113532a86 | ||
|
|
b043688f7f | ||
|
|
3b3e38f1bf | ||
|
|
9502eb787a | ||
|
|
4a9b6fa9c1 | ||
|
|
fb308ed1c6 | ||
|
|
d51a481e50 | ||
|
|
bb3d073fae | ||
|
|
8c250ae83e | ||
|
|
a5543bfe60 | ||
|
|
c40affb32e | ||
|
|
e9331728b4 | ||
|
|
92b0388300 | ||
|
|
f4ea6df204 | ||
|
|
b027ca7c66 | ||
|
|
0573e92ed5 | ||
|
|
672e3b86fd | ||
|
|
b7960eb772 | ||
|
|
bbab114c54 | ||
|
|
e77f48b2c5 | ||
|
|
8fe60bfcda | ||
|
|
09fa662ed1 | ||
|
|
7f2269c4bd | ||
|
|
05de4071d1 | ||
|
|
169abc2376 | ||
|
|
12a3f2689e | ||
|
|
14587463e7 | ||
|
|
6690b4a76e | ||
|
|
c8e51ef21b | ||
|
|
96a5189f14 | ||
|
|
13fcedc3a0 | ||
|
|
c12c26b491 | ||
|
|
6ddce85bdd | ||
|
|
68ee626d07 | ||
|
|
fd5801ffdc | ||
|
|
df02855471 | ||
|
|
b6417d0718 | ||
|
|
6f1f7cbc5e | ||
|
|
aec0da6075 | ||
|
|
c9f0c43bc9 | ||
|
|
b87d7f9899 | ||
|
|
fa51cdd72c | ||
|
|
9b270755d0 | ||
|
|
c5db735773 | ||
|
|
88f5995f40 | ||
|
|
042cd7e6cb | ||
|
|
cb096212f9 | ||
|
|
0363dc8924 | ||
|
|
8cf5053512 | ||
|
|
32046adfb5 | ||
|
|
003a9d0d35 | ||
|
|
db6bed43dc | ||
|
|
80d160a71c | ||
|
|
01d938fb1a | ||
|
|
00eb9869dc | ||
|
|
2987e3143d | ||
|
|
20ca72b794 | ||
|
|
a0e0cc3bbc | ||
|
|
e295558258 | ||
|
|
e67f6c500b | ||
|
|
23015a9f3d | ||
|
|
7daac2d04e | ||
|
|
71955b9181 | ||
|
|
a619b6e5c9 | ||
|
|
3ba3fa6414 | ||
|
|
11fbd6b259 | ||
|
|
073eb0e00d | ||
|
|
c0bf257b55 | ||
|
|
62b37d059f | ||
|
|
ca8f4c454c | ||
|
|
d660dff871 | ||
|
|
c17720a4d7 | ||
|
|
274552f52b | ||
|
|
1e3fe6183c | ||
|
|
88b04377a7 | ||
|
|
92356d3587 | ||
|
|
a3c452eea5 | ||
|
|
68288d9d73 | ||
|
|
022221307c | ||
|
|
ffc6353bf2 | ||
|
|
f4d8144a8b | ||
|
|
30d49ff6e8 | ||
|
|
db9d3b1484 | ||
|
|
a788d71530 | ||
|
|
f5e2abfdb4 | ||
|
|
42f09de7b5 | ||
|
|
72d1f4b2b9 | ||
|
|
d2b3c28f91 | ||
|
|
94c4cd82b0 | ||
|
|
600bc1a41b | ||
|
|
4e8e771293 | ||
|
|
4014ef7a4d | ||
|
|
364db7dc25 | ||
|
|
3dda18ac9a | ||
|
|
7f92ffa20e | ||
|
|
eb4144053d | ||
|
|
cafffde339 | ||
|
|
28be0dd209 | ||
|
|
8bf10c370c | ||
|
|
a32b50f86f | ||
|
|
a781234d05 | ||
|
|
8b66bdd7cb | ||
|
|
ba64639c1d |
@@ -1,7 +1,7 @@
|
||||
language: csharp
|
||||
mono: none
|
||||
dist: xenial
|
||||
dotnet: 3.0
|
||||
dotnet: 3.1
|
||||
before_script:
|
||||
- export PATH="$PATH:/home/travis/.dotnet/tools"
|
||||
script:
|
||||
|
||||
120
Changelog.md
120
Changelog.md
@@ -1,13 +1,121 @@
|
||||
# Not released
|
||||
|
||||
# 5.22.15
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Add BrowserWindow.RemoveMenu() (thanks [hack2root](https://github.com/hack2root))
|
||||
|
||||
# Released
|
||||
|
||||
# 9.31.2
|
||||
|
||||
* Electron-Builder fixed for Windows builds.
|
||||
|
||||
# 9.31.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* New Feature: Added config parameter (thanks [konstantingross](https://github.com/konstantingross)) [\#409](https://github.com/ElectronNET/Electron.NET/pull/409)
|
||||
* New Feature: Set the configuration environment with the electron.manifest.json file.
|
||||
* Fixed bug: Custom user path removed and replaced by the correct directory with VS macro (When ElectronNET.CLI is the Startup Project, press F5 (Debug) and the ElectronNET.WebApp starts correctly without error!) (thanks [konstantingross](https://github.com/konstantingross)) [\#409](https://github.com/ElectronNET/Electron.NET/pull/409)
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Native Electron 9.0.3 support, but not all new features (we search contributors)
|
||||
* New Feature: PowerMonitor API Support (thanks [gustavo-lara-molina](https://github.com/gustavo-lara-molina)) [\#399](https://github.com/ElectronNET/Electron.NET/pull/399) [\#423](https://github.com/ElectronNET/Electron.NET/pull/423)
|
||||
* New Feature: NativeTheme API Support (thanks [konstantingross](https://github.com/konstantingross)) [\#402](https://github.com/ElectronNET/Electron.NET/pull/402)
|
||||
* New Feature: Cookie API Support (thanks [freosc](https://github.com/freosc)) [\#413](https://github.com/ElectronNET/Electron.NET/pull/413)
|
||||
* Changed Feature: Removed dock methods from App API and moved to Dock API (thanks [konstantingross](https://github.com/konstantingross)) [\#422](https://github.com/ElectronNET/Electron.NET/pull/422)
|
||||
* App-Api Enhancement: MenuItems with Submenus need an submenu type workaround [\#412](https://github.com/ElectronNET/Electron.NET/issues/412)
|
||||
* App-Api Enhancement: Added UserAgentFallback (thanks [Mandrakia](https://github.com/Mandrakia)) [\#406](https://github.com/ElectronNET/Electron.NET/pull/406)
|
||||
* App-Api Enhancement: Summaries rewritten, new App.IsReady / App.HasSingleInstanceLock property, App.Ready event, App.Focus with force parameter method, many parameters changes (thanks [konstantingross](https://github.com/konstantingross)) [\#415](https://github.com/ElectronNET/Electron.NET/pull/415) [\#422](https://github.com/ElectronNET/Electron.NET/pull/422)
|
||||
* App-Api Enhancement: New App.IsReady property and App.Ready event (thanks [konstantingross](https://github.com/konstantingross)) [\#415](https://github.com/ElectronNET/Electron.NET/pull/415)
|
||||
* Shell-Api Enhancement: API fixes for Electron 9.0.0 / Added missing parameters / Summaries rewritten (thanks [konstantingross](https://github.com/konstantingross)) [\#417](https://github.com/ElectronNET/Electron.NET/pull/417) [\#418](https://github.com/ElectronNET/Electron.NET/pull/418)
|
||||
* Notification-Api Enhancement: Added missing properties in Notifications (thanks [konstantingross](https://github.com/konstantingross)) [\#410](https://github.com/ElectronNET/Electron.NET/pull/410)
|
||||
* BrowserWindows-Api Enhancement: Add missing API call for SetProgressBar options (thanks [konstantingross](https://github.com/konstantingross)) [\#416](https://github.com/ElectronNET/Electron.NET/pull/416)
|
||||
* BrowserWindow Enhancement: Add BrowserWindow.GetNativeWindowHandle() (thanks [kdlslyv](https://github.com/kdlslyv)) [\#429](https://github.com/ElectronNET/Electron.NET/pull/429)
|
||||
* HostHook-Api Enhancement: HostHook.CallAsync should use TaskCompletionSource.SetException instead of throwing exception (thanks [Fre V](https://github.com/freosc)) [\#430](https://github.com/ElectronNET/Electron.NET/pull/430)
|
||||
* MacOS Enhancement: Application exit logic (thanks [dafergu2](https://github.com/dafergu2)) [\#405](https://github.com/ElectronNET/Electron.NET/pull/405)
|
||||
* Fixed bug: ElectronNET.API.Entities.WebPreferences.ContextIsolation [DefaultValue(true)] [\#411](https://github.com/ElectronNET/Electron.NET/issues/411)
|
||||
|
||||
ElectronNET.WebApp (internal use):
|
||||
* Improvement debugging and testing new API calls (without install ElectronNET.CLI) (thanks [konstantingross](https://github.com/konstantingross)) [\#425](https://github.com/ElectronNET/Electron.NET/pull/425)
|
||||
* Fixed bug: Cannot find modules in ElectronHostHook (thanks [konstantingross](https://github.com/konstantingross)) [\#425](https://github.com/ElectronNET/Electron.NET/pull/425)
|
||||
|
||||
Thank you for donation [Phil Seeman](https://github.com/mpnow) ❤
|
||||
|
||||
# 8.31.2
|
||||
|
||||
ElectronNET.CLI:
|
||||
* New Feature: Deactivate PublishReadyToRun for build or start [\#395](https://github.com/ElectronNET/Electron.NET/issues/395)
|
||||
|
||||
`electronize build /target win /PublishReadyToRun false`
|
||||
`electronize start /PublishReadyToRun false`
|
||||
* Fixed bug: Application window doesn't open after packaging [\#387](https://github.com/ElectronNET/Electron.NET/issues/387)
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: NativeImage Support (thanks [ThrDev](https://github.com/ThrDev)) [\#394](https://github.com/ElectronNET/Electron.NET/pull/394)
|
||||
* New Feature: Update menu items for context menu and system tray on-the-fly. [\#270](https://github.com/ElectronNET/Electron.NET/pull/270)
|
||||
|
||||
|
||||
# 8.31.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
* New Feature: Set a name and author of the app in `electron.manifest.json` [\#348](https://github.com/ElectronNET/Electron.NET/issues/348#issuecomment-615977950) [\#310](https://github.com/ElectronNET/Electron.NET/issues/310#issuecomment-617361086)
|
||||
* New Feature: Live reload (thanks [syedadeel2](https://github.com/syedadeel2)) [\#390](https://github.com/ElectronNET/Electron.NET/pull/390)
|
||||
`electronize start /watch`
|
||||
* New Feature: Every new window will created with an clear cache [\#273](https://github.com/ElectronNET/Electron.NET/issues/273)
|
||||
`electronize start /clear-cache`
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Native Electron 8.2.3 support, but not all new features (we search contributors)
|
||||
* New Feature: We incease the startup time for ~25-36% [\#356](https://github.com/ElectronNET/Electron.NET/issues/356)
|
||||
* New Feature: Added print capability (thanks [x-xx-o](https://github.com/x-xx-o)) [\#355](https://github.com/ElectronNET/Electron.NET/pull/355)
|
||||
* New Feature: BrowserView API [\#371](https://github.com/ElectronNET/Electron.NET/issues/371)
|
||||
* Changed App.GetNameAsync and App.SetNameAsync to the App.Name Property [\#350](https://github.com/ElectronNET/Electron.NET/issues/350)
|
||||
* Fixed bug: Splash Screen disappearing on click [\#357](https://github.com/ElectronNET/Electron.NET/issues/357)
|
||||
* Fixed bug: Start MenuRole enum at 1 (thanks [jjuback](https://github.com/jjuback)) [\#369](https://github.com/ElectronNET/Electron.NET/pull/369)
|
||||
* Fixed bug: BridgeConnector not connected (spam console) [\#347](https://github.com/ElectronNET/Electron.NET/issues/347)
|
||||
* Fixed bug: BrowserWindowOptions is not setting Width and Height properly [\#373](https://github.com/ElectronNET/Electron.NET/issues/373)
|
||||
* Fixed bug: IpcMain.Once(string) is not one time use, is not removing listener [\#366](https://github.com/ElectronNET/Electron.NET/issues/366)
|
||||
* Fixed bug: IpcMain.RemoveAllListeners(string) is not removing the listeners [\#365](https://github.com/ElectronNET/Electron.NET/issues/365)
|
||||
* Fixed bug: GetLoginItemSettingsAsync does not work [\#352](https://github.com/ElectronNET/Electron.NET/issues/352)
|
||||
* Fixed bug: Using OnReadyToShow to display the main window in Blazor does not seem to work with Show set to false [\#361](https://github.com/ElectronNET/Electron.NET/issues/361)
|
||||
* Fixed bug: Unable to disable WebSecurity along with NodeIntegration enabled [\#389](https://github.com/ElectronNET/Electron.NET/issues/389)
|
||||
|
||||
# 7.30.2
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* New Feature: Different manifest file support [\#340](https://github.com/ElectronNET/Electron.NET/issues/340)
|
||||
* Create a additional manifest file: `electronize init /manifest test`
|
||||
* Start the app with your additional manifest file: `electronize start /manifest electron.manifest.test.json`
|
||||
* Build the app with your additional manifest file: `electronize build /target win /manifest electron.manifest.test.json`.
|
||||
|
||||
* New Feature: Command Line support [\#337](https://github.com/ElectronNET/Electron.NET/issues/337)
|
||||
* You can start the app with: `electronize start /args --dog=woof --test=true`
|
||||
* Or as binary: `myapp.exe /args --dog=woof --test=true`
|
||||
* Fixed bug: Start process with listen port 8000 error. [\#308](https://github.com/ElectronNET/Electron.NET/issues/308) (thanks [thecodejedi](https://github.com/thecodejedi))
|
||||
* Fixed bug: `electronize build` with no arguments would throw a `KeyNotFoundException`. (thanks [jamiebrynes7](https://github.com/jamiebrynes7))
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Electron 7.1.2 support, but not all new features (we search contributors) [\#341](https://github.com/ElectronNET/Electron.NET/issues/341)
|
||||
* New Feature: Electron.App.CommandLine API [\#337](https://github.com/ElectronNET/Electron.NET/issues/337)
|
||||
* New Feature: Support of BrowserWindow.AddExtension, BrowserWindow.RemoveExtension, BrowserWindow.GetExtensions (thanks [Daddoon](https://github.com/Daddoon))
|
||||
|
||||
Thank you for donation [robertmclaws](https://github.com/robertmclaws) ❤
|
||||
|
||||
# 5.30.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* Move to .NET Core 3.0
|
||||
* Use npm npx instead of global installations (thanks [jimbuck](https://github.com/jimbuck))
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* Move to .NET Core 3.0
|
||||
* New Feature: Add BrowserWindow.RemoveMenu() (thanks [hack2root](https://github.com/hack2root))
|
||||
|
||||
Thanks to [MaherJendoubi](https://github.com/MaherJendoubi), [kant2002](https://github.com/kant2002), [raz-canva](https://github.com/raz-canva) and [Daddoon](https://github.com/Daddoon) to give .NET Core 3.0 feedback!
|
||||
# 5.22.14
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
138
ElectronNET.API/BrowserView.cs
Normal file
138
ElectronNET.API/BrowserView.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The identifier.
|
||||
/// </value>
|
||||
public int Id { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Render and control web pages.
|
||||
/// </summary>
|
||||
public WebContents WebContents { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the view is destroyed.
|
||||
/// </summary>
|
||||
public Task<bool> IsDestroyedAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<bool>(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserView-isDestroyed-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("browserView-isDestroyed-reply");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserView-isDestroyed", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the view to the supplied bounds relative to the window.
|
||||
///
|
||||
/// (experimental)
|
||||
/// </summary>
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<Rectangle>(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
|
||||
|
||||
BridgeConnector.Socket.On("browserView-getBounds-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("browserView-getBounds-reply");
|
||||
taskCompletionSource.SetResult((Rectangle)result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}).Result;
|
||||
}
|
||||
set
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setBounds", Id, JObject.FromObject(value, _jsonSerializer));
|
||||
}
|
||||
}
|
||||
|
||||
internal Action<BrowserView> Destroyed;
|
||||
|
||||
/// <summary>
|
||||
/// BrowserView
|
||||
/// </summary>
|
||||
internal BrowserView(int id)
|
||||
{
|
||||
Id = id;
|
||||
|
||||
// Workaround: increase the Id so as not to conflict with BrowserWindow id
|
||||
// the backend detect about the value an BrowserView
|
||||
WebContents = new WebContents(id + 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force closing the view, the `unload` and `beforeunload` events won't be emitted
|
||||
/// for the web page.After you're done with a view, call this function in order to
|
||||
/// free memory and other resources as soon as possible.
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-destroy", Id);
|
||||
|
||||
Destroyed?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (experimental)
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void SetAutoResize(AutoResizeOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
|
||||
///
|
||||
/// (experimental)
|
||||
/// </summary>
|
||||
/// <param name="color">Color in #aarrggbb or #argb form. The alpha channel is optional.</param>
|
||||
public void SetBackgroundColor(string color)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserView-setBackgroundColor", Id, color);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1809,6 +1809,25 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the native type of the handle is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.
|
||||
/// </summary>
|
||||
/// <returns>string of the native handle obtained, HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.</returns>
|
||||
public Task<string> GetNativeWindowHandle()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getNativeWindowHandle-completed", (nativeWindowHandle) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("browserWindow-getNativeWindowHandle-completed");
|
||||
taskCompletionSource.SetResult(nativeWindowHandle.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindowGetNativeWindowHandle", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pathname of the file the window represents,
|
||||
/// and the icon of the file will show in window’s title bar.
|
||||
@@ -2305,10 +2324,74 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
public WebContents WebContents { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// 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>
|
||||
/// <param name="browserView"></param>
|
||||
public void SetBrowserView(BrowserView browserView)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setBrowserView", Id, browserView.Id);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Adds Chrome extension located at path, and returns extension's name.
|
||||
/// The method will also not return if the extension's manifest is missing or incomplete.
|
||||
/// Note: This API cannot be called before the ready event of the app module is emitted.
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the Chrome extension</param>
|
||||
/// <returns></returns>
|
||||
public static Task<string> AddExtensionAsync(string path)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-addExtension-completed", (extensionname) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-addExtension-completed");
|
||||
|
||||
taskCompletionSource.SetResult(extensionname.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindowAddExtension", path);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Chrome extension with the specified name.
|
||||
/// Note: This API cannot be called before the ready event of the app module is emitted.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Chrome extension to remove</param>
|
||||
public static void RemoveExtension(string name)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindowRemoveExtension", name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The keys are the extension names and each value is an object containing name and version properties.
|
||||
/// Note: This API cannot be called before the ready event of the app module is emitted.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Task<ChromeExtensionInfo[]> GetExtensionsAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ChromeExtensionInfo[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getExtensions-completed", (extensionslist) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getExtensions-completed");
|
||||
var chromeExtensionInfos = ((JArray)extensionslist).ToObject<ChromeExtensionInfo[]>();
|
||||
|
||||
taskCompletionSource.SetResult(chromeExtensionInfos);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindowGetExtensions");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +237,40 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an image from the clipboard.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Task<NativeImage> ReadImageAsync(string type = "")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<NativeImage>();
|
||||
|
||||
BridgeConnector.Socket.On("clipboard-readImage-Completed", (image) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("clipboard-readImage-Completed");
|
||||
|
||||
var nativeImage = ((JObject)image).ToObject<NativeImage>();
|
||||
|
||||
taskCompletionSource.SetResult(nativeImage);
|
||||
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("clipboard-readImage", type);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an image to the clipboard.
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="type"></param>
|
||||
public void WriteImage(NativeImage image, string type = "")
|
||||
{
|
||||
BridgeConnector.Socket.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
116
ElectronNET.API/CommandLine.cs
Normal file
116
ElectronNET.API/CommandLine.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Manipulate the command line arguments for your app that Chromium reads.
|
||||
/// </summary>
|
||||
public sealed class CommandLine
|
||||
{
|
||||
internal CommandLine() { }
|
||||
|
||||
internal static CommandLine Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_commandLine == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_commandLine == null)
|
||||
{
|
||||
_commandLine = new CommandLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _commandLine;
|
||||
}
|
||||
}
|
||||
|
||||
private static CommandLine _commandLine;
|
||||
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Append a switch (with optional value) to Chromium's command line.
|
||||
/// </summary>
|
||||
/// <param name="the_switch">A command-line switch, without the leading --</param>
|
||||
/// <param name="value">(optional) - A value for the given switch</param>
|
||||
/// <remarks>
|
||||
/// Note: This will not affect process.argv. The intended usage of this function is to control Chromium's behavior.
|
||||
/// </remarks>
|
||||
public void AppendSwitch(string the_switch, string value = "")
|
||||
{
|
||||
BridgeConnector.Socket.Emit("appCommandLineAppendSwitch", the_switch, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append an argument to Chromium's command line. The argument will be quoted correctly. Switches will precede arguments regardless of appending order.
|
||||
///
|
||||
/// If you're appending an argument like <code>--switch=value</code>, consider using <code>appendSwitch('switch', 'value')</code> instead.
|
||||
/// </summary>
|
||||
/// <param name="value">The argument to append to the command line</param>
|
||||
/// <remarks>
|
||||
/// Note: This will not affect process.argv. The intended usage of this function is to control Chromium's behavior.
|
||||
/// </remarks>
|
||||
public void AppendArgument(string value)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("appCommandLineAppendArgument", value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the command-line switch is present.
|
||||
/// </summary>
|
||||
/// <param name="switchName">A command-line switch</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns>Whether the command-line switch is present.</returns>
|
||||
public async Task<bool> HasSwitchAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appCommandLineHasSwitchCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appCommandLineHasSwitchCompleted");
|
||||
taskCompletionSource.SetResult((bool)result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appCommandLineHasSwitch", switchName);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The command-line switch value.
|
||||
/// </summary>
|
||||
/// <param name="switchName">A command-line switch</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns>The command-line switch value.</returns>
|
||||
/// <remarks>
|
||||
/// Note: When the switch is not present or has no value, it returns empty string.
|
||||
/// </remarks>
|
||||
public async Task<string> GetSwitchValueAsync(string switchName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("appCommandLineGetSwitchValueCompleted", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("appCommandLineGetSwitchValueCompleted");
|
||||
taskCompletionSource.SetResult((string)result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("appCommandLineGetSwitchValue", switchName);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
154
ElectronNET.API/Cookies.cs
Normal file
154
ElectronNET.API/Cookies.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Query and modify a session's cookies.
|
||||
/// </summary>
|
||||
public class Cookies
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The identifier.
|
||||
/// </value>
|
||||
public int Id { get; private set; }
|
||||
|
||||
internal Cookies(int id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when a cookie is changed because it was added, edited, removed, or expired.
|
||||
/// </summary>
|
||||
public event Action<Cookie, CookieChangedCause, bool> OnChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_changed == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-changed" + Id, (args) =>
|
||||
{
|
||||
Cookie cookie = ((JArray)args)[0].ToObject<Cookie>();
|
||||
CookieChangedCause cause = ((JArray)args)[1].ToObject<CookieChangedCause>();
|
||||
bool removed = ((JArray)args)[2].ToObject<bool>();
|
||||
_changed(cookie, cause, removed);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-session-cookies-changed", Id);
|
||||
}
|
||||
_changed += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_changed -= value;
|
||||
|
||||
if (_changed == null)
|
||||
BridgeConnector.Socket.Off("webContents-session-cookies-changed" + Id);
|
||||
}
|
||||
}
|
||||
|
||||
private event Action<Cookie, CookieChangedCause, bool> _changed;
|
||||
|
||||
/// <summary>
|
||||
/// Sends a request to get all cookies matching filter, and resolves a callack with the response.
|
||||
/// </summary>
|
||||
/// <param name="filter">
|
||||
/// </param>
|
||||
/// <returns>A task which resolves an array of cookie objects.</returns>
|
||||
public Task<Cookie[]> GetAsync(CookieFilter filter)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Cookie[]>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-get-completed" + guid, (cookies) =>
|
||||
{
|
||||
Cookie[] result = ((JArray)cookies).ToObject<Cookie[]>();
|
||||
|
||||
BridgeConnector.Socket.Off("webContents-session-cookies-get-completed" + guid);
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-get", Id, JObject.FromObject(filter, _jsonSerializer), guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="details"></param>
|
||||
/// <returns></returns>
|
||||
public Task SetAsync(CookieDetails details)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-set-completed" + guid, () =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-cookies-set-completed" + guid);
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-set", Id, JObject.FromObject(details, _jsonSerializer), guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the cookies matching url and name
|
||||
/// </summary>
|
||||
/// <param name="url">The URL associated with the cookie.</param>
|
||||
/// <param name="name">The name of cookie to remove.</param>
|
||||
/// <returns>A task which resolves when the cookie has been removed</returns>
|
||||
public Task RemoveAsync(string url, string name)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-remove-completed" + guid, () =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-cookies-remove-completed" + guid);
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-remove", Id, url, name, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes any unwritten cookies data to disk.
|
||||
/// </summary>
|
||||
/// <returns>A task which resolves when the cookie store has been flushed</returns>
|
||||
public Task FlushStoreAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-cookies-flushStore-completed" + guid, () =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-cookies-flushStore-completed" + guid);
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-flushStore", Id, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
206
ElectronNET.API/Dock.cs
Normal file
206
ElectronNET.API/Dock.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Control your app in the macOS dock.
|
||||
/// </summary>
|
||||
public sealed class Dock
|
||||
{
|
||||
private static Dock _dock;
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
internal Dock()
|
||||
{
|
||||
}
|
||||
|
||||
internal static Dock Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_dock == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_dock == null)
|
||||
{
|
||||
_dock = new Dock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _dock;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When <see cref="DockBounceType.Critical"/> is passed, the dock icon will bounce until either the application becomes
|
||||
/// active or the request is canceled. When <see cref="DockBounceType.Informational"/> is passed, the dock icon will bounce
|
||||
/// for one second. However, the request remains active until either the application becomes active or the request is canceled.
|
||||
/// <para/>
|
||||
/// Note: This method can only be used while the app is not focused; when the app is focused it will return -1.
|
||||
/// </summary>
|
||||
/// <param name="type">Can be critical or informational. The default is informational.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Return an ID representing the request.</returns>
|
||||
public async Task<int> BounceAsync(DockBounceType type, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<int>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-bounce-completed", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-bounce-completed");
|
||||
taskCompletionSource.SetResult((int) id);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-bounce", type.GetDescription());
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel the bounce of id.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the request.</param>
|
||||
public void CancelBounce(int id)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-cancelBounce", id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bounces the Downloads stack if the filePath is inside the Downloads folder.
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
public void DownloadFinished(string filePath)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-downloadFinished", filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the string to be displayed in the dock’s badging area.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
public void SetBadge(string text)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-setBadge", text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string to be displayed in the dock’s badging area.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>The badge string of the dock.</returns>
|
||||
public async Task<string> GetBadgeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-getBadge-completed", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-getBadge-completed");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-getBadge");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the dock icon.
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-hide");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the dock icon.
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-show");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the dock icon is visible. The app.dock.show() call is asynchronous
|
||||
/// so this method might not return true immediately after that call.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Whether the dock icon is visible.</returns>
|
||||
public async Task<bool> IsVisibleAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-isVisible-completed", (isVisible) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-isVisible-completed");
|
||||
taskCompletionSource.SetResult((bool) isVisible);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-isVisible");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Menu (macOS) still to be implemented
|
||||
/// Sets the application's dock menu.
|
||||
/// </summary>
|
||||
public void SetMenu()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-setMenu");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Menu (macOS) still to be implemented
|
||||
/// Gets the application's dock menu.
|
||||
/// </summary>
|
||||
public async Task<Menu> GetMenu(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<Menu>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("dock-getMenu-completed", (menu) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("dock-getMenu-completed");
|
||||
taskCompletionSource.SetResult(((JObject)menu).ToObject<Menu>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("dock-getMenu");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image associated with this dock icon.
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
public void SetIcon(string image)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("dock-setIcon", image);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,5 +73,20 @@
|
||||
/// <c>electronize add HostHook</c>
|
||||
/// </summary>
|
||||
public static HostHook HostHook { get { return HostHook.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to execute native Lock and Unlock process.
|
||||
/// </summary>
|
||||
public static PowerMonitor PowerMonitor { get { return PowerMonitor.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Read and respond to changes in Chromium's native color theme.
|
||||
/// </summary>
|
||||
public static NativeTheme NativeTheme { get { return NativeTheme.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Control your app in the macOS dock.
|
||||
/// </summary>
|
||||
public static Dock Dock { get { return Dock.Instance; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageOutputPath>..\artifacts</PackageOutputPath>
|
||||
<PackageId>ElectronNET.API</PackageId>
|
||||
@@ -19,19 +19,7 @@ This package contains the API to access the "native" electron API.</Description>
|
||||
<PackageReleaseNotes>Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md</PackageReleaseNotes>
|
||||
<PackageIcon>PackageIcon.png</PackageIcon>
|
||||
<Version>99.0.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netcoreapp2.0\ElectronNET.API.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DocumentationFile>bin\Release\netcoreapp3.0\ElectronNET.API.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netcoreapp3.0\ElectronNET.API.xml</DocumentationFile>
|
||||
<Optimize>true</Optimize>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -53,6 +41,7 @@ This package contains the API to access the "native" electron API.</Description>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SocketIoClientDotNet" Version="1.0.5" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// About panel options.
|
||||
/// </summary>
|
||||
public class AboutPanelOptions
|
||||
{
|
||||
@@ -20,14 +20,29 @@
|
||||
/// </summary>
|
||||
public string Copyright { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app's build version number.
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Credit information.
|
||||
/// </summary>
|
||||
public string Credits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app's build version number.
|
||||
/// List of app authors.
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
public string[] Authors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app's website.
|
||||
/// </summary>
|
||||
public string Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path to the app's icon. On Linux, will be shown as 64x64 pixels while retaining aspect ratio.
|
||||
/// </summary>
|
||||
public string IconPath { get; set; }
|
||||
}
|
||||
}
|
||||
33
ElectronNET.API/Entities/AddRepresentationOptions.cs
Normal file
33
ElectronNET.API/Entities/AddRepresentationOptions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class AddRepresentationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the width
|
||||
/// </summary>
|
||||
public int? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height
|
||||
/// </summary>
|
||||
public int? Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the buffer
|
||||
/// </summary>
|
||||
public byte[] Buffer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the dataURL
|
||||
/// </summary>
|
||||
public string DataUrl { get; set; }
|
||||
}
|
||||
}
|
||||
38
ElectronNET.API/Entities/AutoResizeOptions.cs
Normal file
38
ElectronNET.API/Entities/AutoResizeOptions.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class AutoResizeOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// If `true`, the view's width will grow and shrink together with the window.
|
||||
/// `false` by default.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Width { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// If `true`, the view's height will grow and shrink together with the window.
|
||||
/// `false` by default.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Height { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// If `true`, the view's x position and width will grow and shrink proportionally
|
||||
/// with the window. `false` by default.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Horizontal { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// If `true`, the view's y position and height will grow and shrink proportionally
|
||||
/// with the window. `false` by default.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Vertical { get; set; } = false;
|
||||
}
|
||||
}
|
||||
13
ElectronNET.API/Entities/BitmapOptions.cs
Normal file
13
ElectronNET.API/Entities/BitmapOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BitmapOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the scale factor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
13
ElectronNET.API/Entities/BrowserViewConstructorOptions.cs
Normal file
13
ElectronNET.API/Entities/BrowserViewConstructorOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BrowserViewConstructorOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// See BrowserWindow.
|
||||
/// </summary>
|
||||
public WebPreferences WebPreferences { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,15 @@
|
||||
/// </summary>
|
||||
public class CPUUsage
|
||||
{
|
||||
/// <summary>
|
||||
/// Percentage of CPU used since the last call to getCPUUsage. First call returns 0.
|
||||
/// </summary>
|
||||
public int PercentCPUUsage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of average idle cpu wakeups per second since the last call to
|
||||
/// getCPUUsage.First call returns 0.
|
||||
/// </summary>
|
||||
public int IdleWakeupsPerSecond { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Percentage of CPU used since the last call to getCPUUsage. First call returns 0.
|
||||
/// </summary>
|
||||
public int PercentCPUUsage { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
33
ElectronNET.API/Entities/ChromeExtensionInfo.cs
Normal file
33
ElectronNET.API/Entities/ChromeExtensionInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Provide metadata about the current loaded Chrome extension
|
||||
/// </summary>
|
||||
public class ChromeExtensionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChromeExtensionInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the Chrome extension.</param>
|
||||
/// <param name="version">The version of the Chrome extension.</param>
|
||||
public ChromeExtensionInfo(string name, string version)
|
||||
{
|
||||
Name = name;
|
||||
Version = version;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the Chrome extension
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Version of the Chrome extension
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
51
ElectronNET.API/Entities/Cookie.cs
Normal file
51
ElectronNET.API/Entities/Cookie.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace ElectronNET.API.Entities {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Cookie {
|
||||
/// <summary>
|
||||
/// The name of the cookie.
|
||||
/// </summary>
|
||||
public string Name { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// The value of the cookie.
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The domain of the cookie; this will be normalized with a preceding dot so that it's also valid for subdomains.
|
||||
/// </summary>
|
||||
public string Domain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is a host-only cookie; this will only be true if no domain was passed.
|
||||
/// </summary>
|
||||
public bool HostOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The path of the cookie.
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is marked as secure.
|
||||
/// </summary>
|
||||
public bool Secure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is marked as HTTP only.
|
||||
/// </summary>
|
||||
public bool HttpOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is a session cookie or a persistent cookie with an expiration date.
|
||||
/// </summary>
|
||||
public bool Session { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies.
|
||||
/// </summary>
|
||||
public long ExpirationDate { get; set; }
|
||||
}
|
||||
}
|
||||
38
ElectronNET.API/Entities/CookieChangedCause.cs
Normal file
38
ElectronNET.API/Entities/CookieChangedCause.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace ElectronNET.API.Entities {
|
||||
/// <summary>
|
||||
/// The cause of the change
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum CookieChangedCause
|
||||
{
|
||||
/// <summary>
|
||||
///The cookie was changed directly by a consumer's action.
|
||||
/// </summary>
|
||||
[JsonProperty("explicit")]
|
||||
@explicit,
|
||||
|
||||
/// <summary>
|
||||
/// The cookie was automatically removed due to an insert operation that overwrote it.
|
||||
/// </summary>
|
||||
overwrite,
|
||||
|
||||
/// <summary>
|
||||
/// The cookie was automatically removed as it expired.
|
||||
/// </summary>
|
||||
expired,
|
||||
|
||||
/// <summary>
|
||||
/// The cookie was automatically evicted during garbage collection.
|
||||
/// </summary>
|
||||
evicted,
|
||||
|
||||
/// <summary>
|
||||
/// The cookie was overwritten with an already-expired expiration date.
|
||||
/// </summary>
|
||||
[JsonProperty("expired_overwrite")]
|
||||
expiredOverwrite
|
||||
}
|
||||
}
|
||||
56
ElectronNET.API/Entities/CookieDetails.cs
Normal file
56
ElectronNET.API/Entities/CookieDetails.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CookieDetails {
|
||||
/// <summary>
|
||||
/// The URL to associate the cookie with. The callback will be rejected if the URL is invalid.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The name of the cookie. Empty by default if omitted.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The value of the cookie. Empty by default if omitted.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The domain of the cookie; this will be normalized with a preceding dot so that it's also valid for subdomains. Empty by default if omitted.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Domain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The path of the cookie. Empty by default if omitted.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is marked as secure. Defaults to false.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Secure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Whether the cookie is marked as HTTP only. Defaults to false.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool HttpOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - The expiration date of the cookie as the number of seconds since the UNIX epoch.
|
||||
/// If omitted then the cookie becomes a session cookie and will not be retained between sessions.
|
||||
/// </summary>
|
||||
[DefaultValue(0)]
|
||||
public long ExpirationDate { get; set; }
|
||||
}
|
||||
}
|
||||
43
ElectronNET.API/Entities/CookieFilter.cs
Normal file
43
ElectronNET.API/Entities/CookieFilter.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CookieFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// (optional) - Retrieves cookies which are associated with url.Empty implies retrieving cookies of all URLs.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Filters cookies by name.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Retrieves cookies whose domains match or are subdomains of domains.
|
||||
/// </summary>
|
||||
public string Domain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Retrieves cookies whose path matches path.
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Filters cookies by their Secure property.
|
||||
/// </summary>
|
||||
public bool Secure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Filters out session or persistent cookies.
|
||||
/// </summary>
|
||||
public bool Session { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
23
ElectronNET.API/Entities/CreateFromBitmapOptions.cs
Normal file
23
ElectronNET.API/Entities/CreateFromBitmapOptions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateFromBitmapOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the width
|
||||
/// </summary>
|
||||
public int? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height
|
||||
/// </summary>
|
||||
public int? Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
23
ElectronNET.API/Entities/CreateFromBufferOptions.cs
Normal file
23
ElectronNET.API/Entities/CreateFromBufferOptions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateFromBufferOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the width
|
||||
/// </summary>
|
||||
public int? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height
|
||||
/// </summary>
|
||||
public int? Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
namespace ElectronNET.API
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Defines the DockBounceType enumeration.
|
||||
/// </summary>
|
||||
public enum DockBounceType
|
||||
{
|
||||
/// <summary>
|
||||
/// The critical
|
||||
/// Dock icon will bounce until either the application becomes active or the request is canceled.
|
||||
/// </summary>
|
||||
critical,
|
||||
[Description("critical")]
|
||||
Critical,
|
||||
|
||||
/// <summary>
|
||||
/// The informational
|
||||
/// The dock icon will bounce for one second.
|
||||
/// </summary>
|
||||
informational
|
||||
[Description("informational")]
|
||||
Informational
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the stack.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The stack.
|
||||
/// </value>
|
||||
public string Stack { get; set; }
|
||||
}
|
||||
}
|
||||
15
ElectronNET.API/Entities/FocusOptions.cs
Normal file
15
ElectronNET.API/Entities/FocusOptions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls the behavior of <see cref="App.Focus(FocusOptions)"/>.
|
||||
/// </summary>
|
||||
public class FocusOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Make the receiver the active app even if another app is currently active.
|
||||
/// <para/>
|
||||
/// You should seek to use the <see cref="Steal"/> option as sparingly as possible.
|
||||
/// </summary>
|
||||
public bool Steal { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,77 +8,77 @@ namespace ElectronNET.API.Entities
|
||||
public class GPUFeatureStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Canvas
|
||||
/// Canvas.
|
||||
/// </summary>
|
||||
[JsonProperty("2d_canvas")]
|
||||
public string Canvas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash
|
||||
/// Flash.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_3d")]
|
||||
public string Flash3D { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash Stage3D
|
||||
/// Flash Stage3D.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_stage3d")]
|
||||
public string FlashStage3D { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flash Stage3D Baseline profile
|
||||
/// Flash Stage3D Baseline profile.
|
||||
/// </summary>
|
||||
[JsonProperty("flash_stage3d_baseline")]
|
||||
public string FlashStage3dBaseline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compositing
|
||||
/// Compositing.
|
||||
/// </summary>
|
||||
[JsonProperty("gpu_compositing")]
|
||||
public string GpuCompositing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Multiple Raster Threads
|
||||
/// Multiple Raster Threads.
|
||||
/// </summary>
|
||||
[JsonProperty("multiple_raster_threads")]
|
||||
public string MultipleRasterThreads { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Native GpuMemoryBuffers
|
||||
/// Native GpuMemoryBuffers.
|
||||
/// </summary>
|
||||
[JsonProperty("native_gpu_memory_buffers")]
|
||||
public string NativeGpuMemoryBuffers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rasterization
|
||||
/// Rasterization.
|
||||
/// </summary>
|
||||
public string Rasterization { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Video Decode
|
||||
/// Video Decode.
|
||||
/// </summary>
|
||||
[JsonProperty("video_decode")]
|
||||
public string VideoDecode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Video Encode
|
||||
/// Video Encode.
|
||||
/// </summary>
|
||||
[JsonProperty("video_encode")]
|
||||
public string VideoEncode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// VPx Video Decode
|
||||
/// VPx Video Decode.
|
||||
/// </summary>
|
||||
[JsonProperty("vpx_decode")]
|
||||
public string VpxDecode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// WebGL
|
||||
/// WebGL.
|
||||
/// </summary>
|
||||
public string Webgl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// WebGL2
|
||||
/// WebGL2.
|
||||
/// </summary>
|
||||
public string Webgl2 { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum HighlightMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Highlight the tray icon when it is clicked and also when its context menu is open. This is the default.
|
||||
/// </summary>
|
||||
selection,
|
||||
|
||||
/// <summary>
|
||||
/// Always highlight the tray icon.
|
||||
/// </summary>
|
||||
always,
|
||||
|
||||
/// <summary>
|
||||
/// Never highlight the tray icon.
|
||||
/// </summary>
|
||||
never,
|
||||
|
||||
/// <summary>
|
||||
/// Activate highlight the tray icon.
|
||||
/// </summary>
|
||||
on,
|
||||
|
||||
/// <summary>
|
||||
/// Deactivate highlight the tray icon.
|
||||
/// </summary>
|
||||
off
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace ElectronNET.API
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
@@ -25,4 +24,4 @@ namespace ElectronNET.API
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public JumpListCategoryType Type { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ElectronNET.API
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
public class JumpListSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// The minimum number of items that will be shown in the Jump List (for a more detailed description of this value see the MSDN docs).
|
||||
/// The minimum number of items that will be shown in the Jump List (for a more detailed description of this value see the
|
||||
/// <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd378398(v=vs.85).aspx">MSDN</see> docs).
|
||||
/// </summary>
|
||||
public int MinItems { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Array of JumpListItem objects that correspond to items that the user has explicitly removed from custom categories in the Jump List. These items must not be re-added to the Jump List in the next call to app.setJumpList(), Windows will not display any custom category that contains any of the removed items.
|
||||
/// Array of JumpListItem objects that correspond to items that the user has explicitly removed from custom categories
|
||||
/// in the Jump List. These items must not be re-added to the Jump List in the next call to <see cref="App.SetJumpList"/>, Windows will
|
||||
/// not display any custom category that contains any of the removed items.
|
||||
/// </summary>
|
||||
public JumpListItem[] RemovedItems { get; set; } = new JumpListItem[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,33 +6,33 @@
|
||||
public class LoginItemSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// true if the app is set to open at login.
|
||||
/// <see langword="true"/> if the app is set to open at login.
|
||||
/// </summary>
|
||||
public bool OpenAtLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true if the app is set to open as hidden at login. This setting is only
|
||||
/// supported on macOS.
|
||||
/// <see langword="true"/> if the app is set to open as hidden at login. This setting is not available
|
||||
/// on <see href="https://www.electronjs.org/docs/tutorial/mac-app-store-submission-guide">MAS builds</see>.
|
||||
/// </summary>
|
||||
public bool OpenAsHidden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true if the app was opened at login automatically. This setting is only
|
||||
/// supported on macOS.
|
||||
/// <see langword="true"/> if the app was opened at login automatically. This setting is not available
|
||||
/// on <see href="https://www.electronjs.org/docs/tutorial/mac-app-store-submission-guide">MAS builds</see>.
|
||||
/// </summary>
|
||||
public bool WasOpenedAtLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true if the app was opened as a hidden login item. This indicates that the app
|
||||
/// should not open any windows at startup.This setting is only supported on macOS.
|
||||
/// <see langword="true"/> if the app was opened as a hidden login item. This indicates that the app should not
|
||||
/// open any windows at startup. This setting is not available on
|
||||
/// <see href="https://www.electronjs.org/docs/tutorial/mac-app-store-submission-guide">MAS builds</see>.
|
||||
/// </summary>
|
||||
public bool WasOpenedAsHidden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true if the app was opened as a login item that should restore the state from
|
||||
/// the previous session.This indicates that the app should restore the windows
|
||||
/// that were open the last time the app was closed.This setting is only supported
|
||||
/// on macOS.
|
||||
/// <see langword="true"/> if the app was opened as a login item that should restore the state from the previous
|
||||
/// session. This indicates that the app should restore the windows that were open the last time the app was closed.
|
||||
/// This setting is not available on <see href="https://www.electronjs.org/docs/tutorial/mac-app-store-submission-guide">MAS builds</see>.
|
||||
/// </summary>
|
||||
public bool RestoreState { get; set; }
|
||||
}
|
||||
|
||||
@@ -6,16 +6,15 @@
|
||||
public class LoginSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// true to open the app at login, false to remove the app as a login item. Defaults
|
||||
/// to false.
|
||||
/// <see langword="true"/> to open the app at login, <see langword="false"/> to remove the app as a login item.
|
||||
/// Defaults to <see langword="false"/>.
|
||||
/// </summary>
|
||||
public bool OpenAtLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true to open the app as hidden. Defaults to false. The user can edit this
|
||||
/// setting from the System Preferences so
|
||||
/// app.getLoginItemStatus().wasOpenedAsHidden should be checked when the app is
|
||||
/// opened to know the current value.This setting is only supported on macOS.
|
||||
/// <see langword="true"/> to open the app as hidden. Defaults to <see langword="false"/>. The user can edit this
|
||||
/// setting from the System Preferences so app.getLoginItemSettings().wasOpenedAsHidden should be checked when the app is
|
||||
/// opened to know the current value. This setting is not available on <see href="https://www.electronjs.org/docs/tutorial/mac-app-store-submission-guide">MAS builds</see>.
|
||||
/// </summary>
|
||||
public bool OpenAsHidden { get; set; }
|
||||
|
||||
|
||||
@@ -6,31 +6,19 @@
|
||||
public class MemoryInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum amount of memory that has ever been pinned to actual physical RAM.
|
||||
/// On macOS its value will always be 0.
|
||||
/// The amount of memory currently pinned to actual physical RAM.
|
||||
/// </summary>
|
||||
public int PeakWorkingSetSize { get; set; }
|
||||
public int WorkingSetSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process id of the process.
|
||||
/// The maximum amount of memory that has ever been pinned to actual physical RAM.
|
||||
/// </summary>
|
||||
public int Pid { get; set; }
|
||||
public int PeakWorkingSetSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of memory not shared by other processes, such as JS heap or HTML
|
||||
/// content.
|
||||
/// </summary>
|
||||
public int PrivateBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of memory shared between processes, typically memory consumed by the
|
||||
/// Electron code itself
|
||||
/// </summary>
|
||||
public int SharedBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of memory currently pinned to actual physical RAM.
|
||||
/// </summary>
|
||||
public int WorkingSetSize {get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,13 +69,11 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// If false, the menu item will be greyed out and unclickable.
|
||||
/// </summary>
|
||||
[DefaultValue(true)]
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// If false, the menu item will be entirely hidden.
|
||||
/// </summary>
|
||||
[DefaultValue(true)]
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/// <summary>
|
||||
/// The undo
|
||||
/// </summary>
|
||||
undo,
|
||||
undo = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The redo
|
||||
|
||||
@@ -1,109 +1,453 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
// TODO: Need some of real code :)
|
||||
/// <summary>
|
||||
///
|
||||
/// Native Image handler for Electron.NET
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(NativeImageJsonConverter))]
|
||||
public class NativeImage
|
||||
{
|
||||
// public static NativeImage CreateEmpty()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
private readonly Dictionary<float, Image> _images = new Dictionary<float, Image>();
|
||||
private bool _isTemplateImage;
|
||||
|
||||
// public static NativeImage CreateFromBuffer(byte[] buffer)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
private static readonly Dictionary<string, float> ScaleFactorPairs = new Dictionary<string, float>
|
||||
{
|
||||
{"@2x", 2.0f}, {"@3x", 3.0f}, {"@1x", 1.0f}, {"@4x", 4.0f},
|
||||
{"@5x", 5.0f}, {"@1.25x", 1.25f}, {"@1.33x", 1.33f}, {"@1.4x", 1.4f},
|
||||
{"@1.5x", 1.5f}, {"@1.8x", 1.8f}, {"@2.5x", 2.5f}
|
||||
};
|
||||
|
||||
// public static NativeImage CreateFromBuffer(byte[] buffer, CreateFromBufferOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
private static float? ExtractDpiFromFilePath(string filePath)
|
||||
{
|
||||
var withoutExtension = Path.GetFileNameWithoutExtension(filePath);
|
||||
return ScaleFactorPairs
|
||||
.Where(p => withoutExtension.EndsWith(p.Key))
|
||||
.Select(p => p.Value)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
private static Image BytesToImage(byte[] bytes)
|
||||
{
|
||||
var ms = new MemoryStream(bytes);
|
||||
return Image.FromStream(ms);
|
||||
}
|
||||
|
||||
// public static NativeImage CreateFromDataURL(string dataURL)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates an empty NativeImage
|
||||
/// </summary>
|
||||
public static NativeImage CreateEmpty()
|
||||
{
|
||||
return new NativeImage();
|
||||
}
|
||||
|
||||
// public static NativeImage CreateFromPath(string path)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static NativeImage CreateFromBitmap(Bitmap bitmap, CreateFromBitmapOptions options = null)
|
||||
{
|
||||
if (options is null)
|
||||
{
|
||||
options = new CreateFromBitmapOptions();
|
||||
}
|
||||
|
||||
// public void AddRepresentation(AddRepresentationOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
return new NativeImage(bitmap, options.ScaleFactor);
|
||||
}
|
||||
|
||||
// public NativeImage Crop(Rectangle rect)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates a NativeImage from a byte array.
|
||||
/// </summary>
|
||||
public static NativeImage CreateFromBuffer(byte[] buffer, CreateFromBufferOptions options = null)
|
||||
{
|
||||
if (options is null)
|
||||
{
|
||||
options = new CreateFromBufferOptions();
|
||||
}
|
||||
|
||||
// public int GetAspectRatio()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
var ms = new MemoryStream(buffer);
|
||||
var image = Image.FromStream(ms);
|
||||
|
||||
// public byte[] GetBitmap()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
return new NativeImage(image, options.ScaleFactor);
|
||||
}
|
||||
|
||||
// public byte[] GetBitmap(BitmapOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates a NativeImage from a base64 encoded data URL.
|
||||
/// </summary>
|
||||
/// <param name="dataUrl">A data URL with a base64 encoded image.</param>
|
||||
public static NativeImage CreateFromDataURL(string dataUrl)
|
||||
{
|
||||
var images = new Dictionary<float,Image>();
|
||||
var parsedDataUrl = Regex.Match(dataUrl, @"data:image/(?<type>.+?),(?<data>.+)");
|
||||
var actualData = parsedDataUrl.Groups["data"].Value;
|
||||
var binData = Convert.FromBase64String(actualData);
|
||||
|
||||
// public byte[] GetNativeHandle()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
var image = BytesToImage(binData);
|
||||
|
||||
// public Size GetSize()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
images.Add(1.0f, image);
|
||||
|
||||
// public bool IsEmpty()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
return new NativeImage(images);
|
||||
}
|
||||
|
||||
// public bool IsTemplateImage()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates a NativeImage from an image on the disk.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the image</param>
|
||||
public static NativeImage CreateFromPath(string path)
|
||||
{
|
||||
var images = new Dictionary<float,Image>();
|
||||
if (Regex.IsMatch(path, "(@.+?x)"))
|
||||
{
|
||||
var dpi = ExtractDpiFromFilePath(path);
|
||||
if (dpi == null)
|
||||
{
|
||||
throw new Exception($"Invalid scaling factor for '{path}'.");
|
||||
}
|
||||
|
||||
// public NativeImage Resize(ResizeOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
images[dpi.Value] = Image.FromFile(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
|
||||
var extension = Path.GetExtension(path);
|
||||
// Load as 1x dpi
|
||||
images[1.0f] = Image.FromFile(path);
|
||||
|
||||
// public void SetTemplateImage(bool option)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
foreach (var scale in ScaleFactorPairs)
|
||||
{
|
||||
var fileName = $"{fileNameWithoutExtension}{scale}.{extension}";
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
var dpi = ExtractDpiFromFilePath(fileName);
|
||||
if (dpi != null)
|
||||
{
|
||||
images[dpi.Value] = Image.FromFile(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public byte[] ToBitmap(ToBitmapOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
return new NativeImage(images);
|
||||
}
|
||||
|
||||
// public string ToDataURL(ToDataURLOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates an empty NativeImage
|
||||
/// </summary>
|
||||
public NativeImage()
|
||||
{
|
||||
}
|
||||
|
||||
// public byte[] ToJPEG(int quality)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates a NativeImage from a bitmap and scale factor
|
||||
/// </summary>
|
||||
public NativeImage(Image bitmap, float scaleFactor = 1.0f)
|
||||
{
|
||||
_images.Add(scaleFactor, bitmap);
|
||||
}
|
||||
|
||||
// public byte[] ToPNG(ToPNGOptions options)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
/// <summary>
|
||||
/// Creates a NativeImage from a dictionary of scales and images.
|
||||
/// </summary>
|
||||
public NativeImage(Dictionary<float, Image> imageDictionary)
|
||||
{
|
||||
_images = imageDictionary;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crops the image specified by the input rectangle and computes scale factor
|
||||
/// </summary>
|
||||
public NativeImage Crop(Rectangle rect)
|
||||
{
|
||||
var images = new Dictionary<float,Image>();
|
||||
foreach (var image in _images)
|
||||
{
|
||||
images.Add(image.Key, Crop(rect.X, rect.Y, rect.Width, rect.Height, image.Key));
|
||||
}
|
||||
|
||||
return new NativeImage(images);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the image and computes scale factor
|
||||
/// </summary>
|
||||
public NativeImage Resize(ResizeOptions options)
|
||||
{
|
||||
var images = new Dictionary<float, Image>();
|
||||
foreach (var image in _images)
|
||||
{
|
||||
images.Add(image.Key, Resize(options.Width, options.Height, image.Key));
|
||||
}
|
||||
|
||||
return new NativeImage(images);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an image representation for a specific scale factor.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void AddRepresentation(AddRepresentationOptions options)
|
||||
{
|
||||
if (options.Buffer.Length > 0)
|
||||
{
|
||||
_images[options.ScaleFactor] =
|
||||
CreateFromBuffer(options.Buffer, new CreateFromBufferOptions {ScaleFactor = options.ScaleFactor})
|
||||
.GetScale(options.ScaleFactor);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(options.DataUrl))
|
||||
{
|
||||
_images[options.ScaleFactor] = CreateFromDataURL(options.DataUrl).GetScale(options.ScaleFactor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the aspect ratio for the image based on scale factor
|
||||
/// </summary>
|
||||
/// <param name="scaleFactor">Optional</param>
|
||||
public float GetAspectRatio(float scaleFactor = 1.0f)
|
||||
{
|
||||
var image = GetScale(scaleFactor);
|
||||
if (image != null)
|
||||
{
|
||||
return image.Width / image.Height;
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a byte array that contains the image's raw bitmap pixel data.
|
||||
/// </summary>
|
||||
public byte[] GetBitmap(BitmapOptions options)
|
||||
{
|
||||
return ToBitmap(new ToBitmapOptions{ ScaleFactor = options.ScaleFactor });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a byte array that contains the image's raw bitmap pixel data.
|
||||
/// </summary>
|
||||
public byte[] GetNativeHandle()
|
||||
{
|
||||
return ToBitmap(new ToBitmapOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the specified image based on scale factor
|
||||
/// </summary>
|
||||
public Size GetSize(float scaleFactor = 1.0f)
|
||||
{
|
||||
if (_images.ContainsKey(scaleFactor))
|
||||
{
|
||||
var image = _images[scaleFactor];
|
||||
return new Size
|
||||
{
|
||||
Width = image.Width,
|
||||
Height = image.Height
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the NativeImage instance is empty.
|
||||
/// </summary>
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _images.Count <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deprecated. Whether the image is a template image.
|
||||
/// </summary>
|
||||
public bool IsTemplateImage => _isTemplateImage;
|
||||
|
||||
/// <summary>
|
||||
/// Deprecated. Marks the image as a template image.
|
||||
/// </summary>
|
||||
public void SetTemplateImage(bool option)
|
||||
{
|
||||
_isTemplateImage = option;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a bitmap based on the scale factor
|
||||
/// </summary>
|
||||
public byte[] ToBitmap(ToBitmapOptions options)
|
||||
{
|
||||
return ImageToBytes(ImageFormat.Bmp, options.ScaleFactor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a data URL based on the scale factor
|
||||
/// </summary>
|
||||
public string ToDataURL(ToDataUrlOptions options)
|
||||
{
|
||||
if (!_images.ContainsKey(options.ScaleFactor))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = _images[options.ScaleFactor];
|
||||
var mimeType = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == image.RawFormat.Guid)?.MimeType;
|
||||
if (mimeType is null)
|
||||
{
|
||||
mimeType = "image/png";
|
||||
}
|
||||
|
||||
var bytes = ImageToBytes(image.RawFormat, options.ScaleFactor);
|
||||
var base64 = Convert.ToBase64String(bytes);
|
||||
|
||||
return $"data:{mimeType};base64,{base64}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a JPEG for the default scale factor
|
||||
/// </summary>
|
||||
public byte[] ToJPEG(int quality)
|
||||
{
|
||||
return ImageToBytes(ImageFormat.Jpeg, 1.0f, quality);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a PNG for the specified scale factor
|
||||
/// </summary>
|
||||
public byte[] ToPNG(ToPNGOptions options)
|
||||
{
|
||||
return ImageToBytes(ImageFormat.Png, options.ScaleFactor);
|
||||
}
|
||||
|
||||
private byte[] ImageToBytes(ImageFormat imageFormat = null, float scaleFactor = 1.0f, int quality = 100)
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
|
||||
if (_images.ContainsKey(scaleFactor))
|
||||
{
|
||||
var image = _images[scaleFactor];
|
||||
var encoderCodecInfo = GetEncoder(imageFormat ?? image.RawFormat);
|
||||
var encoder = Encoder.Quality;
|
||||
|
||||
var encoderParameters = new EncoderParameters(1)
|
||||
{
|
||||
Param = new[]
|
||||
{
|
||||
new EncoderParameter(encoder, quality)
|
||||
}
|
||||
};
|
||||
|
||||
image.Save(ms, encoderCodecInfo, encoderParameters);
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Image Resize(int? width, int? height, float scaleFactor = 1.0f)
|
||||
{
|
||||
if (!_images.ContainsKey(scaleFactor) || (width is null && height is null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = _images[scaleFactor];
|
||||
using (var g = Graphics.FromImage(image))
|
||||
{
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
|
||||
var aspect = GetAspectRatio(scaleFactor);
|
||||
|
||||
width ??= Convert.ToInt32(image.Width * aspect);
|
||||
height ??= Convert.ToInt32(image.Height * aspect);
|
||||
|
||||
width = Convert.ToInt32(width * scaleFactor);
|
||||
height = Convert.ToInt32(height * scaleFactor);
|
||||
|
||||
var bmp = new Bitmap(width.Value, height.Value);
|
||||
g.DrawImage(bmp,
|
||||
new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
|
||||
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
|
||||
GraphicsUnit.Pixel);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
private Image Crop(int? x, int? y, int? width, int? height, float scaleFactor = 1.0f)
|
||||
{
|
||||
if (!_images.ContainsKey(scaleFactor))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = _images[scaleFactor];
|
||||
using (var g = Graphics.FromImage(image))
|
||||
{
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
|
||||
x ??= 0;
|
||||
y ??= 0;
|
||||
|
||||
x = Convert.ToInt32(x * scaleFactor);
|
||||
y = Convert.ToInt32(y * scaleFactor);
|
||||
|
||||
width ??= image.Width;
|
||||
height ??= image.Height;
|
||||
|
||||
width = Convert.ToInt32(width * scaleFactor);
|
||||
height = Convert.ToInt32(height * scaleFactor);
|
||||
|
||||
var bmp = new Bitmap(width.Value, height.Value);
|
||||
g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, image.Width, image.Height), new System.Drawing.Rectangle(x.Value, y.Value, width.Value, height.Value), GraphicsUnit.Pixel);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
private ImageCodecInfo GetEncoder(ImageFormat format)
|
||||
{
|
||||
var codecs = ImageCodecInfo.GetImageDecoders();
|
||||
foreach (ImageCodecInfo codec in codecs)
|
||||
{
|
||||
if (codec.FormatID == format.Guid)
|
||||
{
|
||||
return codec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal Dictionary<float,string> GetAllScaledImages()
|
||||
{
|
||||
var dict = new Dictionary<float,string>();
|
||||
try
|
||||
{
|
||||
foreach (var (scale, image) in _images)
|
||||
{
|
||||
dict.Add(scale, Convert.ToBase64String(ImageToBytes(null, scale)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal Image GetScale(float scaleFactor)
|
||||
{
|
||||
if (_images.ContainsKey(scaleFactor))
|
||||
{
|
||||
return _images[scaleFactor];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
ElectronNET.API/Entities/NativeImageJsonConverter.cs
Normal file
34
ElectronNET.API/Entities/NativeImageJsonConverter.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
internal class NativeImageJsonConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value is NativeImage nativeImage)
|
||||
{
|
||||
var scaledImages = nativeImage.GetAllScaledImages();
|
||||
serializer.Serialize(writer, scaledImages);
|
||||
}
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var dict = serializer.Deserialize<Dictionary<float, string>>(reader);
|
||||
var newDictionary = new Dictionary<float, Image>();
|
||||
foreach (var item in dict)
|
||||
{
|
||||
var bytes = Convert.FromBase64String(item.Value);
|
||||
newDictionary.Add(item.Key, Image.FromStream(new MemoryStream(bytes)));
|
||||
}
|
||||
return new NativeImage(newDictionary);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) => objectType == typeof(NativeImage);
|
||||
}
|
||||
}
|
||||
@@ -10,28 +10,28 @@ namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// A title for the notification, which will be shown at the top of the notification
|
||||
/// window when it is shown
|
||||
/// window when it is shown.
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A subtitle for the notification, which will be displayed below the title.
|
||||
/// </summary>
|
||||
public string SubTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The body text of the notification, which will be displayed below the title or
|
||||
/// subtitle
|
||||
/// subtitle.
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A subtitle for the notification, which will be displayed below the title.
|
||||
/// </summary>
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to emit an OS notification noise when showing the notification
|
||||
/// Whether or not to emit an OS notification noise when showing the notification.
|
||||
/// </summary>
|
||||
public bool Silent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An icon to use in the notification
|
||||
/// An icon to use in the notification.
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
@@ -40,6 +40,11 @@ namespace ElectronNET.API.Entities
|
||||
/// </summary>
|
||||
public bool HasReply { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The timeout duration of the notification. Can be 'default' or 'never'.
|
||||
/// </summary>
|
||||
public string TimeoutType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The placeholder to write in the inline reply input field.
|
||||
/// </summary>
|
||||
@@ -50,16 +55,27 @@ namespace ElectronNET.API.Entities
|
||||
/// </summary>
|
||||
public string Sound { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The urgency level of the notification. Can be 'normal', 'critical', or 'low'.
|
||||
/// </summary>
|
||||
public string Urgency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Actions to add to the notification. Please read the available actions and
|
||||
/// limitations in the NotificationAction documentation
|
||||
/// limitations in the NotificationAction documentation.
|
||||
/// </summary>
|
||||
public NotificationAction Actions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the notification is shown to the user,
|
||||
/// note this could be fired multiple times as a notification
|
||||
/// can be shown multiple times through the Show() method.
|
||||
/// A custom title for the close button of an alert. An empty string will cause the
|
||||
/// default localized text to be used.
|
||||
/// </summary>
|
||||
public string CloseButtonText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the notification is shown to the user, note this could be fired
|
||||
/// multiple times as a notification can be shown multiple times through the Show()
|
||||
/// method.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Action OnShow { get; set; }
|
||||
@@ -148,4 +164,4 @@ namespace ElectronNET.API.Entities
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Controls the behavior of OpenExternal.
|
||||
/// </summary>
|
||||
public class OpenExternalOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// true to bring the opened application to the foreground. The default is true.
|
||||
/// <see langword="true"/> to bring the opened application to the foreground. The default is <see langword="true"/>.
|
||||
/// </summary>
|
||||
[DefaultValue(true)]
|
||||
public bool Activate { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The working directory.
|
||||
/// </summary>
|
||||
public string WorkingDirectory { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,95 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Defines the PathName enumeration.
|
||||
/// </summary>
|
||||
public enum PathName
|
||||
{
|
||||
/// <summary>
|
||||
/// User’s home directory.
|
||||
/// </summary>
|
||||
home,
|
||||
[Description("home")]
|
||||
Home,
|
||||
|
||||
/// <summary>
|
||||
/// Per-user application data directory.
|
||||
/// </summary>
|
||||
appData,
|
||||
[Description("appData")]
|
||||
AppData,
|
||||
|
||||
/// <summary>
|
||||
/// The directory for storing your app’s configuration files,
|
||||
/// which by default it is the appData directory appended with your app’s name.
|
||||
/// </summary>
|
||||
userData,
|
||||
[Description("userData")]
|
||||
UserData,
|
||||
|
||||
/// <summary>
|
||||
/// Temporary directory.
|
||||
/// </summary>
|
||||
temp,
|
||||
[Description("temp")]
|
||||
Temp,
|
||||
|
||||
/// <summary>
|
||||
/// The current executable file.
|
||||
/// </summary>
|
||||
exe,
|
||||
[Description("exe")]
|
||||
Exe,
|
||||
|
||||
/// <summary>
|
||||
/// The libchromiumcontent library.
|
||||
/// </summary>
|
||||
module,
|
||||
[Description("Module")]
|
||||
Module,
|
||||
|
||||
/// <summary>
|
||||
/// The current user’s Desktop directory.
|
||||
/// </summary>
|
||||
desktop,
|
||||
[Description("desktop")]
|
||||
Desktop,
|
||||
|
||||
/// <summary>
|
||||
/// Directory for a user’s “My Documents”.
|
||||
/// </summary>
|
||||
documents,
|
||||
[Description("documents")]
|
||||
Documents,
|
||||
|
||||
/// <summary>
|
||||
/// Directory for a user’s downloads.
|
||||
/// </summary>
|
||||
downloads,
|
||||
[Description("downloads")]
|
||||
Downloads,
|
||||
|
||||
/// <summary>
|
||||
/// Directory for a user’s music.
|
||||
/// </summary>
|
||||
music,
|
||||
[Description("music")]
|
||||
Music,
|
||||
|
||||
/// <summary>
|
||||
/// Directory for a user’s pictures.
|
||||
/// </summary>
|
||||
pictures,
|
||||
[Description("pictures")]
|
||||
Pictures,
|
||||
|
||||
/// <summary>
|
||||
/// Directory for a user’s videos.
|
||||
/// </summary>
|
||||
videos,
|
||||
[Description("videos")]
|
||||
Videos,
|
||||
|
||||
/// <summary>
|
||||
/// The logs
|
||||
/// The logs.
|
||||
/// </summary>
|
||||
logs,
|
||||
[Description("logs")]
|
||||
Logs,
|
||||
|
||||
/// <summary>
|
||||
/// Full path to the system version of the Pepper Flash plugin.
|
||||
/// </summary>
|
||||
pepperFlashSystemPlugin
|
||||
[Description("PepperFlashSystemPlugin")]
|
||||
PepperFlashSystemPlugin
|
||||
}
|
||||
}
|
||||
|
||||
107
ElectronNET.API/Entities/PrintOptions.cs
Normal file
107
ElectronNET.API/Entities/PrintOptions.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Print dpi
|
||||
/// </summary>
|
||||
public class PrintDpi
|
||||
{
|
||||
/// <summary>
|
||||
/// The horizontal dpi
|
||||
/// </summary>
|
||||
public float Horizontal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The vertical dpi
|
||||
/// </summary>
|
||||
public float Vertical { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The page range to print
|
||||
/// </summary>
|
||||
public class PrintPageRange
|
||||
{
|
||||
/// <summary>
|
||||
/// From
|
||||
/// </summary>
|
||||
public int From { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// To
|
||||
/// </summary>
|
||||
public int To { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print options
|
||||
/// </summary>
|
||||
public class PrintOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't ask user for print settings
|
||||
/// </summary>
|
||||
public bool Silent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Prints the background color and image of the web page
|
||||
/// </summary>
|
||||
public bool PrintBackground { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the printer device name to use
|
||||
/// </summary>
|
||||
public string DeviceName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set whether the printed web page will be in color or grayscale
|
||||
/// </summary>
|
||||
public bool Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the type of margins to use. Uses 0 for default margin, 1 for no
|
||||
/// margin, and 2 for minimum margin.
|
||||
/// </summary>
|
||||
public int MarginsType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// true for landscape, false for portrait.
|
||||
/// </summary>
|
||||
public bool Landscape { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The scale factor of the web page
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of pages to print per page sheet
|
||||
/// </summary>
|
||||
public int PagesPerSheet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of copies of the web page to print
|
||||
/// </summary>
|
||||
public bool Copies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the web page should be collated
|
||||
/// </summary>
|
||||
public bool Collate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The page range to print
|
||||
/// </summary>
|
||||
public PrintPageRange PageRanges { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the duplex mode of the printed web page. Can be simplex, shortEdge, or longEdge.
|
||||
/// </summary>
|
||||
public string DuplexMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dpi
|
||||
/// </summary>
|
||||
public PrintDpi Dpi { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
29
ElectronNET.API/Entities/PrinterInfo.cs
Normal file
29
ElectronNET.API/Entities/PrinterInfo.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Printer info
|
||||
/// </summary>
|
||||
public class PrinterInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Status
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is default
|
||||
/// </summary>
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,42 @@
|
||||
/// </summary>
|
||||
public class ProcessMetric
|
||||
{
|
||||
/// <summary>
|
||||
/// CPU usage of the process.
|
||||
/// </summary>
|
||||
public CPUUsage Cpu { get; set; }
|
||||
/// <summary>
|
||||
/// Process id of the process.
|
||||
/// </summary>
|
||||
public int PId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Memory information for the process.
|
||||
/// </summary>
|
||||
public MemoryInfo Memory {get; set;}
|
||||
/// <summary>
|
||||
/// Process type (Browser or Tab or GPU etc).
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process id of the process.
|
||||
/// </summary>
|
||||
public int Pid { get; set; }
|
||||
/// <summary>
|
||||
/// CPU usage of the process.
|
||||
/// </summary>
|
||||
public CPUUsage Cpu { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process type (Browser or Tab or GPU etc).
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
/// <summary>
|
||||
/// Creation time for this process. The time is represented as number of milliseconds since epoch.
|
||||
/// Since the <see cref="PId"/> can be reused after a process dies, it is useful to use both the <see cref="PId"/>
|
||||
/// and the <see cref="CreationTime"/> to uniquely identify a process.
|
||||
/// </summary>
|
||||
public int CreationTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Memory information for the process.
|
||||
/// </summary>
|
||||
public MemoryInfo Memory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the process is sandboxed on OS level.
|
||||
/// </summary>
|
||||
public bool Sandboxed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// One of the following values:
|
||||
/// untrusted | low | medium | high | unknown
|
||||
/// </summary>
|
||||
public string IntegrityLevel { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Controls the behavior of <see cref="App.Relaunch(RelaunchOptions)"/>.
|
||||
/// </summary>
|
||||
public class RelaunchOptions
|
||||
{
|
||||
@@ -21,4 +21,4 @@
|
||||
/// </value>
|
||||
public string ExecPath { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
23
ElectronNET.API/Entities/ResizeOptions.cs
Normal file
23
ElectronNET.API/Entities/ResizeOptions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ResizeOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the width
|
||||
/// </summary>
|
||||
public int? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height
|
||||
/// </summary>
|
||||
public int? Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// good, better, or best. Default is "best";
|
||||
/// </summary>
|
||||
public string Quality { get; set; } = "best";
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
namespace ElectronNET.API
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Structure of a shortcut.
|
||||
/// </summary>
|
||||
public class ShortcutDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// The Application User Model ID. Default is empty.
|
||||
/// The Application User Model ID. Default is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string AppUserModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The arguments to be applied to target when launching from this shortcut. Default is empty.
|
||||
/// The arguments to be applied to <see cref="Target"/> when launching from this shortcut. Default is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string Args { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The working directory. Default is empty.
|
||||
/// The working directory. Default is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string Cwd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The description of the shortcut. Default is empty.
|
||||
/// The description of the shortcut. Default is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The path to the icon, can be a DLL or EXE. icon and iconIndex have to be set
|
||||
/// together.Default is empty, which uses the target's icon.
|
||||
/// The path to the icon, can be a DLL or EXE. <see cref="Icon"/> and <see cref="IconIndex"/> have to be set
|
||||
/// together. Default is <see cref="string.Empty"/>, which uses the target's icon.
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The resource ID of icon when icon is a DLL or EXE. Default is 0.
|
||||
/// The resource ID of icon when <see cref="Icon"/> is a DLL or EXE. Default is 0.
|
||||
/// </summary>
|
||||
public int IconIndex { get; set; }
|
||||
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
namespace ElectronNET.API
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Defines the ShortcutLinkOperation enumeration.
|
||||
/// </summary>
|
||||
public enum ShortcutLinkOperation
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new shortcut, overwriting if necessary.
|
||||
/// </summary>
|
||||
create,
|
||||
[Description("create")]
|
||||
Create,
|
||||
|
||||
/// <summary>
|
||||
/// Updates specified properties only on an existing shortcut.
|
||||
/// </summary>
|
||||
update,
|
||||
[Description("update")]
|
||||
Update,
|
||||
|
||||
/// <summary>
|
||||
/// Overwrites an existing shortcut, fails if the shortcut doesn’t exist.
|
||||
/// Overwrites an existing shortcut, fails if the shortcut doesn't exist.
|
||||
/// </summary>
|
||||
replace
|
||||
[Description("replace")]
|
||||
Replace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
ElectronNET.API/Entities/ThemeSourceMode.cs
Normal file
28
ElectronNET.API/Entities/ThemeSourceMode.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ThemeSourceMode enumeration.
|
||||
/// </summary>
|
||||
public enum ThemeSourceMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Operating system default.
|
||||
/// </summary>
|
||||
[Description("system")]
|
||||
System,
|
||||
|
||||
/// <summary>
|
||||
/// Light theme.
|
||||
/// </summary>
|
||||
[Description("light")]
|
||||
Light,
|
||||
|
||||
/// <summary>
|
||||
/// Dark theme.
|
||||
/// </summary>
|
||||
[Description("dark")]
|
||||
Dark
|
||||
}
|
||||
}
|
||||
13
ElectronNET.API/Entities/ToBitmapOptions.cs
Normal file
13
ElectronNET.API/Entities/ToBitmapOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ToBitmapOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
13
ElectronNET.API/Entities/ToDataUrlOptions.cs
Normal file
13
ElectronNET.API/Entities/ToDataUrlOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ToDataUrlOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
13
ElectronNET.API/Entities/ToPNGOptions.cs
Normal file
13
ElectronNET.API/Entities/ToPNGOptions.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ToPNGOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the scalefactor
|
||||
/// </summary>
|
||||
public float ScaleFactor { get; set; } = 1.0f;
|
||||
}
|
||||
}
|
||||
@@ -52,5 +52,10 @@
|
||||
/// The title.
|
||||
/// </value>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The working directory. Default is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string WorkingDirectory { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace ElectronNET.API.Entities
|
||||
|
||||
/// <summary>
|
||||
/// Whether to run Electron APIs and the specified preload script in a separate
|
||||
/// JavaScript context.Defaults to false. The context that the preload script runs
|
||||
/// JavaScript context. Defaults to false. The context that the preload script runs
|
||||
/// in will still have full access to the document and window globals but it will
|
||||
/// use its own set of JavaScript builtins (Array, Object, JSON, etc.) and will be
|
||||
/// isolated from any changes made to the global environment by the loaded page.The
|
||||
@@ -185,8 +185,8 @@ namespace ElectronNET.API.Entities
|
||||
/// Context' entry in the combo box at the top of the Console tab. This option is
|
||||
/// currently experimental and may change or be removed in future Electron releases.
|
||||
/// </summary>
|
||||
[DefaultValue(true)]
|
||||
public bool ContextIsolation { get; set; } = true;
|
||||
[DefaultValue(false)]
|
||||
public bool ContextIsolation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use native window.open(). Defaults to false. This option is currently experimental.
|
||||
|
||||
@@ -48,5 +48,24 @@ namespace ElectronNET.API.Extensions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static MenuItem[] AddSubmenuTypes(this MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if (menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
if(menuItem.Type == MenuType.normal)
|
||||
{
|
||||
menuItem.Type = MenuType.submenu;
|
||||
}
|
||||
|
||||
AddSubmenuTypes(menuItem.Submenu);
|
||||
}
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,13 +72,14 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result.ToString());
|
||||
taskCompletionSource.SetException(new Exception($"Host Hook Exception {result}"));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Complete" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
BridgeConnector.Socket.Off(socketEventName + "Complete" + guid);
|
||||
T data;
|
||||
T data = default;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -105,7 +106,8 @@ namespace ElectronNET.API
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new InvalidCastException("Return value does not match with the generic type.", exception);
|
||||
taskCompletionSource.SetException(exception);
|
||||
//throw new InvalidCastException("Return value does not match with the generic type.", exception);
|
||||
}
|
||||
|
||||
taskCompletionSource.SetResult(data);
|
||||
|
||||
41
ElectronNET.API/LifetimeServiceHost.cs
Normal file
41
ElectronNET.API/LifetimeServiceHost.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class that reports if ASP.NET Core has fully started.
|
||||
/// </summary>
|
||||
internal class LifetimeServiceHost : IHostedService
|
||||
{
|
||||
public LifetimeServiceHost(IHostApplicationLifetime lifetime)
|
||||
{
|
||||
lifetime.ApplicationStarted.Register(() =>
|
||||
{
|
||||
App.Instance.IsReady = true;
|
||||
|
||||
Console.WriteLine("ASP.NET Core host has fully started.");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the application host is ready to start the service.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the application host is performing a graceful shutdown.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,8 @@ namespace ElectronNET.API
|
||||
_menuItems.Clear();
|
||||
|
||||
menuItems.AddMenuItemsId();
|
||||
menuItems.AddSubmenuTypes();
|
||||
|
||||
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_menuItems.AddRange(menuItems);
|
||||
|
||||
@@ -82,25 +84,27 @@ namespace ElectronNET.API
|
||||
/// <param name="menuItems">The menu items.</param>
|
||||
public void SetContextMenu(BrowserWindow browserWindow, MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
menuItems.AddSubmenuTypes();
|
||||
|
||||
BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
|
||||
if (!_contextMenuItems.ContainsKey(browserWindow.Id))
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_contextMenuItems.Add(browserWindow.Id, menuItems.ToList());
|
||||
|
||||
var x = _contextMenuItems.ToDictionary(kv => kv.Key, kv => kv.Value.AsReadOnly());
|
||||
ContextMenuItems = new ReadOnlyDictionary<int, ReadOnlyCollection<MenuItem>>(x);
|
||||
|
||||
BridgeConnector.Socket.Off("contextMenuItemClicked");
|
||||
BridgeConnector.Socket.On("contextMenuItemClicked", (results) =>
|
||||
{
|
||||
var id = ((JArray)results).First.ToString();
|
||||
var browserWindowId = (int)((JArray)results).Last;
|
||||
|
||||
MenuItem menuItem = _contextMenuItems[browserWindowId].GetMenuItem(id);
|
||||
menuItem.Click?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
BridgeConnector.Socket.Off("contextMenuItemClicked");
|
||||
BridgeConnector.Socket.On("contextMenuItemClicked", (results) =>
|
||||
{
|
||||
var id = ((JArray)results).First.ToString();
|
||||
var browserWindowId = (int)((JArray)results).Last;
|
||||
|
||||
MenuItem menuItem = _contextMenuItems[browserWindowId].GetMenuItem(id);
|
||||
menuItem.Click?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,8 +119,7 @@ namespace ElectronNET.API
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
212
ElectronNET.API/NativeTheme.cs
Normal file
212
ElectronNET.API/NativeTheme.cs
Normal file
@@ -0,0 +1,212 @@
|
||||
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
|
||||
{
|
||||
private static NativeTheme _nativeTheme;
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
internal NativeTheme() { }
|
||||
|
||||
internal static NativeTheme Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nativeTheme == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_nativeTheme == null)
|
||||
{
|
||||
_nativeTheme = new NativeTheme();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _nativeTheme;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setting this property to <see cref="ThemeSourceMode.System"/> will remove the override and everything will be reset to the OS default. By default 'ThemeSource' is <see cref="ThemeSourceMode.System"/>.
|
||||
/// <para/>
|
||||
/// Settings this property to <see cref="ThemeSourceMode.Dark"/> will have the following effects:
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description><see cref="ShouldUseDarkColorsAsync"/> will be <see langword="true"/> when accessed</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Any UI Electron renders on Linux and Windows including context menus, devtools, etc. will use the dark UI.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Any UI the OS renders on macOS including menus, window frames, etc. will use the dark UI.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>The 'prefers-color-scheme' CSS query will match 'dark' mode.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>The 'updated' event will be emitted</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para/>
|
||||
/// Settings this property to <see cref="ThemeSourceMode.Light"/> will have the following effects:
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description><see cref="ShouldUseDarkColorsAsync"/> will be <see langword="false"/> when accessed</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Any UI Electron renders on Linux and Windows including context menus, devtools, etc. will use the light UI.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Any UI the OS renders on macOS including menus, window frames, etc. will use the light UI.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>The 'prefers-color-scheme' CSS query will match 'light' mode.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>The 'updated' event will be emitted</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// The usage of this property should align with a classic "dark mode" state machine in your application where the user has three options.
|
||||
/// <para/>
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description>Follow OS: SetThemeSource(ThemeSourceMode.System);</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Dark Mode: SetThemeSource(ThemeSourceMode.Dark);</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <description>Light Mode: SetThemeSource(ThemeSourceMode.Light);</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// Your application should then always use <see cref="ShouldUseDarkColorsAsync"/> to determine what CSS to apply.
|
||||
/// </summary>
|
||||
/// <param name="themeSourceMode">The new ThemeSource.</param>
|
||||
public void SetThemeSource(ThemeSourceMode themeSourceMode)
|
||||
{
|
||||
var themeSource = themeSourceMode.GetDescription();
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-themeSource", themeSource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 taskCompletionSource = new TaskCompletionSource<ThemeSourceMode>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-themeSource-getCompleted", (themeSource) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-themeSource-getCompleted");
|
||||
|
||||
var themeSourceValue = (ThemeSourceMode)Enum.Parse(typeof(ThemeSourceMode), (string)themeSource, true);
|
||||
|
||||
taskCompletionSource.SetResult(themeSourceValue);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-themeSource-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <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 taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseDarkColors-completed", (shouldUseDarkColors) => {
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseDarkColors-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseDarkColors);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseDarkColors");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <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 taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseHighContrastColors-completed", (shouldUseHighContrastColors) => {
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseHighContrastColors-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseHighContrastColors);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseHighContrastColors");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <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 taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("nativeTheme-shouldUseInvertedColorScheme-completed", (shouldUseInvertedColorScheme) => {
|
||||
BridgeConnector.Socket.Off("nativeTheme-shouldUseInvertedColorScheme-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)shouldUseInvertedColorScheme);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("nativeTheme-shouldUseInvertedColorScheme");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when something in the underlying NativeTheme has changed. This normally means that either the value of <see cref="ShouldUseDarkColorsAsync"/>,
|
||||
/// <see cref="ShouldUseHighContrastColorsAsync"/> or <see cref="ShouldUseInvertedColorSchemeAsync"/> has changed. You will have to check them to determine which one has changed.
|
||||
/// </summary>
|
||||
public event Action Updated
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_updated == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("nativeTheme-updated" + GetHashCode(), () =>
|
||||
{
|
||||
_updated();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-nativeTheme-updated-event", GetHashCode());
|
||||
}
|
||||
_updated += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_updated -= value;
|
||||
|
||||
if (_updated == null)
|
||||
{
|
||||
BridgeConnector.Socket.Off("nativeTheme-updated" + GetHashCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _updated;
|
||||
}
|
||||
}
|
||||
242
ElectronNET.API/PowerMonitor.cs
Normal file
242
ElectronNET.API/PowerMonitor.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Monitor power state changes..
|
||||
/// </summary>
|
||||
public sealed class PowerMonitor
|
||||
{
|
||||
/// <summary>
|
||||
/// Emitted when the system is about to lock the screen.
|
||||
/// </summary>
|
||||
public event Action OnLockScreen
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_lockScreen == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-lock-screen" , () =>
|
||||
{
|
||||
_lockScreen();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-lock-screen");
|
||||
}
|
||||
_lockScreen += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_lockScreen -= value;
|
||||
|
||||
if (_lockScreen == null)
|
||||
BridgeConnector.Socket.Off("pm-lock-screen");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _lockScreen;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the system is about to unlock the screen.
|
||||
/// </summary>
|
||||
public event Action OnUnLockScreen
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_unlockScreen == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-unlock-screen", () =>
|
||||
{
|
||||
_unlockScreen();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-unlock-screen");
|
||||
}
|
||||
_unlockScreen += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_unlockScreen -= value;
|
||||
|
||||
if (_unlockScreen == null)
|
||||
BridgeConnector.Socket.Off("pm-unlock-screen");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _unlockScreen;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the system is suspending.
|
||||
/// </summary>
|
||||
public event Action OnSuspend
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_suspend == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-suspend", () =>
|
||||
{
|
||||
_suspend();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-suspend");
|
||||
}
|
||||
_suspend += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_suspend -= value;
|
||||
|
||||
if (_suspend == null)
|
||||
BridgeConnector.Socket.Off("pm-suspend");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _suspend;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when system is resuming.
|
||||
/// </summary>
|
||||
public event Action OnResume
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_resume == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-resume", () =>
|
||||
{
|
||||
_resume();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-resume");
|
||||
}
|
||||
_resume += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_resume -= value;
|
||||
|
||||
if (_resume == null)
|
||||
BridgeConnector.Socket.Off("pm-resume");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _resume;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the system changes to AC power.
|
||||
/// </summary>
|
||||
public event Action OnAC
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_onAC == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-on-ac", () =>
|
||||
{
|
||||
_onAC();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-on-ac");
|
||||
}
|
||||
_onAC += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_onAC -= value;
|
||||
|
||||
if (_onAC == null)
|
||||
BridgeConnector.Socket.Off("pm-on-ac");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _onAC;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when system changes to battery power.
|
||||
/// </summary>
|
||||
public event Action OnBattery
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_onBattery == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-on-battery", () =>
|
||||
{
|
||||
_onBattery();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-on-battery");
|
||||
}
|
||||
_onBattery += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_onBattery -= value;
|
||||
|
||||
if (_onBattery == null)
|
||||
BridgeConnector.Socket.Off("pm-on-battery");
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
/// order for the app to exit cleanly.If `e.preventDefault()` is called, the app
|
||||
/// should exit as soon as possible by calling something like `app.quit()`.
|
||||
/// </summary>
|
||||
public event Action OnShutdown
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_shutdown == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("pm-shutdown", () =>
|
||||
{
|
||||
_shutdown();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-pm-shutdown");
|
||||
}
|
||||
_shutdown += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_shutdown -= value;
|
||||
|
||||
if (_shutdown == null)
|
||||
BridgeConnector.Socket.Off("pm-on-shutdown");
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _shutdown;
|
||||
|
||||
private static PowerMonitor _powerMonitor;
|
||||
private static object _syncRoot = new object();
|
||||
|
||||
internal PowerMonitor() { }
|
||||
|
||||
internal static PowerMonitor Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_powerMonitor == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_powerMonitor == null)
|
||||
{
|
||||
_powerMonitor = new PowerMonitor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _powerMonitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Event arguments for the <see cref="App.BeforeQuit"/> / <see cref="App.WillQuit"/> event.
|
||||
/// </summary>
|
||||
public sealed class QuitEventArgs
|
||||
{
|
||||
@@ -13,4 +13,4 @@
|
||||
Electron.App.PreventQuit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,15 @@ namespace ElectronNET.API
|
||||
/// </value>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Query and modify a session's cookies.
|
||||
/// </summary>
|
||||
public Cookies Cookies { get; }
|
||||
|
||||
internal Session(int id)
|
||||
{
|
||||
Id = id;
|
||||
Cookies = new Cookies(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Extensions;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -40,17 +39,14 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// Show the given file in a file manager. If possible, select the file.
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns>Whether the item was successfully shown.</returns>
|
||||
public Task<bool> ShowItemInFolderAsync(string fullPath)
|
||||
/// <param name="fullPath">The full path to the directory / file.</param>
|
||||
public Task ShowItemInFolderAsync(string fullPath)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-showItemInFolderCompleted", (success) =>
|
||||
BridgeConnector.Socket.On("shell-showItemInFolderCompleted", () =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-showItemInFolderCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-showItemInFolder", fullPath);
|
||||
@@ -59,22 +55,22 @@ namespace ElectronNET.API
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the given file in the desktop’s default manner.
|
||||
/// Open the given file in the desktop's default manner.
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns>Whether the item was successfully opened.</returns>
|
||||
public Task<bool> OpenItemAsync(string fullPath)
|
||||
/// <param name="path">The path to the directory / file.</param>
|
||||
/// <returns>The error message corresponding to the failure if a failure occurred, otherwise <see cref="string.Empty"/>.</returns>
|
||||
public Task<string> OpenPathAsync(string path)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openItemCompleted", (success) =>
|
||||
BridgeConnector.Socket.On("shell-openPathCompleted", (errorMessage) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openItemCompleted");
|
||||
BridgeConnector.Socket.Off("shell-openPathCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult((string) errorMessage);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-openItem", fullPath);
|
||||
BridgeConnector.Socket.Emit("shell-openPath", path);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -83,95 +79,50 @@ namespace ElectronNET.API
|
||||
/// Open the given external protocol URL in the desktop’s default manner.
|
||||
/// (For example, mailto: URLs in the user’s default mail agent).
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns>Whether an application was available to open the URL.
|
||||
/// If callback is specified, always returns true.</returns>
|
||||
public Task<bool> OpenExternalAsync(string url)
|
||||
/// <param name="url">Max 2081 characters on windows.</param>
|
||||
/// <returns>The error message corresponding to the failure if a failure occurred, otherwise <see cref="string.Empty"/>.</returns>
|
||||
public Task<string> OpenExternalAsync(string url)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openExternalCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
return OpenExternalAsync(url, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the given external protocol URL in the desktop’s default manner.
|
||||
/// (For example, mailto: URLs in the user’s default mail agent).
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="options">macOS only</param>
|
||||
/// <returns>Whether an application was available to open the URL.
|
||||
/// If callback is specified, always returns true.</returns>
|
||||
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options)
|
||||
/// <param name="url">Max 2081 characters on windows.</param>
|
||||
/// <param name="options">Controls the behavior of OpenExternal.</param>
|
||||
/// <returns>The error message corresponding to the failure if a failure occurred, otherwise <see cref="string.Empty"/>.</returns>
|
||||
public Task<string> OpenExternalAsync(string url, OpenExternalOptions options)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
|
||||
BridgeConnector.Socket.On("shell-openExternalCompleted", (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openExternalCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult((string) error);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer));
|
||||
if (options == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url);
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open the given external protocol URL in the desktop’s default manner.
|
||||
/// (For example, mailto: URLs in the user’s default mail agent).
|
||||
/// Move the given file to trash and returns a <see cref="bool"/> status for the operation.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="options">macOS only</param>
|
||||
/// <param name="errorAction">Action to get the error message.</param>
|
||||
/// <returns>Whether an application was available to open the URL.
|
||||
/// If callback is specified, always returns true.</returns>
|
||||
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options, Action<Error> errorAction)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-openExternalCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Off("shell-openExternalCallback");
|
||||
BridgeConnector.Socket.On("shell-openExternalCallback", (args) => {
|
||||
var urlKey = ((JArray)args).First.ToString();
|
||||
var error = ((JArray)args).Last.ToObject<Error>();
|
||||
|
||||
if(_openExternalCallbacks.ContainsKey(urlKey))
|
||||
{
|
||||
_openExternalCallbacks[urlKey](error);
|
||||
}
|
||||
});
|
||||
|
||||
_openExternalCallbacks.Add(url, errorAction);
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer), true);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private Dictionary<string, Action<Error>> _openExternalCallbacks = new Dictionary<string, Action<Error>>();
|
||||
|
||||
/// <summary>
|
||||
/// Move the given file to trash and returns a boolean status for the operation.
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="fullPath">The full path to the directory / file.</param>
|
||||
/// <param name="deleteOnFail">Whether or not to unilaterally remove the item if the Trash is disabled or unsupported on the volume.</param>
|
||||
/// <returns> Whether the item was successfully moved to the trash.</returns>
|
||||
public Task<bool> MoveItemToTrashAsync(string fullPath)
|
||||
public Task<bool> MoveItemToTrashAsync(string fullPath, bool deleteOnFail)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
@@ -179,10 +130,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-moveItemToTrashCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult((bool) success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-moveItemToTrash", fullPath);
|
||||
BridgeConnector.Socket.Emit("shell-moveItemToTrash", fullPath, deleteOnFail);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -198,9 +149,9 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// Creates or updates a shortcut link at shortcutPath.
|
||||
/// </summary>
|
||||
/// <param name="shortcutPath"></param>
|
||||
/// <param name="operation"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="shortcutPath">The path to the shortcut.</param>
|
||||
/// <param name="operation">Default is <see cref="ShortcutLinkOperation.Create"/></param>
|
||||
/// <param name="options">Structure of a shortcut.</param>
|
||||
/// <returns>Whether the shortcut was created successfully.</returns>
|
||||
public Task<bool> WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperation operation, ShortcutDetails options)
|
||||
{
|
||||
@@ -210,21 +161,20 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-writeShortcutLinkCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult((bool) success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.ToString(), JObject.FromObject(options, _jsonSerializer));
|
||||
BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.GetDescription(), JObject.FromObject(options, _jsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the shortcut link at shortcutPath.
|
||||
///
|
||||
/// An exception will be thrown when any error happens.
|
||||
/// </summary>
|
||||
/// <param name="shortcutPath"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="shortcutPath">The path tot the shortcut.</param>
|
||||
/// <returns><see cref="ShortcutDetails"/> of the shortcut.</returns>
|
||||
public Task<ShortcutDetails> ReadShortcutLinkAsync(string shortcutPath)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ShortcutDetails>();
|
||||
@@ -233,7 +183,10 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-readShortcutLinkCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((ShortcutDetails)shortcutDetails);
|
||||
var shortcutObject = shortcutDetails as JObject;
|
||||
var details = shortcutObject?.ToObject<ShortcutDetails>();
|
||||
|
||||
taskCompletionSource.SetResult(details);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-readShortcutLink", shortcutPath);
|
||||
@@ -241,11 +194,11 @@ namespace ElectronNET.API
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,6 +252,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.Clear();
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("trayMenuItemClicked");
|
||||
@@ -262,6 +263,15 @@ namespace ElectronNET.API
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the Traybar (empty).
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
public void Show(string image)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("create-tray", image);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the tray icon immediately.
|
||||
/// </summary>
|
||||
@@ -307,18 +317,6 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("tray-setTitle", title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// macOS: Sets when the tray’s icon background becomes highlighted (in blue).
|
||||
///
|
||||
/// Note: You can use highlightMode with a BrowserWindow by toggling between
|
||||
/// 'never' and 'always' modes when the window visibility changes.
|
||||
/// </summary>
|
||||
/// <param name="highlightMode"></param>
|
||||
public void SetHighlightMode(HighlightMode highlightMode)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-setHighlightMode", highlightMode.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Windows: Displays a tray balloon.
|
||||
/// </summary>
|
||||
@@ -351,8 +349,7 @@ namespace ElectronNET.API
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,53 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get system printers.
|
||||
/// </summary>
|
||||
/// <returns>printers</returns>
|
||||
public Task<PrinterInfo[]> GetPrintersAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<PrinterInfo[]>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-getPrinters-completed", (printers) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-getPrinters-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((Newtonsoft.Json.Linq.JArray)printers).ToObject<PrinterInfo[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-getPrinters", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints window's web page.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <returns>success</returns>
|
||||
public Task<bool> PrintAsync(PrintOptions options = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-print-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-print-completed");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
if(options == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-print", Id, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-print", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints window's web page as PDF with Chromium's preview printing custom
|
||||
/// settings.The landscape will be ignored if @page CSS at-rule is used in the web page.
|
||||
@@ -158,7 +205,59 @@ namespace ElectronNET.API
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The async method will resolve when the page has finished loading,
|
||||
/// and rejects if the page fails to load.
|
||||
///
|
||||
/// A noop rejection handler is already attached, which avoids unhandled rejection
|
||||
/// errors.
|
||||
///
|
||||
/// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g.
|
||||
/// the `http://` or `file://`. If the load should bypass http cache then use the
|
||||
/// `pragma` header to achieve it.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
public Task LoadURLAsync(string url)
|
||||
{
|
||||
return LoadURLAsync(url, new LoadURLOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The async method will resolve when the page has finished loading,
|
||||
/// and rejects if the page fails to load.
|
||||
///
|
||||
/// A noop rejection handler is already attached, which avoids unhandled rejection
|
||||
/// errors.
|
||||
///
|
||||
/// Loads the `url` in the window. The `url` must contain the protocol prefix, e.g.
|
||||
/// the `http://` or `file://`. If the load should bypass http cache then use the
|
||||
/// `pragma` header to achieve it.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="options"></param>
|
||||
public Task LoadURLAsync(string url, LoadURLOptions options)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-loadURL-complete" + Id, () =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-loadURL-complete" + Id);
|
||||
BridgeConnector.Socket.Off("webContents-loadURL-error" + Id);
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On("webContents-loadURL-error" + Id, (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-loadURL-error" + Id);
|
||||
taskCompletionSource.SetException(new InvalidOperationException(error.ToString()));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -22,19 +24,35 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeSettings.SocketPort = argument.ToUpper().Replace("/ELECTRONPORT=", "");
|
||||
Console.WriteLine("Use Electron Port: " + BridgeSettings.SocketPort);
|
||||
} else if(argument.ToUpper().Contains("ELECTRONWEBPORT"))
|
||||
}
|
||||
else if (argument.ToUpper().Contains("ELECTRONWEBPORT"))
|
||||
{
|
||||
BridgeSettings.WebPort = argument.ToUpper().Replace("/ELECTRONWEBPORT=", "");
|
||||
}
|
||||
}
|
||||
|
||||
if(HybridSupport.IsElectronActive)
|
||||
if (HybridSupport.IsElectronActive)
|
||||
{
|
||||
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.UseUrls("http://127.0.0.1:" + BridgeSettings.WebPort);
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddHostedService<LifetimeServiceHost>();
|
||||
});
|
||||
|
||||
// check for the content folder if its exists in base director otherwise no need to include
|
||||
// It was used before because we are publishing the project which copies everything to bin folder and contentroot wwwroot was folder there.
|
||||
// now we have implemented the live reload if app is run using /watch then we need to use the default project path.
|
||||
if (Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\wwwroot"))
|
||||
{
|
||||
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.UseUrls("http://localhost:" + BridgeSettings.WebPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.UseUrls("http://localhost:" + BridgeSettings.WebPort);
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,15 @@ namespace ElectronNET.API
|
||||
public IReadOnlyCollection<BrowserWindow> BrowserWindows { get { return _browserWindows.AsReadOnly(); } }
|
||||
private List<BrowserWindow> _browserWindows = new List<BrowserWindow>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the browser views.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The browser view.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<BrowserView> BrowserViews { get { return _browserViews.AsReadOnly(); } }
|
||||
private List<BrowserView> _browserViews = new List<BrowserView>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the window asynchronous.
|
||||
/// </summary>
|
||||
@@ -155,6 +164,51 @@ namespace ElectronNET.API
|
||||
return RuntimeInformation.OSDescription.Contains("Windows 10");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// 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>
|
||||
/// <returns></returns>
|
||||
public Task<BrowserView> CreateBrowserViewAsync()
|
||||
{
|
||||
return CreateBrowserViewAsync(new BrowserViewConstructorOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
||||
/// 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>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public Task<BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserView>();
|
||||
|
||||
BridgeConnector.Socket.On("BrowserViewCreated", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserViewCreated");
|
||||
|
||||
string browserViewId = id.ToString();
|
||||
BrowserView browserView = new BrowserView(int.Parse(browserViewId));
|
||||
browserView.Destroyed += (b) => _browserViews.Remove(b);
|
||||
|
||||
_browserViews.Add(browserView);
|
||||
|
||||
taskCompletionSource.SetResult(browserView);
|
||||
});
|
||||
|
||||
var ownjsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
@@ -18,7 +18,9 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "commandLine.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dock.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
|
||||
@@ -28,6 +30,9 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "autoUpdater.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserView.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "powerMonitor.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "nativeTheme.js", "api.");
|
||||
|
||||
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
|
||||
if (Directory.Exists(splashscreenFolder) == false)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.CLI.Commands.Actions;
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace ElectronNET.CLI.Commands
|
||||
private string _paramAbsoluteOutput = "absolute-path";
|
||||
private string _paramPackageJson = "package-json";
|
||||
private string _paramForceNodeInstall = "install-modules";
|
||||
private string _manifest = "manifest";
|
||||
private string _paramPublishReadyToRun = "PublishReadyToRun";
|
||||
|
||||
public Task<bool> ExecuteAsync()
|
||||
{
|
||||
@@ -50,6 +52,13 @@ namespace ElectronNET.CLI.Commands
|
||||
SimpleCommandLineParser parser = new SimpleCommandLineParser();
|
||||
parser.Parse(_args);
|
||||
|
||||
if (!parser.Arguments.ContainsKey(_paramTarget))
|
||||
{
|
||||
Console.WriteLine($"Error: missing '{_paramTarget}' argument.");
|
||||
Console.WriteLine(COMMAND_ARGUMENTS);
|
||||
return false;
|
||||
}
|
||||
|
||||
var desiredPlatform = parser.Arguments[_paramTarget][0];
|
||||
string specifiedFromCustom = string.Empty;
|
||||
if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
|
||||
@@ -72,7 +81,13 @@ namespace ElectronNET.CLI.Commands
|
||||
if (Directory.Exists(tempPath) == false)
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);
|
||||
|
||||
@@ -80,7 +95,17 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
|
||||
|
||||
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c {configuration} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
|
||||
string publishReadyToRun = "/p:PublishReadyToRun=";
|
||||
if (parser.Arguments.ContainsKey(_paramPublishReadyToRun))
|
||||
{
|
||||
publishReadyToRun += parser.Arguments[_paramPublishReadyToRun][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
publishReadyToRun += "true";
|
||||
}
|
||||
|
||||
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} --self-contained", Directory.GetCurrentDirectory());
|
||||
|
||||
if (resultCode != 0)
|
||||
{
|
||||
@@ -150,10 +175,18 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
// ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
|
||||
Console.WriteLine("Create electron-builder configuration file...");
|
||||
ProcessHelper.CmdExecute($"node build-helper.js", tempPath);
|
||||
|
||||
string manifestFileName = "electron.manifest.json";
|
||||
|
||||
if(parser.Arguments.ContainsKey(_manifest))
|
||||
{
|
||||
manifestFileName = parser.Arguments[_manifest].First();
|
||||
}
|
||||
|
||||
ProcessHelper.CmdExecute($"node build-helper.js " + manifestFileName, tempPath);
|
||||
|
||||
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
|
||||
ProcessHelper.CmdExecute($"npx electron-builder . --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=5.0.8 {electronParams}", tempPath);
|
||||
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=9.0.5 {electronParams}", tempPath);
|
||||
|
||||
Console.WriteLine("... done");
|
||||
|
||||
|
||||
@@ -16,26 +16,30 @@ namespace ElectronNET.CLI.Commands
|
||||
public const string COMMAND_ARGUMENTS = "<Path> from ASP.NET Core Project.";
|
||||
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
|
||||
|
||||
private const string ConfigName = "electron.manifest.json";
|
||||
|
||||
private string[] _args;
|
||||
private static SimpleCommandLineParser _parser = new SimpleCommandLineParser();
|
||||
private static string ConfigName = "electron.manifest.json";
|
||||
private const string DefaultConfigFileName = "electron.manifest.json";
|
||||
|
||||
public InitCommand(string[] args)
|
||||
{
|
||||
_args = args;
|
||||
_parser.Parse(args);
|
||||
}
|
||||
|
||||
private static string _aspCoreProjectPath = "project-path";
|
||||
private static string _manifest = "manifest";
|
||||
|
||||
public Task<bool> ExecuteAsync()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
string aspCoreProjectPath = "";
|
||||
|
||||
if (_args.Length > 0)
|
||||
if (_parser.Arguments.ContainsKey(_aspCoreProjectPath))
|
||||
{
|
||||
if (Directory.Exists(_args[0]))
|
||||
string projectPath = _parser.Arguments[_aspCoreProjectPath].First();
|
||||
if (Directory.Exists(projectPath))
|
||||
{
|
||||
aspCoreProjectPath = _args[0];
|
||||
aspCoreProjectPath = projectPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -45,7 +49,15 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
var currentDirectory = aspCoreProjectPath;
|
||||
|
||||
Console.WriteLine("Adding our config file to your project...");
|
||||
if(_parser.Arguments.ContainsKey(_manifest))
|
||||
{
|
||||
ConfigName = "electron.manifest." + _parser.Arguments[_manifest].First() + ".json";
|
||||
Console.WriteLine($"Adding your custom {ConfigName} config file to your project...");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Adding our config file to your project...");
|
||||
}
|
||||
|
||||
var targetFilePath = Path.Combine(currentDirectory, ConfigName);
|
||||
|
||||
@@ -56,7 +68,7 @@ namespace ElectronNET.CLI.Commands
|
||||
}
|
||||
|
||||
// Deploy config file
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName);
|
||||
EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);
|
||||
|
||||
// search .csproj
|
||||
Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
|
||||
@@ -99,7 +111,32 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
string launchSettingText = File.ReadAllText(launchSettingFile);
|
||||
|
||||
if (launchSettingText.Contains("\"executablePath\": \"electronize\"") == false)
|
||||
if(_parser.Arguments.ContainsKey(_manifest))
|
||||
{
|
||||
string manifestName = _parser.Arguments[_manifest].First();
|
||||
|
||||
if(launchSettingText.Contains("start /manifest " + ConfigName) == false)
|
||||
{
|
||||
StringBuilder debugProfileBuilder = new StringBuilder();
|
||||
debugProfileBuilder.AppendLine("profiles\": {");
|
||||
debugProfileBuilder.AppendLine(" \"Electron.NET App - " + manifestName + "\": {");
|
||||
debugProfileBuilder.AppendLine(" \"commandName\": \"Executable\",");
|
||||
debugProfileBuilder.AppendLine(" \"executablePath\": \"electronize\",");
|
||||
debugProfileBuilder.AppendLine(" \"commandLineArgs\": \"start /manifest " + ConfigName + "\",");
|
||||
debugProfileBuilder.AppendLine(" \"workingDirectory\": \".\"");
|
||||
debugProfileBuilder.AppendLine(" },");
|
||||
|
||||
launchSettingText = launchSettingText.Replace("profiles\": {", debugProfileBuilder.ToString());
|
||||
File.WriteAllText(launchSettingFile, launchSettingText);
|
||||
|
||||
Console.WriteLine($"Debug profile added!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Debug profile already existing");
|
||||
}
|
||||
}
|
||||
else if (launchSettingText.Contains("\"executablePath\": \"electronize\"") == false)
|
||||
{
|
||||
StringBuilder debugProfileBuilder = new StringBuilder();
|
||||
debugProfileBuilder.AppendLine("profiles\": {");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.CLI.Commands.Actions;
|
||||
@@ -21,19 +22,30 @@ namespace ElectronNET.CLI.Commands
|
||||
_args = args;
|
||||
}
|
||||
|
||||
private string _aspCoreProjectPath = "project-path";
|
||||
private string _arguments = "args";
|
||||
private string _manifest = "manifest";
|
||||
private string _clearCache = "clear-cache";
|
||||
private string _paramPublishReadyToRun = "PublishReadyToRun";
|
||||
private string _paramDotNetConfig = "dotnet-configuration";
|
||||
|
||||
public Task<bool> ExecuteAsync()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Console.WriteLine("Start Electron Desktop Application...");
|
||||
|
||||
SimpleCommandLineParser parser = new SimpleCommandLineParser();
|
||||
parser.Parse(_args);
|
||||
|
||||
string aspCoreProjectPath = "";
|
||||
|
||||
if (_args.Length > 0)
|
||||
if (parser.Arguments.ContainsKey(_aspCoreProjectPath))
|
||||
{
|
||||
if (Directory.Exists(_args[0]))
|
||||
string projectPath = parser.Arguments[_aspCoreProjectPath].First();
|
||||
if (Directory.Exists(projectPath))
|
||||
{
|
||||
aspCoreProjectPath = _args[0];
|
||||
aspCoreProjectPath = projectPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -50,7 +62,28 @@ namespace ElectronNET.CLI.Commands
|
||||
var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty);
|
||||
|
||||
string tempBinPath = Path.Combine(tempPath, "bin");
|
||||
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\"", aspCoreProjectPath);
|
||||
var resultCode = 0;
|
||||
|
||||
string publishReadyToRun = "/p:PublishReadyToRun=";
|
||||
if (parser.Arguments.ContainsKey(_paramPublishReadyToRun))
|
||||
{
|
||||
publishReadyToRun += parser.Arguments[_paramPublishReadyToRun][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
publishReadyToRun += "true";
|
||||
}
|
||||
|
||||
string configuration = "Debug";
|
||||
if (parser.Arguments.ContainsKey(_paramDotNetConfig))
|
||||
{
|
||||
configuration = parser.Arguments[_paramDotNetConfig][0];
|
||||
}
|
||||
|
||||
if (parser != null && !parser.Arguments.ContainsKey("watch"))
|
||||
{
|
||||
resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} --no-self-contained", aspCoreProjectPath);
|
||||
}
|
||||
|
||||
if (resultCode != 0)
|
||||
{
|
||||
@@ -83,25 +116,45 @@ namespace ElectronNET.CLI.Commands
|
||||
ProcessHelper.CmdExecute(@"npx tsc -p ../../ElectronHostHook", tempPath);
|
||||
}
|
||||
|
||||
string arguments = "";
|
||||
|
||||
if (parser.Arguments.ContainsKey(_arguments))
|
||||
{
|
||||
arguments = string.Join(' ', parser.Arguments[_arguments]);
|
||||
}
|
||||
|
||||
if (parser.Arguments.ContainsKey(_manifest))
|
||||
{
|
||||
arguments += " --manifest=" + parser.Arguments[_manifest].First();
|
||||
}
|
||||
|
||||
if (parser.Arguments.ContainsKey(_clearCache))
|
||||
{
|
||||
arguments += " --clear-cache=true";
|
||||
}
|
||||
|
||||
if (parser.Arguments.ContainsKey("watch"))
|
||||
{
|
||||
arguments += " --watch=true";
|
||||
}
|
||||
|
||||
string path = Path.Combine(tempPath, "node_modules", ".bin");
|
||||
|
||||
|
||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
|
||||
if (isWindows)
|
||||
{
|
||||
Console.WriteLine("Invoke electron.cmd - in dir: " + path);
|
||||
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js""", path);
|
||||
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js"" " + arguments, path);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invoke electron - in dir: " + path);
|
||||
ProcessHelper.CmdExecute(@"./electron ""../../main.js""", path);
|
||||
ProcessHelper.CmdExecute(@"./electron ""../../main.js"" " + arguments, path);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AssemblyName>electronize</AssemblyName>
|
||||
|
||||
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AssemblyName>dotnet-electronize</AssemblyName>
|
||||
<ToolCommandName>electronize</ToolCommandName>
|
||||
|
||||
<PackageType>DotnetCliTool</PackageType>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageOutputPath>..\artifacts</PackageOutputPath>
|
||||
@@ -14,8 +16,10 @@
|
||||
<Authors>Gregor Biswanger, Robert Muehsig</Authors>
|
||||
<Product>Electron.NET</Product>
|
||||
<Company />
|
||||
<Description>Building cross platform electron based desktop apps with .NET Core and ASP.NET Core.
|
||||
This package contains the dotnet tooling to electronize your application.</Description>
|
||||
<Description>
|
||||
Building cross platform electron based desktop apps with .NET Core and ASP.NET Core.
|
||||
This package contains the dotnet tooling to electronize your application.
|
||||
</Description>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/ElectronNET/Electron.NET/</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/ElectronNET/Electron.NET/</RepositoryUrl>
|
||||
@@ -25,6 +29,11 @@ This package contains the dotnet tooling to electronize your application.</Descr
|
||||
<PackageReleaseNotes>Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md</PackageReleaseNotes>
|
||||
<PackageIcon>PackageIcon.png</PackageIcon>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -32,72 +41,39 @@ This package contains the dotnet tooling to electronize your application.</Descr
|
||||
<None Remove="ElectronHost\package.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile></DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DocumentationFile></DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="PackageIcon.png" Pack="true" PackagePath="\"/>
|
||||
<None Include="PackageIcon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\electron.manifest.json" Link="ElectronHost\electron.manifest.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\package.json" Link="ElectronHost\package.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\main.js" Link="ElectronHost\main.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\build-helper.js" Link="ElectronHost\build-helper.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\ipc.js" Link="ElectronHost\api\ipc.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\index.ts" Link="ElectronHost\ElectronHostHook\index.ts" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\connector.ts" Link="ElectronHost\ElectronHostHook\connector.ts" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\tsconfig.json" Link="ElectronHost\ElectronHostHook\tsconfig.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\package.json" Link="ElectronHost\ElectronHostHook\package.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\connector.ts" Link="ElectronHost\ElectronHostHook\connector.ts" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\tsconfig.json" Link="ElectronHost\ElectronHostHook\tsconfig.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\package.json" Link="ElectronHost\ElectronHostHook\package.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\splashscreen\index.html" Link="ElectronHost\splashscreen\index.html" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\app.js" Link="ElectronHost\api\app.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\browserWindows.js" Link="ElectronHost\api\browserWindows.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\commandLine.js" Link="ElectronHost\api\commandLine.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\dialog.js" Link="ElectronHost\api\dialog.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\dock.js" Link="ElectronHost\api\dock.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\menu.js" Link="ElectronHost\api\menu.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\notification.js" Link="ElectronHost\api\notification.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\tray.js" Link="ElectronHost\api\tray.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\globalShortcut.js" Link="ElectronHost\api\globalShortcut.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\screen.js" Link="ElectronHost\api\screen.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\shell.js" Link="ElectronHost\api\shell.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\webContents.js" Link="ElectronHost\api\webContents.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\clipboard.js" Link="ElectronHost\api\clipboard.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\autoUpdater.js" Link="ElectronHost\api\autoUpdater.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\browserView.js" Link="ElectronHost\api\browserView.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\powerMonitor.js" Link="ElectronHost\api\powerMonitor.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\nativeTheme.js" Link="ElectronHost\api\nativeTheme.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -29,5 +29,19 @@ namespace ElectronNET.CLI
|
||||
streamFromEmbeddedFile.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeployEmbeddedFileToTargetFile(string targetPath, string embeddedFile, string targetFile, string namespacePath = "")
|
||||
{
|
||||
using (var fileStream = File.Create(Path.Combine(targetPath, targetFile)))
|
||||
{
|
||||
var streamFromEmbeddedFile = GetTestResourceFileStream("ElectronHost." + namespacePath + embeddedFile);
|
||||
if (streamFromEmbeddedFile == null)
|
||||
{
|
||||
Console.WriteLine("Error: Couldn't find embedded file: " + embeddedFile);
|
||||
}
|
||||
|
||||
streamFromEmbeddedFile.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"profiles": {
|
||||
"ElectronNET.CLI": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "build \"C:\\Users\\Gregor\\Documents\\Visual Studio 2017\\Projects\\ElectronNET\\ElectronNET.WebApp\""
|
||||
"commandLineArgs": "start /project-path \"$(SolutionDir)ElectronNET.WebApp\" /watch"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
ElectronNET.Host/.vscode/launch.json
vendored
18
ElectronNET.Host/.vscode/launch.json
vendored
@@ -10,7 +10,23 @@
|
||||
"name": "Launch Electron App",
|
||||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
|
||||
"program": "${workspaceFolder}/main.js",
|
||||
"sourceMaps": true
|
||||
"sourceMaps": true,
|
||||
"args": [
|
||||
"--test=true",
|
||||
"--blub=wuhuu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch build-helper",
|
||||
"program": "${workspaceFolder}/build-helper.js",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"args": [
|
||||
"electron.manifest.json"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Connector = void 0;
|
||||
class Connector {
|
||||
constructor(socket,
|
||||
// @ts-ignore
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"connector.js","sourceRoot":"","sources":["connector.ts"],"names":[],"mappings":";;AAAA,MAAa,SAAS;IAClB,YAAoB,MAAuB;IACvC,aAAa;IACN,GAAiB;QAFR,WAAM,GAAN,MAAM,CAAiB;QAEhC,QAAG,GAAH,GAAG,CAAc;IAAI,CAAC;IAEjC,EAAE,CAAC,GAAW,EAAE,cAAwB;QACpC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;YACnC,MAAM,EAAE,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;YAE9B,IAAI;g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
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HookService = void 0;
|
||||
const connector_1 = require("./connector");
|
||||
class HookService extends connector_1.Connector {
|
||||
constructor(socket, app) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAEA,2CAAwC;AAExC,MAAa,WAAY,SAAQ,qBAAS;IACtC,YAAY,MAAuB,EAAS,GAAiB;QACzD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QADqB,QAAG,GAAH,GAAG,CAAc;IAE7D,CAAC;IAED,WAAW;QACP,8CAA8C;IAClD,CAAC;CACJ;AARD,kCAQC"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAEA,2CAAwC;AAExC,MAAa,WAAY,SAAQ,qBAAS;IACtC,YAAY,MAAuB,EAAS,GAAiB;QACzD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QADqB,QAAG,GAAH,GAAG,CAAc;IAE7D,CAAC;IAED,WAAW;QACP,8CAA8C;IAClD,CAAC;CACJ;AARD,kCAQC"}
|
||||
@@ -1,23 +1,28 @@
|
||||
"use strict";
|
||||
let isQuitWindowAllClosed = true, electronSocket;
|
||||
let appWindowAllClosedEventId;
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
// Quit when all windows are closed.
|
||||
// By default, quit when all windows are closed
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin' &&
|
||||
isQuitWindowAllClosed) {
|
||||
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
|
||||
app.quit();
|
||||
}
|
||||
else if (appWindowAllClosedEventId) {
|
||||
// If the user is on macOS
|
||||
// - OR -
|
||||
// If the user has indicated NOT to quit when all windows are closed,
|
||||
// emit the event.
|
||||
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
|
||||
}
|
||||
});
|
||||
socket.on('quit-app-window-all-closed-event', (quit) => {
|
||||
isQuitWindowAllClosed = quit;
|
||||
});
|
||||
socket.on('register-app-window-all-closed-event', (id) => {
|
||||
app.on('window-all-closed', () => {
|
||||
electronSocket.emit('app-window-all-closed' + id);
|
||||
});
|
||||
appWindowAllClosedEventId = id;
|
||||
});
|
||||
socket.on('register-app-before-quit-event', (id) => {
|
||||
app.on('before-quit', (event) => {
|
||||
@@ -65,8 +70,8 @@ module.exports = (socket, app) => {
|
||||
socket.on('appRelaunch', (options) => {
|
||||
app.relaunch(options);
|
||||
});
|
||||
socket.on('appFocus', () => {
|
||||
app.focus();
|
||||
socket.on('appFocus', (options) => {
|
||||
app.focus(options);
|
||||
});
|
||||
socket.on('appHide', () => {
|
||||
app.hide();
|
||||
@@ -78,6 +83,9 @@ module.exports = (socket, app) => {
|
||||
const path = app.getAppPath();
|
||||
electronSocket.emit('appGetAppPathCompleted', path);
|
||||
});
|
||||
socket.on('appSetAppLogsPath', (path) => {
|
||||
app.setAppLogsPath(path);
|
||||
});
|
||||
socket.on('appGetPath', (name) => {
|
||||
const path = app.getPath(name);
|
||||
electronSocket.emit('appGetPathCompleted', path);
|
||||
@@ -91,16 +99,15 @@ module.exports = (socket, app) => {
|
||||
// nativeImage[indexCount] = nativeImage;
|
||||
// }
|
||||
// }
|
||||
socket.on('appGetFileIcon', (path, options) => {
|
||||
socket.on('appGetFileIcon', async (path, options) => {
|
||||
let error = {};
|
||||
if (options) {
|
||||
app.getFileIcon(path, options, (error, nativeImage) => {
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
});
|
||||
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
}
|
||||
else {
|
||||
app.getFileIcon(path, (error, nativeImage) => {
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
});
|
||||
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
}
|
||||
});
|
||||
socket.on('appSetPath', (name, path) => {
|
||||
@@ -111,11 +118,10 @@ module.exports = (socket, app) => {
|
||||
electronSocket.emit('appGetVersionCompleted', version);
|
||||
});
|
||||
socket.on('appGetName', () => {
|
||||
const name = app.getName();
|
||||
electronSocket.emit('appGetNameCompleted', name);
|
||||
electronSocket.emit('appGetNameCompleted', app.name);
|
||||
});
|
||||
socket.on('appSetName', (name) => {
|
||||
app.setName(name);
|
||||
app.name = name;
|
||||
});
|
||||
socket.on('appGetLocale', () => {
|
||||
const locale = app.getLocale();
|
||||
@@ -157,16 +163,26 @@ module.exports = (socket, app) => {
|
||||
const success = app.requestSingleInstanceLock();
|
||||
electronSocket.emit('appRequestSingleInstanceLockCompleted', success);
|
||||
});
|
||||
socket.on('appHasSingleInstanceLock', () => {
|
||||
const hasLock = app.hasSingleInstanceLock();
|
||||
electronSocket.emit('appHasSingleInstanceLockCompleted', hasLock);
|
||||
});
|
||||
socket.on('appReleaseSingleInstanceLock', () => {
|
||||
app.releaseSingleInstanceLock();
|
||||
});
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageURL) => {
|
||||
app.setUserActivity(type, userInfo, webpageURL);
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageUrl) => {
|
||||
app.setUserActivity(type, userInfo, webpageUrl);
|
||||
});
|
||||
socket.on('appGetCurrentActivityType', () => {
|
||||
const activityType = app.getCurrentActivityType();
|
||||
electronSocket.emit('appGetCurrentActivityTypeCompleted', activityType);
|
||||
});
|
||||
socket.on('appInvalidateCurrentActivity', () => {
|
||||
app.invalidateCurrentActivity();
|
||||
});
|
||||
socket.on('appResignCurrentActivity', () => {
|
||||
app.resignCurrentActivity();
|
||||
});
|
||||
socket.on('appSetAppUserModelId', (id) => {
|
||||
app.setAppUserModelId(id);
|
||||
});
|
||||
@@ -206,48 +222,20 @@ module.exports = (socket, app) => {
|
||||
const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
|
||||
electronSocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled);
|
||||
});
|
||||
socket.on('appSetAccessibilitySupportEnabled', (enabled) => {
|
||||
app.setAccessibilitySupportEnabled(enabled);
|
||||
});
|
||||
socket.on('appShowAboutPanel', () => {
|
||||
app.showAboutPanel();
|
||||
});
|
||||
socket.on('appSetAboutPanelOptions', (options) => {
|
||||
app.setAboutPanelOptions(options);
|
||||
});
|
||||
socket.on('appCommandLineAppendSwitch', (theSwitch, value) => {
|
||||
app.commandLine.appendSwitch(theSwitch, value);
|
||||
socket.on('appGetUserAgentFallback', () => {
|
||||
electronSocket.emit('appGetUserAgentFallbackCompleted', app.userAgentFallback);
|
||||
});
|
||||
socket.on('appCommandLineAppendArgument', (value) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
socket.on('appDockBounce', (type) => {
|
||||
const id = app.dock.bounce(type);
|
||||
electronSocket.emit('appDockBounceCompleted', id);
|
||||
});
|
||||
socket.on('appDockCancelBounce', (id) => {
|
||||
app.dock.cancelBounce(id);
|
||||
});
|
||||
socket.on('appDockDownloadFinished', (filePath) => {
|
||||
app.dock.downloadFinished(filePath);
|
||||
});
|
||||
socket.on('appDockSetBadge', (text) => {
|
||||
app.dock.setBadge(text);
|
||||
});
|
||||
socket.on('appDockGetBadge', () => {
|
||||
const text = app.dock.getBadge();
|
||||
electronSocket.emit('appDockGetBadgeCompleted', text);
|
||||
});
|
||||
socket.on('appDockHide', () => {
|
||||
app.dock.hide();
|
||||
});
|
||||
socket.on('appDockShow', () => {
|
||||
app.dock.show();
|
||||
});
|
||||
socket.on('appDockIsVisible', () => {
|
||||
const isVisible = app.dock.isVisible();
|
||||
electronSocket.emit('appDockIsVisibleCompleted', isVisible);
|
||||
});
|
||||
// TODO: Menü Lösung muss noch implementiert werden
|
||||
socket.on('appDockSetMenu', (menu) => {
|
||||
app.dock.setMenu(menu);
|
||||
});
|
||||
socket.on('appDockSetIcon', (image) => {
|
||||
app.dock.setIcon(image);
|
||||
socket.on('appSetUserAgentFallback', (userAgent) => {
|
||||
app.userAgentFallback = userAgent;
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=app.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,13 +1,20 @@
|
||||
let isQuitWindowAllClosed = true, electronSocket;
|
||||
let appWindowAllClosedEventId;
|
||||
export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
// Quit when all windows are closed.
|
||||
|
||||
// By default, quit when all windows are closed
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin' &&
|
||||
isQuitWindowAllClosed) {
|
||||
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
|
||||
app.quit();
|
||||
} else if (appWindowAllClosedEventId) {
|
||||
// If the user is on macOS
|
||||
// - OR -
|
||||
// If the user has indicated NOT to quit when all windows are closed,
|
||||
// emit the event.
|
||||
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,9 +23,7 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
});
|
||||
|
||||
socket.on('register-app-window-all-closed-event', (id) => {
|
||||
app.on('window-all-closed', () => {
|
||||
electronSocket.emit('app-window-all-closed' + id);
|
||||
});
|
||||
appWindowAllClosedEventId = id;
|
||||
});
|
||||
|
||||
socket.on('register-app-before-quit-event', (id) => {
|
||||
@@ -79,8 +84,8 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
app.relaunch(options);
|
||||
});
|
||||
|
||||
socket.on('appFocus', () => {
|
||||
app.focus();
|
||||
socket.on('appFocus', (options) => {
|
||||
app.focus(options);
|
||||
});
|
||||
|
||||
socket.on('appHide', () => {
|
||||
@@ -96,6 +101,10 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket.emit('appGetAppPathCompleted', path);
|
||||
});
|
||||
|
||||
socket.on('appSetAppLogsPath', (path) => {
|
||||
app.setAppLogsPath(path);
|
||||
});
|
||||
|
||||
socket.on('appGetPath', (name) => {
|
||||
const path = app.getPath(name);
|
||||
electronSocket.emit('appGetPathCompleted', path);
|
||||
@@ -113,15 +122,17 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
// }
|
||||
// }
|
||||
|
||||
socket.on('appGetFileIcon', (path, options) => {
|
||||
socket.on('appGetFileIcon', async (path, options) => {
|
||||
let error = {};
|
||||
|
||||
if (options) {
|
||||
app.getFileIcon(path, options, (error, nativeImage) => {
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
});
|
||||
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);
|
||||
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
} else {
|
||||
app.getFileIcon(path, (error, nativeImage) => {
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
});
|
||||
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);
|
||||
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -135,12 +146,11 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
});
|
||||
|
||||
socket.on('appGetName', () => {
|
||||
const name = app.getName();
|
||||
electronSocket.emit('appGetNameCompleted', name);
|
||||
electronSocket.emit('appGetNameCompleted', app.name);
|
||||
});
|
||||
|
||||
socket.on('appSetName', (name) => {
|
||||
app.setName(name);
|
||||
app.name = name;
|
||||
});
|
||||
|
||||
socket.on('appGetLocale', () => {
|
||||
@@ -194,18 +204,32 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket.emit('appRequestSingleInstanceLockCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appHasSingleInstanceLock', () => {
|
||||
const hasLock = app.hasSingleInstanceLock();
|
||||
|
||||
electronSocket.emit('appHasSingleInstanceLockCompleted', hasLock);
|
||||
});
|
||||
|
||||
socket.on('appReleaseSingleInstanceLock', () => {
|
||||
app.releaseSingleInstanceLock();
|
||||
});
|
||||
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageURL) => {
|
||||
app.setUserActivity(type, userInfo, webpageURL);
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageUrl) => {
|
||||
app.setUserActivity(type, userInfo, webpageUrl);
|
||||
});
|
||||
|
||||
socket.on('appGetCurrentActivityType', () => {
|
||||
const activityType = app.getCurrentActivityType();
|
||||
electronSocket.emit('appGetCurrentActivityTypeCompleted', activityType);
|
||||
});
|
||||
|
||||
socket.on('appInvalidateCurrentActivity', () => {
|
||||
app.invalidateCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on('appResignCurrentActivity', () => {
|
||||
app.resignCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on('appSetAppUserModelId', (id) => {
|
||||
app.setAppUserModelId(id);
|
||||
@@ -256,59 +280,23 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled);
|
||||
});
|
||||
|
||||
socket.on('appSetAccessibilitySupportEnabled', (enabled) => {
|
||||
app.setAccessibilitySupportEnabled(enabled);
|
||||
});
|
||||
|
||||
socket.on('appShowAboutPanel', () => {
|
||||
app.showAboutPanel();
|
||||
});
|
||||
|
||||
socket.on('appSetAboutPanelOptions', (options) => {
|
||||
app.setAboutPanelOptions(options);
|
||||
});
|
||||
|
||||
socket.on('appGetUserAgentFallback', () => {
|
||||
electronSocket.emit('appGetUserAgentFallbackCompleted', app.userAgentFallback);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineAppendSwitch', (theSwitch, value) => {
|
||||
app.commandLine.appendSwitch(theSwitch, value);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineAppendArgument', (value) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
|
||||
socket.on('appDockBounce', (type) => {
|
||||
const id = app.dock.bounce(type);
|
||||
electronSocket.emit('appDockBounceCompleted', id);
|
||||
});
|
||||
|
||||
socket.on('appDockCancelBounce', (id) => {
|
||||
app.dock.cancelBounce(id);
|
||||
});
|
||||
|
||||
socket.on('appDockDownloadFinished', (filePath) => {
|
||||
app.dock.downloadFinished(filePath);
|
||||
});
|
||||
|
||||
socket.on('appDockSetBadge', (text) => {
|
||||
app.dock.setBadge(text);
|
||||
});
|
||||
|
||||
socket.on('appDockGetBadge', () => {
|
||||
const text = app.dock.getBadge();
|
||||
electronSocket.emit('appDockGetBadgeCompleted', text);
|
||||
});
|
||||
|
||||
socket.on('appDockHide', () => {
|
||||
app.dock.hide();
|
||||
});
|
||||
|
||||
socket.on('appDockShow', () => {
|
||||
app.dock.show();
|
||||
});
|
||||
|
||||
socket.on('appDockIsVisible', () => {
|
||||
const isVisible = app.dock.isVisible();
|
||||
electronSocket.emit('appDockIsVisibleCompleted', isVisible);
|
||||
});
|
||||
|
||||
// TODO: Menü Lösung muss noch implementiert werden
|
||||
socket.on('appDockSetMenu', (menu) => {
|
||||
app.dock.setMenu(menu);
|
||||
});
|
||||
|
||||
socket.on('appDockSetIcon', (image) => {
|
||||
app.dock.setIcon(image);
|
||||
socket.on('appSetUserAgentFallback', (userAgent) => {
|
||||
app.userAgentFallback = userAgent;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
const electron_updater_1 = require("electron-updater");
|
||||
const path = require('path');
|
||||
let electronSocket;
|
||||
@@ -87,25 +79,25 @@ module.exports = (socket) => {
|
||||
electron_updater_1.autoUpdater.channel = value;
|
||||
});
|
||||
// Methods ********
|
||||
socket.on('autoUpdaterCheckForUpdatesAndNotify', (guid) => __awaiter(this, void 0, void 0, function* () {
|
||||
const updateCheckResult = yield electron_updater_1.autoUpdater.checkForUpdatesAndNotify();
|
||||
socket.on('autoUpdaterCheckForUpdatesAndNotify', async (guid) => {
|
||||
const updateCheckResult = await electron_updater_1.autoUpdater.checkForUpdatesAndNotify();
|
||||
electronSocket.emit('autoUpdaterCheckForUpdatesAndNotifyComplete' + guid, updateCheckResult);
|
||||
}));
|
||||
socket.on('autoUpdaterCheckForUpdates', (guid) => __awaiter(this, void 0, void 0, function* () {
|
||||
});
|
||||
socket.on('autoUpdaterCheckForUpdates', async (guid) => {
|
||||
// autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml');
|
||||
const updateCheckResult = yield electron_updater_1.autoUpdater.checkForUpdates();
|
||||
const updateCheckResult = await electron_updater_1.autoUpdater.checkForUpdates();
|
||||
electronSocket.emit('autoUpdaterCheckForUpdatesComplete' + guid, updateCheckResult);
|
||||
}));
|
||||
socket.on('autoUpdaterQuitAndInstall', (isSilent, isForceRunAfter) => __awaiter(this, void 0, void 0, function* () {
|
||||
});
|
||||
socket.on('autoUpdaterQuitAndInstall', async (isSilent, isForceRunAfter) => {
|
||||
electron_updater_1.autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
}));
|
||||
socket.on('autoUpdaterDownloadUpdate', (guid) => __awaiter(this, void 0, void 0, function* () {
|
||||
const downloadedPath = yield electron_updater_1.autoUpdater.downloadUpdate();
|
||||
});
|
||||
socket.on('autoUpdaterDownloadUpdate', async (guid) => {
|
||||
const downloadedPath = await electron_updater_1.autoUpdater.downloadUpdate();
|
||||
electronSocket.emit('autoUpdaterDownloadUpdateComplete' + guid, downloadedPath);
|
||||
}));
|
||||
socket.on('autoUpdaterGetFeedURL', (guid) => __awaiter(this, void 0, void 0, function* () {
|
||||
const feedUrl = yield electron_updater_1.autoUpdater.getFeedURL();
|
||||
});
|
||||
socket.on('autoUpdaterGetFeedURL', async (guid) => {
|
||||
const feedUrl = await electron_updater_1.autoUpdater.getFeedURL();
|
||||
electronSocket.emit('autoUpdaterGetFeedURLComplete' + guid, feedUrl || '');
|
||||
}));
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=autoUpdater.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"autoUpdater.js","sourceRoot":"","sources":["autoUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAA+C;AAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAuB,EAAE,EAAE;IACjC,cAAc,GAAG,MAAM,CAAC;IAExB,kBAAkB;IAElB,MAAM,CAAC,EAAE,CAAC,kCAAkC,EAAE,CAAC,EAAE,EAAE,EAAE;QACjD,8BAAW,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9B,cAAc,CAAC,IAAI,CAAC,mBAAmB,GAAG,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,gDAAgD,EAAE,CAAC,EAAE,EAAE,EAAE;QAC/D,8BAAW,CAAC,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;YACvC,cAAc,CAAC,IAAI,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAC;QAChE,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IAAI,EAAE,EAAE;QACnD,6EAA6E;QAC7E,MAAM,iBAAiB,GAAG,MAAM,8BAAW,CAAC,eAAe,EAAE,CAAC;QAC9D,cAAc,CAAC,IAAI,CAAC,oCAAoC,GAAG,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,2BAA2B,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE;QACvE,8BAAW,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAClD,MAAM,cAAc,GAAG,MAAM,8BAAW,CAAC,cAAc,EAAE,CAAC;QAC1D,cAAc,CAAC,IAAI,CAAC,mCAAmC,GAAG,IAAI,EAAE,cAAc,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,uBAAuB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC9C,MAAM,OAAO,GAAG,MAAM,8BAAW,CAAC,UAAU,EAAE,CAAC;QAC/C,cAAc,CAAC,IAAI,CAAC,+BAA+B,GAAG,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
55
ElectronNET.Host/api/browserView.js
Normal file
55
ElectronNET.Host/api/browserView.js
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
const electron_1 = require("electron");
|
||||
let browserViews = [];
|
||||
let browserView, electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('createBrowserView', (options) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true } };
|
||||
}
|
||||
browserView = new electron_1.BrowserView(options);
|
||||
browserViews.push(browserView);
|
||||
electronSocket.emit('BrowserViewCreated', browserView.id);
|
||||
});
|
||||
socket.on('browserView-isDestroyed', (id) => {
|
||||
const isDestroyed = getBrowserViewById(id).isDestroyed();
|
||||
electronSocket.emit('browserView-isDestroyed-reply', isDestroyed);
|
||||
});
|
||||
socket.on('browserView-getBounds', (id) => {
|
||||
const bounds = getBrowserViewById(id).getBounds();
|
||||
electronSocket.emit('browserView-getBounds-reply', bounds);
|
||||
});
|
||||
socket.on('browserView-setBounds', (id, bounds) => {
|
||||
getBrowserViewById(id).setBounds(bounds);
|
||||
});
|
||||
socket.on('browserView-destroy', (id) => {
|
||||
const browserViewIndex = browserViews.findIndex(b => b.id === id);
|
||||
getBrowserViewById(id).destroy();
|
||||
browserViews.splice(browserViewIndex, 1);
|
||||
});
|
||||
socket.on('browserView-setAutoResize', (id, options) => {
|
||||
getBrowserViewById(id).setAutoResize(options);
|
||||
});
|
||||
socket.on('browserView-setBackgroundColor', (id, color) => {
|
||||
getBrowserViewById(id).setBackgroundColor(color);
|
||||
});
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getBrowserViewById(id) {
|
||||
for (let index = 0; index < browserViews.length; index++) {
|
||||
const browserViewItem = browserViews[index];
|
||||
if (browserViewItem.id === id) {
|
||||
return browserViewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=browserView.js.map
|
||||
1
ElectronNET.Host/api/browserView.js.map
Normal file
1
ElectronNET.Host/api/browserView.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"browserView.js","sourceRoot":"","sources":["browserView.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,IAAI,YAAY,GAA2B,EAAE,CAAC;AAC9C,IAAI,WAA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EAAE;gBAC3B,OAAO,eAAe,CAAC;aAC1B;SACJ;IACL,CAAC;AACL,CAAC,CAAC"}
|
||||
68
ElectronNET.Host/api/browserView.ts
Normal file
68
ElectronNET.Host/api/browserView.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { BrowserView } from 'electron';
|
||||
let browserViews: Electron.BrowserView[] = [];
|
||||
let browserView: BrowserView, electronSocket;
|
||||
|
||||
export = (socket: SocketIO.Socket) => {
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('createBrowserView', (options) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true } };
|
||||
}
|
||||
|
||||
browserView = new BrowserView(options);
|
||||
browserViews.push(browserView);
|
||||
|
||||
electronSocket.emit('BrowserViewCreated', browserView.id);
|
||||
});
|
||||
|
||||
socket.on('browserView-isDestroyed', (id) => {
|
||||
const isDestroyed = getBrowserViewById(id).isDestroyed();
|
||||
|
||||
electronSocket.emit('browserView-isDestroyed-reply', isDestroyed);
|
||||
});
|
||||
|
||||
socket.on('browserView-getBounds', (id) => {
|
||||
const bounds = getBrowserViewById(id).getBounds();
|
||||
|
||||
electronSocket.emit('browserView-getBounds-reply', bounds);
|
||||
});
|
||||
|
||||
socket.on('browserView-setBounds', (id, bounds) => {
|
||||
getBrowserViewById(id).setBounds(bounds);
|
||||
});
|
||||
|
||||
socket.on('browserView-destroy', (id) => {
|
||||
const browserViewIndex = browserViews.findIndex(b => b.id === id);
|
||||
getBrowserViewById(id).destroy();
|
||||
browserViews.splice(browserViewIndex, 1);
|
||||
});
|
||||
|
||||
socket.on('browserView-setAutoResize', (id, options) => {
|
||||
getBrowserViewById(id).setAutoResize(options);
|
||||
});
|
||||
|
||||
socket.on('browserView-setBackgroundColor', (id, color) => {
|
||||
getBrowserViewById(id).setBackgroundColor(color);
|
||||
});
|
||||
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getBrowserViewById(id: number) {
|
||||
for (let index = 0; index < browserViews.length; index++) {
|
||||
const browserViewItem = browserViews[index];
|
||||
if (browserViewItem.id === id) {
|
||||
return browserViewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -2,11 +2,18 @@
|
||||
const electron_1 = require("electron");
|
||||
const path = require('path');
|
||||
const windows = [];
|
||||
let readyToShowWindowsIds = [];
|
||||
let window, lastOptions, electronSocket;
|
||||
let mainWindowURL;
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
socket.on('register-browserWindow-ready-to-show', (id) => {
|
||||
if (readyToShowWindowsIds.includes(id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(value => value !== id);
|
||||
electronSocket.emit('browserWindow-ready-to-show' + id);
|
||||
}
|
||||
getWindowById(id).on('ready-to-show', () => {
|
||||
readyToShowWindowsIds.push(id);
|
||||
electronSocket.emit('browserWindow-ready-to-show' + id);
|
||||
});
|
||||
});
|
||||
@@ -155,20 +162,34 @@ module.exports = (socket, app) => {
|
||||
electronSocket.emit('browserWindow-new-window-for-tab' + id);
|
||||
});
|
||||
});
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
socket.on('createBrowserWindow', (options, loadUrl) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
options = Object.assign({}, options, { webPreferences: { nodeIntegration: true } });
|
||||
if (options.webPreferences && !('nodeIntegration' in options.webPreferences)) {
|
||||
options = { ...options, webPreferences: { ...options.webPreferences, nodeIntegration: true } };
|
||||
}
|
||||
window = new electron_1.BrowserWindow(options);
|
||||
else if (!options.webPreferences) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true } };
|
||||
}
|
||||
// we dont want to recreate the window when watch is ready.
|
||||
if (app.commandLine.hasSwitch('watch') && app['mainWindowURL'] === loadUrl) {
|
||||
window = app['mainWindow'];
|
||||
if (window) {
|
||||
window.reload();
|
||||
windows.push(window);
|
||||
electronSocket.emit('BrowserWindowCreated', window.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
window = new electron_1.BrowserWindow(options);
|
||||
}
|
||||
window.on('ready-to-show', () => {
|
||||
if (readyToShowWindowsIds.includes(window.id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(value => value !== window.id);
|
||||
}
|
||||
else {
|
||||
readyToShowWindowsIds.push(window.id);
|
||||
}
|
||||
});
|
||||
lastOptions = options;
|
||||
window.on('closed', (sender) => {
|
||||
for (let index = 0; index < windows.length; index++) {
|
||||
@@ -196,6 +217,16 @@ module.exports = (socket, app) => {
|
||||
if (loadUrl) {
|
||||
window.loadURL(loadUrl);
|
||||
}
|
||||
if (app.commandLine.hasSwitch('clear-cache') &&
|
||||
app.commandLine.getSwitchValue('clear-cache')) {
|
||||
window.webContents.session.clearCache();
|
||||
console.log('auto clear-cache active for new window.');
|
||||
}
|
||||
// set main window url
|
||||
if (app['mainWindowURL'] == undefined || app['mainWindowURL'] == "") {
|
||||
app['mainWindowURL'] = loadUrl;
|
||||
app['mainWindow'] = window;
|
||||
}
|
||||
windows.push(window);
|
||||
electronSocket.emit('BrowserWindowCreated', window.id);
|
||||
});
|
||||
@@ -404,6 +435,10 @@ module.exports = (socket, app) => {
|
||||
const isKiosk = getWindowById(id).isKiosk();
|
||||
electronSocket.emit('browserWindow-isKiosk-completed', isKiosk);
|
||||
});
|
||||
socket.on('browserWindowGetNativeWindowHandle', (id) => {
|
||||
const nativeWindowHandle = getWindowById(id).getNativeWindowHandle().readInt32LE(0).toString(16);
|
||||
electronSocket.emit('browserWindow-getNativeWindowHandle-completed', nativeWindowHandle);
|
||||
});
|
||||
socket.on('browserWindowSetRepresentedFilename', (id, filename) => {
|
||||
getWindowById(id).setRepresentedFilename(filename);
|
||||
});
|
||||
@@ -456,6 +491,9 @@ module.exports = (socket, app) => {
|
||||
socket.on('browserWindowSetProgressBar', (id, progress) => {
|
||||
getWindowById(id).setProgressBar(progress);
|
||||
});
|
||||
socket.on('browserWindowSetProgressBar', (id, progress, options) => {
|
||||
getWindowById(id).setProgressBar(progress, options);
|
||||
});
|
||||
socket.on('browserWindowSetHasShadow', (id, hasShadow) => {
|
||||
getWindowById(id).setHasShadow(hasShadow);
|
||||
});
|
||||
@@ -538,6 +576,25 @@ module.exports = (socket, app) => {
|
||||
socket.on('browserWindowSetVibrancy', (id, type) => {
|
||||
getWindowById(id).setVibrancy(type);
|
||||
});
|
||||
socket.on('browserWindowAddExtension', (path) => {
|
||||
const extensionName = electron_1.BrowserWindow.addExtension(path);
|
||||
electronSocket.emit('browserWindow-addExtension-completed', extensionName);
|
||||
});
|
||||
socket.on('browserWindowRemoveExtension', (name) => {
|
||||
electron_1.BrowserWindow.removeExtension(name);
|
||||
});
|
||||
socket.on('browserWindowGetExtensions', () => {
|
||||
const extensionsList = electron_1.BrowserWindow.getExtensions();
|
||||
const chromeExtensionInfo = [];
|
||||
Object.keys(extensionsList).forEach(key => {
|
||||
chromeExtensionInfo.push(extensionsList[key]);
|
||||
});
|
||||
electronSocket.emit('browserWindow-getExtensions-completed', chromeExtensionInfo);
|
||||
});
|
||||
socket.on('browserWindow-setBrowserView', (id, browserViewId) => {
|
||||
const browserView = electron_1.BrowserView.fromId(browserViewId);
|
||||
getWindowById(id).setBrowserView(browserView);
|
||||
});
|
||||
function getWindowById(id) {
|
||||
for (let index = 0; index < windows.length; index++) {
|
||||
const element = windows[index];
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,19 @@
|
||||
import { BrowserWindow, Menu, nativeImage } from 'electron';
|
||||
import { BrowserWindow, Menu, nativeImage, BrowserView } from 'electron';
|
||||
const path = require('path');
|
||||
const windows: Electron.BrowserWindow[] = [];
|
||||
let readyToShowWindowsIds: number[] = [];
|
||||
let window, lastOptions, electronSocket;
|
||||
|
||||
let mainWindowURL;
|
||||
export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
socket.on('register-browserWindow-ready-to-show', (id) => {
|
||||
if (readyToShowWindowsIds.includes(id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(value => value !== id);
|
||||
electronSocket.emit('browserWindow-ready-to-show' + id);
|
||||
}
|
||||
|
||||
getWindowById(id).on('ready-to-show', () => {
|
||||
readyToShowWindowsIds.push(id);
|
||||
electronSocket.emit('browserWindow-ready-to-show' + id);
|
||||
});
|
||||
});
|
||||
@@ -185,23 +192,34 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
});
|
||||
});
|
||||
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
socket.on('createBrowserWindow', (options, loadUrl) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
if (options.webPreferences && !('nodeIntegration' in options.webPreferences)) {
|
||||
options = { ...options, webPreferences: { ...options.webPreferences, nodeIntegration: true } };
|
||||
} else if (!options.webPreferences) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true } };
|
||||
}
|
||||
|
||||
window = new BrowserWindow(options);
|
||||
// we dont want to recreate the window when watch is ready.
|
||||
if (app.commandLine.hasSwitch('watch') && app['mainWindowURL'] === loadUrl) {
|
||||
window = app['mainWindow'];
|
||||
if (window) {
|
||||
window.reload();
|
||||
windows.push(window);
|
||||
electronSocket.emit('BrowserWindowCreated', window.id);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
window = new BrowserWindow(options);
|
||||
}
|
||||
|
||||
window.on('ready-to-show', () => {
|
||||
if (readyToShowWindowsIds.includes(window.id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(value => value !== window.id);
|
||||
} else {
|
||||
readyToShowWindowsIds.push(window.id);
|
||||
}
|
||||
});
|
||||
|
||||
lastOptions = options;
|
||||
|
||||
window.on('closed', (sender) => {
|
||||
@@ -233,6 +251,18 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
window.loadURL(loadUrl);
|
||||
}
|
||||
|
||||
if (app.commandLine.hasSwitch('clear-cache') &&
|
||||
app.commandLine.getSwitchValue('clear-cache')) {
|
||||
window.webContents.session.clearCache();
|
||||
console.log('auto clear-cache active for new window.');
|
||||
}
|
||||
|
||||
// set main window url
|
||||
if (app['mainWindowURL'] == undefined || app['mainWindowURL'] == "") {
|
||||
app['mainWindowURL'] = loadUrl;
|
||||
app['mainWindow'] = window;
|
||||
}
|
||||
|
||||
windows.push(window);
|
||||
electronSocket.emit('BrowserWindowCreated', window.id);
|
||||
});
|
||||
@@ -523,6 +553,11 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket.emit('browserWindow-isKiosk-completed', isKiosk);
|
||||
});
|
||||
|
||||
socket.on('browserWindowGetNativeWindowHandle', (id) => {
|
||||
const nativeWindowHandle = getWindowById(id).getNativeWindowHandle().readInt32LE(0).toString(16);
|
||||
electronSocket.emit('browserWindow-getNativeWindowHandle-completed', nativeWindowHandle);
|
||||
});
|
||||
|
||||
socket.on('browserWindowSetRepresentedFilename', (id, filename) => {
|
||||
getWindowById(id).setRepresentedFilename(filename);
|
||||
});
|
||||
@@ -593,6 +628,10 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
getWindowById(id).setProgressBar(progress);
|
||||
});
|
||||
|
||||
socket.on('browserWindowSetProgressBar', (id, progress, options) => {
|
||||
getWindowById(id).setProgressBar(progress, options);
|
||||
});
|
||||
|
||||
socket.on('browserWindowSetHasShadow', (id, hasShadow) => {
|
||||
getWindowById(id).setHasShadow(hasShadow);
|
||||
});
|
||||
@@ -706,6 +745,33 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
getWindowById(id).setVibrancy(type);
|
||||
});
|
||||
|
||||
socket.on('browserWindowAddExtension', (path) => {
|
||||
const extensionName = BrowserWindow.addExtension(path);
|
||||
|
||||
electronSocket.emit('browserWindow-addExtension-completed', extensionName);
|
||||
});
|
||||
|
||||
socket.on('browserWindowRemoveExtension', (name) => {
|
||||
BrowserWindow.removeExtension(name);
|
||||
});
|
||||
|
||||
socket.on('browserWindowGetExtensions', () => {
|
||||
const extensionsList = BrowserWindow.getExtensions();
|
||||
const chromeExtensionInfo = [];
|
||||
|
||||
Object.keys(extensionsList).forEach(key => {
|
||||
chromeExtensionInfo.push(extensionsList[key]);
|
||||
});
|
||||
|
||||
electronSocket.emit('browserWindow-getExtensions-completed', chromeExtensionInfo);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setBrowserView', (id, browserViewId) => {
|
||||
const browserView = BrowserView.fromId(browserViewId);
|
||||
getWindowById(id).setBrowserView(browserView);
|
||||
});
|
||||
|
||||
|
||||
function getWindowById(id: number): Electron.BrowserWindow {
|
||||
for (let index = 0; index < windows.length; index++) {
|
||||
const element = windows[index];
|
||||
|
||||
@@ -48,5 +48,21 @@ module.exports = (socket) => {
|
||||
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') });
|
||||
});
|
||||
socket.on('clipboard-writeImage', (data, type) => {
|
||||
const dataContent = JSON.parse(data);
|
||||
const image = electron_1.nativeImage.createEmpty();
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in dataContent) {
|
||||
const scaleFactor = key;
|
||||
const bytes = data[key];
|
||||
const buffer = Buffer.from(bytes, 'base64');
|
||||
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
|
||||
}
|
||||
electron_1.clipboard.writeImage(image, type);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=clipboard.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["clipboard.ts"],"names":[],"mappings":";AAAA,uCAAqC;AACrC,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAuB,EAAE,EAAE;IACjC,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,oBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,cAAc,CAAC,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC5C,oBAAS,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,oBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzC,cAAc,CAAC,IAAI,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QAC9C,oBAAS,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EA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,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC5C,KAAK,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;SAC1E;QAED,oBAAS,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { clipboard } from 'electron';
|
||||
import { clipboard, nativeImage } from 'electron';
|
||||
let electronSocket;
|
||||
|
||||
export = (socket: SocketIO.Socket) => {
|
||||
@@ -60,4 +60,24 @@ export = (socket: SocketIO.Socket) => {
|
||||
socket.on('clipboard-write', (data, type) => {
|
||||
clipboard.write(data, type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-readImage', (type) => {
|
||||
const image = clipboard.readImage(type);
|
||||
electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeImage', (data, type) => {
|
||||
const dataContent = JSON.parse(data);
|
||||
const image = nativeImage.createEmpty();
|
||||
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in dataContent) {
|
||||
const scaleFactor = key;
|
||||
const bytes = data[key];
|
||||
const buffer = Buffer.from(bytes, 'base64');
|
||||
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
|
||||
}
|
||||
|
||||
clipboard.writeImage(image, type);
|
||||
});
|
||||
};
|
||||
|
||||
20
ElectronNET.Host/api/commandLine.js
Normal file
20
ElectronNET.Host/api/commandLine.js
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
let electronSocket;
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
socket.on('appCommandLineAppendSwitch', (the_switch, value) => {
|
||||
app.commandLine.appendSwitch(the_switch, value);
|
||||
});
|
||||
socket.on('appCommandLineAppendArgument', (value) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
socket.on('appCommandLineHasSwitch', (value) => {
|
||||
const hasSwitch = app.commandLine.hasSwitch(value);
|
||||
electronSocket.emit('appCommandLineHasSwitchCompleted', hasSwitch);
|
||||
});
|
||||
socket.on('appCommandLineGetSwitchValue', (the_switch) => {
|
||||
const value = app.commandLine.getSwitchValue(the_switch);
|
||||
electronSocket.emit('appCommandLineGetSwitchValueCompleted', value);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=commandLine.js.map
|
||||
1
ElectronNET.Host/api/commandLine.js.map
Normal file
1
ElectronNET.Host/api/commandLine.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"commandLine.js","sourceRoot":"","sources":["commandLine.ts"],"names":[],"mappings":";AAAA,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAuB,EAAE,GAAiB,EAAE,EAAE;IACpD,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,UAAkB,EAAE,KAAa,EAAE,EAAE;QAC1E,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,KAAa,EAAE,EAAE;QACxD,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,CAAC,KAAa,EAAE,EAAE;QACnD,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnD,cAAc,CAAC,IAAI,CAAC,kCAAkC,EAAE,SAAS,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,UAAkB,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzD,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
23
ElectronNET.Host/api/commandLine.ts
Normal file
23
ElectronNET.Host/api/commandLine.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
let electronSocket;
|
||||
|
||||
export = (socket: SocketIO.Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('appCommandLineAppendSwitch', (the_switch: string, value: string) => {
|
||||
app.commandLine.appendSwitch(the_switch, value);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineAppendArgument', (value: string) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineHasSwitch', (value: string) => {
|
||||
const hasSwitch = app.commandLine.hasSwitch(value);
|
||||
electronSocket.emit('appCommandLineHasSwitchCompleted', hasSwitch);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineGetSwitchValue', (the_switch: string) => {
|
||||
const value = app.commandLine.getSwitchValue(the_switch);
|
||||
electronSocket.emit('appCommandLineGetSwitchValueCompleted', value);
|
||||
});
|
||||
};
|
||||
@@ -3,40 +3,35 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('showMessageBox', (browserWindow, options, guid) => {
|
||||
socket.on('showMessageBox', async (browserWindow, options, guid) => {
|
||||
if ('id' in browserWindow) {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
electron_1.dialog.showMessageBox(window, options, (response, checkboxChecked) => {
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [response, checkboxChecked]);
|
||||
});
|
||||
const messageBoxReturnValue = await electron_1.dialog.showMessageBox(window, options);
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
}
|
||||
else {
|
||||
const id = guid || options;
|
||||
electron_1.dialog.showMessageBox(browserWindow, (response, checkboxChecked) => {
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [response, checkboxChecked]);
|
||||
});
|
||||
const messageBoxReturnValue = await electron_1.dialog.showMessageBox(browserWindow);
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
}
|
||||
});
|
||||
socket.on('showOpenDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showOpenDialog', async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
electron_1.dialog.showOpenDialog(window, options, (filePaths) => {
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, filePaths || []);
|
||||
});
|
||||
const openDialogReturnValue = await electron_1.dialog.showOpenDialog(window, options);
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, openDialogReturnValue.filePaths || []);
|
||||
});
|
||||
socket.on('showSaveDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showSaveDialog', async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
electron_1.dialog.showSaveDialog(window, options, (filename) => {
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, filename || '');
|
||||
});
|
||||
const saveDialogReturnValue = await electron_1.dialog.showSaveDialog(window, options);
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, saveDialogReturnValue.filePath || '');
|
||||
});
|
||||
socket.on('showErrorBox', (title, content) => {
|
||||
electron_1.dialog.showErrorBox(title, content);
|
||||
});
|
||||
socket.on('showCertificateTrustDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showCertificateTrustDialog', async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
electron_1.dialog.showCertificateTrustDialog(window, options, () => {
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
});
|
||||
await electron_1.dialog.showCertificateTrustDialog(window, options);
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=dialog.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["dialog.ts"],"names":[],"mappings":";AAAA,uCAAiD;AACjD,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAuB,EAAE,EAAE;IACjC,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACzD,IAAI,IAAI,IAAI,aAAa,EAAE;YACvB,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;YAEtD,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE;gBACjE,cAAc,CAAC,IAAI,CAAC,wBAAwB,GAAG,IAAI,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACtF,CAAC,CAAC,CAAC;SACN;aAAM;YACH,MAAM,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC;YAC3B,iBAAM,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE;gBAC/D,cAAc,CAAC,IAAI,CAAC,wBAAwB,GAAG,EAAE,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACpF,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACzD,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAA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gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC/D,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QACtD,MAAM,qBAAqB,GAAG,MAAM,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE3E,cAAc,CAAC,IAAI,CAAC,wBAAwB,GAAG,IAAI,EAAE,qBAAqB,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAC/F,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACzC,iBAAM,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC3E,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QACtD,MAAM,iBAAM,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEzD,cAAc,CAAC,IAAI,CAAC,oCAAoC,GAAG,IAAI,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
@@ -3,43 +3,42 @@ let electronSocket;
|
||||
|
||||
export = (socket: SocketIO.Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('showMessageBox', (browserWindow, options, guid) => {
|
||||
socket.on('showMessageBox', async (browserWindow, options, guid) => {
|
||||
if ('id' in browserWindow) {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
|
||||
dialog.showMessageBox(window, options, (response, checkboxChecked) => {
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [response, checkboxChecked]);
|
||||
});
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(window, options);
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
} else {
|
||||
const id = guid || options;
|
||||
dialog.showMessageBox(browserWindow, (response, checkboxChecked) => {
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [response, checkboxChecked]);
|
||||
});
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(browserWindow);
|
||||
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('showOpenDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showOpenDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
dialog.showOpenDialog(window, options, (filePaths) => {
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, filePaths || []);
|
||||
});
|
||||
const openDialogReturnValue = await dialog.showOpenDialog(window, options);
|
||||
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, openDialogReturnValue.filePaths || []);
|
||||
});
|
||||
|
||||
socket.on('showSaveDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showSaveDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
dialog.showSaveDialog(window, options, (filename) => {
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, filename || '');
|
||||
});
|
||||
const saveDialogReturnValue = await dialog.showSaveDialog(window, options);
|
||||
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, saveDialogReturnValue.filePath || '');
|
||||
});
|
||||
|
||||
socket.on('showErrorBox', (title, content) => {
|
||||
dialog.showErrorBox(title, content);
|
||||
});
|
||||
|
||||
socket.on('showCertificateTrustDialog', (browserWindow, options, guid) => {
|
||||
socket.on('showCertificateTrustDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
dialog.showCertificateTrustDialog(window, options, () => {
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
});
|
||||
await dialog.showCertificateTrustDialog(window, options);
|
||||
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
});
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user