mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 13:44:47 +00:00
Compare commits
252 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2514ed5bc | ||
|
|
b453278803 | ||
|
|
a244382383 | ||
|
|
a82e714ef8 | ||
|
|
b339485fdc | ||
|
|
551635867d | ||
|
|
941b8cf5c2 | ||
|
|
06b01f75da | ||
|
|
e4b1f6586e | ||
|
|
0657a274d4 | ||
|
|
e3acc79c4f | ||
|
|
73c1d1cd46 | ||
|
|
c2a8c627b9 | ||
|
|
1862094861 | ||
|
|
0ad89c7d22 | ||
|
|
0af664b8a6 | ||
|
|
afcd113675 | ||
|
|
0e22ee3fd3 | ||
|
|
ce0cdf39c6 | ||
|
|
305544ab42 | ||
|
|
78d9d601b1 | ||
|
|
fdd643ba48 | ||
|
|
29a257251f | ||
|
|
3676db89d3 | ||
|
|
29011189f8 | ||
|
|
9d7d859764 | ||
|
|
5cdda5595a | ||
|
|
62fe944ae3 | ||
|
|
617eb15df8 | ||
|
|
bff71dc86a | ||
|
|
f0280f420a | ||
|
|
9f7809810f | ||
|
|
e610c96550 | ||
|
|
f3bd3d07d5 | ||
|
|
0e8cfec689 | ||
|
|
c1b3d422d5 | ||
|
|
fc12363e11 | ||
|
|
02f2fd770c | ||
|
|
5ee1918bb4 | ||
|
|
2213c61746 | ||
|
|
3cdff747fe | ||
|
|
476cc9e505 | ||
|
|
fb8ca94e8e | ||
|
|
c94702fc60 | ||
|
|
cd9e06d5db | ||
|
|
613f0a05b3 | ||
|
|
de2ce85a5c | ||
|
|
e5d47e077b | ||
|
|
ac77ccce9f | ||
|
|
504cc59760 | ||
|
|
0ee7097f31 | ||
|
|
2d93d959f7 | ||
|
|
a4d261a4e7 | ||
|
|
3838fe8971 | ||
|
|
b5e69f5dda | ||
|
|
55a3f10d37 | ||
|
|
7e494518f3 | ||
|
|
4596492cd9 | ||
|
|
dd5bfd3961 | ||
|
|
5d907864d8 | ||
|
|
30941df39c | ||
|
|
3588a8696d | ||
|
|
876bb98d92 | ||
|
|
427b57a002 | ||
|
|
cc0b15c61e | ||
|
|
8a0276daf9 | ||
|
|
e94196504e | ||
|
|
6076c727d1 | ||
|
|
300dc49dde | ||
|
|
ce0f3fd61e | ||
|
|
12f5eae65c | ||
|
|
3ef44cf878 | ||
|
|
41fa8e9e74 | ||
|
|
49e21de465 | ||
|
|
d2f6308dd2 | ||
|
|
f06b95803f | ||
|
|
b9feff3436 | ||
|
|
335489d2d9 | ||
|
|
6fe0c6f085 | ||
|
|
f82d185865 | ||
|
|
550e2c2625 | ||
|
|
61f54ebd55 | ||
|
|
c8c818a77a | ||
|
|
fc590f55d8 | ||
|
|
5fbe01df30 | ||
|
|
dbf4d0f720 | ||
|
|
f996b3023e | ||
|
|
7f62e7299b | ||
|
|
b803e42a73 | ||
|
|
da1838db60 | ||
|
|
8af1f50b88 | ||
|
|
c4f2188c62 | ||
|
|
e73655bd68 | ||
|
|
758424d3ce | ||
|
|
7518acb3c2 | ||
|
|
5522addc0b | ||
|
|
7f204c2a42 | ||
|
|
de13f49bb6 | ||
|
|
bca37228d9 | ||
|
|
e17a36f7cb | ||
|
|
deccebb582 | ||
|
|
776ccc21e8 | ||
|
|
d0c92cac85 | ||
|
|
b525bf1a9a | ||
|
|
6337cac588 | ||
|
|
5d4509babe | ||
|
|
3eef85cddf | ||
|
|
3f582d6c4e | ||
|
|
18c5a65d6d | ||
|
|
f8bbb138d8 | ||
|
|
7880d56e4c | ||
|
|
c16a888699 | ||
|
|
814e046d5c | ||
|
|
d2457203bc | ||
|
|
a70304948a | ||
|
|
a49b2ce278 | ||
|
|
1577146187 | ||
|
|
d61f20dd67 | ||
|
|
f7217b417f | ||
|
|
e136ed4127 | ||
|
|
7489543c75 | ||
|
|
cbf3032617 | ||
|
|
68c54b9917 | ||
|
|
26d10fca38 | ||
|
|
bd15587079 | ||
|
|
42613f5b56 | ||
|
|
62117df108 | ||
|
|
f68ea25cba | ||
|
|
4e9de2abfa | ||
|
|
a08d274dc1 | ||
|
|
3dea16798b | ||
|
|
bf8c7c8fa1 | ||
|
|
06724f6eae | ||
|
|
83e579d44b | ||
|
|
ed67aa8072 | ||
|
|
f1ceaa208e | ||
|
|
5e005499ef | ||
|
|
975e4020dc | ||
|
|
15ce35a7d9 | ||
|
|
de1637672a | ||
|
|
6b75f63135 | ||
|
|
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 | ||
|
|
e295558258 | ||
|
|
e67f6c500b | ||
|
|
23015a9f3d | ||
|
|
7daac2d04e |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -260,3 +260,6 @@ paket-files/
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Mac Only settings file
|
||||
.DS_Store
|
||||
|
||||
@@ -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:
|
||||
|
||||
32
.vscode/tasks.json
vendored
32
.vscode/tasks.json
vendored
@@ -1,16 +1,18 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "dotnet",
|
||||
"isShellCommand": true,
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
"args": [
|
||||
"${workspaceRoot}/ElectronNET.CLI/ElectronNET.CLI.csproj"
|
||||
],
|
||||
"isBuildCommand": true,
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
"version": "2.0.0",
|
||||
"command": "dotnet",
|
||||
"args": [],
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"command": "dotnet",
|
||||
"args": ["build", "${workspaceRoot}/ElectronNET.CLI/ElectronNET.CLI.csproj"],
|
||||
"problemMatcher": "$msCompile",
|
||||
"group": {
|
||||
"_id": "build",
|
||||
"isDefault": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
160
Changelog.md
160
Changelog.md
@@ -1,13 +1,169 @@
|
||||
# Not released
|
||||
|
||||
# 23.6.2
|
||||
|
||||
# Released
|
||||
|
||||
# 8.31.1
|
||||
# 23.6.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* New Feature: Upgrade to .NET 6 support
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Electron 8.2.3 support, but not all new features (we search contributors)
|
||||
* New Feature: Native Electron 23.2.0 support, but not all new API features included (we search contributors)
|
||||
* New Feature: Upgrade to .NET 6 support
|
||||
* New Feature: Changed Web-Socket .NET Library to [SocketIOClient](https://github.com/doghappy/socket.io-client-csharp)
|
||||
* Breaking Changes: We removed deprecated API events/methods from ElectronNET.API [(More Details)](https://www.electronjs.org/docs/latest/breaking-changes)
|
||||
|
||||
# 13.5.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* New Feature: Using exit code instead of seek for the term 'error' (thanks [TSrgy](https://github.com/TSrgy)) [\#562](https://github.com/ElectronNET/Electron.NET/pull/562)
|
||||
* Fixed bug: Allow for property overrides to be passed in (thanks [danatcofo](https://github.com/danatcofo)) [\#531](https://github.com/ElectronNET/Electron.NET/pull/531)
|
||||
Use `/p:propertyName=value` or `/property:propertyName=value` to pass in property overrides. This is equivalent to the `-p:` option documented here: [https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish)
|
||||
* Fixed bug: Add ability to pass an argument for "Version" for both the "dotnet publish" and "electron-builder" commands (thanks [tub5](https://github.com/tub5)) [\#546](https://github.com/ElectronNET/Electron.NET/pull/546)
|
||||
* Fixed bug: Version flag not persisting with the referenced executable (thanks [tub5](https://github.com/tub5)) [\#585](https://github.com/ElectronNET/Electron.NET/pull/585)
|
||||
* Fixed bug: Changes PublishSingleFile default to false for NET5 compatibility (thanks [cristiangiagante](https://github.com/cristiangiagante)) [\#570](https://github.com/ElectronNET/Electron.NET/pull/570)
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Native Electron 13.1.5 support, but not all new features (we search contributors)
|
||||
* Breaking API Changes (from native Electron 13.1.5):
|
||||
- `Shell.MoveItemToTrashAsync` renamed with `Shell.TrashItemAsync`
|
||||
- The deprecated extension APIs have been removed: `BrowserWindow.GetAllExtensionsAsync()`, `BrowserWindow.RemoveExtension()`, `BrowserWindow.AddExtensionAsync()`. Use the session APIs instead: `Session.GetAllExtensionsAsync()`, `Session.RemoveExtension()`, `Session.LoadExtensionAsync()`.
|
||||
* New Feature: singleInstance handle command line arguments [\#520](https://github.com/ElectronNET/Electron.NET/issues/520)
|
||||
* New Feature: Add WebContents [insertCSS](https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options) functionality (thanks [nfichter](https://github.com/nfichter)) [\#559](https://github.com/ElectronNET/Electron.NET/pull/559)
|
||||
* New Feature: Allow IpcMain to send IPC messages to BrowserViews (thanks [nfichter](https://github.com/nfichter)) [\#560](https://github.com/ElectronNET/Electron.NET/pull/560)
|
||||
* New Feature: Add support for proxies that require basic username/password authentication (thanks [nfichter](https://github.com/nfichter)) [\#561](https://github.com/ElectronNET/Electron.NET/pull/561)
|
||||
* New Feature: Add PostData to LoadURLOptions to allow http-posts in LoadURL calls (thanks [Funkrusha](https://github.com/Funkrusha)) [\#547](https://github.com/ElectronNET/Electron.NET/pull/547)
|
||||
* Fixed bug: Fix splash screen interaction causing crashes, ghost dragging, and resizable behavior #540 (thanks [MiniguyBrendan](https://github.com/MiniguyBrendan)) [\#540](https://github.com/ElectronNET/Electron.NET/pull/540)
|
||||
* Fixed bug: Vibrancy serialization fix (thanks [tantumalice](https://github.com/tantumalice)) [\#573](https://github.com/ElectronNET/Electron.NET/pull/573)
|
||||
|
||||
# 11.5.1
|
||||
|
||||
ElectronNET.CLI:
|
||||
|
||||
* New Feature: Added new build and start commandline options for single exe (thanks [nathanwienand](https://github.com/nathanwienand)) [\#506](https://github.com/ElectronNET/Electron.NET/pull/506)
|
||||
* New Feature: Set a description of the app in `electron.manifest.json` (thanks [BurtsevC](https://github.com/BurtsevC)) [\#433](https://github.com/ElectronNET/Electron.NET/pull/433)
|
||||
* New Feature: Set a target for the start command (thanks [gabecook](https://github.com/gabecook)) [\#463](https://github.com/ElectronNET/Electron.NET/pull/463)
|
||||
* New Feature: `electronize init` support for F# projects (thanks [kojo12228](https://github.com/kojo12228)) [\#457](https://github.com/ElectronNET/Electron.NET/pull/457)
|
||||
* New Feature: Linux support for the buildAll.sh (thanks [duncanawoods](https://github.com/duncanawoods)) [\#465](https://github.com/ElectronNET/Electron.NET/pull/465)
|
||||
* Fixed bug: ERR_UNKNOWN_URL_SCHEME by intercepting file:// protocol (thanks [duncanawoods](https://github.com/duncanawoods)) [\#467](https://github.com/ElectronNET/Electron.NET/pull/467)
|
||||
|
||||
ElectronNET.API:
|
||||
|
||||
* New Feature: Native Electron 11.1.1 support, but not all new features (we search contributors)
|
||||
* Breaking API Changes (from native Electron 11.0): - Removed: BrowserView.{destroy, fromId, fromWebContents, getAllViews} and id property of BrowserView
|
||||
* New Feature: Upgrade to .NET 5 (thanks [scottkuhl](https://github.com/scottkuhl)) [\#509](https://github.com/ElectronNET/Electron.NET/pull/509)
|
||||
* New Feature: Extension Method for adding the Electron static class members to the standard MS DI Containers, this is a QOL issue only. `services.AddElectron()` (thanks [danatcofo](https://github.com/danatcofo )) [\#528](https://github.com/ElectronNET/Electron.NET/pull/528)
|
||||
* New Feature: SetMenu completed for the Dock (MacOS) (thanks [danatcofo](https://github.com/danatcofo )) [\#528](https://github.com/ElectronNET/Electron.NET/pull/528)
|
||||
|
||||
Example for the Dock Menu
|
||||
|
||||
`Electron.Dock.SetMenu(new [] {
|
||||
new MenuItem {
|
||||
Label = "Dock Menu Item",
|
||||
Click = () => {
|
||||
// do something
|
||||
}
|
||||
},
|
||||
});`
|
||||
|
||||
Example for consuming the activate event (MacOs only)
|
||||
|
||||
`Electron.App.On("activate", obj => {
|
||||
var hasWindows = (bool)obj;
|
||||
// do something
|
||||
});`
|
||||
|
||||
* New Feature: On and Once implementations for the App and Tray to cover the plethora of events that are not mapped explicitly in those two modules. (thanks [danatcofo](https://github.com/danatcofo )) [\#528](https://github.com/ElectronNET/Electron.NET/pull/528)
|
||||
* New Feature: Adding the `EnableRemoteModule` property to the WebPreferences object. As of Electron 10, this property defaulted to false and without it exposed you can't use the remote module within a window. (thanks [danatcofo](https://github.com/danatcofo )) [\#528](https://github.com/ElectronNET/Electron.NET/pull/528)
|
||||
* New Feature: Adding a configurable default electron port. (thanks [aarong-av](https://github.com/aarong-av)) [\#505](https://github.com/ElectronNET/Electron.NET/pull/505)
|
||||
* New Feature: Added support for launching the application with a file on MacOS (thanks [dlitty](https://github.com/dlitty)) [\#478](https://github.com/ElectronNET/Electron.NET/pull/478)
|
||||
* Improved: Avoid Blocking Calls in App and AutoUpdater (thanks [freosc](https://github.com/freosc)) [\#474](https://github.com/ElectronNET/Electron.NET/pull/474)
|
||||
* Fixed bug: Maintain references between socket.io connection events (thanks [danatcofo](https://github.com/danatcofo )) [\#468](https://github.com/ElectronNET/Electron.NET/pull/486)
|
||||
* Fixed bug: Set default WebPreferences.DefaultFontSize (thanks [duncanawoods](https://github.com/duncanawoods)) [\#468](https://github.com/ElectronNET/Electron.NET/pull/468)
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -182,11 +185,48 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The current application version
|
||||
/// </summary>
|
||||
public Task<SemVer> CurrentVersionAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run<SemVer>(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<SemVer>();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdater-currentVersion-get-reply", (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-currentVersion-get-reply");
|
||||
SemVer version = ((JObject)result).ToObject<SemVer>();
|
||||
taskCompletionSource.SetResult(version);
|
||||
});
|
||||
BridgeConnector.Socket.Emit("autoUpdater-currentVersion-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the update channel. Not applicable for GitHub.
|
||||
/// Doesn’t return channel from the update configuration, only if was previously set.
|
||||
/// </summary>
|
||||
[Obsolete("Use the asynchronous version ChannelAsync instead")]
|
||||
public string Channel
|
||||
{
|
||||
get
|
||||
{
|
||||
return ChannelAsync.Result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the update channel. Not applicable for GitHub.
|
||||
/// Doesn’t return channel from the update configuration, only if was previously set.
|
||||
/// </summary>
|
||||
public Task<string> ChannelAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -199,11 +239,45 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Off("autoUpdater-channel-get-reply");
|
||||
taskCompletionSource.SetResult(result.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdater-channel-get");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}).Result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The request headers.
|
||||
/// </summary>
|
||||
public Task<Dictionary<string, string>> RequestHeadersAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Dictionary<string, string>>();
|
||||
BridgeConnector.Socket.On("autoUpdater-requestHeaders-get-reply", (headers) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdater-requestHeaders-get-reply");
|
||||
Dictionary<string, string> result = ((JObject)headers).ToObject<Dictionary<string, string>>();
|
||||
taskCompletionSource.SetResult(result);
|
||||
});
|
||||
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-get");
|
||||
return taskCompletionSource.Task;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The request headers.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> RequestHeaders
|
||||
{
|
||||
set
|
||||
{
|
||||
BridgeConnector.Socket.Emit("autoUpdater-requestHeaders-set", JObject.FromObject(value, _jsonSerializer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,9 +490,26 @@ namespace ElectronNET.API
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesComplete" + guid, (updateCheckResult) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
taskCompletionSource.SetException(ex);
|
||||
}
|
||||
});
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesError" + guid, (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesComplete" + guid);
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesError" + guid);
|
||||
string message = "An error occurred in CheckForUpdatesAsync";
|
||||
if (error != null && !string.IsNullOrEmpty(error.ToString()))
|
||||
message = JsonConvert.SerializeObject(error);
|
||||
taskCompletionSource.SetException(new Exception(message));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdates", guid);
|
||||
@@ -438,9 +529,29 @@ namespace ElectronNET.API
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid, (updateCheckResult) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
|
||||
if (updateCheckResult == null)
|
||||
taskCompletionSource.SetResult(null);
|
||||
else
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
taskCompletionSource.SetException(ex);
|
||||
}
|
||||
});
|
||||
BridgeConnector.Socket.On("autoUpdaterCheckForUpdatesAndNotifyError" + guid, (error) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyComplete" + guid);
|
||||
taskCompletionSource.SetResult(JObject.Parse(updateCheckResult.ToString()).ToObject<UpdateCheckResult>());
|
||||
BridgeConnector.Socket.Off("autoUpdaterCheckForUpdatesAndNotifyError" + guid);
|
||||
string message = "An error occurred in autoUpdaterCheckForUpdatesAndNotify";
|
||||
if (error != null)
|
||||
message = JsonConvert.SerializeObject(error);
|
||||
taskCompletionSource.SetException(new Exception(message));
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("autoUpdaterCheckForUpdatesAndNotify", guid);
|
||||
@@ -501,5 +612,10 @@ namespace ElectronNET.API
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,27 @@
|
||||
using Quobject.SocketIoClientDotNet.Client;
|
||||
using System;
|
||||
|
||||
namespace ElectronNET.API
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
internal static class BridgeConnector
|
||||
{
|
||||
private static Socket _socket;
|
||||
private static object _syncRoot = new object();
|
||||
private static SocketIoFacade _socket;
|
||||
private static readonly object SyncRoot = new();
|
||||
|
||||
public static Socket Socket
|
||||
public static SocketIoFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_socket == null && HybridSupport.IsElectronActive)
|
||||
if (_socket == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (_socket == null && HybridSupport.IsElectronActive)
|
||||
if (_socket == null)
|
||||
{
|
||||
_socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
|
||||
_socket.On(Socket.EVENT_CONNECT, () =>
|
||||
{
|
||||
Console.WriteLine("BridgeConnector connected!");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(_socket == null && !HybridSupport.IsElectronActive)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_socket == null && !HybridSupport.IsElectronActive)
|
||||
{
|
||||
_socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false });
|
||||
|
||||
string socketUrl = HybridSupport.IsElectronActive
|
||||
? $"http://localhost:{BridgeSettings.SocketPort}"
|
||||
: "http://localhost";
|
||||
|
||||
_socket = new SocketIoFacade(socketUrl);
|
||||
_socket.Connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,4 +30,4 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,6 @@
|
||||
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
|
||||
@@ -29,30 +26,6 @@ namespace ElectronNET.API
|
||||
/// </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.
|
||||
///
|
||||
@@ -83,8 +56,6 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
internal Action<BrowserView> Destroyed;
|
||||
|
||||
/// <summary>
|
||||
/// BrowserView
|
||||
/// </summary>
|
||||
@@ -97,18 +68,6 @@ namespace ElectronNET.API
|
||||
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>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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(),
|
||||
|
||||
54
ElectronNET.API/Converter/ModifierTypeListConverter.cs
Normal file
54
ElectronNET.API/Converter/ModifierTypeListConverter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ElectronNET.API.Converter;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ModifierTypeListConverter : JsonConverter<List<ModifierType>>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="objectType"></param>
|
||||
/// <param name="existingValue"></param>
|
||||
/// <param name="hasExistingValue"></param>
|
||||
/// <param name="serializer"></param>
|
||||
/// <returns></returns>
|
||||
public override List<ModifierType> ReadJson(JsonReader reader, Type objectType, List<ModifierType> existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
var token = JToken.Load(reader);
|
||||
|
||||
if (token.Type == JTokenType.Null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return token.ToObject<List<string>>().Select(m => (ModifierType)Enum.Parse(typeof(ModifierType), m)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="serializer"></param>
|
||||
public override void WriteJson(JsonWriter writer, List<ModifierType> value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
|
||||
foreach (var modifier in value)
|
||||
{
|
||||
writer.WriteValue(modifier.ToString());
|
||||
}
|
||||
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
|
||||
232
ElectronNET.API/Dock.cs
Normal file
232
ElectronNET.API/Dock.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
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>
|
||||
/// Gets the dock menu items.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The menu items.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the application's dock menu.
|
||||
/// </summary>
|
||||
public void SetMenu(MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("dock-setMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("dockMenuItemClicked");
|
||||
BridgeConnector.Socket.On("dockMenuItemClicked", (id) => {
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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,11 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageOutputPath>..\artifacts</PackageOutputPath>
|
||||
<PackageId>ElectronNET.API</PackageId>
|
||||
<Authors>Gregor Biswanger, Robert Muehsig</Authors>
|
||||
<Authors>Gregor Biswanger, Florian Rappl</Authors>
|
||||
<Company />
|
||||
<Product>Electron.NET</Product>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
@@ -21,11 +20,9 @@ This package contains the API to access the "native" electron API.</Description>
|
||||
<Version>99.0.0.0</Version>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="PackageIcon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
|
||||
<Exec Command="$(ProjectDir)devCleanup.cmd" IgnoreExitCode="true" />
|
||||
</Target>
|
||||
@@ -33,14 +30,19 @@ This package contains the API to access the "native" electron API.</Description>
|
||||
<Exec Command="$(ProjectDir)devCleanup.sh" IgnoreExitCode="true" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SocketIoClientDotNet" Version="1.0.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SocketIOClient" Version="3.0.8" />
|
||||
<PackageReference Include="SocketIOClient.Newtonsoft.Json" Version="3.0.7" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.410601">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</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; }
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
18
ElectronNET.API/Entities/Blob.cs
Normal file
18
ElectronNET.API/Entities/Blob.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Blob : IPostData
|
||||
{
|
||||
/// <summary>
|
||||
/// The object represents a Blob
|
||||
/// </summary>
|
||||
public string Type { get; } = "blob";
|
||||
|
||||
/// <summary>
|
||||
/// The UUID of the Blob being uploaded
|
||||
/// </summary>
|
||||
public string BlobUUID { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,17 @@
|
||||
/// See BrowserWindow.
|
||||
/// </summary>
|
||||
public WebPreferences WebPreferences { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A proxy to set on creation in the format host:port.
|
||||
/// The proxy can be alternatively set using the BrowserView.WebContents.SetProxyAsync function.
|
||||
/// </summary>
|
||||
public string Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The credentials of the Proxy in the format username:password.
|
||||
/// These will only be used if the Proxy field is also set.
|
||||
/// </summary>
|
||||
public string ProxyCredentials { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,5 +258,17 @@ namespace ElectronNET.API.Entities
|
||||
/// Settings of web page's features.
|
||||
/// </summary>
|
||||
public WebPreferences WebPreferences { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A proxy to set on creation in the format host:port.
|
||||
/// The proxy can be alternatively set using the BrowserWindow.WebContents.SetProxyAsync function.
|
||||
/// </summary>
|
||||
public string Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The credentials of the Proxy in the format username:password.
|
||||
/// These will only be used if the Proxy field is also set.
|
||||
/// </summary>
|
||||
public string ProxyCredentials { 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; }
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
44
ElectronNET.API/Entities/Extension.cs
Normal file
44
ElectronNET.API/Entities/Extension.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Docs: https://electronjs.org/docs/api/structures/extension
|
||||
/// </summary>
|
||||
public class Extension
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Copy of the extension's manifest data.
|
||||
/// </summary>
|
||||
public dynamic Manifest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The extension's file path.
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The extension's `chrome-extension://` URL.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Version { 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; }
|
||||
}
|
||||
|
||||
16
ElectronNET.API/Entities/IPostData.cs
Normal file
16
ElectronNET.API/Entities/IPostData.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface to use Electrons PostData Object
|
||||
/// </summary>
|
||||
public interface IPostData
|
||||
{
|
||||
/// <summary>
|
||||
/// One of the following:
|
||||
/// rawData - <see cref="UploadRawData"/> The data is available as a Buffer, in the rawData field.
|
||||
/// file - <see cref="UploadFile"/> The object represents a file. The filePath, offset, length and modificationTime fields will be used to describe the file.
|
||||
/// blob - <see cref="Blob"/> The object represents a Blob. The blobUUID field will be used to describe the Blob.
|
||||
/// </summary>
|
||||
public string Type { get; }
|
||||
}
|
||||
}
|
||||
81
ElectronNET.API/Entities/InputEvent.cs
Normal file
81
ElectronNET.API/Entities/InputEvent.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Collections.Generic;
|
||||
using ElectronNET.API.Converter;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class InputEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.key.
|
||||
/// </summary>
|
||||
public string Key { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.code.
|
||||
/// </summary>
|
||||
public string Code { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.repeat.
|
||||
/// </summary>
|
||||
public bool IsAutoRepeat { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.isComposing.
|
||||
/// </summary>
|
||||
public bool IsComposing { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.shiftKey.
|
||||
/// </summary>
|
||||
public bool Shift { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.controlKey.
|
||||
/// </summary>
|
||||
public bool Control { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.altKey.
|
||||
/// </summary>
|
||||
public bool Alt { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.metaKey.
|
||||
/// </summary>
|
||||
public bool Meta { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to KeyboardEvent.location.
|
||||
/// </summary>
|
||||
public int Location { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// An array of modifiers of the event, can be `shift`, `control`, `ctrl`, `alt`,
|
||||
/// `meta`, `command`, `cmd`, `isKeypad`, `isAutoRepeat`, `leftButtonDown`,
|
||||
/// `middleButtonDown`, `rightButtonDown`, `capsLock`, `numLock`, `left`, `right`
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ModifierTypeListConverter))]
|
||||
public List<ModifierType> Modifiers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Can be `undefined`, `mouseDown`, `mouseUp`, `mouseMove`, `mouseEnter`,
|
||||
/// `mouseLeave`, `contextMenu`, `mouseWheel`, `rawKeyDown`, `keyDown`, `keyUp`,
|
||||
/// `gestureScrollBegin`, `gestureScrollEnd`, `gestureScrollUpdate`,
|
||||
/// `gestureFlingStart`, `gestureFlingCancel`, `gesturePinchBegin`,
|
||||
/// `gesturePinchEnd`, `gesturePinchUpdate`, `gestureTapDown`, `gestureShowPress`,
|
||||
/// `gestureTap`, `gestureTapCancel`, `gestureShortPress`, `gestureLongPress`,
|
||||
/// `gestureLongTap`, `gestureTwoFingerTap`, `gestureTapUnconfirmed`,
|
||||
/// `gestureDoubleTap`, `touchStart`, `touchMove`, `touchEnd`, `touchCancel`,
|
||||
/// `touchScrollStarted`, `pointerDown`, `pointerUp`, `pointerMove`,
|
||||
/// `pointerRawUpdate`, `pointerCancel` or `pointerCausedUaAction`.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public InputEventType Type { get; set; }
|
||||
}
|
||||
}
|
||||
201
ElectronNET.API/Entities/InputEventType.cs
Normal file
201
ElectronNET.API/Entities/InputEventType.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum InputEventType
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
undefined,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseDown,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseUp,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseMove,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseEnter,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseLeave,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
contextMenu,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
mouseWheel,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
rawKeyDown,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
keyDown,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
keyUp,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureScrollBegin,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureScrollEnd,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureScrollUpdate,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureFlingStart,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureFlingCancel,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gesturePinchBegin,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gesturePinchEnd,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gesturePinchUpdate,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureTapDown,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureShowPress,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureTap,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureTapCancel,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureShortPress,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureLongPress,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureLongTap,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureTwoFingerTap,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureTapUnconfirmed,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
gestureDoubleTap,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
touchStart,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
touchMove,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
touchEnd,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
touchCancel,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
touchScrollStarted,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerDown,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerUp,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerMove,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerRawUpdate,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerCancel,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
pointerCausedUaAction
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,5 +26,11 @@
|
||||
/// Extra headers for the request.
|
||||
/// </summary>
|
||||
public string ExtraHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PostData Object for the request.
|
||||
/// Can be <see cref="UploadRawData"/>, <see cref="UploadFile"/> or <see cref="Blob"/>
|
||||
/// </summary>
|
||||
public IPostData[] PostData { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
|
||||
33
ElectronNET.API/Entities/Margins.cs
Normal file
33
ElectronNET.API/Entities/Margins.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Margins
|
||||
{
|
||||
/// <summary>
|
||||
/// Can be `default`, `none`, `printableArea`, or `custom`. If `custom` is chosen,
|
||||
/// you will also need to specify `top`, `bottom`, `left`, and `right`.
|
||||
/// </summary>
|
||||
public string MarginType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The top margin of the printed web page, in pixels.
|
||||
/// </summary>
|
||||
public int Top { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The bottom margin of the printed web page, in pixels.
|
||||
/// </summary>
|
||||
public int Bottom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The left margin of the printed web page, in pixels.
|
||||
/// </summary>
|
||||
public int Left { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The right margin of the printed web page, in pixels.
|
||||
/// </summary>
|
||||
public int Right { 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>
|
||||
|
||||
87
ElectronNET.API/Entities/ModifierType.cs
Normal file
87
ElectronNET.API/Entities/ModifierType.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the possible modifier keys for a keyboard input.
|
||||
/// </summary>
|
||||
public enum ModifierType
|
||||
{
|
||||
/// <summary>
|
||||
/// The Shift key.
|
||||
/// </summary>
|
||||
shift,
|
||||
|
||||
/// <summary>
|
||||
/// The Control key.
|
||||
/// </summary>
|
||||
control,
|
||||
|
||||
/// <summary>
|
||||
/// The Control key (alias for control).
|
||||
/// </summary>
|
||||
ctrl,
|
||||
|
||||
/// <summary>
|
||||
/// The Alt key.
|
||||
/// </summary>
|
||||
alt,
|
||||
|
||||
/// <summary>
|
||||
/// The Meta key.
|
||||
/// </summary>
|
||||
meta,
|
||||
|
||||
/// <summary>
|
||||
/// The Command key.
|
||||
/// </summary>
|
||||
command,
|
||||
|
||||
/// <summary>
|
||||
/// The Command key (alias for command).
|
||||
/// </summary>
|
||||
cmd,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the keypad modifier key is pressed.
|
||||
/// </summary>
|
||||
isKeypad,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the key is an auto-repeated key.
|
||||
/// </summary>
|
||||
isAutoRepeat,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the left mouse button is pressed.
|
||||
/// </summary>
|
||||
leftButtonDown,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the middle mouse button is pressed.
|
||||
/// </summary>
|
||||
middleButtonDown,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the right mouse button is pressed.
|
||||
/// </summary>
|
||||
rightButtonDown,
|
||||
|
||||
/// <summary>
|
||||
/// The Caps Lock key.
|
||||
/// </summary>
|
||||
capsLock,
|
||||
|
||||
/// <summary>
|
||||
/// The Num Lock key.
|
||||
/// </summary>
|
||||
numlock,
|
||||
|
||||
/// <summary>
|
||||
/// The Left key.
|
||||
/// </summary>
|
||||
left,
|
||||
|
||||
/// <summary>
|
||||
/// The Right key.
|
||||
/// </summary>
|
||||
right
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,63 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PrintToPDFOptions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Paper orientation. `true` for landscape, `false` for portrait. Defaults to false.
|
||||
/// </summary>
|
||||
public class PrintToPDFOptions
|
||||
{
|
||||
/// <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; }
|
||||
public bool Landscape { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Specify page size of the generated PDF. Can be A3, A4, A5, Legal, Letter,
|
||||
/// Tabloid or an Object containing height and width in microns.
|
||||
/// </summary>
|
||||
public string PageSize { get; set; }
|
||||
/// <summary>
|
||||
/// Whether to display header and footer. Defaults to false.
|
||||
/// </summary>
|
||||
public bool DisplayHeaderFooter { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to print CSS backgrounds.
|
||||
/// </summary>
|
||||
public bool PrintBackground { get; set; }
|
||||
/// <summary>
|
||||
/// Whether to print background graphics. Defaults to false.
|
||||
/// </summary>
|
||||
public bool PrintBackground { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to print selection only.
|
||||
/// </summary>
|
||||
public bool PrintSelectionOnly { get; set; }
|
||||
/// <summary>
|
||||
/// Scale of the webpage rendering. Defaults to 1.
|
||||
/// </summary>
|
||||
public double Scale { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// true for landscape, false for portrait.
|
||||
/// </summary>
|
||||
public bool Landscape { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Specify page size of the generated PDF. Can be `A0`, `A1`, `A2`, `A3`, `A4`,
|
||||
/// `A5`, `A6`, `Legal`, `Letter`, `Tabloid`, `Ledger`, or an Object containing
|
||||
/// `height` and `width` in inches. Defaults to `Letter`.
|
||||
/// </summary>
|
||||
public string PageSize { get; set; } = "Letter";
|
||||
|
||||
/// <summary>
|
||||
/// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string,
|
||||
/// which means print all pages.
|
||||
/// </summary>
|
||||
public string PageRanges { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// HTML template for the print header. Should be valid HTML markup with following
|
||||
/// classes used to inject printing values into them: `date` (formatted print date),
|
||||
/// `title` (document title), `url` (document location), `pageNumber` (current page
|
||||
/// number) and `totalPages` (total pages in the document). For example, `<span class="title"></span>`
|
||||
/// would generate span containing the title.
|
||||
/// </summary>
|
||||
public string HeaderTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTML template for the print footer. Should use the same format as the
|
||||
/// `headerTemplate`.
|
||||
/// </summary>
|
||||
public string FooterTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to prefer page size as defined by css. Defaults to false, in
|
||||
/// which case the content will be scaled to fit the paper size.
|
||||
/// </summary>
|
||||
public bool PreferCSSPageSize { get; set; } = false;
|
||||
|
||||
public Margins Margins { 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class RemoveClientCertificate
|
||||
{
|
||||
/// <summary>
|
||||
/// Origin of the server whose associated client certificate must be removed from
|
||||
/// the cache.
|
||||
/// </summary>
|
||||
public string Origin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// clientCertificate.
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="origin">Origin of the server whose associated client certificate
|
||||
/// must be removed from the cache.</param>
|
||||
/// <param name="type">clientCertificate.</param>
|
||||
public RemoveClientCertificate(string origin, string type)
|
||||
{
|
||||
Origin = origin;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
59
ElectronNET.API/Entities/SemVer.cs
Normal file
59
ElectronNET.API/Entities/SemVer.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SemVer
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Raw { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Loose { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SemVerOptions Options { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Major { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Minor { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Patch { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string[] Build { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string[] Prerelease { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SemVerOptions {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool? Loose { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool? IncludePrerelease { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
34
ElectronNET.API/Entities/UploadFile.cs
Normal file
34
ElectronNET.API/Entities/UploadFile.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class UploadFile : IPostData
|
||||
{
|
||||
/// <summary>
|
||||
/// The object represents a file.
|
||||
/// </summary>
|
||||
public string Type { get; } = "file";
|
||||
|
||||
/// <summary>
|
||||
/// The path of the file being uploaded.
|
||||
/// </summary>
|
||||
public string FilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The offset from the beginning of the file being uploaded, in bytes. Defaults to 0.
|
||||
/// </summary>
|
||||
public long Offset { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The length of the file being uploaded, <see cref="Offset"/>. Defaults to 0.
|
||||
/// If set to -1, the whole file will be uploaded.
|
||||
/// </summary>
|
||||
public long Length { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The modification time of the file represented by a double, which is the number of seconds since the UNIX Epoch (Jan 1, 1970)
|
||||
/// </summary>
|
||||
public double ModificationTime { get; set; }
|
||||
}
|
||||
}
|
||||
18
ElectronNET.API/Entities/UploadRawData.cs
Normal file
18
ElectronNET.API/Entities/UploadRawData.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class UploadRawData : IPostData
|
||||
{
|
||||
/// <summary>
|
||||
/// The data is available as a Buffer, in the rawData field.
|
||||
/// </summary>
|
||||
public string Type { get; } = "rawData";
|
||||
|
||||
/// <summary>
|
||||
/// The raw bytes of the post data in a Buffer.
|
||||
/// </summary>
|
||||
public byte[] Bytes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -10,7 +10,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// The appearance based
|
||||
/// </summary>
|
||||
[JsonProperty("appearance-based")]
|
||||
[EnumMember(Value = "appearance-based")]
|
||||
appearanceBased,
|
||||
|
||||
/// <summary>
|
||||
@@ -51,13 +51,13 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// The medium light
|
||||
/// </summary>
|
||||
[JsonProperty("medium-light")]
|
||||
[EnumMember(Value = "medium-light")]
|
||||
mediumLight,
|
||||
|
||||
/// <summary>
|
||||
/// The ultra dark
|
||||
/// </summary>
|
||||
[JsonProperty("ultra-dark")]
|
||||
[EnumMember(Value = "ultra-dark")]
|
||||
ultraDark
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
@@ -142,7 +142,7 @@ namespace ElectronNET.API.Entities
|
||||
/// <summary>
|
||||
/// Defaults to 16.
|
||||
/// </summary>
|
||||
public int DefaultFontSize { get; set; }
|
||||
public int DefaultFontSize { get; set; } = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Defaults to 13.
|
||||
@@ -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; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use native window.open(). Defaults to false. This option is currently experimental.
|
||||
@@ -206,5 +206,11 @@ namespace ElectronNET.API.Entities
|
||||
/// </value>
|
||||
[DefaultValue(false)]
|
||||
public bool WebviewTag { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable the remote module. Defaults to false.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool EnableRemoteModule { get; set; } = false;
|
||||
}
|
||||
}
|
||||
88
ElectronNET.API/Events.cs
Normal file
88
ElectronNET.API/Events.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic Event Consumers for Electron Modules
|
||||
/// </summary>
|
||||
internal class Events
|
||||
{
|
||||
private static Events _events;
|
||||
private static readonly object SyncRoot = new();
|
||||
private readonly TextInfo _textInfo = new CultureInfo("en-US", false).TextInfo;
|
||||
|
||||
private Events()
|
||||
{}
|
||||
|
||||
public static Events Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_events == null)
|
||||
{
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (_events == null)
|
||||
{
|
||||
_events = new Events();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _events;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped electron event.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The name of the module, e.g. app, dock, etc...</param>
|
||||
/// <param name="eventName">The name of the event</param>
|
||||
/// <param name="action">The event handler</param>
|
||||
public void On(string moduleName, string eventName, Action action)
|
||||
=> On(moduleName, eventName, action);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped electron event.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The name of the module, e.g. app, dock, etc...</param>
|
||||
/// <param name="eventName">The name of the event</param>
|
||||
/// <param name="action">The event handler</param>
|
||||
public async Task On<T>(string moduleName, string eventName, Action<T> action)
|
||||
{
|
||||
var listener = $"{moduleName}{_textInfo.ToTitleCase(eventName)}Completed";
|
||||
var subscriber = $"register-{moduleName}-on-event";
|
||||
|
||||
BridgeConnector.Socket.On(listener, action);
|
||||
await BridgeConnector.Socket.Emit(subscriber, eventName, listener);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped electron event.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The name of the module, e.g. app, dock, etc...</param>
|
||||
/// <param name="eventName">The name of the event</param>
|
||||
/// <param name="fn">The event handler</param>
|
||||
public void Once(string moduleName, string eventName, Action action)
|
||||
=> Once(moduleName, eventName, action);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped electron event.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The name of the module, e.g. app, dock, etc...</param>
|
||||
/// <param name="eventName">The name of the event</param>
|
||||
/// <param name="action">The event handler</param>
|
||||
public async Task Once<T>(string moduleName, string eventName, Action<T> action)
|
||||
{
|
||||
var listener = $"{moduleName}{_textInfo.ToTitleCase(eventName)}Completed";
|
||||
var subscriber = $"register-{moduleName}-once-event";
|
||||
BridgeConnector.Socket.Once(listener, action);
|
||||
await BridgeConnector.Socket.Emit(subscriber, eventName, listener);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
ElectronNET.API/GlobalUsings.cs
Normal file
3
ElectronNET.API/GlobalUsings.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
// Global using directives
|
||||
|
||||
global using System.Web;
|
||||
@@ -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);
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -43,9 +44,9 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void On(string channel, Action<object> listener)
|
||||
public async Task On(string channel, Action<object> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerIpcMainChannel", channel);
|
||||
await BridgeConnector.Socket.Emit("registerIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.Off(channel);
|
||||
BridgeConnector.Socket.On(channel, (args) =>
|
||||
{
|
||||
@@ -179,6 +180,45 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to the BrowserView renderer process asynchronously via channel, you can also send
|
||||
/// arbitrary arguments. Arguments will be serialized in JSON internally and hence
|
||||
/// no functions or prototype chain will be included. The renderer process handles it by
|
||||
/// listening for channel with ipcRenderer module.
|
||||
/// </summary>
|
||||
/// <param name="browserView">BrowserView with channel.</param>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(BrowserView browserView, string channel, params object[] data)
|
||||
{
|
||||
List<JObject> jobjects = new List<JObject>();
|
||||
List<JArray> jarrays = new List<JArray>();
|
||||
List<object> objects = new List<object>();
|
||||
|
||||
foreach (var parameterObject in data)
|
||||
{
|
||||
if(parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable)
|
||||
{
|
||||
jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer));
|
||||
} else if(parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string))
|
||||
{
|
||||
jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer));
|
||||
} else if(parameterObject.GetType().IsPrimitive || (parameterObject is string))
|
||||
{
|
||||
objects.Add(parameterObject);
|
||||
}
|
||||
}
|
||||
|
||||
if(jobjects.Count > 0 || jarrays.Count > 0)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, data);
|
||||
}
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
ElectronNET.API/ServiceCollectionExtensions.cs
Normal file
33
ElectronNET.API/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the <see cref="Electron"/> Members to the Service Collection
|
||||
/// </summary>
|
||||
public static IServiceCollection AddElectron(this IServiceCollection services)
|
||||
=> services
|
||||
// adding in this manner to ensure late binding.
|
||||
.AddSingleton(provider => IpcMain.Instance)
|
||||
.AddSingleton(provider => App.Instance)
|
||||
.AddSingleton(provider => AutoUpdater.Instance)
|
||||
.AddSingleton(provider => WindowManager.Instance)
|
||||
.AddSingleton(provider => Menu.Instance)
|
||||
.AddSingleton(provider => Dialog.Instance)
|
||||
.AddSingleton(provider => Notification.Instance)
|
||||
.AddSingleton(provider => Tray.Instance)
|
||||
.AddSingleton(provider => GlobalShortcut.Instance)
|
||||
.AddSingleton(provider => Shell.Instance)
|
||||
.AddSingleton(provider => Screen.Instance)
|
||||
.AddSingleton(provider => Clipboard.Instance)
|
||||
.AddSingleton(provider => HostHook.Instance)
|
||||
.AddSingleton(provider => PowerMonitor.Instance)
|
||||
.AddSingleton(provider => NativeTheme.Instance)
|
||||
.AddSingleton(provider => Dock.Instance);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -58,8 +64,7 @@ namespace ElectronNET.API
|
||||
/// <summary>
|
||||
/// Clears the session’s HTTP authentication cache.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public Task ClearAuthCacheAsync(RemoveClientCertificate options)
|
||||
public Task ClearAuthCacheAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<object>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
@@ -70,7 +75,7 @@ namespace ElectronNET.API
|
||||
taskCompletionSource.SetResult(null);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearAuthCache", Id, JObject.FromObject(options, _jsonSerializer), guid);
|
||||
BridgeConnector.Socket.Emit("webContents-session-clearAuthCache", Id, guid);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -370,6 +375,81 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("webContents-session-setUserAgent", Id, userAgent, acceptLanguages);
|
||||
}
|
||||
|
||||
/// <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 Task<ChromeExtensionInfo[]> GetAllExtensionsAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<ChromeExtensionInfo[]>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-getAllExtensions-completed", (extensionslist) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-getAllExtensions-completed");
|
||||
var chromeExtensionInfos = ((JArray)extensionslist).ToObject<ChromeExtensionInfo[]>();
|
||||
|
||||
taskCompletionSource.SetResult(chromeExtensionInfos);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-getAllExtensions", Id);
|
||||
|
||||
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 void RemoveExtension(string name)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-session-removeExtension", Id, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// resolves when the extension is loaded.
|
||||
///
|
||||
/// This method will raise an exception if the extension could not be loaded.If
|
||||
/// there are warnings when installing the extension (e.g. if the extension requests
|
||||
/// an API that Electron does not support) then they will be logged to the console.
|
||||
///
|
||||
/// Note that Electron does not support the full range of Chrome extensions APIs.
|
||||
/// See Supported Extensions APIs for more details on what is supported.
|
||||
///
|
||||
/// Note that in previous versions of Electron, extensions that were loaded would be
|
||||
/// remembered for future runs of the application.This is no longer the case:
|
||||
/// `loadExtension` must be called on every boot of your app if you want the
|
||||
/// extension to be loaded.
|
||||
///
|
||||
/// This API does not support loading packed (.crx) extensions.
|
||||
///
|
||||
///** Note:** This API cannot be called before the `ready` event of the `app` module
|
||||
/// is emitted.
|
||||
///
|
||||
///** Note:** Loading extensions into in-memory(non-persistent) sessions is not supported and will throw an error.
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the Chrome extension</param>
|
||||
/// <param name="allowFileAccess">Whether to allow the extension to read local files over `file://` protocol and
|
||||
/// inject content scripts into `file://` pages. This is required e.g. for loading
|
||||
/// devtools extensions on `file://` URLs. Defaults to false.</param>
|
||||
/// <returns></returns>
|
||||
public Task<Extension> LoadExtensionAsync(string path, bool allowFileAccess = false)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Extension>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-session-loadExtension-completed", (extension) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-session-loadExtension-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)extension).ToObject<Extension>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-session-loadExtension", Id, path, allowFileAccess);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
@@ -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,106 +79,60 @@ 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>
|
||||
/// <returns> Whether the item was successfully moved to the trash.</returns>
|
||||
public Task<bool> MoveItemToTrashAsync(string fullPath)
|
||||
public Task<bool> TrashItemAsync(string fullPath)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("shell-moveItemToTrashCompleted", (success) =>
|
||||
BridgeConnector.Socket.On("shell-trashItem-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("shell-moveItemToTrashCompleted");
|
||||
BridgeConnector.Socket.Off("shell-trashItem-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
taskCompletionSource.SetResult((bool) success);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("shell-moveItemToTrash", fullPath);
|
||||
BridgeConnector.Socket.Emit("shell-trashItem", fullPath);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
@@ -198,9 +148,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 +160,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 +182,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 +193,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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
93
ElectronNET.API/SocketIOFacade.cs
Normal file
93
ElectronNET.API/SocketIOFacade.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SocketIOClient;
|
||||
using SocketIOClient.Newtonsoft.Json;
|
||||
|
||||
namespace ElectronNET.API;
|
||||
|
||||
internal class SocketIoFacade
|
||||
{
|
||||
private readonly SocketIO _socket;
|
||||
|
||||
public SocketIoFacade(string uri)
|
||||
{
|
||||
_socket = new SocketIO(uri);
|
||||
var jsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
});
|
||||
|
||||
_socket.JsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
_socket.OnError += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine($"BridgeConnector Error: {sender} {e}");
|
||||
};
|
||||
|
||||
_socket.OnConnected += (_, _) =>
|
||||
{
|
||||
Console.WriteLine("BridgeConnector connected!");
|
||||
};
|
||||
|
||||
_socket.OnDisconnected += (_, _) =>
|
||||
{
|
||||
Console.WriteLine("BridgeConnector disconnected!");
|
||||
};
|
||||
|
||||
_socket.ConnectAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public void On(string eventName, Action action)
|
||||
{
|
||||
_socket.On(eventName, response =>
|
||||
{
|
||||
Task.Run(action);
|
||||
});
|
||||
}
|
||||
|
||||
public void On<T>(string eventName, Action<T> action)
|
||||
{
|
||||
_socket.On(eventName, response =>
|
||||
{
|
||||
var value = response.GetValue<T>();
|
||||
Task.Run(() => action(value));
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Remove this method when SocketIoClient supports object deserialization
|
||||
public void On(string eventName, Action<object> action)
|
||||
{
|
||||
_socket.On(eventName, response =>
|
||||
{
|
||||
var value = response.GetValue<object>();
|
||||
Console.WriteLine($"Called Event {eventName} - data {value}");
|
||||
Task.Run(() => action(value));
|
||||
});
|
||||
}
|
||||
|
||||
public void Once<T>(string eventName, Action<T> action)
|
||||
{
|
||||
_socket.On(eventName, (socketIoResponse) =>
|
||||
{
|
||||
_socket.Off(eventName);
|
||||
Task.Run(() => action(socketIoResponse.GetValue<T>()));
|
||||
});
|
||||
}
|
||||
|
||||
public void Off(string eventName)
|
||||
{
|
||||
_socket.Off(eventName);
|
||||
}
|
||||
|
||||
public async Task Emit(string eventName, params object[] args)
|
||||
{
|
||||
await _socket.EmitAsync(eventName, args);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (_click == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("tray-click-event" + GetHashCode(), (result) =>
|
||||
BridgeConnector.Socket.On<dynamic>("tray-click-event" + GetHashCode(), (result) =>
|
||||
{
|
||||
var args = ((JArray)result).ToObject<object[]>();
|
||||
var trayClickEventArgs = ((JObject)args[0]).ToObject<TrayClickEventArgs>();
|
||||
@@ -55,7 +55,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (_rightClick == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("tray-right-click-event" + GetHashCode(), (result) =>
|
||||
BridgeConnector.Socket.On<dynamic>("tray-right-click-event" + GetHashCode(), (result) =>
|
||||
{
|
||||
var args = ((JArray)result).ToObject<object[]>();
|
||||
var trayClickEventArgs = ((JObject)args[0]).ToObject<TrayClickEventArgs>();
|
||||
@@ -87,7 +87,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (_doubleClick == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("tray-double-click-event" + GetHashCode(), (result) =>
|
||||
BridgeConnector.Socket.On<dynamic>("tray-double-click-event" + GetHashCode(), (result) =>
|
||||
{
|
||||
var args = ((JArray)result).ToObject<object[]>();
|
||||
var trayClickEventArgs = ((JObject)args[0]).ToObject<TrayClickEventArgs>();
|
||||
@@ -182,7 +182,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
_balloonClosed();
|
||||
});
|
||||
|
||||
|
||||
BridgeConnector.Socket.Emit("register-tray-balloon-closed", GetHashCode());
|
||||
}
|
||||
_balloonClosed += value;
|
||||
@@ -201,7 +201,7 @@ namespace ElectronNET.API
|
||||
// TODO: Implement macOS Events
|
||||
|
||||
private static Tray _tray;
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
internal Tray() { }
|
||||
|
||||
@@ -230,17 +230,18 @@ namespace ElectronNET.API
|
||||
/// <value>
|
||||
/// The menu items.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
public IReadOnlyCollection<MenuItem> MenuItems => _items.AsReadOnly();
|
||||
|
||||
private readonly List<MenuItem> _items = new();
|
||||
|
||||
/// <summary>
|
||||
/// Shows the Traybar.
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
/// <param name="menuItem">The menu item.</param>
|
||||
public void Show(string image, MenuItem menuItem)
|
||||
public async Task Show(string image, MenuItem menuItem)
|
||||
{
|
||||
Show(image, new MenuItem[] { menuItem });
|
||||
await Show(image, new MenuItem[] { menuItem });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -248,26 +249,36 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
/// <param name="menuItems">The menu items.</param>
|
||||
public void Show(string image, MenuItem[] menuItems)
|
||||
public async Task Show(string image, MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
await BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.Clear();
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("trayMenuItemClicked");
|
||||
BridgeConnector.Socket.On("trayMenuItemClicked", (id) =>
|
||||
BridgeConnector.Socket.On<string>("trayMenuItemClicked", (id) =>
|
||||
{
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
MenuItem menuItem = _items.GetMenuItem(id);
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the Traybar (empty).
|
||||
/// </summary>
|
||||
/// <param name="image">The image.</param>
|
||||
public async Task Show(string image)
|
||||
{
|
||||
await BridgeConnector.Socket.Emit("create-tray", image);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroys the tray icon immediately.
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
public async Task Destroy()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-destroy");
|
||||
await BridgeConnector.Socket.Emit("tray-destroy");
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
@@ -275,72 +286,101 @@ namespace ElectronNET.API
|
||||
/// Sets the image associated with this tray icon.
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
public void SetImage(string image)
|
||||
public async Task SetImage(string image)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-setImage", image);
|
||||
await BridgeConnector.Socket.Emit("tray-setImage", image);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the image associated with this tray icon when pressed on macOS.
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
public void SetPressedImage(string image)
|
||||
public async Task SetPressedImage(string image)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-setPressedImage", image);
|
||||
await BridgeConnector.Socket.Emit("tray-setPressedImage", image);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the hover text for this tray icon.
|
||||
/// </summary>
|
||||
/// <param name="toolTip"></param>
|
||||
public void SetToolTip(string toolTip)
|
||||
public async Task SetToolTip(string toolTip)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-setToolTip", toolTip);
|
||||
await BridgeConnector.Socket.Emit("tray-setToolTip", toolTip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// macOS: Sets the title displayed aside of the tray icon in the status bar.
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void SetTitle(string title)
|
||||
public async Task SetTitle(string title)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-setTitle", title);
|
||||
await BridgeConnector.Socket.Emit("tray-setTitle", title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Windows: Displays a tray balloon.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void DisplayBalloon(DisplayBalloonOptions options)
|
||||
public async Task DisplayBalloon(DisplayBalloonOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("tray-displayBalloon", JObject.FromObject(options, _jsonSerializer));
|
||||
await BridgeConnector.Socket.Emit("tray-displayBalloon", JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the tray icon is destroyed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsDestroyedAsync()
|
||||
public async Task<bool> IsDestroyedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("tray-isDestroyedCompleted", (isDestroyed) =>
|
||||
BridgeConnector.Socket.On<bool>("tray-isDestroyedCompleted", (isDestroyed) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("tray-isDestroyedCompleted");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isDestroyed);
|
||||
taskCompletionSource.SetResult(isDestroyed);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("tray-isDestroyed");
|
||||
await BridgeConnector.Socket.Emit("tray-isDestroyed");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
return await taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
private const string ModuleName = "tray";
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="Tray"/> module.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="action">The handler</param>
|
||||
public void On(string eventName, Action action)
|
||||
=> Events.Instance.On(ModuleName, eventName, action);
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="Tray"/> module.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="action">The handler</param>
|
||||
public async Task On<T>(string eventName, Action<T> action)
|
||||
=> await Events.Instance.On(ModuleName, eventName, action);
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="Tray"/> module once.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="action">The handler</param>
|
||||
public void Once(string eventName, Action action)
|
||||
=> Events.Instance.Once(ModuleName, eventName, action);
|
||||
/// <summary>
|
||||
/// Subscribe to an unmapped event on the <see cref="Tray"/> module once.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="action">The handler</param>
|
||||
public async Task Once<T>(string eventName, Action<T> action)
|
||||
=> await Events.Instance.Once(ModuleName, eventName, action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,264 +5,305 @@ using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
namespace ElectronNET.API;
|
||||
|
||||
/// <summary>
|
||||
/// Render and control web pages.
|
||||
/// </summary>
|
||||
public class WebContents
|
||||
{
|
||||
/// <summary>
|
||||
/// Render and control web pages.
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
public class WebContents
|
||||
/// <value>
|
||||
/// The identifier.
|
||||
/// </value>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Manage browser sessions, cookies, cache, proxy settings, etc.
|
||||
/// </summary>
|
||||
public Session Session { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the renderer process crashes or is killed.
|
||||
/// </summary>
|
||||
public event Action<bool> OnCrashed
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The identifier.
|
||||
/// </value>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Manage browser sessions, cookies, cache, proxy settings, etc.
|
||||
/// </summary>
|
||||
public Session Session { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the renderer process crashes or is killed.
|
||||
/// </summary>
|
||||
public event Action<bool> OnCrashed
|
||||
add
|
||||
{
|
||||
add
|
||||
if (_crashed == null)
|
||||
{
|
||||
if (_crashed == null)
|
||||
BridgeConnector.Socket.On("webContents-crashed" + Id, (killed) =>
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-crashed" + Id, (killed) =>
|
||||
{
|
||||
_crashed((bool)killed);
|
||||
});
|
||||
_crashed((bool)killed);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-crashed", Id);
|
||||
}
|
||||
_crashed += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_crashed -= value;
|
||||
|
||||
if (_crashed == null)
|
||||
BridgeConnector.Socket.Off("webContents-crashed" + Id);
|
||||
BridgeConnector.Socket.Emit("register-webContents-crashed", Id);
|
||||
}
|
||||
_crashed += value;
|
||||
}
|
||||
|
||||
private event Action<bool> _crashed;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the navigation is done, i.e. the spinner of the tab has
|
||||
/// stopped spinning, and the onload event was dispatched.
|
||||
/// </summary>
|
||||
public event Action OnDidFinishLoad
|
||||
remove
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_didFinishLoad == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-didFinishLoad" + Id, () =>
|
||||
{
|
||||
_didFinishLoad();
|
||||
});
|
||||
_crashed -= value;
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-didFinishLoad", Id);
|
||||
}
|
||||
_didFinishLoad += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_didFinishLoad -= value;
|
||||
|
||||
if (_didFinishLoad == null)
|
||||
BridgeConnector.Socket.Off("webContents-didFinishLoad" + Id);
|
||||
}
|
||||
if (_crashed == null)
|
||||
BridgeConnector.Socket.Off("webContents-crashed" + Id);
|
||||
}
|
||||
|
||||
private event Action _didFinishLoad;
|
||||
|
||||
internal WebContents(int id)
|
||||
{
|
||||
Id = id;
|
||||
Session = new Session(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the devtools.
|
||||
/// </summary>
|
||||
public void OpenDevTools()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the devtools.
|
||||
/// </summary>
|
||||
/// <param name="openDevToolsOptions"></param>
|
||||
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
|
||||
{
|
||||
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.
|
||||
/// By default, an empty options will be regarded as: Use page-break-before: always;
|
||||
/// CSS style to force to print to a new page.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns>success</returns>
|
||||
public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-printToPDF-completed");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
if(options == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is used to get the Url of the loaded page.
|
||||
/// It's usefull if a web-server redirects you and you need to know where it redirects. For instance, It's useful in case of Implicit Authorization.
|
||||
/// </summary>
|
||||
/// <returns>URL of the loaded page</returns>
|
||||
public Task<string> GetUrl()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
var eventString = "webContents-getUrl" + Id;
|
||||
BridgeConnector.Socket.On(eventString, (url) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventString);
|
||||
taskCompletionSource.SetResult((string)url);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-getUrl", Id);
|
||||
|
||||
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(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
|
||||
private event Action<bool> _crashed;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the navigation is done, i.e. the spinner of the tab has
|
||||
/// stopped spinning, and the onload event was dispatched.
|
||||
/// </summary>
|
||||
public event Action OnDidFinishLoad
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_didFinishLoad == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-didFinishLoad" + Id, () =>
|
||||
{
|
||||
_didFinishLoad();
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-didFinishLoad", Id);
|
||||
}
|
||||
_didFinishLoad += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_didFinishLoad -= value;
|
||||
|
||||
if (_didFinishLoad == null)
|
||||
BridgeConnector.Socket.Off("webContents-didFinishLoad" + Id);
|
||||
}
|
||||
}
|
||||
|
||||
private event Action _didFinishLoad;
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when an input event is sent to the WebContents.
|
||||
/// </summary>
|
||||
public event Action<InputEvent> InputEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_inputEvent == null)
|
||||
{
|
||||
BridgeConnector.Socket.On("webContents-input-event" + Id, (eventArgs) =>
|
||||
{
|
||||
var inputEvent = ((JObject)eventArgs).ToObject<InputEvent>();
|
||||
_inputEvent(inputEvent);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("register-webContents-input-event", Id);
|
||||
}
|
||||
_inputEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_inputEvent -= value;
|
||||
|
||||
if (_inputEvent == null)
|
||||
BridgeConnector.Socket.Off("webContents-input-event" + Id);
|
||||
}
|
||||
}
|
||||
|
||||
private event Action<InputEvent> _inputEvent;
|
||||
|
||||
internal WebContents(int id)
|
||||
{
|
||||
Id = id;
|
||||
Session = new Session(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the devtools.
|
||||
/// </summary>
|
||||
public void OpenDevTools()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the devtools.
|
||||
/// </summary>
|
||||
/// <param name="openDevToolsOptions"></param>
|
||||
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
|
||||
{
|
||||
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.
|
||||
/// By default, an empty options will be regarded as: Use page-break-before: always;
|
||||
/// CSS style to force to print to a new page.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns>success</returns>
|
||||
public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("webContents-printToPDF-completed");
|
||||
taskCompletionSource.SetResult((bool)success);
|
||||
});
|
||||
|
||||
if(options == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is used to get the Url of the loaded page.
|
||||
/// It's usefull if a web-server redirects you and you need to know where it redirects. For instance, It's useful in case of Implicit Authorization.
|
||||
/// </summary>
|
||||
/// <returns>URL of the loaded page</returns>
|
||||
public Task<string> GetUrl()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
var eventString = "webContents-getUrl" + Id;
|
||||
BridgeConnector.Socket.On(eventString, (url) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventString);
|
||||
taskCompletionSource.SetResult((string)url);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("webContents-getUrl", Id);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts CSS into the web page.
|
||||
/// See: https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options
|
||||
/// Works for both BrowserWindows and BrowserViews.
|
||||
/// </summary>
|
||||
/// <param name="isBrowserWindow">Whether the webContents belong to a BrowserWindow or not (the other option is a BrowserView)</param>
|
||||
/// <param name="path">Absolute path to the CSS file location</param>
|
||||
public void InsertCSS(bool isBrowserWindow, string path)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path);
|
||||
}
|
||||
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -32,6 +33,11 @@ namespace ElectronNET.API
|
||||
|
||||
if (HybridSupport.IsElectronActive)
|
||||
{
|
||||
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.
|
||||
@@ -49,4 +55,4 @@ namespace ElectronNET.API
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -16,7 +17,7 @@ namespace ElectronNET.API
|
||||
public sealed class WindowManager
|
||||
{
|
||||
private static WindowManager _windowManager;
|
||||
private static object _syncRoot = new object();
|
||||
private static readonly object SyncRoot = new();
|
||||
|
||||
internal WindowManager() { }
|
||||
|
||||
@@ -26,7 +27,7 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (_windowManager == null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (_windowManager == null)
|
||||
{
|
||||
@@ -47,7 +48,7 @@ namespace ElectronNET.API
|
||||
/// </value>
|
||||
public bool IsQuitOnWindowAllClosed
|
||||
{
|
||||
get { return _isQuitOnWindowAllClosed; }
|
||||
get => _isQuitOnWindowAllClosed;
|
||||
set
|
||||
{
|
||||
BridgeConnector.Socket.Emit("quit-app-window-all-closed-event", value);
|
||||
@@ -62,8 +63,9 @@ namespace ElectronNET.API
|
||||
/// <value>
|
||||
/// The browser windows.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<BrowserWindow> BrowserWindows { get { return _browserWindows.AsReadOnly(); } }
|
||||
private List<BrowserWindow> _browserWindows = new List<BrowserWindow>();
|
||||
public IReadOnlyCollection<BrowserWindow> BrowserWindows => _browserWindows.AsReadOnly();
|
||||
|
||||
private readonly List<BrowserWindow> _browserWindows = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the browser views.
|
||||
@@ -71,8 +73,9 @@ namespace ElectronNET.API
|
||||
/// <value>
|
||||
/// The browser view.
|
||||
/// </value>
|
||||
public IReadOnlyCollection<BrowserView> BrowserViews { get { return _browserViews.AsReadOnly(); } }
|
||||
private List<BrowserView> _browserViews = new List<BrowserView>();
|
||||
public IReadOnlyCollection<BrowserView> BrowserViews => _browserViews.AsReadOnly();
|
||||
|
||||
private readonly List<BrowserView> _browserViews = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the window asynchronous.
|
||||
@@ -90,7 +93,7 @@ namespace ElectronNET.API
|
||||
/// <param name="options">The options.</param>
|
||||
/// <param name="loadUrl">The load URL.</param>
|
||||
/// <returns></returns>
|
||||
public Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost")
|
||||
public async Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();
|
||||
|
||||
@@ -98,16 +101,18 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserWindowCreated");
|
||||
|
||||
string windowId = id.ToString();
|
||||
BrowserWindow browserWindow = new BrowserWindow(int.Parse(windowId));
|
||||
var browserWindowId = int.Parse(id.ToString()!);
|
||||
|
||||
var browserWindow = new BrowserWindow(browserWindowId);
|
||||
_browserWindows.Add(browserWindow);
|
||||
|
||||
taskCompletionSource.SetResult(browserWindow);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Off("BrowserWindowClosed");
|
||||
BridgeConnector.Socket.On("BrowserWindowClosed", (ids) =>
|
||||
BridgeConnector.Socket.On<object>("BrowserWindowClosed", (ids) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserWindowClosed");
|
||||
|
||||
var browserWindowIds = ((JArray)ids).ToObject<int[]>();
|
||||
|
||||
for (int index = 0; index < _browserWindows.Count; index++)
|
||||
@@ -126,10 +131,10 @@ namespace ElectronNET.API
|
||||
|
||||
// Workaround Windows 10 / Electron Bug
|
||||
// https://github.com/electron/electron/issues/4045
|
||||
if (isWindows10())
|
||||
if (IsWindows10())
|
||||
{
|
||||
options.Width = options.Width + 14;
|
||||
options.Height = options.Height + 7;
|
||||
options.Width += 14;
|
||||
options.Height += 7;
|
||||
}
|
||||
|
||||
if (options.X == -1 && options.Y == -1)
|
||||
@@ -137,15 +142,15 @@ namespace ElectronNET.API
|
||||
options.X = 0;
|
||||
options.Y = 0;
|
||||
|
||||
BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl);
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Workaround Windows 10 / Electron Bug
|
||||
// https://github.com/electron/electron/issues/4045
|
||||
if (isWindows10())
|
||||
if (IsWindows10())
|
||||
{
|
||||
options.X = options.X - 7;
|
||||
options.X -= 7;
|
||||
}
|
||||
|
||||
var ownjsonSerializer = new JsonSerializer()
|
||||
@@ -153,13 +158,13 @@ namespace ElectronNET.API
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, ownjsonSerializer), loadUrl);
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, ownjsonSerializer), loadUrl);
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
return await taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private bool isWindows10()
|
||||
private bool IsWindows10()
|
||||
{
|
||||
return RuntimeInformation.OSDescription.Contains("Windows 10");
|
||||
}
|
||||
@@ -182,7 +187,7 @@ namespace ElectronNET.API
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public Task<BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options)
|
||||
public async Task<BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserView>();
|
||||
|
||||
@@ -192,7 +197,6 @@ namespace ElectronNET.API
|
||||
|
||||
string browserViewId = id.ToString();
|
||||
BrowserView browserView = new BrowserView(int.Parse(browserViewId));
|
||||
browserView.Destroyed += (b) => _browserViews.Remove(b);
|
||||
|
||||
_browserViews.Add(browserView);
|
||||
|
||||
@@ -204,12 +208,12 @@ namespace ElectronNET.API
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer));
|
||||
await BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
return await taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
private readonly JsonSerializer _jsonSerializer = new()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
|
||||
@@ -10,16 +10,26 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "build-helper.js");
|
||||
|
||||
string vscodeFolder = Path.Combine(tempPath, ".vscode");
|
||||
if (Directory.Exists(vscodeFolder) == false)
|
||||
{
|
||||
Directory.CreateDirectory(vscodeFolder);
|
||||
}
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "launch.json", ".vscode.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "tasks.json", ".vscode.");
|
||||
|
||||
string hostApiFolder = Path.Combine(tempPath, "api");
|
||||
if (Directory.Exists(hostApiFolder) == false)
|
||||
{
|
||||
Directory.CreateDirectory(hostApiFolder);
|
||||
}
|
||||
|
||||
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.");
|
||||
@@ -30,6 +40,8 @@ namespace ElectronNET.CLI.Commands.Actions
|
||||
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)
|
||||
|
||||
@@ -75,13 +75,16 @@ namespace ElectronNET.CLI.Commands
|
||||
// ToDo: Not sure if this runs under linux/macos
|
||||
ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);
|
||||
|
||||
// search .csproj
|
||||
Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'");
|
||||
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
|
||||
// search .csproj or .fsproj (.csproj has higher precedence)
|
||||
Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'");
|
||||
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
|
||||
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
|
||||
.FirstOrDefault();
|
||||
|
||||
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
|
||||
var extension = Path.GetExtension(projectFile);
|
||||
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
|
||||
|
||||
if (!EditCsProj(projectFile)) return false;
|
||||
if (!EditProjectFile(projectFile)) return false;
|
||||
|
||||
Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!");
|
||||
|
||||
@@ -90,7 +93,7 @@ namespace ElectronNET.CLI.Commands
|
||||
}
|
||||
|
||||
// ToDo: Cleanup this copy/past code.
|
||||
private static bool EditCsProj(string projectFile)
|
||||
private static bool EditProjectFile(string projectFile)
|
||||
{
|
||||
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||
{
|
||||
@@ -128,7 +131,7 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine($"Publish setting added in csproj!");
|
||||
Console.WriteLine($"Publish setting added in csproj/fsproj!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.CLI.Commands.Actions;
|
||||
|
||||
@@ -14,14 +13,16 @@ namespace ElectronNET.CLI.Commands
|
||||
public const string COMMAND_DESCRIPTION = "Build your Electron Application.";
|
||||
public static string COMMAND_ARGUMENTS = "Needed: '/target' with params 'win/osx/linux' to build for a typical app or use 'custom' and specify .NET Core build config & electron build config" + Environment.NewLine +
|
||||
" for custom target, check .NET Core RID Catalog and Electron build target/" + Environment.NewLine +
|
||||
" e.g. '/target win' or '/target custom \"win7-x86;win32\"'" + Environment.NewLine +
|
||||
" e.g. '/target win' or '/target custom \"win7-x86;win\"'" + Environment.NewLine +
|
||||
"Optional: '/dotnet-configuration' with the desired .NET Core build config e.g. release or debug. Default = Release" + Environment.NewLine +
|
||||
"Optional: '/electron-arch' to specify the resulting electron processor architecture (e.g. ia86 for x86 builds). Be aware to use the '/target custom' param as well!" + Environment.NewLine +
|
||||
"Optional: '/electron-params' specify any other valid parameter, which will be routed to the electron-packager." + Environment.NewLine +
|
||||
"Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine +
|
||||
"Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine +
|
||||
"Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine +
|
||||
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
|
||||
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
|
||||
"Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine +
|
||||
"Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine +
|
||||
"Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \"";
|
||||
|
||||
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
|
||||
@@ -42,6 +43,9 @@ namespace ElectronNET.CLI.Commands
|
||||
private string _paramPackageJson = "package-json";
|
||||
private string _paramForceNodeInstall = "install-modules";
|
||||
private string _manifest = "manifest";
|
||||
private string _paramPublishReadyToRun = "PublishReadyToRun";
|
||||
private string _paramPublishSingleFile = "PublishSingleFile";
|
||||
private string _paramVersion = "Version";
|
||||
|
||||
public Task<bool> ExecuteAsync()
|
||||
{
|
||||
@@ -52,6 +56,11 @@ namespace ElectronNET.CLI.Commands
|
||||
SimpleCommandLineParser parser = new SimpleCommandLineParser();
|
||||
parser.Parse(_args);
|
||||
|
||||
//This version will be shared between the dotnet publish and electron-builder commands
|
||||
string version = null;
|
||||
if (parser.Arguments.ContainsKey(_paramVersion))
|
||||
version = parser.Arguments[_paramVersion][0];
|
||||
|
||||
if (!parser.Arguments.ContainsKey(_paramTarget))
|
||||
{
|
||||
Console.WriteLine($"Error: missing '{_paramTarget}' argument.");
|
||||
@@ -77,25 +86,35 @@ namespace ElectronNET.CLI.Commands
|
||||
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
|
||||
|
||||
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
string tempBinPath = Path.Combine(tempPath, "bin");
|
||||
|
||||
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
|
||||
|
||||
var dotNetPublishFlags = GetDotNetPublishFlags(parser);
|
||||
|
||||
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c {configuration} --output \"{tempBinPath}\" /p:PublishReadyToRun=true --no-self-contained", Directory.GetCurrentDirectory());
|
||||
var command =
|
||||
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
|
||||
|
||||
// output the command
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(command);
|
||||
Console.ResetColor();
|
||||
|
||||
var resultCode = ProcessHelper.CmdExecute(command, Directory.GetCurrentDirectory());
|
||||
|
||||
if (resultCode != 0)
|
||||
{
|
||||
@@ -117,7 +136,7 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
|
||||
|
||||
Console.WriteLine("Start npm install...");
|
||||
Console.WriteLine("Start npm install...");
|
||||
ProcessHelper.CmdExecute("npm install --production", tempPath);
|
||||
|
||||
Console.WriteLine("ElectronHostHook handling started...");
|
||||
@@ -146,7 +165,7 @@ namespace ElectronNET.CLI.Commands
|
||||
}
|
||||
else if (parser.Arguments.ContainsKey(_paramOutputDirectory))
|
||||
{
|
||||
buildPath = Path.Combine(Directory.GetCurrentDirectory(),parser.Arguments[_paramOutputDirectory][0]);
|
||||
buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]);
|
||||
}
|
||||
|
||||
Console.WriteLine("Executing electron magic in this directory: " + buildPath);
|
||||
@@ -168,20 +187,69 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
string manifestFileName = "electron.manifest.json";
|
||||
|
||||
if(parser.Arguments.ContainsKey(_manifest))
|
||||
if (parser.Arguments.ContainsKey(_manifest))
|
||||
{
|
||||
manifestFileName = parser.Arguments[_manifest].First();
|
||||
}
|
||||
|
||||
ProcessHelper.CmdExecute($"node build-helper.js " + manifestFileName, tempPath);
|
||||
ProcessHelper.CmdExecute(
|
||||
string.IsNullOrWhiteSpace(version)
|
||||
? $"node build-helper.js {manifestFileName}"
|
||||
: $"node build-helper.js {manifestFileName} {version}", 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=8.2.3 {electronParams}", tempPath);
|
||||
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=23.2.0 {electronParams}", tempPath);
|
||||
|
||||
Console.WriteLine("... done");
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser parser)
|
||||
{
|
||||
var dotNetPublishFlags = new Dictionary<string, string>
|
||||
{
|
||||
{"/p:PublishReadyToRun", parser.TryGet(_paramPublishReadyToRun, out var rtr) ? rtr[0] : "true"},
|
||||
{"/p:PublishSingleFile", parser.TryGet(_paramPublishSingleFile, out var psf) ? psf[0] : "true"},
|
||||
};
|
||||
|
||||
if (parser.Arguments.ContainsKey(_paramVersion))
|
||||
{
|
||||
if(parser.Arguments.Keys.All(key => !key.StartsWith("p:Version=") && !key.StartsWith("property:Version=")))
|
||||
dotNetPublishFlags.Add("/p:Version", parser.Arguments[_paramVersion][0]);
|
||||
if(parser.Arguments.Keys.All(key => !key.StartsWith("p:ProductVersion=") && !key.StartsWith("property:ProductVersion=")))
|
||||
dotNetPublishFlags.Add("/p:ProductVersion", parser.Arguments[_paramVersion][0]);
|
||||
}
|
||||
|
||||
foreach (var parm in parser.Arguments.Keys.Where(key => key.StartsWith("p:") || key.StartsWith("property:")))
|
||||
{
|
||||
var split = parm.IndexOf('=');
|
||||
if (split < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = $"/{parm.Substring(0, split)}";
|
||||
// normalize the key
|
||||
if (key.StartsWith("/property:"))
|
||||
{
|
||||
key = key.Replace("/property:", "/p:");
|
||||
}
|
||||
|
||||
var value = parm.Substring(split + 1);
|
||||
|
||||
if (dotNetPublishFlags.ContainsKey(key))
|
||||
{
|
||||
dotNetPublishFlags[key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
dotNetPublishFlags.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return dotNetPublishFlags;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,19 +70,22 @@ namespace ElectronNET.CLI.Commands
|
||||
// Deploy config file
|
||||
EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);
|
||||
|
||||
// search .csproj
|
||||
Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
|
||||
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
|
||||
// search .csproj/.fsproj (.csproj has higher precedence)
|
||||
Console.WriteLine($"Search your .csproj/fsproj to add the needed {ConfigName}...");
|
||||
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
|
||||
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
|
||||
.FirstOrDefault();
|
||||
|
||||
// update config file with the name of the csproj
|
||||
// ToDo: If the csproj name != application name, this will fail
|
||||
// update config file with the name of the csproj/fsproj
|
||||
// ToDo: If the csproj/fsproj name != application name, this will fail
|
||||
string text = File.ReadAllText(targetFilePath);
|
||||
text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
|
||||
File.WriteAllText(targetFilePath, text);
|
||||
|
||||
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");
|
||||
var extension = Path.GetExtension(projectFile);
|
||||
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing config or update it.");
|
||||
|
||||
if (!EditCsProj(projectFile)) return false;
|
||||
if (!EditProjectFile(projectFile)) return false;
|
||||
|
||||
// search launchSettings.json
|
||||
Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");
|
||||
@@ -158,7 +161,7 @@ namespace ElectronNET.CLI.Commands
|
||||
}
|
||||
}
|
||||
|
||||
private static bool EditCsProj(string projectFile)
|
||||
private static bool EditProjectFile(string projectFile)
|
||||
{
|
||||
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||
{
|
||||
@@ -174,11 +177,11 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\""))
|
||||
{
|
||||
Console.WriteLine($"{ConfigName} already in csproj.");
|
||||
Console.WriteLine($"{ConfigName} already in csproj/fsproj.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Console.WriteLine($"{ConfigName} will be added to csproj.");
|
||||
Console.WriteLine($"{ConfigName} will be added to csproj/fsproj.");
|
||||
|
||||
string itemGroupXmlString = "<ItemGroup>" +
|
||||
"<Content Update=\"" + ConfigName + "\">" +
|
||||
@@ -204,7 +207,7 @@ namespace ElectronNET.CLI.Commands
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine($"{ConfigName} added in csproj!");
|
||||
Console.WriteLine($"{ConfigName} added in csproj/fsproj!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace ElectronNET.CLI.Commands
|
||||
private string _arguments = "args";
|
||||
private string _manifest = "manifest";
|
||||
private string _clearCache = "clear-cache";
|
||||
private string _paramPublishReadyToRun = "PublishReadyToRun";
|
||||
private string _paramPublishSingleFile = "PublishSingleFile";
|
||||
private string _paramDotNetConfig = "dotnet-configuration";
|
||||
private string _paramTarget = "target";
|
||||
|
||||
public Task<bool> ExecuteAsync()
|
||||
{
|
||||
@@ -57,14 +61,53 @@ namespace ElectronNET.CLI.Commands
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
|
||||
var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty);
|
||||
|
||||
string tempBinPath = Path.Combine(tempPath, "bin");
|
||||
var resultCode = 0;
|
||||
|
||||
string publishReadyToRun = "/p:PublishReadyToRun=";
|
||||
if (parser.Arguments.ContainsKey(_paramPublishReadyToRun))
|
||||
{
|
||||
publishReadyToRun += parser.Arguments[_paramPublishReadyToRun][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
publishReadyToRun += "true";
|
||||
}
|
||||
|
||||
string publishSingleFile = "/p:PublishSingleFile=";
|
||||
if (parser.Arguments.ContainsKey(_paramPublishSingleFile))
|
||||
{
|
||||
publishSingleFile += parser.Arguments[_paramPublishSingleFile][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
publishSingleFile += "true";
|
||||
}
|
||||
|
||||
// If target is specified as a command line argument, use it.
|
||||
// Format is the same as the build command.
|
||||
// If target is not specified, autodetect it.
|
||||
var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty);
|
||||
if (parser.Arguments.ContainsKey(_paramTarget))
|
||||
{
|
||||
var desiredPlatform = parser.Arguments[_paramTarget][0];
|
||||
string specifiedFromCustom = string.Empty;
|
||||
if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
|
||||
{
|
||||
specifiedFromCustom = parser.Arguments[_paramTarget][1];
|
||||
}
|
||||
platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom);
|
||||
}
|
||||
|
||||
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} --output \"{tempBinPath}\" /p:PublishReadyToRun=true --no-self-contained", aspCoreProjectPath);
|
||||
resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --no-self-contained", aspCoreProjectPath);
|
||||
}
|
||||
|
||||
if (resultCode != 0)
|
||||
@@ -138,7 +181,5 @@ namespace ElectronNET.CLI.Commands
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<AssemblyName>dotnet-electronize</AssemblyName>
|
||||
<ToolCommandName>electronize</ToolCommandName>
|
||||
|
||||
<PackageType>DotnetCliTool</PackageType>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageOutputPath>..\artifacts</PackageOutputPath>
|
||||
<PackageId>ElectronNET.CLI</PackageId>
|
||||
<!-- Version 99 is just set for local development stuff to avoid a conflict with "real" packages on NuGet.org -->
|
||||
<Version>99.0.0.0</Version>
|
||||
<Authors>Gregor Biswanger, Robert Muehsig</Authors>
|
||||
<Authors>Gregor Biswanger, Florian Rappl</Authors>
|
||||
<Product>Electron.NET</Product>
|
||||
<Company />
|
||||
<Description>
|
||||
@@ -29,22 +26,19 @@
|
||||
<PackageReleaseNotes>Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md</PackageReleaseNotes>
|
||||
<PackageIcon>PackageIcon.png</PackageIcon>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<StartupObject></StartupObject>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="ElectronHost\package-lock.json" />
|
||||
<None Remove="ElectronHost\package.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="PackageIcon.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\electron.manifest.json" Link="ElectronHost\electron.manifest.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\package.json" Link="ElectronHost\package.json" />
|
||||
@@ -61,6 +55,7 @@
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\browserWindows.js" Link="ElectronHost\api\browserWindows.js" />
|
||||
<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" />
|
||||
@@ -71,13 +66,19 @@
|
||||
<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" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\.vscode\launch.json" Link="ElectronHost\.vscode\launch.json" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\.vscode\tasks.json" Link="ElectronHost\.vscode\tasks.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.410601">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
|
||||
<Exec Command="$(ProjectDir)devCleanup.cmd" IgnoreExitCode="true" />
|
||||
@@ -85,4 +86,4 @@
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' != 'Windows_NT'">
|
||||
<Exec Command="$(ProjectDir)devCleanup.sh" IgnoreExitCode="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ElectronNET.CLI
|
||||
{
|
||||
public class ProcessHelper
|
||||
{
|
||||
private readonly static Regex ErrorRegex = new Regex(@"\berror\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
public static int CmdExecute(string command, string workingDirectoryPath, bool output = true, bool waitForExit = true)
|
||||
{
|
||||
using (Process cmd = new Process())
|
||||
@@ -17,12 +14,13 @@ namespace ElectronNET.CLI
|
||||
|
||||
if (isWindows)
|
||||
{
|
||||
cmd.StartInfo.FileName = "cmd.exe";
|
||||
cmd.StartInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
|
||||
}
|
||||
else
|
||||
{
|
||||
// works for OSX and Linux (at least on Ubuntu)
|
||||
cmd.StartInfo.FileName = "bash";
|
||||
var escapedArgs = command.Replace("\"", "\\\"");
|
||||
cmd.StartInfo = new ProcessStartInfo("bash", $"-c \"{escapedArgs}\"");
|
||||
}
|
||||
|
||||
cmd.StartInfo.RedirectStandardInput = true;
|
||||
@@ -32,65 +30,23 @@ namespace ElectronNET.CLI
|
||||
cmd.StartInfo.UseShellExecute = false;
|
||||
cmd.StartInfo.WorkingDirectory = workingDirectoryPath;
|
||||
|
||||
int returnCode = 0;
|
||||
|
||||
if (output)
|
||||
{
|
||||
cmd.OutputDataReceived += (s, e) =>
|
||||
{
|
||||
// (sometimes error messages are only visbile here)
|
||||
// poor mans solution, we just seek for the term 'error'
|
||||
|
||||
// we can't just use cmd.ExitCode, because
|
||||
// we delegate it to cmd.exe, which runs fine
|
||||
// but we can catch any error here and return
|
||||
// 1 if something fails
|
||||
if (e != null && string.IsNullOrWhiteSpace(e.Data) == false)
|
||||
{
|
||||
if (ErrorRegex.IsMatch(e.Data))
|
||||
{
|
||||
returnCode = 1;
|
||||
}
|
||||
|
||||
Console.WriteLine(e.Data);
|
||||
}
|
||||
|
||||
};
|
||||
cmd.ErrorDataReceived += (s, e) =>
|
||||
{
|
||||
// poor mans solution, we just seek for the term 'error'
|
||||
|
||||
// we can't just use cmd.ExitCode, because
|
||||
// we delegate it to cmd.exe, which runs fine
|
||||
// but we can catch any error here and return
|
||||
// 1 if something fails
|
||||
if (e != null && string.IsNullOrWhiteSpace(e.Data) == false)
|
||||
{
|
||||
if (ErrorRegex.IsMatch(e.Data))
|
||||
{
|
||||
returnCode = 1;
|
||||
}
|
||||
|
||||
Console.WriteLine(e.Data);
|
||||
}
|
||||
|
||||
};
|
||||
cmd.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
|
||||
cmd.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data);
|
||||
}
|
||||
|
||||
Console.WriteLine(command);
|
||||
cmd.Start();
|
||||
cmd.BeginOutputReadLine();
|
||||
cmd.BeginErrorReadLine();
|
||||
|
||||
cmd.StandardInput.WriteLine(command);
|
||||
cmd.StandardInput.Flush();
|
||||
cmd.StandardInput.Close();
|
||||
|
||||
if (waitForExit)
|
||||
{
|
||||
cmd.WaitForExit();
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
return cmd.ExitCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"profiles": {
|
||||
"ElectronNET.CLI": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "start /project-path \"C:\\Users\\Rizvi\\source\\repos\\Electron.NET\\ElectronNET.WebApp\" /watch"
|
||||
"commandLineArgs": "start /project-path \"$(SolutionDir)ElectronNET.WebApp\" /watch"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ElectronNET.CLI
|
||||
{
|
||||
@@ -29,10 +31,24 @@ namespace ElectronNET.CLI
|
||||
}
|
||||
if (currentName != "")
|
||||
Arguments[currentName] = values.ToArray();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine($"Arguments: \n\t{string.Join("\n\t",Arguments.Keys.Select(i => $"{i} = {string.Join(" ", Arguments[i])}"))}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
public bool Contains(string name)
|
||||
{
|
||||
return Arguments.ContainsKey(name);
|
||||
}
|
||||
|
||||
internal bool TryGet(string key, out string[] value)
|
||||
{
|
||||
value = null;
|
||||
if (!Contains(key)) {
|
||||
return false;
|
||||
}
|
||||
value = Arguments[key];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;gBACA,cAAc,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;oBAC7B,IAAI,IAAI,EAAE;wBACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,WAAW,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;qBACjD;gBACL,CAAC,CAAC,CAAC;aACN;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,QAAQ,EAAE,EAAE,EAAE,qBAAqB,EAAE,KAAK,CAAC,CAAC;aACtE;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AApBD,8BAoBC"}
|
||||
{"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;gBACA,cAAc,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;oBAC7B,IAAI,IAAI,EAAE;wBACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,WAAW,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;qBACjD;gBACL,CAAC,CAAC,CAAC;aACN;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,QAAQ,EAAE,EAAE,EAAE,qBAAqB,EAAE,KAAK,CAAC,CAAC;aACtE;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AApBD,8BAoBC"}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Socket } from 'socket.io';
|
||||
|
||||
export class Connector {
|
||||
constructor(private socket: SocketIO.Socket,
|
||||
constructor(private socket: Socket,
|
||||
// @ts-ignore
|
||||
public app: Electron.App) { }
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user