mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-05 21:24:33 +00:00
Compare commits
155 Commits
0.3.0-pre.
...
feature/se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5eb49b0e54 | ||
|
|
2390ba7b2f | ||
|
|
564ec7b191 | ||
|
|
32bcfa95ab | ||
|
|
cf735fab4c | ||
|
|
cf1cb18d7a | ||
|
|
8009348941 | ||
|
|
b3b124bde1 | ||
|
|
21226e1ef0 | ||
|
|
7174118a3e | ||
|
|
931aec8cd9 | ||
|
|
bbd1065a05 | ||
|
|
0fa0abd093 | ||
|
|
bfd51e64f7 | ||
|
|
bb4337a31c | ||
|
|
57753eb632 | ||
|
|
614673605a | ||
|
|
52744a1922 | ||
|
|
03da5cd7cb | ||
|
|
805d942b11 | ||
|
|
29b1f088ce | ||
|
|
4a62103749 | ||
|
|
38ee6fabb4 | ||
|
|
0ee2bbe31c | ||
|
|
a88e10bbf2 | ||
|
|
39c7e61ae5 | ||
|
|
96c454aedb | ||
|
|
5a77284610 | ||
|
|
0a23659196 | ||
|
|
5d224568d0 | ||
|
|
1c0b9378d2 | ||
|
|
c12a706289 | ||
|
|
8cc3fe4fd7 | ||
|
|
893de1510d | ||
|
|
6f49a663ea | ||
|
|
5b9e2b8b3b | ||
|
|
dee640c526 | ||
|
|
f598fbf5ce | ||
|
|
6847520ea8 | ||
|
|
75151282ff | ||
|
|
17ef6853ab | ||
|
|
12f011bc33 | ||
|
|
217fe83334 | ||
|
|
1fc881674d | ||
|
|
6e369aabef | ||
|
|
06a332827b | ||
|
|
23f79244ae | ||
|
|
6b9187cf6e | ||
|
|
108ef19a3b | ||
|
|
8c6020e35b | ||
|
|
547e9f1196 | ||
|
|
4b971af119 | ||
|
|
da8216b292 | ||
|
|
be609a513e | ||
|
|
c4a8de6c4e | ||
|
|
5b3d5e07ee | ||
|
|
9135aff855 | ||
|
|
e9efb26dff | ||
|
|
e29a3bc27a | ||
|
|
f55abb357c | ||
|
|
0b92336de2 | ||
|
|
4c17027039 | ||
|
|
5d04ab686a | ||
|
|
de0c02c503 | ||
|
|
054f5b1c4c | ||
|
|
04ec52208a | ||
|
|
268b9c90ce | ||
|
|
cb7d721b7d | ||
|
|
c1740b53fc | ||
|
|
40aed60c7d | ||
|
|
8ee81f6abd | ||
|
|
7f2ea4839e | ||
|
|
092789a5ec | ||
|
|
bff3fffcbd | ||
|
|
456135a562 | ||
|
|
300f52510c | ||
|
|
d85a64f515 | ||
|
|
53698d1d44 | ||
|
|
04a224aa4f | ||
|
|
891da140b7 | ||
|
|
17f761d184 | ||
|
|
9f6489891e | ||
|
|
c8f1cdf59f | ||
|
|
6c95dfd476 | ||
|
|
b180fc2ea8 | ||
|
|
682a1c38ed | ||
|
|
809b0a6be7 | ||
|
|
ae3f755648 | ||
|
|
7e6760a428 | ||
|
|
29fdbb5315 | ||
|
|
36bba6a49f | ||
|
|
44a010e0ed | ||
|
|
25770db138 | ||
|
|
1c99ab02cc | ||
|
|
73c56e2450 | ||
|
|
30037fce69 | ||
|
|
69048d5565 | ||
|
|
d9c8e04b5c | ||
|
|
368ef412bb | ||
|
|
cb20fbad25 | ||
|
|
89cdf2f55b | ||
|
|
1c62c1f132 | ||
|
|
d3e3188681 | ||
|
|
4f95043309 | ||
|
|
13f1203ccc | ||
|
|
9d0378798b | ||
|
|
1d6ef7a250 | ||
|
|
2d6d4e2320 | ||
|
|
df8e269d5c | ||
|
|
bdfbcd5b77 | ||
|
|
19e785f53f | ||
|
|
0b453177b5 | ||
|
|
8ed7f27722 | ||
|
|
321b8cd9e5 | ||
|
|
b326f863d8 | ||
|
|
f148fe6a14 | ||
|
|
515d325731 | ||
|
|
f32a40fe17 | ||
|
|
c53a5a9163 | ||
|
|
8d4cdddc46 | ||
|
|
70e8f85123 | ||
|
|
5a7cbd972f | ||
|
|
33da428c45 | ||
|
|
f1b4766360 | ||
|
|
e070759645 | ||
|
|
49eaa5e129 | ||
|
|
b3f5a3c52b | ||
|
|
0d732ce99e | ||
|
|
218b99808b | ||
|
|
7f507a6d86 | ||
|
|
81b3793966 | ||
|
|
1baa5c6200 | ||
|
|
5f76804065 | ||
|
|
70ffebf39d | ||
|
|
0a54735f35 | ||
|
|
1ac371b3da | ||
|
|
e854451043 | ||
|
|
331c2f548c | ||
|
|
b00adcbd38 | ||
|
|
ed6d24dbb1 | ||
|
|
bbc7c79d5a | ||
|
|
2389ae32bd | ||
|
|
42fecbdc98 | ||
|
|
95e02e2655 | ||
|
|
153625ba51 | ||
|
|
c97f914e7a | ||
|
|
d95b41fbae | ||
|
|
2b2b26e13b | ||
|
|
9bb2adca78 | ||
|
|
88d2daacb1 | ||
|
|
c90f003519 | ||
|
|
daa9f399e9 | ||
|
|
6246b44d68 | ||
|
|
347c1ef0e4 | ||
|
|
7c8eeef225 |
137
.github/CONTRIBUTING.md
vendored
Normal file
137
.github/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
# Contributing
|
||||
|
||||
## Project Scope
|
||||
|
||||
The Electron.NET project ultimately tries to provide a framework for developing cross-platform client applications on the basis of .NET and Electron. Anything that is related to this goal will be considered. The project aims to be as close to Electron with .NET as a basis as possible. If your contribution does not reflect that goal, the chances of accepting it are limited.
|
||||
|
||||
## Code License
|
||||
|
||||
This is an open source project falling under the [MIT License](../LICENSE). By using, distributing, or contributing to this project, you accept and agree that all code within the Electron.NET project and its libraries are licensed under MIT license.
|
||||
|
||||
## Becoming a Contributor
|
||||
|
||||
Usually appointing someone as a contributor follows this process:
|
||||
|
||||
1. An individual contributes actively via discussions (reporting bugs, giving feedback to existing or opening new issues) and / or pull requests
|
||||
2. The individual is either directly asked, invited or asks for contributor rights on the project
|
||||
3. The individual uses the contribution rights to sustain or increase the active contributions
|
||||
|
||||
Every contributor might have to sign the contributor's license agreement (CLA) to establish a legal trust between the project and its contributors.
|
||||
|
||||
## Working on Electron.NET
|
||||
|
||||
### Issue Discussion
|
||||
|
||||
Discussion of issues should be placed transparently in the issue tracker here on GitHub.
|
||||
|
||||
* [General issues, bugs, new features](https://github.com/ElectronNET/Electron.NET/issues)
|
||||
* [General discussions, help, exchange of ideas](https://github.com/ElectronNET/Electron.NET/discussions)
|
||||
|
||||
### Modifying the code
|
||||
|
||||
Electron.NET and its libraries uses features from the latest versions of C# (e.g., C# 10). You will therefore need a C# compiler that is up for the job.
|
||||
|
||||
1. Fork and clone the repo.
|
||||
2. First try to build the ElectronNET.Core library and see if you get the tests running.
|
||||
3. You will be required to resolve some dependencies via NuGet.
|
||||
|
||||
The build system of Electron.NET uses NUKE.
|
||||
|
||||
### Code Conventions
|
||||
|
||||
Most parts in the Electron.NET project are fairly straight forward. Among these are:
|
||||
|
||||
* Always use statement blocks for control statements, e.g., in a for-loop, if-condition, ...
|
||||
* You may use a simple (throw) statement in case of enforcing contracts on argument
|
||||
* Be explicit about modifiers (some files follow an older convention of the code base, but we settled on the explicit style)
|
||||
|
||||
### Development Workflow
|
||||
|
||||
1. If no issue already exists for the work you'll be doing, create one to document the problem(s) being solved and self-assign.
|
||||
2. Otherwise please let us know that you are working on the problem. Regular status updates (e.g. "still in progress", "no time anymore", "practically done", "pull request issued") are highly welcome.
|
||||
3. Create a new branch—please don't work in the `main` branch directly. It is reserved for releases. We recommend naming the branch to match the issue being addressed (`feature/#777` or `issue-777`).
|
||||
4. Add failing tests for the change you want to make. Tests are crucial and should be taken from W3C (or other specification).
|
||||
5. Fix stuff. Always go from edge case to edge case.
|
||||
6. All tests should pass now. Also your new implementation should not break existing tests.
|
||||
7. Update the documentation to reflect any changes. (or document such changes in the original issue)
|
||||
8. Push to your fork or push your issue-specific branch to the main repository, then submit a pull request against `develop`.
|
||||
|
||||
Just to illustrate the git workflow for Electron.NET a little bit more we've added the following graphs.
|
||||
|
||||
Initially, Electron.NET starts at the `main` branch. This branch should contain the latest stable (or released) version.
|
||||
|
||||
Here we now created a new branch called `develop`. This is the development branch.
|
||||
|
||||
Now active work is supposed to be done. Therefore a new branch should be created. Let's create one:
|
||||
|
||||
```sh
|
||||
git checkout -b feature/#777
|
||||
```
|
||||
|
||||
There may be many of these feature branches. Most of them are also pushed to the server for discussion or synchronization.
|
||||
|
||||
```sh
|
||||
git push -u origin feature/#777
|
||||
```
|
||||
|
||||
Now feature branches may be closed when they are done. Here we simply merge with the feature branch(es). For instance the following command takes the `feature/#777` branch from the server and merges it with the `develop` branch.
|
||||
|
||||
```sh
|
||||
git checkout develop
|
||||
git pull
|
||||
git pull origin feature/#777
|
||||
git push
|
||||
```
|
||||
|
||||
Finally, we may have all the features that are needed to release a new version of Electron.NET. Here we tag the release. For instance for the 1.0 release we use `v1.0`.
|
||||
|
||||
```sh
|
||||
git checkout main
|
||||
git merge develop
|
||||
git tag v1.0
|
||||
```
|
||||
|
||||
(The last part is automatically performed by our CI system. Don't tag manually.)
|
||||
|
||||
### Versioning
|
||||
|
||||
The rules of [semver](http://semver.org/) don't necessarily apply here, but we will try to stay quite close to them.
|
||||
|
||||
Prior to version 1.0.0 we use the following scheme:
|
||||
|
||||
1. MINOR versions for reaching a feature milestone potentially combined with dramatic API changes
|
||||
2. PATCH versions for refinements (e.g. performance improvements, bug fixes)
|
||||
|
||||
After releasing version 1.0.0 the scheme changes to become:
|
||||
|
||||
1. MAJOR versions at maintainers' discretion following significant changes to the codebase (e.g., API changes)
|
||||
2. MINOR versions for backwards-compatible enhancements (e.g., performance improvements)
|
||||
3. PATCH versions for backwards-compatible bug fixes (e.g., spec compliance bugs, support issues)
|
||||
|
||||
#### Code style
|
||||
|
||||
Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.** In general most of the [C# coding guidelines from Microsoft](https://msdn.microsoft.com/en-us/library/ff926074.aspx) are followed. This project prefers type inference with `var` to explicitly stating (redundant) information.
|
||||
|
||||
It is also important to keep a certain `async`-flow and to always use `ConfigureAwait(false)` in conjunction with an `await` expression.
|
||||
|
||||
## Backwards Compatibility
|
||||
|
||||
We always try to remain backwards compatible beyond the currently supported versions of .NET.
|
||||
|
||||
For instance, in December 2025 there have been activity to remove .NET 6 support from the codebase. We rejected this. Key points:
|
||||
|
||||
1. We have absolutely no need to drop `.net6` support. It doesn't hurt us in any way.
|
||||
2. Many are still using `.net6`, including Electron.NET (non-Core) users. It doesn't make sense to force them to update two things at the same time (.NET + Electron.NET).
|
||||
3. We MUST NOT and NEVER update `Microsoft.Build.Utilities.Core`. This will make Electron.NET stop working on older Visual Studio and MSBuild versions. There's are also no reasons to update it in the first place.
|
||||
|
||||
It's important to note that the Microsoft label of "Out of support" on .NET has almost no practical meaning. We've rarely (if ever) seen any bugs fixed in the same .NET version which mattered. The bugs that all new .NET versions have are much worse than mature .NET versions which are declared as "out of support". Keep in mind that the LTS matters most for active development / ongoing supported projects. If, e.g., a TV has been released a decade ago it most likely won't be patched. Still, you might want to deploy applications to it, which then naturally would involve being based on "out of support" versions of the framework.
|
||||
|
||||
TL;DR: Unless there is a technical reason (e.g., a crucial new API not being available) we should not drop "out of support" .NET versions. At the time of writing (December 2025) the minimum supported .NET version remains at `.net6`.
|
||||
|
||||
## Timeline
|
||||
|
||||
**All of this information is related to ElectronNET.Core pre-v1!**
|
||||
|
||||
We pretty much release whenever we have something new (i.e., do fixes such as a 0.1.1, or add new features, such as a 0.2.0) quite quickly.
|
||||
|
||||
We will go for a 1.0.0 release of this as early as ~mid of January 2026 (unless we find some critical things or want to extend the beta phase for ElectronNET.Core). This should be sufficient time to get some user input and have enough experience to call it stable.
|
||||
@@ -1,33 +1,25 @@
|
||||
name: CI
|
||||
name: Build and Publish
|
||||
|
||||
on: [push, pull_request]
|
||||
on: [push]
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
|
||||
|
||||
concurrency:
|
||||
group: build-publish-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# linux:
|
||||
# runs-on: ubuntu-latest
|
||||
# timeout-minutes: 10
|
||||
Integration-Tests:
|
||||
uses: ./.github/workflows/integration-tests.yml
|
||||
name: '1'
|
||||
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
|
||||
# - name: Setup dotnet
|
||||
# uses: actions/setup-dotnet@v4
|
||||
# with:
|
||||
# dotnet-version: |
|
||||
# 6.0.x
|
||||
# 8.0.x
|
||||
# 10.0.x
|
||||
|
||||
# - name: Build
|
||||
# run: ./build.sh
|
||||
|
||||
windows:
|
||||
Publish:
|
||||
needs: [Integration-Tests]
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 10
|
||||
name: '2 / Publish'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
39
.github/workflows/PR Validation.yml
vendored
Normal file
39
.github/workflows/PR Validation.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
name: PR Validation
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
concurrency:
|
||||
group: pr-validation-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
Whitespace-Check:
|
||||
uses: ./.github/workflows/trailing-whitespace-check.yml
|
||||
secrets: inherit
|
||||
name: '1'
|
||||
|
||||
Tests:
|
||||
needs: Whitespace-Check
|
||||
uses: ./.github/workflows/integration-tests.yml
|
||||
secrets: inherit
|
||||
name: '2'
|
||||
|
||||
build:
|
||||
needs: [Whitespace-Check, Tests]
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 10
|
||||
name: '3 / Build'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup dotnet
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Build
|
||||
run: .\build.ps1
|
||||
16
.github/workflows/integration-tests.yml
vendored
16
.github/workflows/integration-tests.yml
vendored
@@ -1,10 +1,7 @@
|
||||
name: Tests
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ develop, main ]
|
||||
pull_request:
|
||||
branches: [ develop, main ]
|
||||
workflow_call:
|
||||
|
||||
concurrency:
|
||||
group: integration-tests-${{ github.ref }}
|
||||
@@ -12,7 +9,7 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: Integration Tests (${{ matrix.os }} / Electron ${{ matrix.electronVersion }})
|
||||
name: ${{ matrix.os }} API-${{ matrix.electronVersion }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -45,6 +42,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Random delay (0-20 seconds)
|
||||
shell: bash
|
||||
run: |
|
||||
DELAY=$((RANDOM % 21))
|
||||
echo "Waiting for $DELAY seconds..."
|
||||
sleep $DELAY
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
|
||||
4
.github/workflows/pr-comment.yml
vendored
4
.github/workflows/pr-comment.yml
vendored
@@ -2,7 +2,7 @@ name: Create PR Comments
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Tests"]
|
||||
workflows: [ "PR Validation" ]
|
||||
types: [completed]
|
||||
|
||||
permissions:
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
pr-comment:
|
||||
name: Post Test Result as PR comment
|
||||
runs-on: ubuntu-24.04
|
||||
if: github.event.workflow_run.event == 'pull_request'
|
||||
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'cancelled'
|
||||
|
||||
steps:
|
||||
- name: Download CTRF artifact
|
||||
|
||||
49
.github/workflows/retry-test-jobs.yml
vendored
Normal file
49
.github/workflows/retry-test-jobs.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
name: Tests auto-rerun
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [ "PR Validation", "Build and Publish" ]
|
||||
types: [ completed ]
|
||||
|
||||
jobs:
|
||||
rerun-failed-matrix-jobs-once:
|
||||
if: >
|
||||
${{
|
||||
github.event.workflow_run.conclusion == 'failure' &&
|
||||
github.event.workflow_run.run_attempt == 1
|
||||
}}
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Decide whether to rerun (only if matrix jobs failed)
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
RUN_ID: ${{ github.event.workflow_run.id }}
|
||||
run: |
|
||||
echo "Inspecting jobs of workflow run $RUN_ID in $REPO"
|
||||
|
||||
jobs_json="$(gh api -R $REPO repos/$REPO/actions/runs/$RUN_ID/jobs)"
|
||||
|
||||
echo "Jobs and conclusions:"
|
||||
echo "$jobs_json" | jq '.jobs[] | {name: .name, conclusion: .conclusion}'
|
||||
|
||||
failed_matrix_jobs=$(echo "$jobs_json" | jq -r '
|
||||
[ .jobs[]
|
||||
| select(.conclusion == "failure"
|
||||
and (.name | contains(" API-")))
|
||||
]
|
||||
| length // 0
|
||||
')
|
||||
failed_matrix_jobs=${failed_matrix_jobs:-0}
|
||||
|
||||
if [ "${failed_matrix_jobs}" -gt 0 ]; then
|
||||
echo "Detected failing Integration Tests jobs – re-running failed jobs for this run."
|
||||
gh run rerun -R "$REPO" "$RUN_ID" --failed
|
||||
else
|
||||
echo "Only non-matrix jobs (like Test Results) failed – not auto-rerunning."
|
||||
fi
|
||||
@@ -1,11 +1,10 @@
|
||||
name: Trailing Whitespace Check
|
||||
name: Whitespace Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
check-trailing-whitespace:
|
||||
check-whitespace:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
35
Changelog.md
35
Changelog.md
@@ -1,10 +1,45 @@
|
||||
# 0.4.1
|
||||
|
||||
## ElectronNET.Core
|
||||
|
||||
- Fixed handling of `Center` property for windows (#1001)
|
||||
- Added missing methods on `Cookies` (#1000)
|
||||
|
||||
# 0.4.0
|
||||
|
||||
## ElectronNET.Core
|
||||
|
||||
- Fixed ElectronSingleInstance handling (#996) @softworkz
|
||||
- Fixed `PackageId` handling (#993) @softworkz
|
||||
- Added cross-platform npm restore and check mismatch on publish (#988) @softworkz
|
||||
|
||||
# 0.3.1
|
||||
|
||||
## ElectronNET.Core
|
||||
|
||||
- Fixed issue transforming the project ID (#989, #990) @softworkz
|
||||
|
||||
# 0.3.0
|
||||
|
||||
## ElectronNET.Core
|
||||
|
||||
- Updated infrastructure (#937, #939) @softworkz
|
||||
- Updated all model classes to Electron API 39.2 (#949) @softworkz
|
||||
- Fixed output path for `electron-builder` (#942) @softworkz
|
||||
- Fixed floating point display resolution (#944) @softworkz
|
||||
- Fixed error in case of missing electron-host-hook (#978)
|
||||
- Fixed previous API break using exposed `JsonElement` objects (#938) @softworkz
|
||||
- Fixed and improved several test cases (#962) @softworkz
|
||||
- Fixed startup of Electron.NET from VS Code Debug Adapter (#952)
|
||||
- Fixed the `BrowserWindowOptions` (#945) @softworkz
|
||||
- Fixed example for `AutoMenuHide` to reflect platform capabilities (#982) @markatosi
|
||||
- Added several migration checks for publishing (#966) @softworkz
|
||||
- Added more test runners for E2E tests (#950, #951) @agracio
|
||||
- Added dynamic updates for tray menu (#973) @davidroth
|
||||
- Added matrix tests with 6 runners and 2 electron version (#948) @softworkz
|
||||
- Added additional APIs for WebContents (#958) @agracio
|
||||
- Added documentation for MacOS package publish (#983) @markatosi
|
||||
- Added sample application for `ElectronHostHook` (#967) @adityashirsatrao007
|
||||
|
||||
# 0.2.0
|
||||
|
||||
|
||||
@@ -133,9 +133,10 @@ builder.UseElectron(args, async () =>
|
||||
{
|
||||
var options = new BrowserWindowOptions {
|
||||
Show = false,
|
||||
AutoHideMenuBar = true,
|
||||
IsRunningBlazor = true, // <-- crucial
|
||||
};
|
||||
if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux())
|
||||
options.AutoHideMenuBar = true;
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync(options);
|
||||
browserWindow.OnReadyToShow += () => browserWindow.Show();
|
||||
});
|
||||
|
||||
@@ -8,7 +8,9 @@ When you build an Electron.NET project, the following validation checks are perf
|
||||
|
||||
| Code | Check | Description |
|
||||
|------|-------|-------------|
|
||||
| [ELECTRON001](#1-packagejson-not-allowed) | package.json not allowed | Ensures no package.json exists outside ElectronHostHook |
|
||||
| [ELECTRON001](#1-packagejson-rules) | package.json location rules | Ensures `package.json`/`package-lock.json` aren’t present in unsupported locations (root `package.json` handled separately) |
|
||||
| [ELECTRON008](#1-packagejson-rules) | root package.json contains electron | Warns when root `package.json` contains the word `electron` (case-insensitive) |
|
||||
| [ELECTRON009](#1-packagejson-rules) | root package.json copied to output | Warns when root `package.json` is configured to be copied to output/publish |
|
||||
| [ELECTRON002](#2-electron-manifestjson-not-allowed) | electron-manifest.json not allowed | Detects deprecated manifest files |
|
||||
| [ELECTRON003](#3-electron-builderjson-location) | electron-builder.json location | Verifies electron-builder.json exists in Properties folder |
|
||||
| [ELECTRON004](#3-electron-builderjson-location) | electron-builder.json wrong location | Warns if electron-builder.json is found in incorrect locations |
|
||||
@@ -18,30 +20,44 @@ When you build an Electron.NET project, the following validation checks are perf
|
||||
|
||||
---
|
||||
|
||||
## 1. package.json not allowed
|
||||
## 1. package.json rules
|
||||
|
||||
**Warning Code:** `ELECTRON001`
|
||||
**Warning Codes:** `ELECTRON001`, `ELECTRON008`, `ELECTRON009`
|
||||
|
||||
### What is checked
|
||||
|
||||
The build system scans for `package.json` and `package-lock.json` files in your project directory. These files should not exist in the project root or subdirectories (with one exception).
|
||||
The build system scans for `package.json` and `package-lock.json` files in your project directory.
|
||||
|
||||
Rules:
|
||||
|
||||
- **ELECTRON001**: `package.json` / `package-lock.json` must not exist in the project directory or subdirectories
|
||||
- Exception: `ElectronHostHook` folder is allowed
|
||||
- Note: a **root** `package.json` is **excluded** from `ELECTRON001` and validated by `ELECTRON008` / `ELECTRON009`
|
||||
|
||||
- **ELECTRON008**: If a root `package.json` exists, it must **not** contain electron-related dependencies or configuration.
|
||||
|
||||
- **ELECTRON009**: If a root `package.json` exists, it must **not** be configured to be copied to output/publish (for example via `CopyToOutputDirectory` / `CopyToPublishDirectory` metadata)
|
||||
|
||||
### Why this matters
|
||||
|
||||
In previous versions of Electron.NET, a `package.json` file was required in the project. The new version generates this file automatically from MSBuild properties defined in your `.csproj` file.
|
||||
Electron.NET generates its Electron-related `package.json` during publishing based on MSBuild properties. A user-maintained Electron-related `package.json` can conflict with that process.
|
||||
|
||||
Also, ensuring the root `package.json` is not copied prevents accidentally shipping it with the published app.
|
||||
|
||||
### Exception
|
||||
|
||||
A `package.json` file **is allowed** in the `ElectronHostHook` folder if you're using custom host hooks. This is the only valid location for a manually maintained package.json.
|
||||
A `package.json` / `package-lock.json` file **is allowed** in the `ElectronHostHook` folder if you're using custom host hooks.
|
||||
|
||||
### How to fix
|
||||
|
||||
If you have an Electron-related `package.json` from older Electron.NET versions:
|
||||
|
||||
1. **Open your project's `.csproj` file**
|
||||
2. **Add the required properties** to a PropertyGroup with the label `ElectronNetCommon`:
|
||||
|
||||
```xml
|
||||
<PropertyGroup Label="ElectronNetCommon">
|
||||
<PackageId>my-electron-app</PackageId>
|
||||
<ElectronPackageId>my-electron-app</ElectronPackageId>
|
||||
<Title>My Electron App</Title>
|
||||
<Version>1.0.0</Version>
|
||||
<Description>My awesome Electron.NET application</Description>
|
||||
@@ -51,7 +67,12 @@ A `package.json` file **is allowed** in the `ElectronHostHook` folder if you're
|
||||
</PropertyGroup>
|
||||
```
|
||||
|
||||
3. **Delete the old `package.json`** file from your project root
|
||||
3. **Delete** Electron-related `package.json` / `package-lock.json` files (except those under `ElectronHostHook` if applicable)
|
||||
|
||||
If you keep a root `package.json` for non-Electron reasons:
|
||||
|
||||
- Ensure it does **not** contain electron dependencies or configuration (fixes `ELECTRON008`)
|
||||
- Ensure it is **not** copied to output/publish (fixes `ELECTRON009`)
|
||||
|
||||
> **See also:** [Migration Guide](Migration-Guide.md) for complete migration instructions.
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ dotnet add package ElectronNET.Core.AspNet # For ASP.NET projects
|
||||
### Step 2: Configure Project Settings
|
||||
|
||||
**Auto-generated Configuration:**
|
||||
ElectronNET.Core automatically creates `electron-builder.json` during the first build or NuGet restore. No manual configuration is needed for basic setups.
|
||||
ElectronNET.Core automatically creates `electron-builder.json` in the `Properties` folder of your project during the first build or NuGet restore. No manual configuration is needed for basic setups.
|
||||
|
||||
**Migrate Existing Configuration:**
|
||||
If you have an existing `electron.manifest.json` file:
|
||||
@@ -63,6 +63,9 @@ You can also manually edit `electron-builder.json`:
|
||||
}
|
||||
```
|
||||
|
||||
**Modify Launch Settings:**
|
||||
ElectronNET.Core no longer needs a separate CLI tool (electronize.exe) for launching. You should update your launch settings to use either the ASP.NET-first or Electron-first approach. See [Debugging](../Using/Debugging.md) for details.
|
||||
|
||||
## 🎯 Testing Migration
|
||||
|
||||
After completing the migration steps:
|
||||
|
||||
@@ -54,7 +54,7 @@ Add the Electron.NET configuration to your `.csproj` file:
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.3.0" />
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.4.1" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
|
||||
583
docs/SignalR-Authentication-Guide.md
Normal file
583
docs/SignalR-Authentication-Guide.md
Normal file
@@ -0,0 +1,583 @@
|
||||
# Electron.NET SignalR Authentication Guide
|
||||
|
||||
This guide explains the token-based authentication system implemented for SignalR mode in Electron.NET, designed to protect applications in multi-user environments.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
1. [Overview](#overview)
|
||||
2. [Threat Model](#threat-model)
|
||||
3. [Authentication Architecture](#authentication-architecture)
|
||||
4. [Implementation Details](#implementation-details)
|
||||
5. [Security Properties](#security-properties)
|
||||
6. [Troubleshooting](#troubleshooting)
|
||||
7. [FAQ](#faq)
|
||||
|
||||
## Overview
|
||||
|
||||
Electron.NET's SignalR mode includes built-in authentication to ensure that only the Electron process spawned by a specific .NET instance can connect to that instance's HTTP and SignalR endpoints.
|
||||
|
||||
**When is this important?**
|
||||
- Multi-user Windows Server environments (Terminal Services, RDP)
|
||||
- Shared development machines with multiple users
|
||||
- Any scenario where multiple users run the same application simultaneously
|
||||
|
||||
**What does it protect against?**
|
||||
- User A's Electron process connecting to User B's .NET backend
|
||||
- Unauthorized port scanning and connection attempts from other users
|
||||
- Accidental misconfigurations causing cross-user connections
|
||||
|
||||
## Threat Model
|
||||
|
||||
### The Problem
|
||||
|
||||
When multiple users run the same Electron.NET application on a shared server:
|
||||
|
||||
1. Each .NET process binds to a TCP port (e.g., `http://localhost:58971`)
|
||||
2. TCP ports are visible to **all users** on the machine
|
||||
3. Without authentication, User A's Electron could connect to User B's backend
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────┐
|
||||
│ Windows Server (Terminal Services) │
|
||||
├─────────────────────────────────────────────────┤
|
||||
│ User A Session │
|
||||
│ ├─ .NET Process (localhost:58971) │
|
||||
│ └─ Electron Process │
|
||||
│ │
|
||||
│ User B Session │
|
||||
│ ├─ .NET Process (localhost:61234) │
|
||||
│ └─ Electron Process (could connect to 58971) │ ❌ Prevent this!
|
||||
└─────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### The Solution
|
||||
|
||||
Each .NET process generates a unique authentication token when launching Electron. Only requests with the correct token are allowed to connect.
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────┐
|
||||
│ User A Session │
|
||||
│ ├─ .NET (token: abc123...) │
|
||||
│ └─ Electron (has token abc123...) │ ✅ Authenticated
|
||||
│ │
|
||||
│ User B Session │
|
||||
│ ├─ .NET (token: xyz789...) │
|
||||
│ └─ Electron (has token xyz789...) │ ✅ Authenticated
|
||||
│ │
|
||||
│ ❌ User B's Electron → User A's .NET │
|
||||
│ (lacks token abc123...) │ ❌ Rejected (401)
|
||||
└─────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Authentication Architecture
|
||||
|
||||
### Flow Diagram
|
||||
|
||||
```
|
||||
┌──────────────┐ ┌─────────────────┐
|
||||
│ .NET Process │ │ Electron Process│
|
||||
└──────┬───────┘ └────────┬────────┘
|
||||
│ │
|
||||
│ 1. Generate Token (GUID) │
|
||||
│ Token: a3f8b2c1d4e5... │
|
||||
│ │
|
||||
│ 2. Launch Electron │
|
||||
│ --authtoken=a3f8b2c1d4e5... │
|
||||
│────────────────────────────────────────────────────>│
|
||||
│ │
|
||||
│ │ 3. Extract Token
|
||||
│ │ global.authToken = ...
|
||||
│ │
|
||||
│ │ 4. Initial Page Load
|
||||
│<────────────────────────────────────────────────────│
|
||||
│ GET /?token=a3f8b2c1d4e5... │
|
||||
│ │
|
||||
│ 5. Validate Token │
|
||||
│ ✓ Valid → Set Cookie │
|
||||
│────────────────────────────────────────────────────>│
|
||||
│ HTTP 200 + Set-Cookie: ElectronAuth=... │
|
||||
│ │
|
||||
│ │ 6. SignalR Connection
|
||||
│<────────────────────────────────────────────────────│
|
||||
│ GET /electron-hub?token=a3f8b2c1d4e5... │
|
||||
│ │
|
||||
│ 7. Validate Token, Set Cookie │
|
||||
│────────────────────────────────────────────────────>│
|
||||
│ HTTP 200 + Set-Cookie │
|
||||
│ │
|
||||
│ │ 8. Subsequent Requests
|
||||
│<────────────────────────────────────────────────────│
|
||||
│ GET /api/data │
|
||||
│ Cookie: ElectronAuth=a3f8b2c1d4e5... │
|
||||
│ │
|
||||
│ 9. Validate Cookie │
|
||||
│────────────────────────────────────────────────────>│
|
||||
│ HTTP 200 (authenticated) │
|
||||
│ │
|
||||
```
|
||||
|
||||
### Key Steps
|
||||
|
||||
1. **Token Generation**: .NET generates 128-bit cryptographic random GUID
|
||||
2. **Command-Line Passing**: Token passed to Electron via `--authtoken` parameter
|
||||
3. **Token Extraction**: Electron stores token in `global.authToken`
|
||||
4. **URL Appending**: Token appended to initial page and SignalR connection URLs
|
||||
5. **Middleware Validation**: Every HTTP request validated by middleware
|
||||
6. **Cookie Setting**: Valid token results in secure HttpOnly cookie
|
||||
7. **Cookie-Based Requests**: Subsequent requests use cookie (no token in URL)
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### 1. Token Generation (.NET)
|
||||
|
||||
**File**: `src/ElectronNET.AspNet/Runtime/Controllers/RuntimeControllerAspNetDotnetFirstSignalR.cs`
|
||||
|
||||
```csharp
|
||||
private void LaunchElectron()
|
||||
{
|
||||
// Generate secure authentication token (128-bit cryptographic random GUID)
|
||||
this.authenticationToken = Guid.NewGuid().ToString("N"); // 32 hex chars
|
||||
|
||||
// Register token with authentication service
|
||||
this.authenticationService.SetExpectedToken(this.authenticationToken);
|
||||
|
||||
// Launch Electron with token
|
||||
var args = $"--unpackeddotnetsignalr --electronurl={this.actualUrl} --authtoken={this.authenticationToken}";
|
||||
this.electronProcess = new ElectronProcessActive(isUnPacked, ElectronNetRuntime.ElectronExecutable, args, this.port.Value);
|
||||
_ = this.electronProcess.Start();
|
||||
}
|
||||
```
|
||||
|
||||
**Token Format**: 32-character hexadecimal string (e.g., `a3f8b2c1d4e5f6a7b8c9d0e1f2a3b4c5`)
|
||||
|
||||
### 2. Authentication Service (.NET)
|
||||
|
||||
**File**: `src/ElectronNET.AspNet/Services/ElectronAuthenticationService.cs`
|
||||
|
||||
```csharp
|
||||
public class ElectronAuthenticationService : IElectronAuthenticationService
|
||||
{
|
||||
private string _expectedToken;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public void SetExpectedToken(string token)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_expectedToken = token;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateToken(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token))
|
||||
return false;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_expectedToken))
|
||||
return false;
|
||||
|
||||
// Constant-time comparison prevents timing attacks
|
||||
return ConstantTimeEquals(token, _expectedToken);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ConstantTimeEquals(string a, string b)
|
||||
{
|
||||
if (a == null || b == null || a.Length != b.Length)
|
||||
return false;
|
||||
|
||||
var result = 0;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
result |= a[i] ^ b[i];
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key Features**:
|
||||
- Thread-safe with lock
|
||||
- Constant-time comparison (prevents timing attacks)
|
||||
- Singleton lifetime (one per .NET instance)
|
||||
|
||||
### 3. Authentication Middleware (.NET)
|
||||
|
||||
**File**: `src/ElectronNET.AspNet/Middleware/ElectronAuthenticationMiddleware.cs`
|
||||
|
||||
```csharp
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
// Check if authentication cookie exists
|
||||
var authCookie = context.Request.Cookies["ElectronAuth"];
|
||||
|
||||
if (!string.IsNullOrEmpty(authCookie))
|
||||
{
|
||||
if (_authService.ValidateToken(authCookie))
|
||||
{
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Invalid cookie for path {Path}", context.Request.Path);
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized: Invalid authentication");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No cookie - check for token in query string
|
||||
var token = context.Request.Query["token"].ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(token) && _authService.ValidateToken(token))
|
||||
{
|
||||
// Valid token - set cookie for future requests
|
||||
context.Response.Cookies.Append("ElectronAuth", token, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Path = "/",
|
||||
Secure = false, // localhost is HTTP
|
||||
IsEssential = true
|
||||
});
|
||||
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reject - no valid cookie or token
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized: Authentication required");
|
||||
}
|
||||
```
|
||||
|
||||
**Middleware Order** (IMPORTANT):
|
||||
```csharp
|
||||
app.UseMiddleware<ElectronAuthenticationMiddleware>(); // ← FIRST
|
||||
app.UseRouting();
|
||||
app.UseStaticFiles();
|
||||
app.UseAntiforgery();
|
||||
app.MapHub<ElectronHub>("/electron-hub");
|
||||
app.MapRazorComponents<App>();
|
||||
```
|
||||
|
||||
### 4. Token Extraction (Electron)
|
||||
|
||||
**File**: `src/ElectronNET.Host/main.js`
|
||||
|
||||
```javascript
|
||||
// Extract authentication token from command-line
|
||||
if (app.commandLine.hasSwitch('authtoken')) {
|
||||
global.authToken = app.commandLine.getSwitchValue('authtoken');
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Token in URLs (Electron)
|
||||
|
||||
**Initial Page Load** (`src/ElectronNET.Host/api/browserWindows.js`):
|
||||
```javascript
|
||||
// Append token to window URL
|
||||
if (global.authToken) {
|
||||
const separator = electronUrl.includes('?') ? '&' : '?';
|
||||
electronUrl = `${electronUrl}${separator}token=${global.authToken}`;
|
||||
}
|
||||
window.loadURL(electronUrl);
|
||||
```
|
||||
|
||||
**SignalR Connection** (`src/ElectronNET.Host/api/signalr-bridge.js`):
|
||||
```javascript
|
||||
async connect() {
|
||||
// Append token to SignalR hub URL
|
||||
const connectionUrl = this.authToken ?
|
||||
`${this.hubUrl}?token=${this.authToken}` :
|
||||
this.hubUrl;
|
||||
|
||||
this.connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl(connectionUrl)
|
||||
.build();
|
||||
|
||||
await this.connection.start();
|
||||
}
|
||||
```
|
||||
|
||||
### 6. Service Registration (Application)
|
||||
|
||||
**File**: Your application's `Program.cs`
|
||||
|
||||
```csharp
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Register authentication service as singleton
|
||||
builder.Services.AddSingleton<IElectronAuthenticationService, ElectronAuthenticationService>();
|
||||
|
||||
builder.Services.AddElectron();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Register middleware BEFORE UseRouting()
|
||||
app.UseMiddleware<ElectronAuthenticationMiddleware>();
|
||||
|
||||
app.UseRouting();
|
||||
app.MapHub<ElectronHub>("/electron-hub");
|
||||
app.Run();
|
||||
```
|
||||
|
||||
## Security Properties
|
||||
|
||||
### Cookie Configuration
|
||||
|
||||
| Property | Value | Purpose |
|
||||
|----------|-------|---------|
|
||||
| `HttpOnly` | `true` | Prevents JavaScript access (XSS protection) |
|
||||
| `SameSite` | `Strict` | Prevents CSRF attacks |
|
||||
| `Path` | `/` | Cookie sent with all requests |
|
||||
| `Secure` | `false` | Cannot use on localhost HTTP |
|
||||
| `IsEssential` | `true` | Required for app to function |
|
||||
| **Lifetime** | Session | Expires when Electron closes |
|
||||
|
||||
### Token Properties
|
||||
|
||||
- **Entropy**: 128 bits (2^128 possible values)
|
||||
- **Format**: 32 hexadecimal characters (GUID without hyphens)
|
||||
- **Generation**: `Guid.NewGuid()` uses cryptographically secure RNG
|
||||
- **Lifetime**: Entire application session
|
||||
- **Uniqueness**: Each .NET instance generates unique token
|
||||
|
||||
### What's Protected
|
||||
|
||||
✅ **All HTTP endpoints**:
|
||||
- Blazor Server pages (`/`, `/counter`, etc.)
|
||||
- Static files (`/css/app.css`, `/js/script.js`)
|
||||
- API endpoints (custom controllers)
|
||||
- SignalR hub (`/electron-hub`)
|
||||
|
||||
✅ **Both transport modes**:
|
||||
- Initial token-based authentication (query parameter)
|
||||
- Cookie-based subsequent requests
|
||||
|
||||
✅ **Cross-user isolation**:
|
||||
- Different users = different tokens
|
||||
- Invalid token = 401 Unauthorized
|
||||
|
||||
### What's NOT Protected Against
|
||||
|
||||
❌ **Same-user attacks** (by design):
|
||||
- Process memory inspection
|
||||
- Debugger attachment
|
||||
- Command-line parameter visibility
|
||||
|
||||
**Rationale**: A malicious process running as the same user already has full access to:
|
||||
- Process memory (can read token from RAM)
|
||||
- Cookies (stored in Electron's data directory)
|
||||
- All files owned by the user
|
||||
|
||||
Token-based authentication focuses on **cross-user isolation**, not same-user security.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Problem: 401 Unauthorized on Initial Load
|
||||
|
||||
**Symptoms**:
|
||||
```
|
||||
GET / HTTP/1.1
|
||||
Response: 401 Unauthorized
|
||||
```
|
||||
|
||||
**Possible Causes**:
|
||||
1. Token not passed to Electron
|
||||
2. Token not appended to URL
|
||||
3. Middleware rejecting valid token
|
||||
|
||||
**Debugging Steps**:
|
||||
|
||||
1. Check Electron command-line:
|
||||
```javascript
|
||||
console.log('Auth Token:', global.authToken);
|
||||
```
|
||||
Should print 32-character hex string.
|
||||
|
||||
2. Check URL in browser window:
|
||||
```javascript
|
||||
console.log('Loading URL:', electronUrl);
|
||||
```
|
||||
Should include `?token=<guid>` parameter.
|
||||
|
||||
3. Check .NET logs:
|
||||
```
|
||||
[Warning] Authentication failed: Invalid token (prefix: a3f8b2c1...)
|
||||
```
|
||||
|
||||
4. Verify middleware registration:
|
||||
```csharp
|
||||
app.UseMiddleware<ElectronAuthenticationMiddleware>(); // Before UseRouting()
|
||||
```
|
||||
|
||||
### Problem: SignalR Connection Fails
|
||||
|
||||
**Symptoms**:
|
||||
```
|
||||
[SignalRBridge] Authentication failed: The authentication token is invalid or missing.
|
||||
```
|
||||
|
||||
**Possible Causes**:
|
||||
1. Token not passed to `SignalRBridge` constructor
|
||||
2. Token not appended to hub URL
|
||||
3. Cookie not being sent
|
||||
|
||||
**Debugging Steps**:
|
||||
|
||||
1. Check token passed to SignalRBridge:
|
||||
```javascript
|
||||
console.log('SignalRBridge token:', this.authToken);
|
||||
```
|
||||
|
||||
2. Check connection URL:
|
||||
```javascript
|
||||
console.log('Hub URL:', connectionUrl);
|
||||
```
|
||||
Should be `http://localhost:PORT/electron-hub?token=<guid>`.
|
||||
|
||||
3. Enable verbose logging:
|
||||
```javascript
|
||||
.configureLogging(signalR.LogLevel.Debug)
|
||||
```
|
||||
|
||||
### Problem: Cookie Not Persisting
|
||||
|
||||
**Symptoms**: Every request includes token in URL, cookie never set.
|
||||
|
||||
**Possible Causes**:
|
||||
1. Cookie settings incompatible with browser
|
||||
2. Middleware not setting cookie
|
||||
3. Response headers not sent
|
||||
|
||||
**Debugging Steps**:
|
||||
|
||||
1. Check response headers:
|
||||
```
|
||||
Set-Cookie: ElectronAuth=a3f8b2c1...; Path=/; HttpOnly; SameSite=Strict
|
||||
```
|
||||
|
||||
2. Check subsequent requests:
|
||||
```
|
||||
Cookie: ElectronAuth=a3f8b2c1...
|
||||
```
|
||||
|
||||
3. Enable middleware logging:
|
||||
```csharp
|
||||
_logger.LogInformation("Setting cookie for path {Path}", path);
|
||||
```
|
||||
|
||||
### Problem: Token Visible in Process List
|
||||
|
||||
**Observation**:
|
||||
```powershell
|
||||
wmic process where "name='electron.exe'" get commandline
|
||||
...--authtoken=a3f8b2c1d4e5f6a7b8c9d0e1f2a3b4c5...
|
||||
```
|
||||
|
||||
**Is this a problem?** No, by design.
|
||||
|
||||
**Explanation**:
|
||||
- Command-line parameters are visible to same-user processes
|
||||
- This is acceptable because:
|
||||
- Same user already has access to process memory
|
||||
- Same user can read cookies from Electron's data directory
|
||||
- Token-based auth protects against **other users**, not same-user processes
|
||||
|
||||
**If you need same-user protection**: Use OS-level access controls (file permissions, process isolation) or consider named pipes with ACLs.
|
||||
|
||||
## FAQ
|
||||
|
||||
### Q: Why use tokens instead of Process ID validation?
|
||||
|
||||
**A**: PIDs can be recycled and reused, making validation unreliable. Additionally:
|
||||
- PIDs don't provide cryptographic security
|
||||
- Parent-child validation is platform-specific
|
||||
- Adds complexity without meaningful security benefit
|
||||
|
||||
Token-based authentication provides:
|
||||
- Cryptographic randomness (128-bit entropy)
|
||||
- Simple cross-platform implementation
|
||||
- No race conditions or PID recycling issues
|
||||
|
||||
### Q: Why not use HTTPS with certificates?
|
||||
|
||||
**A**: Localhost doesn't support HTTPS certificates easily:
|
||||
- Self-signed certificates trigger browser warnings
|
||||
- Certificate management adds complexity
|
||||
- Token-based auth provides equivalent security for localhost IPC
|
||||
|
||||
### Q: Can I disable authentication?
|
||||
|
||||
**A**: Not recommended, but possible by removing middleware registration:
|
||||
|
||||
```csharp
|
||||
// Remove this line:
|
||||
// app.UseMiddleware<ElectronAuthenticationMiddleware>();
|
||||
```
|
||||
|
||||
**Warning**: Only do this if:
|
||||
- Application runs on single-user machines only
|
||||
- No Terminal Services / RDP access
|
||||
- You understand the security implications
|
||||
|
||||
### Q: Does this work with hot reload?
|
||||
|
||||
**A**: Yes, cookie persists across hot reload as long as Electron process keeps running.
|
||||
|
||||
### Q: What about multiple Electron windows?
|
||||
|
||||
**A**: All windows in the same Electron process share cookies automatically. Authentication works seamlessly across multiple windows.
|
||||
|
||||
### Q: How do I test authentication?
|
||||
|
||||
**Test 1 - Happy Path**:
|
||||
1. Run application normally
|
||||
2. Check logs for "Authentication successful"
|
||||
3. Verify cookie is set (DevTools → Application → Cookies)
|
||||
4. Subsequent requests should not include token in URL
|
||||
|
||||
**Test 2 - Invalid Token**:
|
||||
1. Modify token in browser URL: `?token=invalid`
|
||||
2. Should receive 401 Unauthorized
|
||||
3. Check logs for "Authentication failed: Invalid token"
|
||||
|
||||
**Test 3 - No Token**:
|
||||
1. Open browser manually to `http://localhost:PORT/`
|
||||
2. Should receive 401 Unauthorized
|
||||
3. Check logs for "Authentication failed: No cookie or token"
|
||||
|
||||
**Test 4 - Multi-User** (Windows Server/Terminal Services):
|
||||
1. Launch app as User A
|
||||
2. In User B session, try to connect to User A's port
|
||||
3. Should receive 401 Unauthorized
|
||||
|
||||
### Q: What about packaged applications?
|
||||
|
||||
**A**: Authentication works identically in packaged mode. The `--authtoken` parameter is included in the packaged Electron executable.
|
||||
|
||||
### Q: Can I customize the cookie name?
|
||||
|
||||
**A**: Yes, modify `AuthCookieName` constant in `ElectronAuthenticationMiddleware.cs`:
|
||||
|
||||
```csharp
|
||||
private const string AuthCookieName = "MyCustomCookieName";
|
||||
```
|
||||
|
||||
## Summary
|
||||
|
||||
Electron.NET's token-based authentication provides:
|
||||
|
||||
✅ **Security**: 128-bit entropy, constant-time comparison, secure cookies
|
||||
✅ **Simplicity**: Automatic token generation and validation
|
||||
✅ **Compatibility**: Works with Blazor, SignalR, and static files
|
||||
✅ **Monitoring**: Structured logging for security events
|
||||
✅ **Multi-User**: Cross-user isolation on shared servers
|
||||
|
||||
The authentication system is **enabled by default** in SignalR mode and requires minimal configuration. For most applications, simply register the services and middleware - everything else happens automatically.
|
||||
|
||||
For additional help or questions, see the [SignalR Implementation Summary](SignalR-Implementation-Summary.md) or open an issue on GitHub.
|
||||
450
docs/SignalR-Implementation-Summary.md
Normal file
450
docs/SignalR-Implementation-Summary.md
Normal file
@@ -0,0 +1,450 @@
|
||||
# SignalR Implementation Summary
|
||||
|
||||
This document summarizes the completed implementation of SignalR-based bidirectional communication in Electron.NET as an alternative to Socket.IO.
|
||||
|
||||
## Overview
|
||||
|
||||
The SignalR implementation provides a modern, .NET-native alternative to Socket.IO for communication between the ASP.NET Core host and the Electron process. This new startup mode was designed specifically for **Blazor Server applications** where ASP.NET Core and Electron need tighter integration and lifecycle control.
|
||||
|
||||
**Key Innovation**: .NET-first startup with dynamic port assignment - ASP.NET Core starts first, binds to port 0 (letting Kestrel choose an available port), then launches Electron with the actual URL.
|
||||
|
||||
## Primary Use Case
|
||||
|
||||
Blazor Server applications where:
|
||||
- ASP.NET Core owns the application lifecycle
|
||||
- Dynamic port binding is needed (no fixed port configuration)
|
||||
- Modern SignalR infrastructure is preferred over Socket.IO
|
||||
- Single process debugging is desired (.NET process controls Electron)
|
||||
|
||||
## Implementation Phases (All Complete)
|
||||
|
||||
### Phase 1: Core Infrastructure ✅
|
||||
- Added new `StartupMethod` enum values:
|
||||
- `UnpackagedDotnetFirstSignalR`
|
||||
- `PackagedDotnetFirstSignalR`
|
||||
- Created `ElectronHub` SignalR hub for bidirectional communication
|
||||
- Registered hub endpoint at `/electron-hub` (separate from Blazor's `/_blazor` hub)
|
||||
|
||||
### Phase 2: Runtime Controller ✅
|
||||
- Created `RuntimeControllerAspNetDotnetFirstSignalR`
|
||||
- Implemented logic to:
|
||||
- Bind Kestrel to port 0
|
||||
- Wait for Kestrel startup and capture actual port via `IServerAddressesFeature`
|
||||
- Launch Electron with `--electronurl` parameter
|
||||
- Wait for SignalR connection from Electron
|
||||
- Transition to Ready state when connected
|
||||
|
||||
### Phase 3: Electron/Node.js Side ✅
|
||||
- Added `@microsoft/signalr` npm package dependency
|
||||
- Created SignalR connection module (`signalr-bridge.js`)
|
||||
- Updated `main.js` to detect SignalR modes and connect to `/electron-hub`
|
||||
- Implemented Socket.IO-compatible interface for API compatibility
|
||||
|
||||
### Phase 4: API Bridge Adaptation ✅
|
||||
- Created `SignalRFacade` implementing `IFacade` interface
|
||||
- Ensured existing Electron API classes work with SignalR
|
||||
- Implemented type conversion helper for SignalR's JSON deserialization
|
||||
- Event routing from both directions (.NET ↔ Electron)
|
||||
|
||||
### Phase 5: Configuration & Extensions ✅
|
||||
- Updated `WebHostBuilderExtensions` for automatic SignalR configuration
|
||||
- Added startup mode detection via command-line flags
|
||||
- Configured dynamic port binding (port 0) for SignalR modes
|
||||
- Integrated with `UseElectron()` API for seamless usage
|
||||
|
||||
### Phase 6: Testing & Fixes ✅
|
||||
- Created sample Blazor Server application
|
||||
- Fixed multiple critical issues discovered during integration testing
|
||||
- Cleaned up debug logging
|
||||
- Added comprehensive code documentation
|
||||
|
||||
## Key Components
|
||||
|
||||
### 1. SignalRFacade (`src/ElectronNET.AspNet/Bridge/SignalRFacade.cs`)
|
||||
- Implements `IFacade` interface to match Socket.IO facade API
|
||||
- Handles bidirectional event routing using `IHubContext<ElectronHub>`
|
||||
- Includes `ConvertToType<T>` helper for handling SignalR's JSON deserialization quirks
|
||||
- Critical fix: Handles `JsonElement` and numeric type conversions (long → int)
|
||||
|
||||
### 2. ElectronHub (`src/ElectronNET.AspNet/Hubs/ElectronHub.cs`)
|
||||
- SignalR hub for .NET ↔ Electron communication
|
||||
- Key methods:
|
||||
- `RegisterElectronClient()` - Called by Electron on connection
|
||||
- `ElectronEvent(string, object[])` - Receives events from Electron
|
||||
- Connection/disconnection handlers notify runtime controller
|
||||
|
||||
### 3. RuntimeControllerAspNetDotnetFirstSignalR
|
||||
- Manages SignalR mode lifecycle
|
||||
- Critical flow:
|
||||
1. Wait for ASP.NET server to start
|
||||
2. Capture dynamic port from `IServerAddressesFeature`
|
||||
3. Update `ElectronNetRuntime.AspNetWebPort` with actual port
|
||||
4. Launch Electron with `--electronurl` parameter
|
||||
5. Wait for `electron-host-ready` signal before calling app ready callback
|
||||
|
||||
### 4. SignalRBridge (`src/ElectronNET.Host/api/signalr-bridge.js`)
|
||||
- JavaScript SignalR client that mimics Socket.IO interface
|
||||
- Provides `on()` and `emit()` methods for API compatibility
|
||||
- Critical fix: Event args passed as arrays, spread when calling handlers
|
||||
- Uses `@microsoft/signalr` npm package
|
||||
|
||||
### 5. Main.js Startup (`src/ElectronNET.Host/main.js`)
|
||||
- Detects SignalR mode via `--unpackeddotnetsignalr` or `--dotnetpackedsignalr` flags
|
||||
- Creates invisible keep-alive window (destroyed when first real window is created)
|
||||
- Loads API modules then signals `electron-host-ready` to .NET
|
||||
|
||||
## Usage
|
||||
|
||||
Enable SignalR mode by passing the appropriate command-line flag:
|
||||
|
||||
```bash
|
||||
# Unpacked mode (development)
|
||||
dotnet run --unpackeddotnetsignalr
|
||||
|
||||
# Packed mode (production)
|
||||
dotnet run --dotnetpackedsignalr
|
||||
```
|
||||
|
||||
Or set environment variable (deprecated, flags preferred):
|
||||
```bash
|
||||
ELECTRON_USE_SIGNALR=true
|
||||
```
|
||||
|
||||
In your ASP.NET Core Program.cs:
|
||||
|
||||
```csharp
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add Electron.NET services
|
||||
builder.Services.AddElectron();
|
||||
|
||||
// Configure Electron with SignalR mode
|
||||
builder.WebHost.UseElectron(args, async () =>
|
||||
{
|
||||
var window = await Electron.WindowManager.CreateWindowAsync();
|
||||
window.OnReadyToShow += () => window.Show();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// Map SignalR hub for Electron communication
|
||||
app.MapHub<ElectronHub>("/electron-hub");
|
||||
|
||||
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
||||
app.Run();
|
||||
```
|
||||
|
||||
**Note**: `UseElectron()` automatically detects SignalR mode and configures everything. The rest happens automatically:
|
||||
1. Port 0 binding (dynamic port assignment)
|
||||
2. Electron launch with actual URL
|
||||
3. SignalR connection establishment (WebSockets enabled automatically by MapHub)
|
||||
4. App ready callback execution
|
||||
2. Electron launch with actual URL
|
||||
3. SignalR connection establishment (WebSockets enabled automatically by `MapHub`)
|
||||
4. App ready callback execution
|
||||
|
||||
## Architecture Decisions
|
||||
|
||||
### Why .NET-First Startup?
|
||||
SignalR mode uses .NET-first startup (vs. Electron-first in Socket.IO mode) because:
|
||||
1. **No port scanning needed** - .NET can pass the actual URL to Electron
|
||||
2. **SignalR hub must be registered** before Electron connects
|
||||
3. **Simpler lifecycle** - ASP.NET controls when Electron launches
|
||||
4. **Better for Blazor Server** - Blazor is already running when Electron starts
|
||||
5. **Single process debugging** - Developer debugs .NET process which owns Electron
|
||||
|
||||
### Why IFacade Interface?
|
||||
Introducing `IFacade` allows `BridgeConnector.Socket` to return either `SocketIOFacade` or `SignalRFacade` based on startup mode, ensuring existing API code works with both transport mechanisms without modification.
|
||||
|
||||
### Why Keep-Alive Window?
|
||||
Electron quits immediately on macOS if no windows exist. The keep-alive window ensures Electron stays running during the connection and API initialization phase. It's automatically destroyed when the first real window is created.
|
||||
|
||||
### Why 'electron-host-ready' Signal?
|
||||
Without this signal, .NET would call the app ready callback before Electron finished loading API modules, causing API calls to fail. The signal ensures proper initialization order:
|
||||
1. Electron connects to SignalR
|
||||
2. Electron loads all API modules (browserWindows, dialog, menu, etc.)
|
||||
3. Electron signals `electron-host-ready`
|
||||
4. .NET calls app ready callback
|
||||
5. App code can safely use Electron APIs
|
||||
|
||||
## Blazor Server Considerations
|
||||
|
||||
### SignalR Hub Coexistence
|
||||
Blazor Server already uses SignalR for component communication (`/_blazor` hub). Our implementation:
|
||||
- Uses separate endpoint (`/electron-hub`) to avoid conflicts
|
||||
- Both hubs coexist on the same Kestrel server without interference
|
||||
- No impact on Blazor's reconnection logic
|
||||
- Compatible with hot reload scenarios
|
||||
|
||||
### Lifecycle Integration
|
||||
- Electron window creation happens **after** Blazor app is ready
|
||||
- `UseElectron()` callback fires when SignalR hub is connected
|
||||
- Blazor components can inject Electron services to control windows
|
||||
- Proper disposal when Electron process exits
|
||||
|
||||
### Development Experience
|
||||
- Hot reload works for both Blazor and Electron integration
|
||||
- F5 debugging works seamlessly
|
||||
- No need to manually coordinate ports
|
||||
- Single process to debug (.NET process owns the lifecycle)
|
||||
|
||||
## Critical Fixes Applied
|
||||
|
||||
### 1. Race Condition: API Module Loading
|
||||
**Problem**: .NET called app ready callback before Electron finished loading API modules.
|
||||
|
||||
**Solution**: Electron signals `electron-host-ready` after loading all API modules. .NET waits for this signal before calling the app ready callback.
|
||||
|
||||
### 2. Event Argument Mismatch
|
||||
**Problem**: SignalR sent event data as nested arrays `[[data]]` instead of `[data]`.
|
||||
|
||||
**Solution**:
|
||||
- C#: Use explicit `object[] args` parameter (not `params`)
|
||||
- JS: Always pass args as array: `invoke('ElectronEvent', eventName, args)`
|
||||
- JS: Spread args when calling handlers: `handler(...argsArray)`
|
||||
|
||||
### 3. Type Conversion Failures
|
||||
**Problem**: SignalR deserializes JSON numbers as `JsonElement` or `long`, causing `Once<int>` handlers to fail silently.
|
||||
|
||||
**Solution**: `SignalRFacade.ConvertToType<T>` handles JsonElement deserialization and numeric conversions.
|
||||
|
||||
### 4. Window Shutdown Not Triggering Exit
|
||||
**Problem**: Keep-alive window prevented `window-all-closed` event from firing.
|
||||
|
||||
**Solution**: Destroy keep-alive window when first real window is created using `app.once('browser-window-created')`.
|
||||
|
||||
### 5. Dynamic Port Not Propagated
|
||||
**Problem**: When using port 0, Kestrel assigns a dynamic port, but `ElectronNetRuntime.AspNetWebPort` was not updated.
|
||||
|
||||
**Solution**: Update `AspNetWebPort` after capturing port from `IServerAddressesFeature` in `CapturePortAndLaunchElectron()`.
|
||||
|
||||
### 7. Blazor Static Files Not Loading
|
||||
**Problem**: Blazor CSS and framework files returned 404 errors.
|
||||
|
||||
**Solution**:
|
||||
- Added `app.UseStaticFiles()` to serve wwwroot content
|
||||
- Fixed middleware order: `UseAntiforgery()` must be between `UseRouting()` and `UseEndpoints()`
|
||||
- Updated scoped CSS asset reference to use lowercase name matching .NET 9+ convention
|
||||
|
||||
## Authentication & Security
|
||||
|
||||
### Token-Based Authentication (Multi-User Protection)
|
||||
|
||||
SignalR mode includes built-in authentication to prevent unauthorized connections in multi-user scenarios (e.g., Windows Server with Terminal Services/RDP).
|
||||
|
||||
**Threat Model**: On shared servers, multiple users can run the same application simultaneously. Without authentication, User A's Electron process could potentially connect to User B's ASP.NET backend.
|
||||
|
||||
**Solution**: Token-based authentication with secure cookies.
|
||||
|
||||
### Authentication Flow
|
||||
|
||||
1. **.NET generates token**: When launching Electron, `RuntimeControllerAspNetDotnetFirstSignalR` generates a cryptographically secure GUID (128-bit entropy)
|
||||
2. **Token passed via command-line**: Electron receives `--authtoken=<guid>` parameter
|
||||
3. **Token appended to URLs**:
|
||||
- Initial page load: `http://localhost:PORT/?token=<guid>`
|
||||
- SignalR connection: `http://localhost:PORT/electron-hub?token=<guid>`
|
||||
4. **Middleware validates token**: `ElectronAuthenticationMiddleware` checks every HTTP request
|
||||
5. **Cookie set on first request**: After successful token validation, secure HttpOnly cookie is set
|
||||
6. **Subsequent requests use cookie**: No token in URLs after initial authentication
|
||||
|
||||
### Security Properties
|
||||
|
||||
- **Cookie Settings**:
|
||||
- `HttpOnly`: true (prevents JavaScript access, XSS protection)
|
||||
- `SameSite`: Strict (prevents CSRF)
|
||||
- `Path`: / (applies to all routes)
|
||||
- `Secure`: false (localhost is HTTP, not HTTPS)
|
||||
- `IsEssential`: true (required for app to function)
|
||||
- **Lifetime**: Session scope (expires when Electron closes)
|
||||
|
||||
- **Token Validation**:
|
||||
- Constant-time string comparison (prevents timing attacks)
|
||||
- Token stored in singleton service (one per .NET instance)
|
||||
- Never logged in full (only first 8 characters for debugging)
|
||||
|
||||
- **Protection Scope**:
|
||||
- All HTTP endpoints (Blazor pages, static files, API calls)
|
||||
- SignalR hub connection (negotiate and all hub traffic)
|
||||
- Both initial request and cookie-based requests validated
|
||||
|
||||
### What This Protects Against
|
||||
|
||||
✅ **Protected**:
|
||||
- Cross-user connections (User A → User B's backend)
|
||||
- Port scanning attacks from other users
|
||||
- Accidental connections from misconfigured processes
|
||||
|
||||
❌ **NOT Protected Against** (By Design):
|
||||
- Malicious same-user processes with debugger access
|
||||
- Process memory inspection tools (same privilege level)
|
||||
- Command-line parameter visibility (same user can see all processes)
|
||||
|
||||
**Rationale**: Same-user attacks already have full access to process memory, files, and cookies. Token-based authentication focuses on cross-user isolation, which is the primary threat in multi-user environments.
|
||||
|
||||
### Implementation Components
|
||||
|
||||
1. **IElectronAuthenticationService** (`src/ElectronNET.AspNet/Services/`)
|
||||
- Singleton service storing expected token
|
||||
- Thread-safe with lock-based validation
|
||||
- Constant-time comparison to prevent timing attacks
|
||||
|
||||
2. **ElectronAuthenticationMiddleware** (`src/ElectronNET.AspNet/Middleware/`)
|
||||
- Validates every HTTP request before routing
|
||||
- Checks cookie first, then token query parameter
|
||||
- Sets cookie on first valid token
|
||||
- Returns 401 for invalid/missing authentication
|
||||
- Structured logging for security monitoring
|
||||
|
||||
3. **Token Generation** (`RuntimeControllerAspNetDotnetFirstSignalR.cs`)
|
||||
- `Guid.NewGuid().ToString("N")` = 32 hex characters
|
||||
- Called in `LaunchElectron()` method
|
||||
- Registered with authentication service immediately
|
||||
|
||||
4. **Electron Integration** (`main.js`, `signalr-bridge.js`)
|
||||
- Extracts token from `--authtoken` parameter
|
||||
- Stores in `global.authToken` for module access
|
||||
- Appends to browser window URL and SignalR connection URL
|
||||
|
||||
### Usage in Custom Applications
|
||||
|
||||
Authentication is **enabled by default** in SignalR mode. No additional configuration required beyond service registration:
|
||||
|
||||
```csharp
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Register authentication service (singleton)
|
||||
builder.Services.AddSingleton<IElectronAuthenticationService, ElectronAuthenticationService>();
|
||||
|
||||
builder.Services.AddElectron();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Register middleware BEFORE UseRouting()
|
||||
app.UseMiddleware<ElectronAuthenticationMiddleware>();
|
||||
|
||||
app.UseRouting();
|
||||
app.MapHub<ElectronHub>("/electron-hub");
|
||||
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
||||
app.Run();
|
||||
```
|
||||
|
||||
The rest is automatic:
|
||||
- Token generation happens when Electron launches
|
||||
- Token validation happens on every request
|
||||
- Cookie management is handled by the middleware
|
||||
|
||||
### Logging & Monitoring
|
||||
|
||||
Authentication events are logged with structured logging:
|
||||
|
||||
**Successful authentication**:
|
||||
```
|
||||
[Information] Authentication successful: Setting cookie for path /
|
||||
```
|
||||
|
||||
**Failed authentication**:
|
||||
```
|
||||
[Warning] Authentication failed: Invalid token (prefix: a3f8b2c1...) for path / from 127.0.0.1
|
||||
[Warning] Authentication failed: No cookie or token provided for path /api/data from 127.0.0.1
|
||||
[Warning] Authentication failed: Invalid cookie for path /_blazor from 127.0.0.1
|
||||
```
|
||||
|
||||
**SignalR connection failures**:
|
||||
```
|
||||
[SignalRBridge] Authentication failed: The authentication token is invalid or missing.
|
||||
[SignalRBridge] Please ensure the --authtoken parameter is correctly passed to Electron.
|
||||
```
|
||||
|
||||
Log failed authentication attempts for security monitoring and troubleshooting.
|
||||
|
||||
### Testing Multi-User Scenarios
|
||||
|
||||
To test authentication in multi-user environments:
|
||||
|
||||
1. **Run as different Windows users**:
|
||||
```powershell
|
||||
# User A session
|
||||
dotnet run
|
||||
|
||||
# User B session (different RDP/Terminal Services session)
|
||||
dotnet run
|
||||
```
|
||||
|
||||
2. **Verify isolation**: User A's Electron cannot access User B's backend
|
||||
3. **Check logs**: Failed auth attempts should be logged
|
||||
4. **Monitor tokens**: Each instance generates unique token
|
||||
|
||||
For development testing on single-user machines, simulate by running multiple instances and attempting to connect with wrong/missing tokens.
|
||||
|
||||
## Backward Compatibility
|
||||
|
||||
This is a **new optional startup mode** - all existing modes continue to work unchanged:
|
||||
- `PackagedElectronFirst` - unchanged
|
||||
- `PackagedDotnetFirst` - unchanged
|
||||
- `UnpackedElectronFirst` - unchanged
|
||||
- `UnpackedDotnetFirst` - unchanged
|
||||
|
||||
Existing applications do not need to change. SignalR mode is opt-in via command-line flags.
|
||||
|
||||
## File Changes Summary
|
||||
|
||||
**New Files**:
|
||||
- `src/ElectronNET.AspNet/Bridge/SignalRFacade.cs` (225 lines)
|
||||
- `src/ElectronNET.AspNet/Hubs/ElectronHub.cs` (108 lines)
|
||||
- `src/ElectronNET.AspNet/Runtime/Controllers/RuntimeControllerAspNetDotnetFirstSignalR.cs` (163 lines)
|
||||
- `src/ElectronNET.AspNet/Services/IElectronAuthenticationService.cs` (20 lines)
|
||||
- `src/ElectronNET.AspNet/Services/ElectronAuthenticationService.cs` (65 lines)
|
||||
- `src/ElectronNET.AspNet/Middleware/ElectronAuthenticationMiddleware.cs` (105 lines)
|
||||
- `src/ElectronNET.Host/api/signalr-bridge.js` (125 lines)
|
||||
|
||||
**Modified Files**:
|
||||
- `src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs` - Added SignalR service registration
|
||||
- `src/ElectronNET.Host/main.js` - Added SignalR startup flow and token extraction
|
||||
- `src/ElectronNET.Host/api/browserWindows.js` - Token appended to window URLs
|
||||
- `src/ElectronNET.Host/package.json` - Added `@microsoft/signalr` dependency
|
||||
- `src/ElectronNET.Samples.BlazorSignalR/Program.cs` - Sample with authentication
|
||||
|
||||
**Total Changes**: ~1,220 lines added
|
||||
|
||||
## Testing Recommendations
|
||||
|
||||
1. Test with dynamic port (port 0) to ensure URL propagation works
|
||||
2. Verify window-all-closed triggers app exit
|
||||
3. Test rapid window creation/destruction
|
||||
4. Verify reconnection behavior if SignalR connection drops
|
||||
5. Test with both packed and unpacked modes
|
||||
6. Verify API calls work correctly (especially those returning data)
|
||||
|
||||
## Known Limitations
|
||||
|
||||
1. **Request-response pattern not yet implemented** - `InvokeElectronApi` is a placeholder. Current API calls use event-based pattern.
|
||||
2. **TouchBar API not yet supported** on macOS SignalR mode
|
||||
3. **SignalR automatic reconnection** may cause issues with pending API calls (needs circuit breaker pattern)
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
1. **Request-response pattern** - Implement proper async/await pattern for API calls that return values
|
||||
2. **Metrics/diagnostics** - Add SignalR connection health monitoring
|
||||
3. **Circuit breaker** - Handle reconnection scenarios gracefully
|
||||
4. **Integration tests** - Comprehensive test suite for SignalR mode
|
||||
5. **Performance benchmarks** - Compare SignalR vs Socket.IO performance
|
||||
|
||||
## Success Metrics
|
||||
|
||||
The implementation is considered complete and functional:
|
||||
- ✅ .NET starts first with dynamic port (port 0)
|
||||
- ✅ Electron launches with actual URL
|
||||
- ✅ SignalR connection establishes successfully
|
||||
- ✅ API modules load before app ready callback
|
||||
- ✅ Window creation works from .NET
|
||||
- ✅ Window shutdown triggers app exit
|
||||
- ✅ Blazor Server pages load with correct styling
|
||||
- ✅ Both SignalR hubs coexist (Electron + Blazor)
|
||||
- ✅ Clean codebase with minimal debug logging
|
||||
- ✅ Comprehensive inline documentation
|
||||
- ✅ Token-based authentication for multi-user scenarios
|
||||
- ✅ Secure cookie-based session management
|
||||
- ✅ Structured logging for security monitoring
|
||||
- ✅ Protection against cross-user connection attempts
|
||||
236
docs/SignalR-Startup-Mode.md
Normal file
236
docs/SignalR-Startup-Mode.md
Normal file
@@ -0,0 +1,236 @@
|
||||
# SignalR-Based Startup Mode for Electron.NET
|
||||
|
||||
## Overview
|
||||
|
||||
This feature adds a new startup mode for Electron.NET where:
|
||||
- **.NET/ASP.NET Core starts first** and binds to port 0 (dynamic port)
|
||||
- **Kestrel picks an available port** automatically
|
||||
- **Electron process is launched** with the actual URL
|
||||
- **SignalR is used for communication** instead of socket.io
|
||||
- **Blazor Server apps** can coexist with Electron control
|
||||
|
||||
## Status
|
||||
|
||||
✅ **Phases 1-5 Complete** - Infrastructure ready, basic functionality implemented
|
||||
⏸️ **Phase 6 Pending** - Full API integration, testing, and documentation
|
||||
|
||||
## How It Works
|
||||
|
||||
### Startup Sequence
|
||||
|
||||
1. ASP.NET Core application starts
|
||||
2. Kestrel binds to `http://localhost:0` (random available port)
|
||||
3. `RuntimeControllerAspNetDotnetFirstSignalR` captures the actual port via `IServerAddressesFeature`
|
||||
4. Electron process is launched with `--electronUrl=http://localhost:XXXXX`
|
||||
5. Electron's main.js detects SignalR mode (via `--dotnetpackedsignalr` or `--unpackeddotnetsignalr` flag)
|
||||
6. Electron connects to SignalR hub at `/electron-hub`
|
||||
7. Hub notifies runtime controller of successful connection
|
||||
8. Application transitions to "Ready" state
|
||||
9. `ElectronAppReady` callback is invoked
|
||||
|
||||
### Communication Flow
|
||||
|
||||
```
|
||||
.NET/Kestrel (Port 0) ←→ SignalR Hub (/electron-hub) ←→ Electron Process
|
||||
↓ ↓ ↓
|
||||
Blazor Server ElectronHub class SignalR Client
|
||||
(/_blazor hub) (API commands) (main.js + signalr-bridge.js)
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### 1. Enable SignalR Mode
|
||||
|
||||
Set the environment variable:
|
||||
```bash
|
||||
ELECTRON_USE_SIGNALR=true
|
||||
```
|
||||
|
||||
Or in launchSettings.json:
|
||||
```json
|
||||
{
|
||||
"environmentVariables": {
|
||||
"ELECTRON_USE_SIGNALR": "true"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Configure ASP.NET Core
|
||||
|
||||
In your `Program.cs`:
|
||||
|
||||
```csharp
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Entities;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddElectron();
|
||||
|
||||
builder.UseElectron(args, async () =>
|
||||
{
|
||||
var window = await Electron.WindowManager.CreateWindowAsync(
|
||||
new BrowserWindowOptions { Show = false });
|
||||
|
||||
window.OnReadyToShow += () => window.Show();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure middleware
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
// Map the Electron SignalR hub
|
||||
app.MapElectronHub(); // ← Required for SignalR mode
|
||||
app.MapRazorPages();
|
||||
|
||||
app.Run();
|
||||
```
|
||||
|
||||
### 3. Run Your Application
|
||||
|
||||
Just press F5 in Visual Studio or run:
|
||||
```bash
|
||||
dotnet run
|
||||
```
|
||||
|
||||
The application will:
|
||||
- Automatically detect SignalR mode via environment variable
|
||||
- Bind Kestrel to port 0
|
||||
- Launch Electron with the correct URL
|
||||
- Establish SignalR connection
|
||||
|
||||
## Components
|
||||
|
||||
### .NET Side
|
||||
|
||||
- **`ElectronHub`** - SignalR hub at `/electron-hub`
|
||||
- **`SignalRFacade`** - Mimics `SocketIoFacade` interface for compatibility
|
||||
- **`RuntimeControllerAspNetDotnetFirstSignalR`** - Lifecycle management
|
||||
- **`StartupMethod.PackagedDotnetFirstSignalR`** - For packaged apps
|
||||
- **`StartupMethod.UnpackedDotnetFirstSignalR`** - For debugging
|
||||
|
||||
### Electron Side
|
||||
|
||||
- **`signalr-bridge.js`** - SignalR client wrapper
|
||||
- **`main.js`** - Detects SignalR mode and connects to hub
|
||||
- **`@microsoft/signalr`** npm package
|
||||
|
||||
## Key Features
|
||||
|
||||
✅ **Dynamic Port Assignment** - No hardcoded ports, no conflicts
|
||||
✅ **Blazor Server Compatible** - Separate hub endpoints (`/electron-hub` vs `/_blazor`)
|
||||
✅ **Bidirectional Communication** - Both .NET→Electron and Electron→.NET
|
||||
✅ **Hot Reload Support** - SignalR automatic reconnection
|
||||
✅ **Multiple Instances** - Each instance gets its own port
|
||||
|
||||
## Current Limitations (Phase 6 Work Needed)
|
||||
|
||||
⚠️ **Electron API Integration** - Existing Electron APIs (WindowManager, Dialog, etc.) still use SocketIoFacade. Full integration requires:
|
||||
- Refactoring APIs to work with both facades, or
|
||||
- Creating an adapter pattern
|
||||
|
||||
⚠️ **Request-Response Pattern** - Current hub methods are one-way. Need to implement proper async request-response for API calls.
|
||||
|
||||
⚠️ **Event Routing** - Electron events need to be routed through SignalR back to .NET.
|
||||
|
||||
⚠️ **Testing** - Integration tests needed to validate end-to-end functionality.
|
||||
|
||||
## What's Implemented
|
||||
|
||||
### Phase 1: Core Infrastructure ✅
|
||||
- New `StartupMethod` enum values
|
||||
- `ElectronHub` SignalR hub
|
||||
- Hub endpoint registration
|
||||
|
||||
### Phase 2: Runtime Controller ✅
|
||||
- `RuntimeControllerAspNetDotnetFirstSignalR`
|
||||
- Port 0 binding logic
|
||||
- Electron launch with URL parameter
|
||||
- SignalR connection tracking
|
||||
|
||||
### Phase 3: Electron/Node.js Side ✅
|
||||
- `@microsoft/signalr` package integration
|
||||
- SignalR connection module
|
||||
- Startup mode detection
|
||||
- URL parameter handling
|
||||
|
||||
### Phase 4: API Bridge ✅ (Basic Structure)
|
||||
- `SignalRFacade` class
|
||||
- Event handler system
|
||||
- Hub connection integration
|
||||
|
||||
### Phase 5: Configuration ✅
|
||||
- Environment variable detection
|
||||
- Port 0 configuration
|
||||
- Automatic service registration
|
||||
|
||||
## Next Steps (Phase 6)
|
||||
|
||||
To fully utilize this feature, the following work is recommended:
|
||||
|
||||
1. **API Integration** - Make existing Electron APIs work with SignalR
|
||||
2. **Sample Application** - Create a Blazor Server demo
|
||||
3. **Integration Tests** - Validate end-to-end scenarios
|
||||
4. **Documentation** - Complete user guides and examples
|
||||
5. **Performance Testing** - Compare with socket.io mode
|
||||
|
||||
## Files Changed
|
||||
|
||||
### .NET
|
||||
- `src/ElectronNET.API/Runtime/Data/StartupMethod.cs`
|
||||
- `src/ElectronNET.AspNet/Hubs/ElectronHub.cs`
|
||||
- `src/ElectronNET.AspNet/Bridge/SignalRFacade.cs`
|
||||
- `src/ElectronNET.AspNet/Runtime/Controllers/RuntimeControllerAspNetDotnetFirstSignalR.cs`
|
||||
- `src/ElectronNET.AspNet/API/ElectronEndpointRouteBuilderExtensions.cs`
|
||||
- `src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs`
|
||||
- `src/ElectronNET.API/Runtime/StartupManager.cs`
|
||||
|
||||
### Electron/Node.js
|
||||
- `src/ElectronNET.Host/package.json`
|
||||
- `src/ElectronNET.Host/main.js`
|
||||
- `src/ElectronNET.Host/api/signalr-bridge.js` (new file)
|
||||
|
||||
## Commits
|
||||
|
||||
```
|
||||
7f2ea48 - Add PackagedDotnetFirstSignalR and UnpackedDotnetFirstSignalR startup methods
|
||||
8ee81f6 - Add ElectronHub and SignalR infrastructure for new startup modes
|
||||
40aed60 - Add RuntimeControllerAspNetDotnetFirstSignalR for SignalR-based startup
|
||||
c1740b5 - Add SignalR client support to Electron Host for new startup modes
|
||||
cb7d721 - Add SignalRFacade for SignalR-based API communication
|
||||
268b9c9 - Update RuntimeControllerAspNetDotnetFirstSignalR to use SignalRFacade
|
||||
04ec522 - Fix compilation errors - Phase 4 complete (basic structure)
|
||||
054f5b1 - Complete Phase 5: Add SignalR startup detection and port 0 configuration
|
||||
```
|
||||
|
||||
## Benefits Over Socket.io Mode
|
||||
|
||||
- **Better Integration** - Native SignalR is part of ASP.NET Core stack
|
||||
- **Type Safety** - SignalR has better TypeScript support
|
||||
- **Performance** - SignalR is optimized for ASP.NET Core
|
||||
- **Reliability** - Built-in reconnection and error handling
|
||||
- **Scalability** - Can leverage SignalR's scale-out features
|
||||
- **Consistency** - Blazor Server already uses SignalR
|
||||
|
||||
## Contributing
|
||||
|
||||
To contribute to Phase 6 (full API integration):
|
||||
|
||||
1. Focus on adapting existing Electron API classes to work with SignalRFacade
|
||||
2. Implement request-response pattern in ElectronHub
|
||||
3. Add integration tests
|
||||
4. Create sample applications
|
||||
5. Update documentation
|
||||
|
||||
## License
|
||||
|
||||
MIT - Same as Electron.NET
|
||||
|
||||
---
|
||||
|
||||
**Created**: January 30, 2026
|
||||
**Status**: Infrastructure Complete, API Integration Pending
|
||||
**Contact**: See Electron.NET maintainers
|
||||
@@ -25,7 +25,7 @@ These are the current default values when you don't make any changes:
|
||||
<ElectronSingleInstance>true</ElectronSingleInstance>
|
||||
<ElectronSplashScreen></ElectronSplashScreen>
|
||||
<ElectronIcon></ElectronIcon>
|
||||
<PackageId>$(MSBuildProjectName.Replace(".", "-").ToLower())</PackageId>
|
||||
<ElectronPackageId>$(MSBuildProjectName.Replace(".", "-").ToLower())</ElectronPackageId>
|
||||
<ElectronBuilderJson>electron-builder.json</ElectronBuilderJson>
|
||||
<Title>$(MSBuildProjectName)</Title>
|
||||
</PropertyGroup>
|
||||
@@ -38,15 +38,15 @@ Since electron builder still expects a `package.json` file to exist, ElectronNET
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "$(PackageId)",
|
||||
"name": "$(ElectronPackageId)",
|
||||
"productName": "$(ElectronTitle)",
|
||||
"build": {
|
||||
"appId": "$(PackageId)",
|
||||
"appId": "$(ElectronPackageId)",
|
||||
"linux": {
|
||||
"desktop": {
|
||||
"entry": { "Name": "$(Title)" }
|
||||
},
|
||||
"executableName": "$(PackageId)"
|
||||
"executableName": "$(ElectronPackageId)"
|
||||
},
|
||||
"deb": {
|
||||
"desktop": {
|
||||
|
||||
74
docs/Using/Custom_main.md
Normal file
74
docs/Using/Custom_main.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Using custom_main.js
|
||||
|
||||
This guide explains how to include and use a `custom_main.js` file in your Electron.NET application for advanced Electron/Node.js customization.
|
||||
|
||||
## Why use custom_main.js?
|
||||
|
||||
- Register custom protocol handlers (e.g., `myapp://`) — protocols must be registered before the app is fully initialized
|
||||
- Integrate Node.js modules (e.g., telemetry, OS APIs)
|
||||
- Control startup logic (abort, environment checks)
|
||||
- Set up IPC messaging or preload scripts
|
||||
|
||||
## Step-by-Step Process
|
||||
|
||||
### 1. Create the custom_main.js file
|
||||
|
||||
Place your custom logic in `electron/custom_main.js`:
|
||||
|
||||
```javascript
|
||||
module.exports.onStartup = function(host) {
|
||||
// Example: Register a global shortcut for opening dev tools
|
||||
const { app, globalShortcut, BrowserWindow } = require('electron');
|
||||
app.on('ready', () => {
|
||||
const ret = globalShortcut.register('Control+Shift+I', () => {
|
||||
BrowserWindow.getAllWindows().forEach(win => win.webContents.openDevTools());
|
||||
console.log('Ctrl+Shift+I is pressed: DevTools opened!');
|
||||
});
|
||||
});
|
||||
app.on('will-quit', () => {
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
return true;
|
||||
};
|
||||
```
|
||||
|
||||
### 2. Configure your .csproj to copy custom_main.js to output
|
||||
|
||||
Add this to your `.csproj` file:
|
||||
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<None Update="electron\custom_main.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<TargetPath>.electron\custom_main.js</TargetPath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
### 3. Build and run your app
|
||||
|
||||
Use the standard build/run commands:
|
||||
|
||||
```powershell
|
||||
dotnet build
|
||||
dotnet run
|
||||
```
|
||||
|
||||
Electron.NET will automatically load and execute your `custom_main.js` before initializing the .NET backend.
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
Use environment variables to control features:
|
||||
|
||||
```javascript
|
||||
const env = process.env.ASPNETCORE_ENVIRONMENT || 'Production';
|
||||
if (env === 'Development') { /* enable dev features */ }
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- `custom_main.js` must use CommonJS syntax (`module.exports.onStartup = ...`).
|
||||
- Place the file in your source directory and copy it to `.electron` using `.csproj`.
|
||||
- Electron.NET will abort startup if `onStartup` returns `false`.
|
||||
|
||||
### Complete example is available here [ElectronNetSampleApp](https://github.com/niteshsinghal85/ElectronNetSampleApp)
|
||||
@@ -62,6 +62,52 @@ Add publish profiles to `Properties/PublishProfiles/`:
|
||||
</Project>
|
||||
```
|
||||
|
||||
#### ASP.NET Application Profile (macOS Apple Silicon ARM64)
|
||||
|
||||
**osx-arm64.pubxml:**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<DeleteExistingFiles>true</DeleteExistingFiles>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
|
||||
<ProjectGuid>48eff821-2f4d-60cc-aa44-be0f1d6e5f35</ProjectGuid>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
```
|
||||
|
||||
#### ASP.NET Application Profile (macOS Intel x64)
|
||||
|
||||
**osx-x64.pubxml:**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<DeleteExistingFiles>true</DeleteExistingFiles>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<PublishUrl>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<ProjectGuid>48eff821-2f4d-60cc-aa44-be0f1d6e5f35</ProjectGuid>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
```
|
||||
|
||||
#### Console Application Profile (Windows)
|
||||
|
||||
**win-x64.pubxml:**
|
||||
@@ -103,6 +149,46 @@ Add publish profiles to `Properties/PublishProfiles/`:
|
||||
</Project>
|
||||
```
|
||||
|
||||
#### Console Application Profile (macOS Apple Silicon ARM64)
|
||||
|
||||
**osx-arm64.pubxml:**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
```
|
||||
|
||||
#### Console Application Profile (macOS Intel x64)
|
||||
|
||||
**osx-x64.pubxml:**
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<PublishDir>publish\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
```
|
||||
|
||||
### Step 2: Configure Electron Builder
|
||||
|
||||
ElectronNET.Core automatically adds a default `electron-builder.json` file under `Properties\electron-builder.json`.
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
- [Startup-Methods](Using/Startup-Methods.md)
|
||||
- [Debugging](Using/Debugging.md)
|
||||
- [Package Building](Using/Package-Building.md)
|
||||
- [Adding a `custom_main.js`](Using/Custom_main.md)
|
||||
|
||||
# API Reference
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace></RootNamespace>
|
||||
<NoWarn>CS0649;CS0169</NoWarn>
|
||||
<NukeRootDirectory>..</NukeRootDirectory>
|
||||
@@ -11,9 +11,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build" Version="17.11.48" />
|
||||
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.11.48" />
|
||||
<PackageReference Include="Nuke.Common" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Build" Version="18.0.2" />
|
||||
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="18.0.2" />
|
||||
<PackageReference Include="Nuke.Common" Version="10.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ElectronNET.API
|
||||
CamelCase,
|
||||
}
|
||||
|
||||
private const int InvocationTimeout = 1000;
|
||||
private static readonly TimeSpan InvocationTimeout = 1000.ms();
|
||||
|
||||
private readonly string objectName;
|
||||
private readonly ConcurrentDictionary<string, Invocator> invocators;
|
||||
@@ -120,7 +120,7 @@ namespace ElectronNET.API
|
||||
return this.InvokeAsyncWithTimeout<T>(InvocationTimeout, arg, callerName);
|
||||
}
|
||||
|
||||
protected Task<T> InvokeAsyncWithTimeout<T>(int invocationTimeout, object arg = null, [CallerMemberName] string callerName = null)
|
||||
protected Task<T> InvokeAsyncWithTimeout<T>(TimeSpan invocationTimeout, object arg = null, [CallerMemberName] string callerName = null)
|
||||
{
|
||||
Debug.Assert(callerName != null, nameof(callerName) + " != null");
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace ElectronNET.API
|
||||
private readonly Task<T> tcsTask;
|
||||
private TaskCompletionSource<T> tcs;
|
||||
|
||||
public Invocator(ApiBase apiBase, string callerName, int timeoutMs, object arg = null)
|
||||
public Invocator(ApiBase apiBase, string callerName, TimeSpan timeout, object arg = null)
|
||||
{
|
||||
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
this.tcsTask = this.tcs.Task;
|
||||
@@ -306,7 +306,7 @@ namespace ElectronNET.API
|
||||
_ = apiBase.Id >= 0 ? BridgeConnector.Socket.Emit(messageName, apiBase.Id) : BridgeConnector.Socket.Emit(messageName);
|
||||
}
|
||||
|
||||
System.Threading.Tasks.Task.Delay(timeoutMs).ContinueWith(_ =>
|
||||
System.Threading.Tasks.Task.Delay(timeout).ContinueWith(_ =>
|
||||
{
|
||||
if (this.tcs != null)
|
||||
{
|
||||
@@ -314,7 +314,9 @@ namespace ElectronNET.API
|
||||
{
|
||||
if (this.tcs != null)
|
||||
{
|
||||
var ex = new TimeoutException($"No response after {timeoutMs:D}ms trying to retrieve value {apiBase.objectName}.{callerName}()");
|
||||
var ex = new TimeoutException(
|
||||
$"No response after {(long)timeout.TotalMilliseconds}ms trying to retrieve value {apiBase.objectName}.{callerName}()"
|
||||
);
|
||||
this.tcs.TrySetException(ex);
|
||||
this.tcs = null;
|
||||
}
|
||||
|
||||
@@ -186,6 +186,19 @@ public class BrowserWindow : ApiBase
|
||||
remove => RemoveEvent(value, Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emitted when the window is moved or resized.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// While not being an original Electron event, this one includes the bounds values,
|
||||
/// saving the additional roundtrip for calling <see cref="GetBoundsAsync"/>.
|
||||
/// </remarks>
|
||||
public event Action<Rectangle> OnBoundsChanged
|
||||
{
|
||||
add => AddEvent(value, Id);
|
||||
remove => RemoveEvent(value, Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// macOS: Emitted once when the window is moved to a new position.
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@ using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Serialization;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -54,10 +55,79 @@ namespace ElectronNET.API
|
||||
_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 tcs = new TaskCompletionSource<Cookie[]>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.Once<Cookie[]>("webContents-session-cookies-get-completed" + guid, tcs.SetResult);
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-get", Id, filter, guid);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="details"></param>
|
||||
/// <returns></returns>
|
||||
public Task SetAsync(CookieDetails details)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.Once<object>("webContents-session-cookies-set-completed" + guid, tcs.SetResult);
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-set", Id, details, guid);
|
||||
|
||||
return tcs.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 tcs = new TaskCompletionSource<object>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.Once<object>("webContents-session-cookies-remove-completed" + guid, tcs.SetResult);
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-remove", Id, url, name, guid);
|
||||
|
||||
return tcs.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 tcs = new TaskCompletionSource<object>();
|
||||
var guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.Once<object>("webContents-session-cookies-flushStore-completed" + guid, tcs.SetResult);
|
||||
BridgeConnector.Socket.Emit("webContents-session-cookies-flushStore", Id, guid);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,13 @@ namespace ElectronNET.API.Entities
|
||||
/// ( if y is used) Window's left offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int X { get; set; } = -1;
|
||||
public int? X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ( if x is used) Window's top offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int Y { get; set; } = -1;
|
||||
public int? Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width and height would be used as web page's size, which means the actual
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the cookie is a host-only cookie; this will only be true if no domain was passed.
|
||||
/// </summary>
|
||||
public bool HostOnly { get; set; }
|
||||
public bool? HostOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the cookie.
|
||||
@@ -34,22 +34,22 @@
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the cookie is marked as secure.
|
||||
/// </summary>
|
||||
public bool Secure { get; set; }
|
||||
public bool? Secure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the cookie is marked as HTTP only.
|
||||
/// </summary>
|
||||
public bool HttpOnly { get; set; }
|
||||
public bool? HttpOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the cookie is a session cookie or a persistent cookie with an expiration date.
|
||||
/// </summary>
|
||||
public bool Session { get; set; }
|
||||
public bool? Session { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the expiration date of the cookie as the number of seconds since the UNIX epoch. Not provided for session cookies.
|
||||
/// </summary>
|
||||
public double ExpirationDate { get; set; }
|
||||
public double? ExpirationDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SameSite policy applied to this cookie. Can be "unspecified", "no_restriction", "lax" or "strict".
|
||||
|
||||
@@ -29,16 +29,16 @@
|
||||
/// <summary>
|
||||
/// (optional) - Filters cookies by their Secure property.
|
||||
/// </summary>
|
||||
public bool Secure { get; set; }
|
||||
public bool? Secure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Filters out session or persistent cookies.
|
||||
/// </summary>
|
||||
public bool Session { get; set; }
|
||||
public bool? Session { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// (optional) - Filters cookies by httpOnly.
|
||||
/// </summary>
|
||||
public bool HttpOnly { get; set; }
|
||||
public bool? HttpOnly { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,29 @@ namespace ElectronNET.API
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to the renderer process synchronously via channel,
|
||||
/// you can also send arbitrary arguments.
|
||||
///
|
||||
/// Note: Sending a synchronous message will block the whole renderer process,
|
||||
/// unless you know what you are doing you should never use it.
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
/// <param name="listener"></param>
|
||||
public void OnSync(string channel, Func<object, Task<object>> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerSyncIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.On<JsonElement>(channel, (args) =>
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var arg = FormatArguments(args);
|
||||
var result = await listener(arg);
|
||||
BridgeConnector.Socket.Emit(channel + "Sync", result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a one time listener method for the event. This listener is invoked only
|
||||
/// the next time a message is sent to channel, after which it is removed.
|
||||
@@ -154,5 +177,88 @@ namespace ElectronNET.API
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a handler for an invokeable IPC. This handler will be called
|
||||
/// whenever a renderer calls ipcRenderer.invoke(channel, ...args).
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void Handle(string channel, Func<object, object> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerHandleIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.On<JsonElement>(channel, (args) =>
|
||||
{
|
||||
var arg = FormatArguments(args);
|
||||
var result = listener(arg);
|
||||
BridgeConnector.Socket.Emit(channel + "Handle", result);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a handler for an invokeable IPC. This handler will be called
|
||||
/// whenever a renderer calls ipcRenderer.invoke(channel, ...args).
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void Handle(string channel, Func<object, Task<object>> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerHandleIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.On<JsonElement>(channel, (args) =>
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var arg = FormatArguments(args);
|
||||
var result = await listener(arg);
|
||||
BridgeConnector.Socket.Emit(channel + "Handle", result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a single invokeable IPC message, then removes the listener.
|
||||
/// See ipcMain.handle(channel, listener).
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void HandleOnce(string channel, Func<object, object> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerHandleOnceIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.Once<JsonElement>(channel, (args) =>
|
||||
{
|
||||
var arg = FormatArguments(args);
|
||||
var result = listener(arg);
|
||||
BridgeConnector.Socket.Emit(channel + "HandleOnce", result);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a single invokeable IPC message, then removes the listener.
|
||||
/// See ipcMain.handle(channel, listener).
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="listener">Callback Method.</param>
|
||||
public void HandleOnce(string channel, Func<object, Task<object>> listener)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("registerHandleOnceIpcMainChannel", channel);
|
||||
BridgeConnector.Socket.Once<JsonElement>(channel, (args) =>
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var arg = FormatArguments(args);
|
||||
var result = await listener(arg);
|
||||
BridgeConnector.Socket.Emit(channel + "HandleOnce", result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes any handler for channel, if present.
|
||||
/// </summary>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
public void RemoveHandler(string channel)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("removeHandlerIpcMainChannel", channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,11 +220,33 @@ namespace ElectronNET.API
|
||||
_items.Clear();
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
RegisterMenuItemClickedHandler();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the tray menu items.
|
||||
/// </summary>
|
||||
/// <remarks>Calling this method updates the context menu with the specified items. Any previously
|
||||
/// set menu items will be replaced.</remarks>
|
||||
/// <param name="menuItems">An array of <see cref="MenuItem"/> objects representing the menu items to display in the tray menu.
|
||||
/// Cannot be null.</param>
|
||||
public async Task SetMenuItems(MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
await BridgeConnector.Socket.Emit("set-contextMenu", new object[] { menuItems }).ConfigureAwait(false);
|
||||
_items.Clear();
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
RegisterMenuItemClickedHandler();
|
||||
}
|
||||
|
||||
private void RegisterMenuItemClickedHandler()
|
||||
{
|
||||
BridgeConnector.Socket.Off("trayMenuItemClicked");
|
||||
BridgeConnector.Socket.On<string>("trayMenuItemClicked", (id) =>
|
||||
{
|
||||
MenuItem menuItem = _items.GetMenuItem(id);
|
||||
menuItem?.Click();
|
||||
menuItem?.Click?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -343,4 +365,4 @@ namespace ElectronNET.API
|
||||
public async Task Once<T>(string eventName, Action<T> action)
|
||||
=> await Events.Instance.Once(ModuleName, eventName, action).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.Common;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@@ -173,7 +174,7 @@ public class WebContents : ApiBase
|
||||
/// Get system printers.
|
||||
/// </summary>
|
||||
/// <returns>printers</returns>
|
||||
public Task<PrinterInfo[]> GetPrintersAsync() => this.InvokeAsyncWithTimeout<PrinterInfo[]>(5_000);
|
||||
public Task<PrinterInfo[]> GetPrintersAsync() => this.InvokeAsyncWithTimeout<PrinterInfo[]>(8.seconds());
|
||||
|
||||
/// <summary>
|
||||
/// Prints window's web page.
|
||||
@@ -388,7 +389,7 @@ public class WebContents : ApiBase
|
||||
/// Returns string - The user agent for this web page.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<string> GetUserAgentAsync() => InvokeAsync<string>();
|
||||
public Task<string> GetUserAgentAsync() => InvokeAsyncWithTimeout<string>(3.seconds());
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the user agent for this web page.
|
||||
|
||||
@@ -130,11 +130,8 @@ namespace ElectronNET.API
|
||||
options.Height += 7;
|
||||
}
|
||||
|
||||
if (options.X == -1 && options.Y == -1)
|
||||
if (!options.X.HasValue && !options.Y.HasValue)
|
||||
{
|
||||
options.X = 0;
|
||||
options.Y = 0;
|
||||
|
||||
await BridgeConnector.Socket.Emit("createBrowserWindow", options, loadUrl).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
using ElectronNET.API.Bridge;
|
||||
|
||||
internal static class BridgeConnector
|
||||
{
|
||||
public static SocketIoFacade Socket
|
||||
public static IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
62
src/ElectronNET.API/Bridge/IFacade.cs
Normal file
62
src/ElectronNET.API/Bridge/IFacade.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
namespace ElectronNET.API.Bridge
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Common interface for communication facades (SocketIO and SignalR).
|
||||
/// Provides methods for bidirectional communication between .NET and Electron.
|
||||
/// </summary>
|
||||
internal interface IFacade
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised when the bridge connection is established.
|
||||
/// </summary>
|
||||
event EventHandler BridgeConnected;
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the bridge connection is lost.
|
||||
/// </summary>
|
||||
event EventHandler BridgeDisconnected;
|
||||
|
||||
/// <summary>
|
||||
/// Establishes the connection to Electron.
|
||||
/// </summary>
|
||||
void Connect();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a persistent event handler.
|
||||
/// </summary>
|
||||
void On(string eventName, Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a persistent event handler with a typed parameter.
|
||||
/// </summary>
|
||||
void On<T>(string eventName, Action<T> action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a one-time event handler.
|
||||
/// </summary>
|
||||
void Once(string eventName, Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a one-time event handler with a typed parameter.
|
||||
/// </summary>
|
||||
void Once<T>(string eventName, Action<T> action);
|
||||
|
||||
/// <summary>
|
||||
/// Removes an event handler.
|
||||
/// </summary>
|
||||
void Off(string eventName);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message to Electron.
|
||||
/// </summary>
|
||||
Task Emit(string eventName, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the connection.
|
||||
/// </summary>
|
||||
void DisposeSocket();
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@ namespace ElectronNET.API;
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.API.Serialization;
|
||||
using SocketIO.Serializer.SystemTextJson;
|
||||
using SocketIO = SocketIOClient.SocketIO;
|
||||
|
||||
internal class SocketIoFacade
|
||||
internal class SocketIoFacade : IFacade
|
||||
{
|
||||
private readonly SocketIO _socket;
|
||||
private readonly object _lockObj = new object();
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace ElectronNET.Common
|
||||
{
|
||||
case StartupMethod.UnpackedElectronFirst:
|
||||
case StartupMethod.UnpackedDotnetFirst:
|
||||
case StartupMethod.UnpackedDotnetFirstSignalR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
74
src/ElectronNET.API/Common/TimeSpanExtensions.cs
Normal file
74
src/ElectronNET.API/Common/TimeSpanExtensions.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
// <copyright file="TimeSpanExtensions.cs" company="Emby LLC">
|
||||
// Copyright © Emby LLC. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace ElectronNET.Common
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
/// <summary>
|
||||
/// The TimeSpanExtensions class.
|
||||
/// </summary>
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "OK")]
|
||||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "OK")]
|
||||
[SuppressMessage("ReSharper", "StyleCop.SA1300", Justification = "OK")]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "OK")]
|
||||
internal static class TimeSpanExtensions
|
||||
{
|
||||
public static TimeSpan ms(this int value)
|
||||
{
|
||||
return TimeSpan.FromMilliseconds(value);
|
||||
}
|
||||
|
||||
public static TimeSpan ms(this long value)
|
||||
{
|
||||
return TimeSpan.FromMilliseconds(value);
|
||||
}
|
||||
|
||||
public static TimeSpan seconds(this int value)
|
||||
{
|
||||
return TimeSpan.FromSeconds(value);
|
||||
}
|
||||
|
||||
public static TimeSpan minutes(this int value)
|
||||
{
|
||||
return TimeSpan.FromMinutes(value);
|
||||
}
|
||||
|
||||
public static TimeSpan hours(this int value)
|
||||
{
|
||||
return TimeSpan.FromHours(value);
|
||||
}
|
||||
|
||||
public static TimeSpan days(this int value)
|
||||
{
|
||||
return TimeSpan.FromDays(value);
|
||||
}
|
||||
|
||||
public static TimeSpan ms(this double value)
|
||||
{
|
||||
return TimeSpan.FromMilliseconds(value);
|
||||
}
|
||||
|
||||
public static TimeSpan seconds(this double value)
|
||||
{
|
||||
return TimeSpan.FromSeconds(value);
|
||||
}
|
||||
|
||||
public static TimeSpan minutes(this double value)
|
||||
{
|
||||
return TimeSpan.FromMinutes(value);
|
||||
}
|
||||
|
||||
public static TimeSpan hours(this double value)
|
||||
{
|
||||
return TimeSpan.FromHours(value);
|
||||
}
|
||||
|
||||
public static TimeSpan days(this double value)
|
||||
{
|
||||
return TimeSpan.FromDays(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,13 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SocketIOClient" Version="3.1.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.16" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.22" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="ElectronNET.AspNet" />
|
||||
<InternalsVisibleTo Include="ElectronNET.Core.AspNet" />
|
||||
<InternalsVisibleTo Include="ElectronNET.IntegrationTests" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Runtime;
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
@@ -49,7 +50,7 @@
|
||||
|
||||
internal static Func<Task> OnAppReadyCallback { get; set; }
|
||||
|
||||
internal static SocketIoFacade GetSocket()
|
||||
internal static IFacade GetSocket()
|
||||
{
|
||||
return RuntimeControllerCore?.Socket;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Runtime.Services;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
@@ -12,7 +13,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
internal abstract SocketIoFacade Socket { get; }
|
||||
internal abstract IFacade Socket { get; }
|
||||
|
||||
internal abstract ElectronProcessBase ElectronProcess { get; }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace ElectronNET.Runtime.Controllers
|
||||
{
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
@@ -19,7 +20,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
internal override SocketIoFacade Socket
|
||||
internal override IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
public string RuntimeIdentifier { get; internal set; }
|
||||
|
||||
public string ElectronSingleInstance { get; internal set; }
|
||||
public bool ElectronSingleInstance { get; internal set; }
|
||||
|
||||
public string Title { get; internal set; }
|
||||
|
||||
|
||||
@@ -33,5 +33,23 @@
|
||||
/// On the command lines, this is "unpackeddotnet"
|
||||
/// </remarks>
|
||||
UnpackedDotnetFirst,
|
||||
|
||||
/// <summary>Packaged Electron app where DotNet launches Electron and uses SignalR for communication.</summary>
|
||||
/// <remarks>
|
||||
/// DotNet starts first on port 0 (dynamic), launches Electron with the actual URL,
|
||||
/// and uses SignalR instead of socket.io for bidirectional communication.
|
||||
/// Optimized for Blazor Server scenarios. ASP.NET Core only.
|
||||
/// On the command lines, this is "dotnetpackedsignalr"
|
||||
/// </remarks>
|
||||
PackagedDotnetFirstSignalR,
|
||||
|
||||
/// <summary>Unpackaged execution where DotNet launches Electron and uses SignalR for communication.</summary>
|
||||
/// <remarks>
|
||||
/// Similar to PackagedDotnetFirstSignalR but for debugging scenarios.
|
||||
/// DotNet starts first on port 0 (dynamic), launches Electron with the actual URL,
|
||||
/// and uses SignalR instead of socket.io for bidirectional communication.
|
||||
/// On the command lines, this is "unpackeddotnetsignalr"
|
||||
/// </remarks>
|
||||
UnpackedDotnetFirstSignalR,
|
||||
}
|
||||
}
|
||||
@@ -63,13 +63,15 @@
|
||||
|
||||
private static bool? CheckUnpackaged2()
|
||||
{
|
||||
var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
||||
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
var dir = new DirectoryInfo(baseDir);
|
||||
|
||||
if (dir.Name == "bin" && dir.Parent?.Name == "resources")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dir.GetDirectories().Any(e => e.Name == ".electron"))
|
||||
if (Directory.Exists(Path.Combine(baseDir, ".electron")))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -84,7 +86,6 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
namespace ElectronNET.Runtime.Services.ElectronProcess
|
||||
{
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Launches and manages the Electron app process.
|
||||
@@ -33,14 +34,42 @@
|
||||
this.socketPort = socketPort;
|
||||
}
|
||||
|
||||
protected override Task StartCore()
|
||||
protected override async Task StartCore()
|
||||
{
|
||||
var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
||||
string startCmd, args, workingDir;
|
||||
|
||||
if (this.isUnpackaged)
|
||||
{
|
||||
this.CheckRuntimeIdentifier();
|
||||
|
||||
var electrondir = Path.Combine(dir.FullName, ".electron");
|
||||
|
||||
ProcessRunner chmodRunner = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var distFolder = Path.Combine(electrondir, "node_modules", "electron", "dist");
|
||||
|
||||
chmodRunner = new ProcessRunner("ElectronRunner-Chmod");
|
||||
chmodRunner.Run("chmod", "-R +x " + distFolder, electrondir);
|
||||
await chmodRunner.WaitForExitAsync().ConfigureAwait(true);
|
||||
|
||||
if (chmodRunner.LastExitCode != 0)
|
||||
{
|
||||
throw new Exception("Failed to set executable permissions on Electron dist folder.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine("[StartCore]: Exception: " + chmodRunner?.StandardError);
|
||||
Console.Error.WriteLine("[StartCore]: Exception: " + chmodRunner?.StandardOutput);
|
||||
Console.Error.WriteLine("[StartCore]: Exception: " + ex);
|
||||
}
|
||||
|
||||
startCmd = Path.Combine(electrondir, "node_modules", "electron", "dist", "electron");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
@@ -53,17 +82,71 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = dir.Parent?.Parent;
|
||||
dir = dir.Parent!.Parent!;
|
||||
startCmd = Path.Combine(dir.FullName, this.electronBinaryName);
|
||||
args = $"-dotnetpacked -electronforcedport={this.socketPort:D} " + this.extraArguments;
|
||||
workingDir = dir.FullName;
|
||||
}
|
||||
|
||||
|
||||
// We don't await this in order to let the state transition to "Starting"
|
||||
Task.Run(async () => await this.StartInternal(startCmd, args, workingDir).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
private void CheckRuntimeIdentifier()
|
||||
{
|
||||
var buildInfoRid = ElectronNetRuntime.BuildInfo.RuntimeIdentifier;
|
||||
if (string.IsNullOrEmpty(buildInfoRid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var osPart = buildInfoRid.Split('-').First();
|
||||
|
||||
var mismatch = false;
|
||||
|
||||
switch (osPart)
|
||||
{
|
||||
case "win":
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
mismatch = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "linux":
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
mismatch = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "osx":
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
mismatch = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "freebsd":
|
||||
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
|
||||
{
|
||||
mismatch = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (mismatch)
|
||||
{
|
||||
throw new PlatformNotSupportedException($"This Electron.NET application was built for '{buildInfoRid}'. It cannot run on this platform.");
|
||||
}
|
||||
}
|
||||
|
||||
protected override Task StopCore()
|
||||
@@ -76,7 +159,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
await Task.Delay(10.ms()).ConfigureAwait(false);
|
||||
|
||||
Console.Error.WriteLine("[StartInternal]: startCmd: {0}", startCmd);
|
||||
Console.Error.WriteLine("[StartInternal]: args: {0}", args);
|
||||
@@ -85,7 +168,7 @@
|
||||
this.process.ProcessExited += this.Process_Exited;
|
||||
this.process.Run(startCmd, args, directoriy);
|
||||
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
await Task.Delay(500.ms()).ConfigureAwait(false);
|
||||
|
||||
Console.Error.WriteLine("[StartInternal]: after run:");
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
this.CollectProcessData();
|
||||
this.SetElectronExecutable();
|
||||
|
||||
|
||||
ElectronNetRuntime.StartupMethod = this.DetectAppTypeAndStartup();
|
||||
Console.WriteLine((string)("Evaluated StartupMethod: " + ElectronNetRuntime.StartupMethod));
|
||||
|
||||
@@ -54,15 +53,19 @@
|
||||
{
|
||||
var isLaunchedByDotNet = LaunchOrderDetector.CheckIsLaunchedByDotNet();
|
||||
var isUnPackaged = UnpackagedDetector.CheckIsUnpackaged();
|
||||
|
||||
// Check for SignalR mode via environment variable
|
||||
var useSignalR = Environment.GetEnvironmentVariable("ELECTRON_USE_SIGNALR");
|
||||
var isSignalRMode = !string.IsNullOrEmpty(useSignalR) && useSignalR.Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (isLaunchedByDotNet)
|
||||
{
|
||||
if (isUnPackaged)
|
||||
{
|
||||
return StartupMethod.UnpackedDotnetFirst;
|
||||
return isSignalRMode ? StartupMethod.UnpackedDotnetFirstSignalR : StartupMethod.UnpackedDotnetFirst;
|
||||
}
|
||||
|
||||
return StartupMethod.PackagedDotnetFirst;
|
||||
return isSignalRMode ? StartupMethod.PackagedDotnetFirstSignalR : StartupMethod.PackagedDotnetFirst;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -165,13 +168,9 @@
|
||||
ElectronNetRuntime.DotnetAppType = DotnetAppType.AspNetCoreApp;
|
||||
}
|
||||
|
||||
if (isSingleInstance?.Length > 0 && bool.TryParse(isSingleInstance, out var isSingleInstanceActive) && isSingleInstanceActive)
|
||||
if (bool.TryParse(isSingleInstance, out var parsedBool))
|
||||
{
|
||||
buildInfo.ElectronSingleInstance = "yes";
|
||||
}
|
||||
else
|
||||
{
|
||||
buildInfo.ElectronSingleInstance = "no";
|
||||
buildInfo.ElectronSingleInstance = parsedBool;
|
||||
}
|
||||
|
||||
if (httpPort?.Length > 0 && int.TryParse(httpPort, out var port))
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
using ElectronNET.AspNet.Hubs;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for mapping the Electron SignalR hub.
|
||||
/// </summary>
|
||||
public static class ElectronEndpointRouteBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the Electron SignalR hub to the /electron-hub endpoint.
|
||||
/// This is required when using SignalR-based startup modes.
|
||||
/// </summary>
|
||||
/// <param name="endpoints">The endpoint route builder.</param>
|
||||
/// <returns>The endpoint route builder for chaining.</returns>
|
||||
public static IEndpointRouteBuilder MapElectronHub(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
endpoints.MapHub<ElectronHub>("/electron-hub");
|
||||
return endpoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
using ElectronNET.Runtime.Helpers;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for <see cref="IWebHostBuilder"/> to enable Electron.NET
|
||||
@@ -61,23 +62,36 @@
|
||||
{
|
||||
ElectronNetRuntime.OnAppReadyCallback = onAppReadyCallback;
|
||||
|
||||
var webPort = PortHelper.GetFreePort(ElectronNetRuntime.AspNetWebPort ?? ElectronNetRuntime.DefaultWebPort);
|
||||
// no matter how this is set - let's unset to prevent Electron not starting as expected
|
||||
// e.g., VS Code sets this env variable, but this will cause `require("electron")` to not
|
||||
// work as expected, see issue #952
|
||||
Environment.SetEnvironmentVariable("ELECTRON_RUN_AS_NODE", null);
|
||||
|
||||
// For SignalR modes, use port 0 for dynamic port assignment
|
||||
var usePort0 = ElectronNetRuntime.StartupMethod == StartupMethod.PackagedDotnetFirstSignalR ||
|
||||
ElectronNetRuntime.StartupMethod == StartupMethod.UnpackedDotnetFirstSignalR;
|
||||
|
||||
var webPort = usePort0 ? 0 : PortHelper.GetFreePort(ElectronNetRuntime.AspNetWebPort ?? ElectronNetRuntime.DefaultWebPort);
|
||||
ElectronNetRuntime.AspNetWebPort = webPort;
|
||||
|
||||
// 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.
|
||||
|
||||
// For port 0 (dynamic port assignment), Kestrel requires binding to specific IP (127.0.0.1) not localhost
|
||||
var host = usePort0 ? "127.0.0.1" : "localhost";
|
||||
|
||||
if (Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\wwwroot"))
|
||||
{
|
||||
builder = builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.UseUrls("http://localhost:" + webPort);
|
||||
.UseUrls($"http://{host}:{webPort}");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder = builder.UseUrls("http://localhost:" + webPort);
|
||||
builder = builder.UseUrls($"http://{host}:{webPort}");
|
||||
}
|
||||
|
||||
builder = builder.ConfigureServices(services =>
|
||||
builder = builder.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddTransient<IStartupFilter, ServerReadyStartupFilter>();
|
||||
services.AddSingleton<AspNetLifetimeAdapter>();
|
||||
@@ -92,6 +106,17 @@
|
||||
case StartupMethod.UnpackedDotnetFirst:
|
||||
services.AddSingleton<IElectronNetRuntimeController, RuntimeControllerAspNetDotnetFirst>();
|
||||
break;
|
||||
case StartupMethod.PackagedDotnetFirstSignalR:
|
||||
case StartupMethod.UnpackedDotnetFirstSignalR:
|
||||
services.AddSignalR(options =>
|
||||
{
|
||||
// Enable detailed errors only in development for security
|
||||
options.EnableDetailedErrors =
|
||||
Debugger.IsAttached ||
|
||||
context.HostingEnvironment.IsDevelopment();
|
||||
});
|
||||
services.AddSingleton<IElectronNetRuntimeController, RuntimeControllerAspNetDotnetFirstSignalR>();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
232
src/ElectronNET.AspNet/Bridge/SignalRFacade.cs
Normal file
232
src/ElectronNET.AspNet/Bridge/SignalRFacade.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.AspNet.Hubs;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR-based facade that mimics the SocketIoFacade interface
|
||||
/// for compatibility with existing Electron API code.
|
||||
///
|
||||
/// Key implementation details:
|
||||
/// - Uses IHubContext to send events to Electron via 'event' hub method
|
||||
/// - Receives events from Electron via ElectronHub.ElectronEvent() method
|
||||
/// - Includes ConvertToType<T> helper to handle JsonElement and numeric type conversions
|
||||
/// - Event args are passed as arrays to match SignalR serialization behavior
|
||||
/// - Connection ID is set by ElectronHub when Electron client connects
|
||||
/// </summary>
|
||||
internal class SignalRFacade : IFacade
|
||||
{
|
||||
private readonly IHubContext<ElectronHub> _hubContext;
|
||||
private string _connectionId;
|
||||
private readonly ConcurrentDictionary<string, Action<object>> _eventHandlers;
|
||||
private readonly object _lockObj = new object();
|
||||
|
||||
public SignalRFacade(IHubContext<ElectronHub> hubContext)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_eventHandlers = new ConcurrentDictionary<string, Action<object>>();
|
||||
}
|
||||
|
||||
public event EventHandler BridgeDisconnected;
|
||||
public event EventHandler BridgeConnected;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR connections are managed by ASP.NET Core, so this is a no-op.
|
||||
/// Connection establishment happens via the ElectronHub.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
// No-op: SignalR connection is managed by ASP.NET Core
|
||||
}
|
||||
|
||||
public void SetConnectionId(string connectionId)
|
||||
{
|
||||
_connectionId = connectionId;
|
||||
this.BridgeConnected?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void OnDisconnected()
|
||||
{
|
||||
this.BridgeDisconnected?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void On(string eventName, Action action)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_eventHandlers[eventName] = _ => Task.Run(action);
|
||||
}
|
||||
}
|
||||
|
||||
public void On<T>(string eventName, Action<T> action)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_eventHandlers[eventName] = obj =>
|
||||
{
|
||||
var converted = ConvertToType<T>(obj);
|
||||
if (converted != null)
|
||||
{
|
||||
Task.Run(() => action(converted));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] Failed to convert event data to type {typeof(T).Name}");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Once(string eventName, Action action)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_eventHandlers[eventName] = _ =>
|
||||
{
|
||||
this.Off(eventName);
|
||||
Task.Run(action);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Once<T>(string eventName, Action<T> action)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_eventHandlers[eventName] = obj =>
|
||||
{
|
||||
this.Off(eventName);
|
||||
var converted = ConvertToType<T>(obj);
|
||||
if (converted != null)
|
||||
{
|
||||
Task.Run(() => action(converted));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] Failed to convert event data to type {typeof(T).Name} for event '{eventName}'");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Off(string eventName)
|
||||
{
|
||||
lock (_lockObj)
|
||||
{
|
||||
_eventHandlers.TryRemove(eventName, out _);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Emit(string eventName, params object[] args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_connectionId))
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] Cannot emit '{eventName}' - no connection ID");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Send message to specific Electron client via the 'event' hub method
|
||||
// This will be received by signalr-bridge.js's connection.on('event', ...)
|
||||
await _hubContext.Clients.Client(_connectionId).SendAsync("event", eventName, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] Error emitting '{eventName}': {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerEvent(string eventName, params object[] args)
|
||||
{
|
||||
if (_eventHandlers.TryGetValue(eventName, out var handler))
|
||||
{
|
||||
// If single arg, pass it directly; otherwise pass the array
|
||||
var data = args.Length == 1 ? args[0] : args;
|
||||
handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an object to the specified type, handling JsonElement and numeric conversions.
|
||||
/// </summary>
|
||||
private static T ConvertToType<T>(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return default;
|
||||
|
||||
// Direct type match
|
||||
if (obj is T typedValue)
|
||||
return typedValue;
|
||||
|
||||
var targetType = typeof(T);
|
||||
|
||||
// Handle JsonElement (common from SignalR deserialization)
|
||||
if (obj is JsonElement jsonElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(jsonElement.GetRawText());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] JsonElement deserialization failed: {ex.Message}");
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle numeric conversions (SignalR often sends numbers as long/double)
|
||||
try
|
||||
{
|
||||
if (targetType == typeof(int) || targetType == typeof(int?))
|
||||
{
|
||||
return (T)(object)Convert.ToInt32(obj);
|
||||
}
|
||||
if (targetType == typeof(long) || targetType == typeof(long?))
|
||||
{
|
||||
return (T)(object)Convert.ToInt64(obj);
|
||||
}
|
||||
if (targetType == typeof(double) || targetType == typeof(double?))
|
||||
{
|
||||
return (T)(object)Convert.ToDouble(obj);
|
||||
}
|
||||
if (targetType == typeof(bool) || targetType == typeof(bool?))
|
||||
{
|
||||
return (T)(object)Convert.ToBoolean(obj);
|
||||
}
|
||||
if (targetType == typeof(string))
|
||||
{
|
||||
return (T)(object)obj.ToString();
|
||||
}
|
||||
|
||||
// For arrays, try JSON serialization roundtrip
|
||||
if (targetType.IsArray && obj is object[] arr)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(arr);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
// Last resort: try to serialize and deserialize
|
||||
var serialized = JsonSerializer.Serialize(obj);
|
||||
return JsonSerializer.Deserialize<T>(serialized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"[SignalRFacade] Type conversion failed from {obj.GetType().Name} to {targetType.Name}: {ex.Message}");
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public void DisposeSocket()
|
||||
{
|
||||
// SignalR connections are managed by ASP.NET Core
|
||||
_eventHandlers.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
108
src/ElectronNET.AspNet/Hubs/ElectronHub.cs
Normal file
108
src/ElectronNET.AspNet/Hubs/ElectronHub.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
namespace ElectronNET.AspNet.Hubs
|
||||
{
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.AspNet.Runtime;
|
||||
using ElectronNET.Runtime;
|
||||
|
||||
/// <summary>
|
||||
/// SignalR hub for bidirectional communication between ASP.NET Core and Electron.
|
||||
/// Replaces socket.io for SignalR-based startup modes.
|
||||
/// </summary>
|
||||
public class ElectronHub : Hub
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when Electron client connects to the hub.
|
||||
/// </summary>
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
// Notify the runtime controller about the connection
|
||||
var runtimeController = ElectronNetRuntime.RuntimeController as RuntimeControllerAspNetDotnetFirstSignalR;
|
||||
if (runtimeController != null)
|
||||
{
|
||||
runtimeController.OnSignalRConnected(Context.ConnectionId);
|
||||
}
|
||||
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when Electron client disconnects from the hub.
|
||||
/// </summary>
|
||||
public override async Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
if (exception != null)
|
||||
{
|
||||
Console.Error.WriteLine($"[ElectronHub] Disconnect error: {exception.Message}");
|
||||
}
|
||||
|
||||
// Notify the runtime controller about the disconnection
|
||||
var runtimeController = ElectronNetRuntime.RuntimeController as RuntimeControllerAspNetDotnetFirstSignalR;
|
||||
if (runtimeController != null)
|
||||
{
|
||||
runtimeController.OnSignalRDisconnected();
|
||||
}
|
||||
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the Electron client. Called by Electron on connection.
|
||||
/// </summary>
|
||||
public async Task RegisterElectronClient()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Receives events from Electron (e.g., "BrowserWindowCreated", "dialogResult").
|
||||
/// Called by Electron to send data back to .NET.
|
||||
/// </summary>
|
||||
/// <param name="eventName">The event name</param>
|
||||
/// <param name="args">The event arguments as an array</param>
|
||||
public async Task ElectronEvent(string eventName, object[] args)
|
||||
{
|
||||
// Get the SignalRFacade and trigger the event handlers
|
||||
var runtimeController = ElectronNetRuntime.RuntimeController as RuntimeControllerAspNetDotnetFirstSignalR;
|
||||
if (runtimeController?.SignalRSocket is SignalRFacade signalRFacade)
|
||||
{
|
||||
// Invoke the event handlers registered via On/Once
|
||||
signalRFacade.TriggerEvent(eventName, args ?? Array.Empty<object>());
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes an Electron API method. Called by .NET to control Electron.
|
||||
/// This is a placeholder for future API invocation patterns.
|
||||
/// </summary>
|
||||
/// <param name="method">The API method name</param>
|
||||
/// <param name="data">The method parameters as JSON</param>
|
||||
/// <returns>The result of the API call</returns>
|
||||
public async Task<string> InvokeElectronApi(string method, string data)
|
||||
{
|
||||
// Forward to Electron client
|
||||
await Clients.Caller.SendAsync("electronApiCall", method, data);
|
||||
|
||||
// TODO: Implement proper request-response pattern
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles responses from Electron API calls.
|
||||
/// This is a placeholder for future API invocation patterns.
|
||||
/// </summary>
|
||||
/// <param name="callId">The unique identifier for this API call</param>
|
||||
/// <param name="result">The result data as JSON</param>
|
||||
public async Task ElectronApiResponse(string callId, string result)
|
||||
{
|
||||
// This will be handled by the SignalR facade to complete pending tasks
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
namespace ElectronNET.AspNet.Middleware
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ElectronNET.AspNet.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Middleware that validates authentication for all Electron requests.
|
||||
/// Checks for authentication cookie or token query parameter on first request.
|
||||
/// Sets HttpOnly cookie for subsequent requests.
|
||||
///
|
||||
/// Security Model:
|
||||
/// - First request includes token as query parameter (?token=guid)
|
||||
/// - Middleware validates token and sets secure HttpOnly cookie
|
||||
/// - Subsequent requests use cookie (no token in URL)
|
||||
/// - Both HTTP endpoints and SignalR hub protected
|
||||
/// </summary>
|
||||
public class ElectronAuthenticationMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IElectronAuthenticationService _authService;
|
||||
private readonly ILogger<ElectronAuthenticationMiddleware> _logger;
|
||||
private const string AuthCookieName = "ElectronAuth";
|
||||
|
||||
public ElectronAuthenticationMiddleware(
|
||||
RequestDelegate next,
|
||||
IElectronAuthenticationService authService,
|
||||
ILogger<ElectronAuthenticationMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_authService = authService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
var path = context.Request.Path.Value;
|
||||
|
||||
// Check if authentication cookie exists
|
||||
var authCookie = context.Request.Cookies[AuthCookieName];
|
||||
|
||||
if (!string.IsNullOrEmpty(authCookie))
|
||||
{
|
||||
// Cookie present - validate it
|
||||
if (_authService.ValidateToken(authCookie))
|
||||
{
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid cookie - reject
|
||||
_logger.LogWarning("Authentication failed: Invalid cookie for path {Path} from {RemoteIp}",
|
||||
path, context.Connection.RemoteIpAddress);
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized: Invalid authentication");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No cookie - check for token in query string (first-time authentication)
|
||||
var token = context.Request.Query["token"].ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
if (_authService.ValidateToken(token))
|
||||
{
|
||||
// Valid token - set cookie for future requests
|
||||
_logger.LogInformation("Authentication successful: Setting cookie for path {Path}", path);
|
||||
|
||||
context.Response.Cookies.Append(AuthCookieName, token, new CookieOptions
|
||||
{
|
||||
HttpOnly = true, // Prevent JavaScript access (XSS protection)
|
||||
SameSite = SameSiteMode.Strict, // CSRF protection
|
||||
Path = "/", // Valid for all routes
|
||||
Secure = false, // False because localhost is HTTP
|
||||
IsEssential = true // Required for app to function
|
||||
});
|
||||
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid token - reject
|
||||
_logger.LogWarning("Authentication failed: Invalid token (prefix: {TokenPrefix}...) for path {Path} from {RemoteIp}",
|
||||
token.Length > 8 ? token.Substring(0, 8) : token, path, context.Connection.RemoteIpAddress);
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized: Invalid authentication");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Neither cookie nor valid token present - reject
|
||||
_logger.LogWarning("Authentication failed: No cookie or token provided for path {Path} from {RemoteIp}",
|
||||
path, context.Connection.RemoteIpAddress);
|
||||
context.Response.StatusCode = 401;
|
||||
await context.Response.WriteAsync("Unauthorized: Authentication required");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Controllers;
|
||||
using ElectronNET.Runtime.Data;
|
||||
@@ -25,7 +26,7 @@
|
||||
|
||||
internal override SocketBridgeService SocketBridge => this.socketBridge;
|
||||
|
||||
internal override SocketIoFacade Socket
|
||||
internal override IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
namespace ElectronNET.AspNet.Runtime
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Bridge;
|
||||
using ElectronNET.Common;
|
||||
using ElectronNET.Runtime.Data;
|
||||
using ElectronNET.Runtime.Services.ElectronProcess;
|
||||
using ElectronNET.Runtime.Services.SocketBridge;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using ElectronNET.AspNet.Hubs;
|
||||
using ElectronNET.AspNet.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Runtime controller for SignalR-based .NET-first startup mode.
|
||||
/// Key differences from Socket.IO mode:
|
||||
/// - Waits for ASP.NET server to start, then captures the dynamic port
|
||||
/// - Launches Electron with the actual URL (no port scanning needed)
|
||||
/// - Uses SignalRFacade instead of SocketIOFacade for bidirectional communication
|
||||
/// - Waits for 'electron-host-ready' signal to ensure API modules are loaded before calling app callback
|
||||
/// </summary>
|
||||
internal class RuntimeControllerAspNetDotnetFirstSignalR : RuntimeControllerAspNetBase
|
||||
{
|
||||
private ElectronProcessBase electronProcess;
|
||||
private readonly IServer server;
|
||||
private readonly IHubContext<ElectronHub> hubContext;
|
||||
private readonly IElectronAuthenticationService authenticationService;
|
||||
private SignalRFacade signalRFacade;
|
||||
private int? port;
|
||||
private string actualUrl;
|
||||
private bool electronLaunched;
|
||||
private string authenticationToken;
|
||||
|
||||
public RuntimeControllerAspNetDotnetFirstSignalR(
|
||||
AspNetLifetimeAdapter aspNetLifetimeAdapter,
|
||||
IServer server,
|
||||
IHubContext<ElectronHub> hubContext,
|
||||
IElectronAuthenticationService authenticationService)
|
||||
: base(aspNetLifetimeAdapter)
|
||||
{
|
||||
this.server = server;
|
||||
this.hubContext = hubContext;
|
||||
this.authenticationService = authenticationService;
|
||||
this.signalRFacade = new SignalRFacade(hubContext);
|
||||
this.electronLaunched = false;
|
||||
|
||||
this.signalRFacade.BridgeConnected += this.SignalRFacade_Connected;
|
||||
this.signalRFacade.BridgeDisconnected += this.SignalRFacade_Disconnected;
|
||||
|
||||
// Subscribe to ASP.NET ready event to launch Electron
|
||||
aspNetLifetimeAdapter.Ready += this.OnAspNetReady;
|
||||
}
|
||||
|
||||
internal override ElectronProcessBase ElectronProcess => this.electronProcess;
|
||||
internal override SocketBridgeService SocketBridge => null;
|
||||
|
||||
internal override IFacade Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.State == LifetimeState.Ready)
|
||||
{
|
||||
return this.signalRFacade;
|
||||
}
|
||||
|
||||
throw new Exception("Cannot access SignalR facade. Runtime is not in 'Ready' state");
|
||||
}
|
||||
}
|
||||
|
||||
internal SignalRFacade SignalRSocket => this.signalRFacade;
|
||||
|
||||
protected override Task StartCore()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override Task StopCore()
|
||||
{
|
||||
this.electronProcess?.Stop();
|
||||
this.signalRFacade?.DisposeSocket();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void OnAspNetReady(object sender, EventArgs e)
|
||||
{
|
||||
if (!this.electronLaunched)
|
||||
{
|
||||
this.CapturePortAndLaunchElectron();
|
||||
}
|
||||
}
|
||||
|
||||
private void CapturePortAndLaunchElectron()
|
||||
{
|
||||
var addresses = this.server.Features.Get<IServerAddressesFeature>();
|
||||
if (addresses == null || !addresses.Addresses.Any())
|
||||
{
|
||||
throw new Exception("Could not retrieve server addresses");
|
||||
}
|
||||
|
||||
this.actualUrl = addresses.Addresses.First();
|
||||
this.port = new Uri(this.actualUrl).Port;
|
||||
|
||||
// Update the runtime port so WindowManager uses the correct URL
|
||||
ElectronNetRuntime.AspNetWebPort = this.port;
|
||||
|
||||
this.LaunchElectron();
|
||||
this.electronLaunched = true;
|
||||
}
|
||||
|
||||
private void LaunchElectron()
|
||||
{
|
||||
// Generate secure authentication token (128-bit cryptographic random GUID)
|
||||
// This token protects against unauthorized connections from other users on the same machine
|
||||
this.authenticationToken = Guid.NewGuid().ToString("N"); // 32 hex chars, no hyphens
|
||||
|
||||
// Register token with authentication service for validation
|
||||
// The middleware will validate this token on all HTTP and SignalR requests
|
||||
this.authenticationService.SetExpectedToken(this.authenticationToken);
|
||||
|
||||
var isUnPacked = ElectronNetRuntime.StartupMethod.IsUnpackaged();
|
||||
var flag = isUnPacked ? "--unpackeddotnetsignalr" : "--dotnetpackedsignalr";
|
||||
var args = $"{flag} --electronurl={this.actualUrl} --authtoken={this.authenticationToken}";
|
||||
|
||||
this.electronProcess = new ElectronProcessActive(isUnPacked, ElectronNetRuntime.ElectronExecutable, args, this.port.Value);
|
||||
// Note: We do NOT subscribe to electronProcess.Ready in SignalR mode.
|
||||
// The "ready" signal comes from the SignalR connection, not stdout.
|
||||
this.electronProcess.Stopped += this.ElectronProcess_Stopped;
|
||||
_ = this.electronProcess.Start();
|
||||
}
|
||||
|
||||
private async void SignalRFacade_Connected(object sender, EventArgs e)
|
||||
{
|
||||
// Register handler for 'electron-host-ready' signal from Electron.
|
||||
// This ensures API modules are fully loaded before calling the app ready callback.
|
||||
this.signalRFacade.Once("electron-host-ready", () =>
|
||||
{
|
||||
this.OnElectronHostReady();
|
||||
});
|
||||
}
|
||||
|
||||
private async void OnElectronHostReady()
|
||||
{
|
||||
this.TransitionState(LifetimeState.Ready);
|
||||
|
||||
// Execute the app ready callback
|
||||
if (ElectronNetRuntime.OnAppReadyCallback != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ElectronNetRuntime.OnAppReadyCallback().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Exception in app ready callback: {ex}");
|
||||
this.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SignalRFacade_Disconnected(object sender, EventArgs e)
|
||||
{
|
||||
// IMPORTANT: Do NOT call HandleStopped synchronously here!
|
||||
// This event fires from within SignalR's OnDisconnectedAsync, and calling
|
||||
// StopApplication() synchronously causes a deadlock: the host waits for
|
||||
// OnDisconnectedAsync to complete, but we're waiting for the host to stop.
|
||||
// Fire and forget to break the deadlock.
|
||||
_ = Task.Run(() => this.HandleStopped());
|
||||
}
|
||||
|
||||
private void ElectronProcess_Stopped(object sender, EventArgs e)
|
||||
{
|
||||
this.HandleStopped();
|
||||
}
|
||||
|
||||
public void OnSignalRConnected(string connectionId)
|
||||
{
|
||||
this.signalRFacade.SetConnectionId(connectionId);
|
||||
}
|
||||
|
||||
public void OnSignalRDisconnected()
|
||||
{
|
||||
this.signalRFacade.OnDisconnected();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace ElectronNET.AspNet.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of authentication service for Electron clients.
|
||||
/// Stores and validates the authentication token to ensure only the spawned Electron process can connect.
|
||||
/// </summary>
|
||||
public class ElectronAuthenticationService : IElectronAuthenticationService
|
||||
{
|
||||
private string _expectedToken;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetExpectedToken(string token)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_expectedToken = token;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ValidateToken(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token))
|
||||
return false;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_expectedToken))
|
||||
return false;
|
||||
|
||||
// Constant-time comparison to prevent timing attacks
|
||||
return ConstantTimeEquals(token, _expectedToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs constant-time string comparison to prevent timing attacks.
|
||||
/// </summary>
|
||||
private static bool ConstantTimeEquals(string a, string b)
|
||||
{
|
||||
if (a == null || b == null || a.Length != b.Length)
|
||||
return false;
|
||||
|
||||
var result = 0;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
result |= a[i] ^ b[i];
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace ElectronNET.AspNet.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Service for validating authentication tokens from Electron clients.
|
||||
/// Used to ensure only the Electron process spawned by this .NET instance can connect.
|
||||
/// </summary>
|
||||
public interface IElectronAuthenticationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the expected authentication token for this instance.
|
||||
/// Should be called when launching Electron with the generated token.
|
||||
/// </summary>
|
||||
/// <param name="token">The authentication token</param>
|
||||
void SetExpectedToken(string token);
|
||||
|
||||
/// <summary>
|
||||
/// Validates an incoming token against the expected token.
|
||||
/// Uses constant-time comparison to prevent timing attacks.
|
||||
/// </summary>
|
||||
/// <param name="token">The token to validate</param>
|
||||
/// <returns>True if token is valid, false otherwise</returns>
|
||||
bool ValidateToken(string token);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<Import Project="..\ElectronNET\build\ElectronNET.Core.props" Condition="$(ElectronNetDevMode)" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
@@ -70,7 +70,7 @@
|
||||
<ProjectReference Include="..\ElectronNET.API\ElectronNET.API.csproj" Condition="$(ElectronNetDevMode)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.3.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.4.1" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\ElectronNET\build\ElectronNET.Core.targets" Condition="$(ElectronNetDevMode)" />
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<PublishDir>publish\Release\net8.0\linux-x64</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
|
||||
@@ -12,7 +12,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
<PublishUrl>publish\Release\net8.0\win-x64\</PublishUrl>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<PublishDir>publish\Release\net8.0\win-x64</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.4110890">
|
||||
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.3864779">
|
||||
<ItemGroup>
|
||||
<None Include=".vscode\tasks.json" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use strict";
|
||||
let isQuitWindowAllClosed = true, electronSocket;
|
||||
let isQuitWindowAllClosed = true;
|
||||
let electronSocket;
|
||||
let appWindowAllClosedEventId;
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
// By default, quit when all windows are closed
|
||||
app.on('window-all-closed', () => {
|
||||
app.on("window-all-closed", () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
|
||||
if (process.platform !== "darwin" && isQuitWindowAllClosed) {
|
||||
app.quit();
|
||||
}
|
||||
else if (appWindowAllClosedEventId) {
|
||||
@@ -15,220 +16,224 @@ module.exports = (socket, app) => {
|
||||
// - OR -
|
||||
// If the user has indicated NOT to quit when all windows are closed,
|
||||
// emit the event.
|
||||
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
|
||||
electronSocket.emit("app-window-all-closed" + appWindowAllClosedEventId);
|
||||
}
|
||||
});
|
||||
socket.on('quit-app-window-all-closed', (quit) => {
|
||||
socket.on("quit-app-window-all-closed", (quit) => {
|
||||
isQuitWindowAllClosed = quit;
|
||||
});
|
||||
socket.on('register-app-window-all-closed', (id) => {
|
||||
socket.on("register-app-window-all-closed", (id) => {
|
||||
appWindowAllClosedEventId = id;
|
||||
});
|
||||
socket.on('register-app-before-quit', (id) => {
|
||||
app.on('before-quit', (event) => {
|
||||
socket.on("register-app-before-quit", (id) => {
|
||||
app.on("before-quit", (event) => {
|
||||
event.preventDefault();
|
||||
electronSocket.emit('app-before-quit' + id);
|
||||
electronSocket.emit("app-before-quit" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-will-quit', (id) => {
|
||||
app.on('will-quit', (event) => {
|
||||
socket.on("register-app-will-quit", (id) => {
|
||||
app.on("will-quit", (event) => {
|
||||
event.preventDefault();
|
||||
electronSocket.emit('app-will-quit' + id);
|
||||
electronSocket.emit("app-will-quit" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-browser-window-blur', (id) => {
|
||||
app.on('browser-window-blur', () => {
|
||||
electronSocket.emit('app-browser-window-blur' + id);
|
||||
socket.on("register-app-browser-window-blur", (id) => {
|
||||
app.on("browser-window-blur", () => {
|
||||
electronSocket.emit("app-browser-window-blur" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-browser-window-focus', (id) => {
|
||||
app.on('browser-window-focus', () => {
|
||||
electronSocket.emit('app-browser-window-focus' + id);
|
||||
socket.on("register-app-browser-window-focus", (id) => {
|
||||
app.on("browser-window-focus", () => {
|
||||
electronSocket.emit("app-browser-window-focus" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-browser-window-created', (id) => {
|
||||
app.on('browser-window-created', () => {
|
||||
electronSocket.emit('app-browser-window-created' + id);
|
||||
socket.on("register-app-browser-window-created", (id) => {
|
||||
app.on("browser-window-created", () => {
|
||||
electronSocket.emit("app-browser-window-created" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-web-contents-created', (id) => {
|
||||
app.on('web-contents-created', () => {
|
||||
electronSocket.emit('app-web-contents-created' + id);
|
||||
socket.on("register-app-web-contents-created", (id) => {
|
||||
app.on("web-contents-created", () => {
|
||||
electronSocket.emit("app-web-contents-created" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-app-accessibility-support-changed', (id) => {
|
||||
app.on('accessibility-support-changed', (event, accessibilitySupportEnabled) => {
|
||||
electronSocket.emit('app-accessibility-support-changed' + id, accessibilitySupportEnabled);
|
||||
socket.on("register-app-accessibility-support-changed", (id) => {
|
||||
app.on("accessibility-support-changed", (event, accessibilitySupportEnabled) => {
|
||||
electronSocket.emit("app-accessibility-support-changed" + id, accessibilitySupportEnabled);
|
||||
});
|
||||
});
|
||||
socket.on('appQuit', () => {
|
||||
socket.on("appQuit", () => {
|
||||
app.quit();
|
||||
});
|
||||
socket.on('appExit', (exitCode = 0) => {
|
||||
socket.on("appExit", (exitCode = 0) => {
|
||||
app.exit(exitCode);
|
||||
});
|
||||
socket.on('appRelaunch', (options) => {
|
||||
socket.on("appRelaunch", (options) => {
|
||||
app.relaunch(options);
|
||||
});
|
||||
socket.on('appFocus', (options) => {
|
||||
socket.on("appFocus", (options) => {
|
||||
app.focus(options);
|
||||
});
|
||||
socket.on('appHide', () => {
|
||||
socket.on("appHide", () => {
|
||||
app.hide();
|
||||
});
|
||||
socket.on('appShow', () => {
|
||||
socket.on("appShow", () => {
|
||||
app.show();
|
||||
});
|
||||
socket.on('appGetAppPath', () => {
|
||||
socket.on("appGetAppPath", () => {
|
||||
const path = app.getAppPath();
|
||||
electronSocket.emit('appGetAppPathCompleted', path);
|
||||
electronSocket.emit("appGetAppPathCompleted", path);
|
||||
});
|
||||
socket.on('appSetAppLogsPath', (path) => {
|
||||
socket.on("appSetAppLogsPath", (path) => {
|
||||
app.setAppLogsPath(path);
|
||||
});
|
||||
socket.on('appGetPath', (name) => {
|
||||
socket.on("appGetPath", (name) => {
|
||||
const path = app.getPath(name);
|
||||
electronSocket.emit('appGetPathCompleted', path);
|
||||
electronSocket.emit("appGetPathCompleted", path);
|
||||
});
|
||||
socket.on('appGetFileIcon', async (path, options) => {
|
||||
socket.on("appGetFileIcon", async (path, options) => {
|
||||
let error = {};
|
||||
if (options) {
|
||||
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
const nativeImage = await app
|
||||
.getFileIcon(path, options)
|
||||
.catch((errorFileIcon) => (error = errorFileIcon));
|
||||
electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]);
|
||||
}
|
||||
else {
|
||||
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
const nativeImage = await app
|
||||
.getFileIcon(path)
|
||||
.catch((errorFileIcon) => (error = errorFileIcon));
|
||||
electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]);
|
||||
}
|
||||
});
|
||||
socket.on('appSetPath', (name, path) => {
|
||||
socket.on("appSetPath", (name, path) => {
|
||||
app.setPath(name, path);
|
||||
});
|
||||
socket.on('appGetVersion', () => {
|
||||
socket.on("appGetVersion", () => {
|
||||
const version = app.getVersion();
|
||||
electronSocket.emit('appGetVersionCompleted', version);
|
||||
electronSocket.emit("appGetVersionCompleted", version);
|
||||
});
|
||||
socket.on('appGetName', () => {
|
||||
electronSocket.emit('appGetNameCompleted', app.name);
|
||||
socket.on("appGetName", () => {
|
||||
electronSocket.emit("appGetNameCompleted", app.name);
|
||||
});
|
||||
socket.on('appSetName', (name) => {
|
||||
socket.on("appSetName", (name) => {
|
||||
app.name = name;
|
||||
});
|
||||
socket.on('appGetLocale', () => {
|
||||
socket.on("appGetLocale", () => {
|
||||
const locale = app.getLocale();
|
||||
electronSocket.emit('appGetLocaleCompleted', locale);
|
||||
electronSocket.emit("appGetLocaleCompleted", locale);
|
||||
});
|
||||
socket.on('appAddRecentDocument', (path) => {
|
||||
socket.on("appAddRecentDocument", (path) => {
|
||||
app.addRecentDocument(path);
|
||||
});
|
||||
socket.on('appClearRecentDocuments', () => {
|
||||
socket.on("appClearRecentDocuments", () => {
|
||||
app.clearRecentDocuments();
|
||||
});
|
||||
socket.on('appSetAsDefaultProtocolClient', (protocol, path, args) => {
|
||||
socket.on("appSetAsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.setAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appSetAsDefaultProtocolClientCompleted', success);
|
||||
electronSocket.emit("appSetAsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
socket.on('appRemoveAsDefaultProtocolClient', (protocol, path, args) => {
|
||||
socket.on("appRemoveAsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.removeAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appRemoveAsDefaultProtocolClientCompleted', success);
|
||||
electronSocket.emit("appRemoveAsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
socket.on('appIsDefaultProtocolClient', (protocol, path, args) => {
|
||||
socket.on("appIsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.isDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appIsDefaultProtocolClientCompleted', success);
|
||||
electronSocket.emit("appIsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
socket.on('appSetUserTasks', (tasks) => {
|
||||
socket.on("appSetUserTasks", (tasks) => {
|
||||
const success = app.setUserTasks(tasks);
|
||||
electronSocket.emit('appSetUserTasksCompleted', success);
|
||||
electronSocket.emit("appSetUserTasksCompleted", success);
|
||||
});
|
||||
socket.on('appGetJumpListSettings', () => {
|
||||
socket.on("appGetJumpListSettings", () => {
|
||||
const jumpListSettings = app.getJumpListSettings();
|
||||
electronSocket.emit('appGetJumpListSettingsCompleted', jumpListSettings);
|
||||
electronSocket.emit("appGetJumpListSettingsCompleted", jumpListSettings);
|
||||
});
|
||||
socket.on('appSetJumpList', (categories) => {
|
||||
socket.on("appSetJumpList", (categories) => {
|
||||
app.setJumpList(categories);
|
||||
});
|
||||
socket.on('appRequestSingleInstanceLock', () => {
|
||||
socket.on("appRequestSingleInstanceLock", () => {
|
||||
const success = app.requestSingleInstanceLock();
|
||||
electronSocket.emit('appRequestSingleInstanceLockCompleted', success);
|
||||
app.on('second-instance', (event, args = [], workingDirectory = '') => {
|
||||
electronSocket.emit('secondInstance', [args, workingDirectory]);
|
||||
electronSocket.emit("appRequestSingleInstanceLockCompleted", success);
|
||||
app.on("second-instance", (event, args = [], workingDirectory = "") => {
|
||||
electronSocket.emit("secondInstance", [args, workingDirectory]);
|
||||
});
|
||||
});
|
||||
socket.on('appHasSingleInstanceLock', () => {
|
||||
socket.on("appHasSingleInstanceLock", () => {
|
||||
const hasLock = app.hasSingleInstanceLock();
|
||||
electronSocket.emit('appHasSingleInstanceLockCompleted', hasLock);
|
||||
electronSocket.emit("appHasSingleInstanceLockCompleted", hasLock);
|
||||
});
|
||||
socket.on('appReleaseSingleInstanceLock', () => {
|
||||
socket.on("appReleaseSingleInstanceLock", () => {
|
||||
app.releaseSingleInstanceLock();
|
||||
});
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageUrl) => {
|
||||
socket.on("appSetUserActivity", (type, userInfo, webpageUrl) => {
|
||||
app.setUserActivity(type, userInfo, webpageUrl);
|
||||
});
|
||||
socket.on('appGetCurrentActivityType', () => {
|
||||
socket.on("appGetCurrentActivityType", () => {
|
||||
const activityType = app.getCurrentActivityType();
|
||||
electronSocket.emit('appGetCurrentActivityTypeCompleted', activityType);
|
||||
electronSocket.emit("appGetCurrentActivityTypeCompleted", activityType);
|
||||
});
|
||||
socket.on('appInvalidateCurrentActivity', () => {
|
||||
socket.on("appInvalidateCurrentActivity", () => {
|
||||
app.invalidateCurrentActivity();
|
||||
});
|
||||
socket.on('appResignCurrentActivity', () => {
|
||||
socket.on("appResignCurrentActivity", () => {
|
||||
app.resignCurrentActivity();
|
||||
});
|
||||
socket.on('appSetAppUserModelId', (id) => {
|
||||
socket.on("appSetAppUserModelId", (id) => {
|
||||
app.setAppUserModelId(id);
|
||||
});
|
||||
socket.on('appImportCertificate', (options) => {
|
||||
socket.on("appImportCertificate", (options) => {
|
||||
app.importCertificate(options, (result) => {
|
||||
electronSocket.emit('appImportCertificateCompleted', result);
|
||||
electronSocket.emit("appImportCertificateCompleted", result);
|
||||
});
|
||||
});
|
||||
socket.on('appGetAppMetrics', () => {
|
||||
socket.on("appGetAppMetrics", () => {
|
||||
const processMetrics = app.getAppMetrics();
|
||||
electronSocket.emit('appGetAppMetricsCompleted', processMetrics);
|
||||
electronSocket.emit("appGetAppMetricsCompleted", processMetrics);
|
||||
});
|
||||
socket.on('appGetGpuFeatureStatus', () => {
|
||||
socket.on("appGetGpuFeatureStatus", () => {
|
||||
const gpuFeatureStatus = app.getGPUFeatureStatus();
|
||||
electronSocket.emit('appGetGpuFeatureStatusCompleted', gpuFeatureStatus);
|
||||
electronSocket.emit("appGetGpuFeatureStatusCompleted", gpuFeatureStatus);
|
||||
});
|
||||
socket.on('appSetBadgeCount', (count) => {
|
||||
socket.on("appSetBadgeCount", (count) => {
|
||||
const success = app.setBadgeCount(count);
|
||||
electronSocket.emit('appSetBadgeCountCompleted', success);
|
||||
electronSocket.emit("appSetBadgeCountCompleted", success);
|
||||
});
|
||||
socket.on('appGetBadgeCount', () => {
|
||||
socket.on("appGetBadgeCount", () => {
|
||||
const count = app.getBadgeCount();
|
||||
electronSocket.emit('appGetBadgeCountCompleted', count);
|
||||
electronSocket.emit("appGetBadgeCountCompleted", count);
|
||||
});
|
||||
socket.on('appIsUnityRunning', () => {
|
||||
socket.on("appIsUnityRunning", () => {
|
||||
const isUnityRunning = app.isUnityRunning();
|
||||
electronSocket.emit('appIsUnityRunningCompleted', isUnityRunning);
|
||||
electronSocket.emit("appIsUnityRunningCompleted", isUnityRunning);
|
||||
});
|
||||
socket.on('appGetLoginItemSettings', (options) => {
|
||||
socket.on("appGetLoginItemSettings", (options) => {
|
||||
const loginItemSettings = app.getLoginItemSettings(options);
|
||||
electronSocket.emit('appGetLoginItemSettingsCompleted', loginItemSettings);
|
||||
electronSocket.emit("appGetLoginItemSettingsCompleted", loginItemSettings);
|
||||
});
|
||||
socket.on('appSetLoginItemSettings', (settings) => {
|
||||
socket.on("appSetLoginItemSettings", (settings) => {
|
||||
app.setLoginItemSettings(settings);
|
||||
});
|
||||
socket.on('appIsAccessibilitySupportEnabled', () => {
|
||||
socket.on("appIsAccessibilitySupportEnabled", () => {
|
||||
const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
|
||||
electronSocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled);
|
||||
electronSocket.emit("appIsAccessibilitySupportEnabledCompleted", isAccessibilitySupportEnabled);
|
||||
});
|
||||
socket.on('appSetAccessibilitySupportEnabled', (enabled) => {
|
||||
socket.on("appSetAccessibilitySupportEnabled", (enabled) => {
|
||||
app.setAccessibilitySupportEnabled(enabled);
|
||||
});
|
||||
socket.on('appShowAboutPanel', () => {
|
||||
socket.on("appShowAboutPanel", () => {
|
||||
app.showAboutPanel();
|
||||
});
|
||||
socket.on('appSetAboutPanelOptions', (options) => {
|
||||
socket.on("appSetAboutPanelOptions", (options) => {
|
||||
app.setAboutPanelOptions(options);
|
||||
});
|
||||
socket.on('appGetUserAgentFallback', () => {
|
||||
electronSocket.emit('appGetUserAgentFallbackCompleted', app.userAgentFallback);
|
||||
socket.on("appGetUserAgentFallback", () => {
|
||||
electronSocket.emit("appGetUserAgentFallbackCompleted", app.userAgentFallback);
|
||||
});
|
||||
socket.on('appSetUserAgentFallback', (userAgent) => {
|
||||
socket.on("appSetUserAgentFallback", (userAgent) => {
|
||||
app.userAgentFallback = userAgent;
|
||||
});
|
||||
socket.on('register-app-on-event', (eventName, listenerName) => {
|
||||
socket.on("register-app-on-event", (eventName, listenerName) => {
|
||||
app.on(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
@@ -238,7 +243,7 @@ module.exports = (socket, app) => {
|
||||
}
|
||||
});
|
||||
});
|
||||
socket.on('register-app-once-event', (eventName, listenerName) => {
|
||||
socket.on("register-app-once-event", (eventName, listenerName) => {
|
||||
app.once(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,313 +1,338 @@
|
||||
import { RelaunchOptions, LoginItemSettingsOptions, Settings, AboutPanelOptionsOptions } from "electron";
|
||||
import { Socket } from "net";
|
||||
import type { Socket } from "net";
|
||||
import {
|
||||
RelaunchOptions,
|
||||
LoginItemSettingsOptions,
|
||||
Settings,
|
||||
AboutPanelOptionsOptions,
|
||||
} from "electron";
|
||||
|
||||
let isQuitWindowAllClosed = true;
|
||||
let electronSocket: Socket;
|
||||
let appWindowAllClosedEventId: string;
|
||||
|
||||
let isQuitWindowAllClosed = true, electronSocket;
|
||||
let appWindowAllClosedEventId;
|
||||
export = (socket: Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
// By default, quit when all windows are closed
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
|
||||
app.quit();
|
||||
} else if (appWindowAllClosedEventId) {
|
||||
// If the user is on macOS
|
||||
// - OR -
|
||||
// If the user has indicated NOT to quit when all windows are closed,
|
||||
// emit the event.
|
||||
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
|
||||
}
|
||||
// By default, quit when all windows are closed
|
||||
app.on("window-all-closed", () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== "darwin" && isQuitWindowAllClosed) {
|
||||
app.quit();
|
||||
} else if (appWindowAllClosedEventId) {
|
||||
// If the user is on macOS
|
||||
// - OR -
|
||||
// If the user has indicated NOT to quit when all windows are closed,
|
||||
// emit the event.
|
||||
electronSocket.emit("app-window-all-closed" + appWindowAllClosedEventId);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("quit-app-window-all-closed", (quit) => {
|
||||
isQuitWindowAllClosed = quit;
|
||||
});
|
||||
|
||||
socket.on("register-app-window-all-closed", (id) => {
|
||||
appWindowAllClosedEventId = id;
|
||||
});
|
||||
|
||||
socket.on("register-app-before-quit", (id) => {
|
||||
app.on("before-quit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
electronSocket.emit("app-before-quit" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('quit-app-window-all-closed', (quit) => {
|
||||
isQuitWindowAllClosed = quit;
|
||||
socket.on("register-app-will-quit", (id) => {
|
||||
app.on("will-quit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
electronSocket.emit("app-will-quit" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-window-all-closed', (id) => {
|
||||
appWindowAllClosedEventId = id;
|
||||
socket.on("register-app-browser-window-blur", (id) => {
|
||||
app.on("browser-window-blur", () => {
|
||||
electronSocket.emit("app-browser-window-blur" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-before-quit', (id) => {
|
||||
app.on('before-quit', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
electronSocket.emit('app-before-quit' + id);
|
||||
});
|
||||
socket.on("register-app-browser-window-focus", (id) => {
|
||||
app.on("browser-window-focus", () => {
|
||||
electronSocket.emit("app-browser-window-focus" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-will-quit', (id) => {
|
||||
app.on('will-quit', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
electronSocket.emit('app-will-quit' + id);
|
||||
});
|
||||
socket.on("register-app-browser-window-created", (id) => {
|
||||
app.on("browser-window-created", () => {
|
||||
electronSocket.emit("app-browser-window-created" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-browser-window-blur', (id) => {
|
||||
app.on('browser-window-blur', () => {
|
||||
electronSocket.emit('app-browser-window-blur' + id);
|
||||
});
|
||||
socket.on("register-app-web-contents-created", (id) => {
|
||||
app.on("web-contents-created", () => {
|
||||
electronSocket.emit("app-web-contents-created" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-browser-window-focus', (id) => {
|
||||
app.on('browser-window-focus', () => {
|
||||
electronSocket.emit('app-browser-window-focus' + id);
|
||||
});
|
||||
socket.on("register-app-accessibility-support-changed", (id) => {
|
||||
app.on(
|
||||
"accessibility-support-changed",
|
||||
(event, accessibilitySupportEnabled) => {
|
||||
electronSocket.emit(
|
||||
"app-accessibility-support-changed" + id,
|
||||
accessibilitySupportEnabled,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("appQuit", () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
socket.on("appExit", (exitCode = 0) => {
|
||||
app.exit(exitCode);
|
||||
});
|
||||
|
||||
socket.on("appRelaunch", (options) => {
|
||||
app.relaunch(options as RelaunchOptions);
|
||||
});
|
||||
|
||||
socket.on("appFocus", (options) => {
|
||||
app.focus(options);
|
||||
});
|
||||
|
||||
socket.on("appHide", () => {
|
||||
app.hide();
|
||||
});
|
||||
|
||||
socket.on("appShow", () => {
|
||||
app.show();
|
||||
});
|
||||
|
||||
socket.on("appGetAppPath", () => {
|
||||
const path = app.getAppPath();
|
||||
electronSocket.emit("appGetAppPathCompleted", path);
|
||||
});
|
||||
|
||||
socket.on("appSetAppLogsPath", (path) => {
|
||||
app.setAppLogsPath(path);
|
||||
});
|
||||
|
||||
socket.on("appGetPath", (name) => {
|
||||
const path = app.getPath(name);
|
||||
electronSocket.emit("appGetPathCompleted", path);
|
||||
});
|
||||
|
||||
socket.on("appGetFileIcon", async (path, options) => {
|
||||
let error = {};
|
||||
|
||||
if (options) {
|
||||
const nativeImage = await app
|
||||
.getFileIcon(path, options)
|
||||
.catch((errorFileIcon) => (error = errorFileIcon));
|
||||
|
||||
electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]);
|
||||
} else {
|
||||
const nativeImage = await app
|
||||
.getFileIcon(path)
|
||||
.catch((errorFileIcon) => (error = errorFileIcon));
|
||||
|
||||
electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("appSetPath", (name, path) => {
|
||||
app.setPath(name, path);
|
||||
});
|
||||
|
||||
socket.on("appGetVersion", () => {
|
||||
const version = app.getVersion();
|
||||
electronSocket.emit("appGetVersionCompleted", version);
|
||||
});
|
||||
|
||||
socket.on("appGetName", () => {
|
||||
electronSocket.emit("appGetNameCompleted", app.name);
|
||||
});
|
||||
|
||||
socket.on("appSetName", (name) => {
|
||||
app.name = name;
|
||||
});
|
||||
|
||||
socket.on("appGetLocale", () => {
|
||||
const locale = app.getLocale();
|
||||
electronSocket.emit("appGetLocaleCompleted", locale);
|
||||
});
|
||||
|
||||
socket.on("appAddRecentDocument", (path) => {
|
||||
app.addRecentDocument(path);
|
||||
});
|
||||
|
||||
socket.on("appClearRecentDocuments", () => {
|
||||
app.clearRecentDocuments();
|
||||
});
|
||||
|
||||
socket.on("appSetAsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.setAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit("appSetAsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
|
||||
socket.on("appRemoveAsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.removeAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit("appRemoveAsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
|
||||
socket.on("appIsDefaultProtocolClient", (protocol, path, args) => {
|
||||
const success = app.isDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit("appIsDefaultProtocolClientCompleted", success);
|
||||
});
|
||||
|
||||
socket.on("appSetUserTasks", (tasks) => {
|
||||
const success = app.setUserTasks(tasks);
|
||||
electronSocket.emit("appSetUserTasksCompleted", success);
|
||||
});
|
||||
|
||||
socket.on("appGetJumpListSettings", () => {
|
||||
const jumpListSettings = app.getJumpListSettings();
|
||||
electronSocket.emit("appGetJumpListSettingsCompleted", jumpListSettings);
|
||||
});
|
||||
|
||||
socket.on("appSetJumpList", (categories) => {
|
||||
app.setJumpList(categories);
|
||||
});
|
||||
|
||||
socket.on("appRequestSingleInstanceLock", () => {
|
||||
const success = app.requestSingleInstanceLock();
|
||||
electronSocket.emit("appRequestSingleInstanceLockCompleted", success);
|
||||
|
||||
app.on("second-instance", (event, args = [], workingDirectory = "") => {
|
||||
electronSocket.emit("secondInstance", [args, workingDirectory]);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-browser-window-created', (id) => {
|
||||
app.on('browser-window-created', () => {
|
||||
electronSocket.emit('app-browser-window-created' + id);
|
||||
});
|
||||
socket.on("appHasSingleInstanceLock", () => {
|
||||
const hasLock = app.hasSingleInstanceLock();
|
||||
|
||||
electronSocket.emit("appHasSingleInstanceLockCompleted", hasLock);
|
||||
});
|
||||
|
||||
socket.on("appReleaseSingleInstanceLock", () => {
|
||||
app.releaseSingleInstanceLock();
|
||||
});
|
||||
|
||||
socket.on("appSetUserActivity", (type, userInfo, webpageUrl) => {
|
||||
app.setUserActivity(type, userInfo, webpageUrl);
|
||||
});
|
||||
|
||||
socket.on("appGetCurrentActivityType", () => {
|
||||
const activityType = app.getCurrentActivityType();
|
||||
electronSocket.emit("appGetCurrentActivityTypeCompleted", activityType);
|
||||
});
|
||||
|
||||
socket.on("appInvalidateCurrentActivity", () => {
|
||||
app.invalidateCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on("appResignCurrentActivity", () => {
|
||||
app.resignCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on("appSetAppUserModelId", (id) => {
|
||||
app.setAppUserModelId(id);
|
||||
});
|
||||
|
||||
socket.on("appImportCertificate", (options) => {
|
||||
app.importCertificate(options, (result) => {
|
||||
electronSocket.emit("appImportCertificateCompleted", result);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-web-contents-created', (id) => {
|
||||
app.on('web-contents-created', () => {
|
||||
electronSocket.emit('app-web-contents-created' + id);
|
||||
});
|
||||
socket.on("appGetAppMetrics", () => {
|
||||
const processMetrics = app.getAppMetrics();
|
||||
electronSocket.emit("appGetAppMetricsCompleted", processMetrics);
|
||||
});
|
||||
|
||||
socket.on("appGetGpuFeatureStatus", () => {
|
||||
const gpuFeatureStatus = app.getGPUFeatureStatus();
|
||||
electronSocket.emit("appGetGpuFeatureStatusCompleted", gpuFeatureStatus);
|
||||
});
|
||||
|
||||
socket.on("appSetBadgeCount", (count) => {
|
||||
const success = app.setBadgeCount(count);
|
||||
electronSocket.emit("appSetBadgeCountCompleted", success);
|
||||
});
|
||||
|
||||
socket.on("appGetBadgeCount", () => {
|
||||
const count = app.getBadgeCount();
|
||||
electronSocket.emit("appGetBadgeCountCompleted", count);
|
||||
});
|
||||
|
||||
socket.on("appIsUnityRunning", () => {
|
||||
const isUnityRunning = app.isUnityRunning();
|
||||
electronSocket.emit("appIsUnityRunningCompleted", isUnityRunning);
|
||||
});
|
||||
|
||||
socket.on("appGetLoginItemSettings", (options) => {
|
||||
const loginItemSettings = app.getLoginItemSettings(
|
||||
options as LoginItemSettingsOptions,
|
||||
);
|
||||
electronSocket.emit("appGetLoginItemSettingsCompleted", loginItemSettings);
|
||||
});
|
||||
|
||||
socket.on("appSetLoginItemSettings", (settings) => {
|
||||
app.setLoginItemSettings(settings as Settings);
|
||||
});
|
||||
|
||||
socket.on("appIsAccessibilitySupportEnabled", () => {
|
||||
const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
|
||||
electronSocket.emit(
|
||||
"appIsAccessibilitySupportEnabledCompleted",
|
||||
isAccessibilitySupportEnabled,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("appSetAccessibilitySupportEnabled", (enabled) => {
|
||||
app.setAccessibilitySupportEnabled(enabled);
|
||||
});
|
||||
|
||||
socket.on("appShowAboutPanel", () => {
|
||||
app.showAboutPanel();
|
||||
});
|
||||
|
||||
socket.on("appSetAboutPanelOptions", (options) => {
|
||||
app.setAboutPanelOptions(options as AboutPanelOptionsOptions);
|
||||
});
|
||||
|
||||
socket.on("appGetUserAgentFallback", () => {
|
||||
electronSocket.emit(
|
||||
"appGetUserAgentFallbackCompleted",
|
||||
app.userAgentFallback,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("appSetUserAgentFallback", (userAgent) => {
|
||||
app.userAgentFallback = userAgent;
|
||||
});
|
||||
|
||||
socket.on("register-app-on-event", (eventName, listenerName) => {
|
||||
app.on(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
} else {
|
||||
electronSocket.emit(listenerName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-accessibility-support-changed', (id) => {
|
||||
app.on('accessibility-support-changed', (event, accessibilitySupportEnabled) => {
|
||||
electronSocket.emit('app-accessibility-support-changed' + id, accessibilitySupportEnabled);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('appQuit', () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
socket.on('appExit', (exitCode = 0) => {
|
||||
app.exit(exitCode);
|
||||
});
|
||||
|
||||
socket.on('appRelaunch', (options) => {
|
||||
app.relaunch(options as RelaunchOptions);
|
||||
});
|
||||
|
||||
socket.on('appFocus', (options) => {
|
||||
app.focus(options);
|
||||
});
|
||||
|
||||
socket.on('appHide', () => {
|
||||
app.hide();
|
||||
});
|
||||
|
||||
socket.on('appShow', () => {
|
||||
app.show();
|
||||
});
|
||||
|
||||
socket.on('appGetAppPath', () => {
|
||||
const path = app.getAppPath();
|
||||
electronSocket.emit('appGetAppPathCompleted', path);
|
||||
});
|
||||
|
||||
socket.on('appSetAppLogsPath', (path) => {
|
||||
app.setAppLogsPath(path);
|
||||
});
|
||||
|
||||
socket.on('appGetPath', (name) => {
|
||||
const path = app.getPath(name);
|
||||
electronSocket.emit('appGetPathCompleted', path);
|
||||
});
|
||||
|
||||
socket.on('appGetFileIcon', async (path, options) => {
|
||||
let error = {};
|
||||
|
||||
if (options) {
|
||||
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);
|
||||
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
} else {
|
||||
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);
|
||||
|
||||
electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('appSetPath', (name, path) => {
|
||||
app.setPath(name, path);
|
||||
});
|
||||
|
||||
socket.on('appGetVersion', () => {
|
||||
const version = app.getVersion();
|
||||
electronSocket.emit('appGetVersionCompleted', version);
|
||||
});
|
||||
|
||||
socket.on('appGetName', () => {
|
||||
electronSocket.emit('appGetNameCompleted', app.name);
|
||||
});
|
||||
|
||||
socket.on('appSetName', (name) => {
|
||||
app.name = name;
|
||||
});
|
||||
|
||||
socket.on('appGetLocale', () => {
|
||||
const locale = app.getLocale();
|
||||
electronSocket.emit('appGetLocaleCompleted', locale);
|
||||
});
|
||||
|
||||
socket.on('appAddRecentDocument', (path) => {
|
||||
app.addRecentDocument(path);
|
||||
});
|
||||
|
||||
socket.on('appClearRecentDocuments', () => {
|
||||
app.clearRecentDocuments();
|
||||
});
|
||||
|
||||
socket.on('appSetAsDefaultProtocolClient', (protocol, path, args) => {
|
||||
const success = app.setAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appSetAsDefaultProtocolClientCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appRemoveAsDefaultProtocolClient', (protocol, path, args) => {
|
||||
const success = app.removeAsDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appRemoveAsDefaultProtocolClientCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appIsDefaultProtocolClient', (protocol, path, args) => {
|
||||
const success = app.isDefaultProtocolClient(protocol, path, args);
|
||||
electronSocket.emit('appIsDefaultProtocolClientCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appSetUserTasks', (tasks) => {
|
||||
const success = app.setUserTasks(tasks);
|
||||
electronSocket.emit('appSetUserTasksCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appGetJumpListSettings', () => {
|
||||
const jumpListSettings = app.getJumpListSettings();
|
||||
electronSocket.emit('appGetJumpListSettingsCompleted', jumpListSettings);
|
||||
});
|
||||
|
||||
socket.on('appSetJumpList', (categories) => {
|
||||
app.setJumpList(categories);
|
||||
});
|
||||
|
||||
socket.on('appRequestSingleInstanceLock', () => {
|
||||
const success = app.requestSingleInstanceLock();
|
||||
electronSocket.emit('appRequestSingleInstanceLockCompleted', success);
|
||||
|
||||
app.on('second-instance', (event, args = [], workingDirectory = '') => {
|
||||
electronSocket.emit('secondInstance', [args, workingDirectory]);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('appHasSingleInstanceLock', () => {
|
||||
const hasLock = app.hasSingleInstanceLock();
|
||||
|
||||
electronSocket.emit('appHasSingleInstanceLockCompleted', hasLock);
|
||||
});
|
||||
|
||||
socket.on('appReleaseSingleInstanceLock', () => {
|
||||
app.releaseSingleInstanceLock();
|
||||
});
|
||||
|
||||
socket.on('appSetUserActivity', (type, userInfo, webpageUrl) => {
|
||||
app.setUserActivity(type, userInfo, webpageUrl);
|
||||
});
|
||||
|
||||
socket.on('appGetCurrentActivityType', () => {
|
||||
const activityType = app.getCurrentActivityType();
|
||||
electronSocket.emit('appGetCurrentActivityTypeCompleted', activityType);
|
||||
});
|
||||
|
||||
socket.on('appInvalidateCurrentActivity', () => {
|
||||
app.invalidateCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on('appResignCurrentActivity', () => {
|
||||
app.resignCurrentActivity();
|
||||
});
|
||||
|
||||
socket.on('appSetAppUserModelId', (id) => {
|
||||
app.setAppUserModelId(id);
|
||||
});
|
||||
|
||||
socket.on('appImportCertificate', (options) => {
|
||||
app.importCertificate(options, (result) => {
|
||||
electronSocket.emit('appImportCertificateCompleted', result);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('appGetAppMetrics', () => {
|
||||
const processMetrics = app.getAppMetrics();
|
||||
electronSocket.emit('appGetAppMetricsCompleted', processMetrics);
|
||||
});
|
||||
|
||||
socket.on('appGetGpuFeatureStatus', () => {
|
||||
const gpuFeatureStatus = app.getGPUFeatureStatus();
|
||||
electronSocket.emit('appGetGpuFeatureStatusCompleted', gpuFeatureStatus);
|
||||
});
|
||||
|
||||
socket.on('appSetBadgeCount', (count) => {
|
||||
const success = app.setBadgeCount(count);
|
||||
electronSocket.emit('appSetBadgeCountCompleted', success);
|
||||
});
|
||||
|
||||
socket.on('appGetBadgeCount', () => {
|
||||
const count = app.getBadgeCount();
|
||||
electronSocket.emit('appGetBadgeCountCompleted', count);
|
||||
});
|
||||
|
||||
socket.on('appIsUnityRunning', () => {
|
||||
const isUnityRunning = app.isUnityRunning();
|
||||
electronSocket.emit('appIsUnityRunningCompleted', isUnityRunning);
|
||||
});
|
||||
|
||||
socket.on('appGetLoginItemSettings', (options) => {
|
||||
const loginItemSettings = app.getLoginItemSettings(options as LoginItemSettingsOptions);
|
||||
electronSocket.emit('appGetLoginItemSettingsCompleted', loginItemSettings);
|
||||
});
|
||||
|
||||
socket.on('appSetLoginItemSettings', (settings) => {
|
||||
app.setLoginItemSettings(settings as Settings);
|
||||
});
|
||||
|
||||
socket.on('appIsAccessibilitySupportEnabled', () => {
|
||||
const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
|
||||
electronSocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled);
|
||||
});
|
||||
|
||||
socket.on('appSetAccessibilitySupportEnabled', (enabled) => {
|
||||
app.setAccessibilitySupportEnabled(enabled);
|
||||
});
|
||||
|
||||
socket.on('appShowAboutPanel', () => {
|
||||
app.showAboutPanel();
|
||||
});
|
||||
|
||||
socket.on('appSetAboutPanelOptions', (options) => {
|
||||
app.setAboutPanelOptions(options as AboutPanelOptionsOptions);
|
||||
});
|
||||
|
||||
socket.on('appGetUserAgentFallback', () => {
|
||||
electronSocket.emit('appGetUserAgentFallbackCompleted', app.userAgentFallback);
|
||||
});
|
||||
|
||||
socket.on('appSetUserAgentFallback', (userAgent) => {
|
||||
app.userAgentFallback = userAgent;
|
||||
});
|
||||
|
||||
socket.on('register-app-on-event', (eventName, listenerName) => {
|
||||
app.on(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
} else {
|
||||
electronSocket.emit(listenerName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-app-once-event', (eventName, listenerName) => {
|
||||
app.once(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
} else {
|
||||
electronSocket.emit(listenerName);
|
||||
}
|
||||
});
|
||||
socket.on("register-app-once-event", (eventName, listenerName) => {
|
||||
app.once(eventName, (...args) => {
|
||||
if (args.length > 1) {
|
||||
electronSocket.emit(listenerName, args[1]);
|
||||
} else {
|
||||
electronSocket.emit(listenerName);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,112 +3,118 @@ const electron_updater_1 = require("electron-updater");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('register-autoUpdater-error', (id) => {
|
||||
electron_updater_1.autoUpdater.on('error', (error) => {
|
||||
electronSocket.emit('autoUpdater-error' + id, error.message);
|
||||
socket.on("register-autoUpdater-error", (id) => {
|
||||
electron_updater_1.autoUpdater.on("error", (error) => {
|
||||
electronSocket.emit("autoUpdater-error" + id, error.message);
|
||||
});
|
||||
});
|
||||
socket.on('register-autoUpdater-checking-for-update', (id) => {
|
||||
electron_updater_1.autoUpdater.on('checking-for-update', () => {
|
||||
electronSocket.emit('autoUpdater-checking-for-update' + id);
|
||||
socket.on("register-autoUpdater-checking-for-update", (id) => {
|
||||
electron_updater_1.autoUpdater.on("checking-for-update", () => {
|
||||
electronSocket.emit("autoUpdater-checking-for-update" + id);
|
||||
});
|
||||
});
|
||||
socket.on('register-autoUpdater-update-available', (id) => {
|
||||
electron_updater_1.autoUpdater.on('update-available', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-available' + id, updateInfo);
|
||||
socket.on("register-autoUpdater-update-available", (id) => {
|
||||
electron_updater_1.autoUpdater.on("update-available", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-available" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
socket.on('register-autoUpdater-update-not-available', (id) => {
|
||||
electron_updater_1.autoUpdater.on('update-not-available', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-not-available' + id, updateInfo);
|
||||
socket.on("register-autoUpdater-update-not-available", (id) => {
|
||||
electron_updater_1.autoUpdater.on("update-not-available", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
socket.on('register-autoUpdater-download-progress', (id) => {
|
||||
electron_updater_1.autoUpdater.on('download-progress', (progressInfo) => {
|
||||
electronSocket.emit('autoUpdater-download-progress' + id, progressInfo);
|
||||
socket.on("register-autoUpdater-download-progress", (id) => {
|
||||
electron_updater_1.autoUpdater.on("download-progress", (progressInfo) => {
|
||||
electronSocket.emit("autoUpdater-download-progress" + id, progressInfo);
|
||||
});
|
||||
});
|
||||
socket.on('register-autoUpdater-update-downloaded', (id) => {
|
||||
electron_updater_1.autoUpdater.on('update-downloaded', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-downloaded' + id, updateInfo);
|
||||
socket.on("register-autoUpdater-update-downloaded", (id) => {
|
||||
electron_updater_1.autoUpdater.on("update-downloaded", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
// Properties *****
|
||||
socket.on('autoUpdater-autoDownload', () => {
|
||||
electronSocket.emit('autoUpdater-autoDownload-completed', electron_updater_1.autoUpdater.autoDownload);
|
||||
socket.on("autoUpdater-autoDownload", () => {
|
||||
electronSocket.emit("autoUpdater-autoDownload-completed", electron_updater_1.autoUpdater.autoDownload);
|
||||
});
|
||||
socket.on('autoUpdater-autoDownload-set', (value) => {
|
||||
socket.on("autoUpdater-autoDownload-set", (value) => {
|
||||
electron_updater_1.autoUpdater.autoDownload = value;
|
||||
});
|
||||
socket.on('autoUpdater-autoInstallOnAppQuit', () => {
|
||||
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', electron_updater_1.autoUpdater.autoInstallOnAppQuit);
|
||||
socket.on("autoUpdater-autoInstallOnAppQuit", () => {
|
||||
electronSocket.emit("autoUpdater-autoInstallOnAppQuit-completed", electron_updater_1.autoUpdater.autoInstallOnAppQuit);
|
||||
});
|
||||
socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => {
|
||||
socket.on("autoUpdater-autoInstallOnAppQuit-set", (value) => {
|
||||
electron_updater_1.autoUpdater.autoInstallOnAppQuit = value;
|
||||
});
|
||||
socket.on('autoUpdater-allowPrerelease', () => {
|
||||
electronSocket.emit('autoUpdater-allowPrerelease-completed', electron_updater_1.autoUpdater.allowPrerelease);
|
||||
socket.on("autoUpdater-allowPrerelease", () => {
|
||||
electronSocket.emit("autoUpdater-allowPrerelease-completed", electron_updater_1.autoUpdater.allowPrerelease);
|
||||
});
|
||||
socket.on('autoUpdater-allowPrerelease-set', (value) => {
|
||||
socket.on("autoUpdater-allowPrerelease-set", (value) => {
|
||||
electron_updater_1.autoUpdater.allowPrerelease = value;
|
||||
});
|
||||
socket.on('autoUpdater-fullChangelog', () => {
|
||||
electronSocket.emit('autoUpdater-fullChangelog-completed', electron_updater_1.autoUpdater.fullChangelog);
|
||||
socket.on("autoUpdater-fullChangelog", () => {
|
||||
electronSocket.emit("autoUpdater-fullChangelog-completed", electron_updater_1.autoUpdater.fullChangelog);
|
||||
});
|
||||
socket.on('autoUpdater-fullChangelog-set', (value) => {
|
||||
socket.on("autoUpdater-fullChangelog-set", (value) => {
|
||||
electron_updater_1.autoUpdater.fullChangelog = value;
|
||||
});
|
||||
socket.on('autoUpdater-allowDowngrade', () => {
|
||||
electronSocket.emit('autoUpdater-allowDowngrade-completed', electron_updater_1.autoUpdater.allowDowngrade);
|
||||
socket.on("autoUpdater-allowDowngrade", () => {
|
||||
electronSocket.emit("autoUpdater-allowDowngrade-completed", electron_updater_1.autoUpdater.allowDowngrade);
|
||||
});
|
||||
socket.on('autoUpdater-allowDowngrade-set', (value) => {
|
||||
socket.on("autoUpdater-allowDowngrade-set", (value) => {
|
||||
electron_updater_1.autoUpdater.allowDowngrade = value;
|
||||
});
|
||||
socket.on('autoUpdater-updateConfigPath', () => {
|
||||
electronSocket.emit('autoUpdater-updateConfigPath-completed', electron_updater_1.autoUpdater.updateConfigPath || '');
|
||||
socket.on("autoUpdater-updateConfigPath", () => {
|
||||
electronSocket.emit("autoUpdater-updateConfigPath-completed", electron_updater_1.autoUpdater.updateConfigPath || "");
|
||||
});
|
||||
socket.on('autoUpdater-updateConfigPath-set', (value) => {
|
||||
socket.on("autoUpdater-updateConfigPath-set", (value) => {
|
||||
electron_updater_1.autoUpdater.updateConfigPath = value;
|
||||
});
|
||||
socket.on('autoUpdater-currentVersion', () => {
|
||||
electronSocket.emit('autoUpdater-currentVersion-completed', electron_updater_1.autoUpdater.currentVersion);
|
||||
socket.on("autoUpdater-currentVersion", () => {
|
||||
electronSocket.emit("autoUpdater-currentVersion-completed", electron_updater_1.autoUpdater.currentVersion);
|
||||
});
|
||||
socket.on('autoUpdater-channel', () => {
|
||||
electronSocket.emit('autoUpdater-channel-completed', electron_updater_1.autoUpdater.channel || '');
|
||||
socket.on("autoUpdater-channel", () => {
|
||||
electronSocket.emit("autoUpdater-channel-completed", electron_updater_1.autoUpdater.channel || "");
|
||||
});
|
||||
socket.on('autoUpdater-channel-set', (value) => {
|
||||
socket.on("autoUpdater-channel-set", (value) => {
|
||||
electron_updater_1.autoUpdater.channel = value;
|
||||
});
|
||||
socket.on('autoUpdater-requestHeaders', () => {
|
||||
electronSocket.emit('autoUpdater-requestHeaders-completed', electron_updater_1.autoUpdater.requestHeaders);
|
||||
socket.on("autoUpdater-requestHeaders", () => {
|
||||
electronSocket.emit("autoUpdater-requestHeaders-completed", electron_updater_1.autoUpdater.requestHeaders);
|
||||
});
|
||||
socket.on('autoUpdater-requestHeaders-set', (value) => {
|
||||
socket.on("autoUpdater-requestHeaders-set", (value) => {
|
||||
electron_updater_1.autoUpdater.requestHeaders = value;
|
||||
});
|
||||
socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => {
|
||||
electron_updater_1.autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult);
|
||||
}).catch((error) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error);
|
||||
socket.on("autoUpdater-checkForUpdatesAndNotify", async (guid) => {
|
||||
electron_updater_1.autoUpdater
|
||||
.checkForUpdatesAndNotify()
|
||||
.then((updateCheckResult) => {
|
||||
electronSocket.emit("autoUpdater-checkForUpdatesAndNotify-completed" + guid, updateCheckResult);
|
||||
})
|
||||
.catch((error) => {
|
||||
electronSocket.emit("autoUpdater-checkForUpdatesAndNotifyError" + guid, error);
|
||||
});
|
||||
});
|
||||
socket.on('autoUpdater-checkForUpdates', async (guid) => {
|
||||
electron_updater_1.autoUpdater.checkForUpdates().then((updateCheckResult) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult);
|
||||
}).catch((error) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error);
|
||||
socket.on("autoUpdater-checkForUpdates", async (guid) => {
|
||||
electron_updater_1.autoUpdater
|
||||
.checkForUpdates()
|
||||
.then((updateCheckResult) => {
|
||||
electronSocket.emit("autoUpdater-checkForUpdates-completed" + guid, updateCheckResult);
|
||||
})
|
||||
.catch((error) => {
|
||||
electronSocket.emit("autoUpdater-checkForUpdatesError" + guid, error);
|
||||
});
|
||||
});
|
||||
socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => {
|
||||
socket.on("autoUpdater-quitAndInstall", async (isSilent, isForceRunAfter) => {
|
||||
electron_updater_1.autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
});
|
||||
socket.on('autoUpdater-downloadUpdate', async (guid) => {
|
||||
socket.on("autoUpdater-downloadUpdate", async (guid) => {
|
||||
const downloadedPath = await electron_updater_1.autoUpdater.downloadUpdate();
|
||||
electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath);
|
||||
electronSocket.emit("autoUpdater-downloadUpdate-completed" + guid, downloadedPath);
|
||||
});
|
||||
socket.on('autoUpdater-getFeedURL', async (guid) => {
|
||||
socket.on("autoUpdater-getFeedURL", async (guid) => {
|
||||
const feedUrl = await electron_updater_1.autoUpdater.getFeedURL();
|
||||
electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || '');
|
||||
electronSocket.emit("autoUpdater-getFeedURL-completed" + guid, feedUrl || "");
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=autoUpdater.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"autoUpdater.js","sourceRoot":"","sources":["autoUpdater.ts"],"names":[],"mappings":";AACA,uDAA+C;AAC/C,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,EAAE,EAAE,EAAE;QAC3C,8BAAW,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;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AAM,OAAO,GAAG,MAAM,8BAAW,CAAC,UAAU,EAAE,CAAC;QAC/C,cAAc,CAAC,IAAI,CACjB,kCAAkC,GAAG,IAAI,EACzC,OAAO,IAAI,EAAE,CACd,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,143 +1,192 @@
|
||||
import { Socket } from 'net';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('register-autoUpdater-error', (id) => {
|
||||
autoUpdater.on('error', (error) => {
|
||||
electronSocket.emit('autoUpdater-error' + id, error.message);
|
||||
});
|
||||
socket.on("register-autoUpdater-error", (id) => {
|
||||
autoUpdater.on("error", (error) => {
|
||||
electronSocket.emit("autoUpdater-error" + id, error.message);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-autoUpdater-checking-for-update', (id) => {
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
electronSocket.emit('autoUpdater-checking-for-update' + id);
|
||||
});
|
||||
socket.on("register-autoUpdater-checking-for-update", (id) => {
|
||||
autoUpdater.on("checking-for-update", () => {
|
||||
electronSocket.emit("autoUpdater-checking-for-update" + id);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-autoUpdater-update-available', (id) => {
|
||||
autoUpdater.on('update-available', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-available' + id, updateInfo);
|
||||
});
|
||||
socket.on("register-autoUpdater-update-available", (id) => {
|
||||
autoUpdater.on("update-available", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-available" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-autoUpdater-update-not-available', (id) => {
|
||||
autoUpdater.on('update-not-available', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-not-available' + id, updateInfo);
|
||||
});
|
||||
socket.on("register-autoUpdater-update-not-available", (id) => {
|
||||
autoUpdater.on("update-not-available", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-autoUpdater-download-progress', (id) => {
|
||||
autoUpdater.on('download-progress', (progressInfo) => {
|
||||
electronSocket.emit('autoUpdater-download-progress' + id, progressInfo);
|
||||
});
|
||||
socket.on("register-autoUpdater-download-progress", (id) => {
|
||||
autoUpdater.on("download-progress", (progressInfo) => {
|
||||
electronSocket.emit("autoUpdater-download-progress" + id, progressInfo);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('register-autoUpdater-update-downloaded', (id) => {
|
||||
autoUpdater.on('update-downloaded', (updateInfo) => {
|
||||
electronSocket.emit('autoUpdater-update-downloaded' + id, updateInfo);
|
||||
});
|
||||
socket.on("register-autoUpdater-update-downloaded", (id) => {
|
||||
autoUpdater.on("update-downloaded", (updateInfo) => {
|
||||
electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo);
|
||||
});
|
||||
});
|
||||
|
||||
// Properties *****
|
||||
// Properties *****
|
||||
|
||||
socket.on('autoUpdater-autoDownload', () => {
|
||||
electronSocket.emit('autoUpdater-autoDownload-completed', autoUpdater.autoDownload);
|
||||
});
|
||||
socket.on("autoUpdater-autoDownload", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-autoDownload-completed",
|
||||
autoUpdater.autoDownload,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-autoDownload-set', (value) => {
|
||||
autoUpdater.autoDownload = value;
|
||||
});
|
||||
socket.on("autoUpdater-autoDownload-set", (value) => {
|
||||
autoUpdater.autoDownload = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-autoInstallOnAppQuit', () => {
|
||||
electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', autoUpdater.autoInstallOnAppQuit);
|
||||
});
|
||||
socket.on("autoUpdater-autoInstallOnAppQuit", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-autoInstallOnAppQuit-completed",
|
||||
autoUpdater.autoInstallOnAppQuit,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => {
|
||||
autoUpdater.autoInstallOnAppQuit = value;
|
||||
});
|
||||
socket.on("autoUpdater-autoInstallOnAppQuit-set", (value) => {
|
||||
autoUpdater.autoInstallOnAppQuit = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-allowPrerelease', () => {
|
||||
electronSocket.emit('autoUpdater-allowPrerelease-completed', autoUpdater.allowPrerelease);
|
||||
});
|
||||
socket.on("autoUpdater-allowPrerelease", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-allowPrerelease-completed",
|
||||
autoUpdater.allowPrerelease,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-allowPrerelease-set', (value) => {
|
||||
autoUpdater.allowPrerelease = value;
|
||||
});
|
||||
socket.on("autoUpdater-allowPrerelease-set", (value) => {
|
||||
autoUpdater.allowPrerelease = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-fullChangelog', () => {
|
||||
electronSocket.emit('autoUpdater-fullChangelog-completed', autoUpdater.fullChangelog);
|
||||
});
|
||||
socket.on("autoUpdater-fullChangelog", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-fullChangelog-completed",
|
||||
autoUpdater.fullChangelog,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-fullChangelog-set', (value) => {
|
||||
autoUpdater.fullChangelog = value;
|
||||
});
|
||||
socket.on("autoUpdater-fullChangelog-set", (value) => {
|
||||
autoUpdater.fullChangelog = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-allowDowngrade', () => {
|
||||
electronSocket.emit('autoUpdater-allowDowngrade-completed', autoUpdater.allowDowngrade);
|
||||
});
|
||||
socket.on("autoUpdater-allowDowngrade", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-allowDowngrade-completed",
|
||||
autoUpdater.allowDowngrade,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-allowDowngrade-set', (value) => {
|
||||
autoUpdater.allowDowngrade = value;
|
||||
});
|
||||
socket.on("autoUpdater-allowDowngrade-set", (value) => {
|
||||
autoUpdater.allowDowngrade = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-updateConfigPath', () => {
|
||||
electronSocket.emit('autoUpdater-updateConfigPath-completed', autoUpdater.updateConfigPath || '');
|
||||
});
|
||||
socket.on("autoUpdater-updateConfigPath", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-updateConfigPath-completed",
|
||||
autoUpdater.updateConfigPath || "",
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-updateConfigPath-set', (value) => {
|
||||
autoUpdater.updateConfigPath = value;
|
||||
});
|
||||
socket.on("autoUpdater-updateConfigPath-set", (value) => {
|
||||
autoUpdater.updateConfigPath = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-currentVersion', () => {
|
||||
electronSocket.emit('autoUpdater-currentVersion-completed', autoUpdater.currentVersion);
|
||||
});
|
||||
socket.on("autoUpdater-currentVersion", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-currentVersion-completed",
|
||||
autoUpdater.currentVersion,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-channel', () => {
|
||||
electronSocket.emit('autoUpdater-channel-completed', autoUpdater.channel || '');
|
||||
});
|
||||
socket.on("autoUpdater-channel", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-channel-completed",
|
||||
autoUpdater.channel || "",
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-channel-set', (value) => {
|
||||
autoUpdater.channel = value;
|
||||
});
|
||||
socket.on("autoUpdater-channel-set", (value) => {
|
||||
autoUpdater.channel = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-requestHeaders', () => {
|
||||
electronSocket.emit('autoUpdater-requestHeaders-completed', autoUpdater.requestHeaders);
|
||||
});
|
||||
socket.on("autoUpdater-requestHeaders", () => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-requestHeaders-completed",
|
||||
autoUpdater.requestHeaders,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-requestHeaders-set', (value) => {
|
||||
autoUpdater.requestHeaders = value;
|
||||
});
|
||||
socket.on("autoUpdater-requestHeaders-set", (value) => {
|
||||
autoUpdater.requestHeaders = value;
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => {
|
||||
autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult);
|
||||
}).catch((error) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error);
|
||||
});
|
||||
});
|
||||
socket.on("autoUpdater-checkForUpdatesAndNotify", async (guid) => {
|
||||
autoUpdater
|
||||
.checkForUpdatesAndNotify()
|
||||
.then((updateCheckResult) => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-checkForUpdatesAndNotify-completed" + guid,
|
||||
updateCheckResult,
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-checkForUpdatesAndNotifyError" + guid,
|
||||
error,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-checkForUpdates', async (guid) => {
|
||||
autoUpdater.checkForUpdates().then((updateCheckResult) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult);
|
||||
}).catch((error) => {
|
||||
electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error);
|
||||
});
|
||||
});
|
||||
socket.on("autoUpdater-checkForUpdates", async (guid) => {
|
||||
autoUpdater
|
||||
.checkForUpdates()
|
||||
.then((updateCheckResult) => {
|
||||
electronSocket.emit(
|
||||
"autoUpdater-checkForUpdates-completed" + guid,
|
||||
updateCheckResult,
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
electronSocket.emit("autoUpdater-checkForUpdatesError" + guid, error);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => {
|
||||
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
});
|
||||
socket.on("autoUpdater-quitAndInstall", async (isSilent, isForceRunAfter) => {
|
||||
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-downloadUpdate', async (guid) => {
|
||||
const downloadedPath = await autoUpdater.downloadUpdate();
|
||||
electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath);
|
||||
});
|
||||
socket.on("autoUpdater-downloadUpdate", async (guid) => {
|
||||
const downloadedPath = await autoUpdater.downloadUpdate();
|
||||
electronSocket.emit(
|
||||
"autoUpdater-downloadUpdate-completed" + guid,
|
||||
downloadedPath,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('autoUpdater-getFeedURL', async (guid) => {
|
||||
const feedUrl = await autoUpdater.getFeedURL();
|
||||
electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || '');
|
||||
});
|
||||
socket.on("autoUpdater-getFeedURL", async (guid) => {
|
||||
const feedUrl = await autoUpdater.getFeedURL();
|
||||
electronSocket.emit(
|
||||
"autoUpdater-getFeedURL-completed" + guid,
|
||||
feedUrl || "",
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,17 +2,22 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.browserViewMediateService = exports.browserViewApi = void 0;
|
||||
const electron_1 = require("electron");
|
||||
const browserViews = (global['browserViews'] = global['browserViews'] || []);
|
||||
let browserView, electronSocket;
|
||||
const proxyToCredentialsMap = (global['proxyToCredentialsMap'] = global['proxyToCredentialsMap'] || []);
|
||||
const browserViews = (global["browserViews"] =
|
||||
global["browserViews"] || []);
|
||||
const proxyToCredentialsMap = (global["proxyToCredentialsMap"] = global["proxyToCredentialsMap"] || []);
|
||||
let browserView;
|
||||
let electronSocket;
|
||||
const browserViewApi = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('createBrowserView', (options) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true, contextIsolation: false } };
|
||||
socket.on("createBrowserView", (options) => {
|
||||
if (!hasOwnChildreen(options, "webPreferences", "nodeIntegration")) {
|
||||
options = {
|
||||
...options,
|
||||
webPreferences: { nodeIntegration: true, contextIsolation: false },
|
||||
};
|
||||
}
|
||||
browserView = new electron_1.BrowserView(options);
|
||||
browserView['id'] = browserViews.length + 1;
|
||||
browserView["id"] = browserViews.length + 1;
|
||||
if (options.proxy) {
|
||||
browserView.webContents.session.setProxy({ proxyRules: options.proxy });
|
||||
}
|
||||
@@ -20,19 +25,19 @@ const browserViewApi = (socket) => {
|
||||
proxyToCredentialsMap[options.proxy] = options.proxyCredentials;
|
||||
}
|
||||
browserViews.push(browserView);
|
||||
electronSocket.emit('BrowserViewCreated', browserView['id']);
|
||||
electronSocket.emit("BrowserViewCreated", browserView["id"]);
|
||||
});
|
||||
socket.on('browserView-bounds', (id) => {
|
||||
socket.on("browserView-bounds", (id) => {
|
||||
const bounds = getBrowserViewById(id).getBounds();
|
||||
electronSocket.emit('browserView-bounds-completed', bounds);
|
||||
electronSocket.emit("browserView-bounds-completed", bounds);
|
||||
});
|
||||
socket.on('browserView-bounds-set', (id, bounds) => {
|
||||
socket.on("browserView-bounds-set", (id, bounds) => {
|
||||
getBrowserViewById(id).setBounds(bounds);
|
||||
});
|
||||
socket.on('browserView-setAutoResize', (id, options) => {
|
||||
socket.on("browserView-setAutoResize", (id, options) => {
|
||||
getBrowserViewById(id).setAutoResize(options);
|
||||
});
|
||||
socket.on('browserView-setBackgroundColor', (id, color) => {
|
||||
socket.on("browserView-setBackgroundColor", (id, color) => {
|
||||
getBrowserViewById(id).setBackgroundColor(color);
|
||||
});
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
@@ -53,7 +58,7 @@ exports.browserViewMediateService = browserViewMediateService;
|
||||
function getBrowserViewById(id) {
|
||||
for (let index = 0; index < browserViews.length; index++) {
|
||||
const browserViewItem = browserViews[index];
|
||||
if (browserViewItem['id'] === id) {
|
||||
if (browserViewItem["id"] === id) {
|
||||
return browserViewItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"browserView.js","sourceRoot":"","sources":["browserView.ts"],"names":[],"mappings":";;;AACA,uCAAuC;AACvC,MAAM,YAAY,GAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAkB,CAAC;AAC7G,IAAI,WAAwB,EAAE,cAAc,CAAC;AAC7C,MAAM,qBAAqB,GAAgC,CAAC,MAAM,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAgC,CAAC;AAEpK,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE;IACtC,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;QACvC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,EAAE,CAAC;YACjE,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,CAAC;QACjG,CAAC;QAED,WAAW,GAAG,IAAI,sBAAW,CAAC,OAAO,CAAC,CAAC;QACvC,WAAW,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QAE5C,IAAI,OAAO,CAAC,KA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C,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACjC,OAAO,eAAe,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC"}
|
||||
@@ -1,74 +1,83 @@
|
||||
import { Socket } from 'net';
|
||||
import { BrowserView } from 'electron';
|
||||
const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[];
|
||||
let browserView: BrowserView, electronSocket;
|
||||
const proxyToCredentialsMap: { [proxy: string]: string } = (global['proxyToCredentialsMap'] = global['proxyToCredentialsMap'] || []) as { [proxy: string]: string };
|
||||
import type { Socket } from "net";
|
||||
import { BrowserView } from "electron";
|
||||
|
||||
const browserViews: BrowserView[] = (global["browserViews"] =
|
||||
global["browserViews"] || []) as BrowserView[];
|
||||
const proxyToCredentialsMap: { [proxy: string]: string } = (global[
|
||||
"proxyToCredentialsMap"
|
||||
] = global["proxyToCredentialsMap"] || []) as { [proxy: string]: string };
|
||||
|
||||
let browserView: BrowserView;
|
||||
let electronSocket: Socket;
|
||||
|
||||
const browserViewApi = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('createBrowserView', (options) => {
|
||||
if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) {
|
||||
options = { ...options, webPreferences: { nodeIntegration: true, contextIsolation: false } };
|
||||
}
|
||||
|
||||
browserView = new BrowserView(options);
|
||||
browserView['id'] = browserViews.length + 1;
|
||||
|
||||
if (options.proxy) {
|
||||
browserView.webContents.session.setProxy({proxyRules: options.proxy});
|
||||
}
|
||||
|
||||
if (options.proxy && options.proxyCredentials) {
|
||||
proxyToCredentialsMap[options.proxy] = options.proxyCredentials;
|
||||
}
|
||||
|
||||
browserViews.push(browserView);
|
||||
|
||||
electronSocket.emit('BrowserViewCreated', browserView['id']);
|
||||
});
|
||||
|
||||
socket.on('browserView-bounds', (id) => {
|
||||
const bounds = getBrowserViewById(id).getBounds();
|
||||
|
||||
electronSocket.emit('browserView-bounds-completed', bounds);
|
||||
});
|
||||
|
||||
socket.on('browserView-bounds-set', (id, bounds) => {
|
||||
getBrowserViewById(id).setBounds(bounds);
|
||||
});
|
||||
|
||||
socket.on('browserView-setAutoResize', (id, options) => {
|
||||
getBrowserViewById(id).setAutoResize(options);
|
||||
});
|
||||
|
||||
socket.on('browserView-setBackgroundColor', (id, color) => {
|
||||
getBrowserViewById(id).setBackgroundColor(color);
|
||||
});
|
||||
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
|
||||
return true;
|
||||
socket.on("createBrowserView", (options) => {
|
||||
if (!hasOwnChildreen(options, "webPreferences", "nodeIntegration")) {
|
||||
options = {
|
||||
...options,
|
||||
webPreferences: { nodeIntegration: true, contextIsolation: false },
|
||||
};
|
||||
}
|
||||
|
||||
browserView = new BrowserView(options);
|
||||
browserView["id"] = browserViews.length + 1;
|
||||
|
||||
if (options.proxy) {
|
||||
browserView.webContents.session.setProxy({ proxyRules: options.proxy });
|
||||
}
|
||||
|
||||
if (options.proxy && options.proxyCredentials) {
|
||||
proxyToCredentialsMap[options.proxy] = options.proxyCredentials;
|
||||
}
|
||||
|
||||
browserViews.push(browserView);
|
||||
|
||||
electronSocket.emit("BrowserViewCreated", browserView["id"]);
|
||||
});
|
||||
|
||||
socket.on("browserView-bounds", (id) => {
|
||||
const bounds = getBrowserViewById(id).getBounds();
|
||||
|
||||
electronSocket.emit("browserView-bounds-completed", bounds);
|
||||
});
|
||||
|
||||
socket.on("browserView-bounds-set", (id, bounds) => {
|
||||
getBrowserViewById(id).setBounds(bounds);
|
||||
});
|
||||
|
||||
socket.on("browserView-setAutoResize", (id, options) => {
|
||||
getBrowserViewById(id).setAutoResize(options);
|
||||
});
|
||||
|
||||
socket.on("browserView-setBackgroundColor", (id, color) => {
|
||||
getBrowserViewById(id).setBackgroundColor(color);
|
||||
});
|
||||
|
||||
function hasOwnChildreen(obj, ...childNames) {
|
||||
for (let i = 0; i < childNames.length; i++) {
|
||||
if (!obj || !obj.hasOwnProperty(childNames[i])) {
|
||||
return false;
|
||||
}
|
||||
obj = obj[childNames[i]];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const browserViewMediateService = (browserViewId: number): BrowserView => {
|
||||
return getBrowserViewById(browserViewId);
|
||||
return getBrowserViewById(browserViewId);
|
||||
};
|
||||
|
||||
function getBrowserViewById(id: number) {
|
||||
for (let index = 0; index < browserViews.length; index++) {
|
||||
const browserViewItem = browserViews[index];
|
||||
if (browserViewItem['id'] === id) {
|
||||
return browserViewItem;
|
||||
}
|
||||
for (let index = 0; index < browserViews.length; index++) {
|
||||
const browserViewItem = browserViews[index];
|
||||
if (browserViewItem["id"] === id) {
|
||||
return browserViewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { browserViewApi, browserViewMediateService };
|
||||
|
||||
@@ -1,12 +1,46 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
const path = __importStar(require("path"));
|
||||
const electron_1 = require("electron");
|
||||
const browserView_1 = require("./browserView");
|
||||
const path = require("path");
|
||||
const windows = (global["browserWindows"] =
|
||||
global["browserWindows"] || []);
|
||||
let readyToShowWindowsIds = [];
|
||||
let window, lastOptions, electronSocket;
|
||||
let mainWindowURL;
|
||||
let window;
|
||||
let lastOptions;
|
||||
let electronSocket;
|
||||
const proxyToCredentialsMap = (global["proxyToCredentialsMap"] = global["proxyToCredentialsMap"] || []);
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
@@ -112,6 +146,12 @@ module.exports = (socket, app) => {
|
||||
electronSocket.emit("browserWindow-move" + id);
|
||||
});
|
||||
});
|
||||
socket.on("register-browserWindow-bounds-changed", (id) => {
|
||||
const window = getWindowById(id);
|
||||
const cb = () => electronSocket.emit("browserWindow-bounds-changed" + id, window.getBounds());
|
||||
window.on("resize", cb);
|
||||
window.on("move", cb);
|
||||
});
|
||||
socket.on("register-browserWindow-moved", (id) => {
|
||||
getWindowById(id).on("moved", () => {
|
||||
electronSocket.emit("browserWindow-moved" + id);
|
||||
@@ -237,7 +277,15 @@ module.exports = (socket, app) => {
|
||||
}
|
||||
});
|
||||
if (loadUrl) {
|
||||
window.loadURL(loadUrl);
|
||||
// Append authentication token to initial URL if available
|
||||
const token = global["authToken"];
|
||||
if (token) {
|
||||
const separator = loadUrl.includes("?") ? "&" : "?";
|
||||
window.loadURL(`${loadUrl}${separator}token=${token}`);
|
||||
}
|
||||
else {
|
||||
window.loadURL(loadUrl);
|
||||
}
|
||||
}
|
||||
if (app.commandLine.hasSwitch("clear-cache") &&
|
||||
app.commandLine.getSwitchValue("clear-cache")) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,18 @@
|
||||
import { Socket } from "net";
|
||||
import { BrowserWindow, Menu, nativeImage } from "electron";
|
||||
import * as path from "path";
|
||||
import type { Socket } from "net";
|
||||
import { BrowserWindow, Menu } from "electron";
|
||||
|
||||
import { browserViewMediateService } from "./browserView";
|
||||
const path = require("path");
|
||||
|
||||
const windows: Electron.BrowserWindow[] = (global["browserWindows"] =
|
||||
global["browserWindows"] || []) as Electron.BrowserWindow[];
|
||||
|
||||
let readyToShowWindowsIds: number[] = [];
|
||||
let window, lastOptions, electronSocket;
|
||||
let mainWindowURL;
|
||||
|
||||
let window;
|
||||
let lastOptions;
|
||||
let electronSocket;
|
||||
|
||||
const proxyToCredentialsMap: { [proxy: string]: string } = (global[
|
||||
"proxyToCredentialsMap"
|
||||
] = global["proxyToCredentialsMap"] || []) as { [proxy: string]: string };
|
||||
@@ -32,7 +38,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
socket.on("register-browserWindow-ready-to-show", (id) => {
|
||||
if (readyToShowWindowsIds.includes(id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(
|
||||
(value) => value !== id
|
||||
(value) => value !== id,
|
||||
);
|
||||
electronSocket.emit("browserWindow-ready-to-show" + id);
|
||||
}
|
||||
@@ -139,6 +145,17 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("register-browserWindow-bounds-changed", (id) => {
|
||||
const window = getWindowById(id);
|
||||
const cb = () =>
|
||||
electronSocket.emit(
|
||||
"browserWindow-bounds-changed" + id,
|
||||
window.getBounds(),
|
||||
);
|
||||
window.on("resize", cb);
|
||||
window.on("move", cb);
|
||||
});
|
||||
|
||||
socket.on("register-browserWindow-moved", (id) => {
|
||||
getWindowById(id).on("moved", () => {
|
||||
electronSocket.emit("browserWindow-moved" + id);
|
||||
@@ -224,7 +241,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
__dirname,
|
||||
"..",
|
||||
"scripts",
|
||||
"blazor-preload.js"
|
||||
"blazor-preload.js",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -257,7 +274,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
window.on("ready-to-show", () => {
|
||||
if (readyToShowWindowsIds.includes(window.id)) {
|
||||
readyToShowWindowsIds = readyToShowWindowsIds.filter(
|
||||
(value) => value !== window.id
|
||||
(value) => value !== window.id,
|
||||
);
|
||||
} else {
|
||||
readyToShowWindowsIds.push(window.id);
|
||||
@@ -292,7 +309,15 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
});
|
||||
|
||||
if (loadUrl) {
|
||||
window.loadURL(loadUrl);
|
||||
// Append authentication token to initial URL if available
|
||||
const token = global["authToken"];
|
||||
|
||||
if (token) {
|
||||
const separator = loadUrl.includes("?") ? "&" : "?";
|
||||
window.loadURL(`${loadUrl}${separator}token=${token}`);
|
||||
} else {
|
||||
window.loadURL(loadUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -524,7 +549,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
electronSocket.emit(
|
||||
"browserWindow-isFullScreenable-completed",
|
||||
fullscreenable
|
||||
fullscreenable,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -609,7 +634,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
.toString(16);
|
||||
electronSocket.emit(
|
||||
"browserWindow-getNativeWindowHandle-completed",
|
||||
nativeWindowHandle
|
||||
nativeWindowHandle,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -622,7 +647,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
"setRepresentedFilename failed (likely unsupported platform):",
|
||||
e
|
||||
e,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -637,12 +662,12 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
"getRepresentedFilename failed (likely unsupported platform):",
|
||||
e
|
||||
e,
|
||||
);
|
||||
}
|
||||
electronSocket.emit(
|
||||
"browserWindow-getRepresentedFilename-completed",
|
||||
pathname
|
||||
pathname,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -734,7 +759,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
imagePath = path.join(
|
||||
__dirname.replace("api", ""),
|
||||
"bin",
|
||||
originalIconPath
|
||||
originalIconPath,
|
||||
);
|
||||
}
|
||||
const { nativeImage } = require("electron");
|
||||
@@ -751,7 +776,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
const success = getWindowById(id).setThumbarButtons(thumbarButtons);
|
||||
electronSocket.emit("browserWindowSetThumbarButtons-completed", success);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
socket.on("browserWindowSetThumbnailClip", (id, rectangle) => {
|
||||
@@ -779,7 +804,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
electronSocket.emit(
|
||||
"browserWindow-isMenuBarAutoHide-completed",
|
||||
isMenuBarAutoHide
|
||||
isMenuBarAutoHide,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -792,7 +817,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
electronSocket.emit(
|
||||
"browserWindow-isMenuBarVisible-completed",
|
||||
isMenuBarVisible
|
||||
isMenuBarVisible,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -806,7 +831,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
electronSocket.emit(
|
||||
"browserWindow-isVisibleOnAllWorkspaces-completed",
|
||||
isVisibleOnAllWorkspaces
|
||||
isVisibleOnAllWorkspaces,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -838,7 +863,7 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
electronSocket.emit(
|
||||
"browserWindow-getParentWindow-completed",
|
||||
browserWindow.id
|
||||
browserWindow.id,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,63 +3,65 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('clipboard-readText', (type) => {
|
||||
socket.on("clipboard-readText", (type) => {
|
||||
const text = electron_1.clipboard.readText(type);
|
||||
electronSocket.emit('clipboard-readText-completed', text);
|
||||
electronSocket.emit("clipboard-readText-completed", text);
|
||||
});
|
||||
socket.on('clipboard-writeText', (text, type) => {
|
||||
socket.on("clipboard-writeText", (text, type) => {
|
||||
electron_1.clipboard.writeText(text, type);
|
||||
});
|
||||
socket.on('clipboard-readHTML', (type) => {
|
||||
socket.on("clipboard-readHTML", (type) => {
|
||||
const content = electron_1.clipboard.readHTML(type);
|
||||
electronSocket.emit('clipboard-readHTML-completed', content);
|
||||
electronSocket.emit("clipboard-readHTML-completed", content);
|
||||
});
|
||||
socket.on('clipboard-writeHTML', (markup, type) => {
|
||||
socket.on("clipboard-writeHTML", (markup, type) => {
|
||||
electron_1.clipboard.writeHTML(markup, type);
|
||||
});
|
||||
socket.on('clipboard-readRTF', (type) => {
|
||||
socket.on("clipboard-readRTF", (type) => {
|
||||
const content = electron_1.clipboard.readRTF(type);
|
||||
electronSocket.emit('clipboard-readRTF-completed', content);
|
||||
electronSocket.emit("clipboard-readRTF-completed", content);
|
||||
});
|
||||
socket.on('clipboard-writeRTF', (text, type) => {
|
||||
socket.on("clipboard-writeRTF", (text, type) => {
|
||||
electron_1.clipboard.writeHTML(text, type);
|
||||
});
|
||||
socket.on('clipboard-readBookmark', () => {
|
||||
socket.on("clipboard-readBookmark", () => {
|
||||
const bookmark = electron_1.clipboard.readBookmark();
|
||||
electronSocket.emit('clipboard-readBookmark-completed', bookmark);
|
||||
electronSocket.emit("clipboard-readBookmark-completed", bookmark);
|
||||
});
|
||||
socket.on('clipboard-writeBookmark', (title, url, type) => {
|
||||
socket.on("clipboard-writeBookmark", (title, url, type) => {
|
||||
electron_1.clipboard.writeBookmark(title, url, type);
|
||||
});
|
||||
socket.on('clipboard-readFindText', () => {
|
||||
socket.on("clipboard-readFindText", () => {
|
||||
const content = electron_1.clipboard.readFindText();
|
||||
electronSocket.emit('clipboard-readFindText-completed', content);
|
||||
electronSocket.emit("clipboard-readFindText-completed", content);
|
||||
});
|
||||
socket.on('clipboard-writeFindText', (text) => {
|
||||
socket.on("clipboard-writeFindText", (text) => {
|
||||
electron_1.clipboard.writeFindText(text);
|
||||
});
|
||||
socket.on('clipboard-clear', (type) => {
|
||||
socket.on("clipboard-clear", (type) => {
|
||||
electron_1.clipboard.clear(type);
|
||||
});
|
||||
socket.on('clipboard-availableFormats', (type) => {
|
||||
socket.on("clipboard-availableFormats", (type) => {
|
||||
const formats = electron_1.clipboard.availableFormats(type);
|
||||
electronSocket.emit('clipboard-availableFormats-completed', formats);
|
||||
electronSocket.emit("clipboard-availableFormats-completed", formats);
|
||||
});
|
||||
socket.on('clipboard-write', (data, type) => {
|
||||
socket.on("clipboard-write", (data, type) => {
|
||||
electron_1.clipboard.write(data, type);
|
||||
});
|
||||
socket.on('clipboard-readImage', (type) => {
|
||||
socket.on("clipboard-readImage", (type) => {
|
||||
const image = electron_1.clipboard.readImage(type);
|
||||
electronSocket.emit('clipboard-readImage-completed', { 1: image.toPNG().toString('base64') });
|
||||
electronSocket.emit("clipboard-readImage-completed", {
|
||||
1: image.toPNG().toString("base64"),
|
||||
});
|
||||
});
|
||||
socket.on('clipboard-writeImage', (data, type) => {
|
||||
socket.on("clipboard-writeImage", (data, type) => {
|
||||
const dataContent = JSON.parse(data);
|
||||
const image = electron_1.nativeImage.createEmpty();
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in dataContent) {
|
||||
const scaleFactor = key;
|
||||
const bytes = data[key];
|
||||
const buffer = Buffer.from(bytes, 'base64');
|
||||
const buffer = Buffer.from(bytes, "base64");
|
||||
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
|
||||
}
|
||||
electron_1.clipboard.writeImage(image, type);
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["clipboard.ts"],"names":[],"mappings":";AACA,uCAAkD;AAClD,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,oBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,cAAc,CAAC,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC5C,oBAAS,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,oBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzC,cAAc,CAAC,IAAI,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QAC9C,oBAAS,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,IAAI,EAAE,EAAE;QACpC,MAAM,OAAO,GAAG,oBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxC,cAAc,C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AM,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC1C,oBAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,oBAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACxC,cAAc,CAAC,IAAI,CAAC,+BAA+B,EAAE;YACnD,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;SACpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,sBAAW,CAAC,WAAW,EAAE,CAAC;QAExC,kCAAkC;QAClC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,WAAW,GAAG,GAAG,CAAC;YACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;YACxB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC5C,KAAK,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACzE,CAAC;QAED,oBAAS,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,84 +1,87 @@
|
||||
import { Socket } from 'net';
|
||||
import { clipboard, nativeImage } from 'electron';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { clipboard, nativeImage } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('clipboard-readText', (type) => {
|
||||
const text = clipboard.readText(type);
|
||||
electronSocket.emit('clipboard-readText-completed', text);
|
||||
electronSocket = socket;
|
||||
socket.on("clipboard-readText", (type) => {
|
||||
const text = clipboard.readText(type);
|
||||
electronSocket.emit("clipboard-readText-completed", text);
|
||||
});
|
||||
|
||||
socket.on("clipboard-writeText", (text, type) => {
|
||||
clipboard.writeText(text, type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-readHTML", (type) => {
|
||||
const content = clipboard.readHTML(type);
|
||||
electronSocket.emit("clipboard-readHTML-completed", content);
|
||||
});
|
||||
|
||||
socket.on("clipboard-writeHTML", (markup, type) => {
|
||||
clipboard.writeHTML(markup, type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-readRTF", (type) => {
|
||||
const content = clipboard.readRTF(type);
|
||||
electronSocket.emit("clipboard-readRTF-completed", content);
|
||||
});
|
||||
|
||||
socket.on("clipboard-writeRTF", (text, type) => {
|
||||
clipboard.writeHTML(text, type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-readBookmark", () => {
|
||||
const bookmark = clipboard.readBookmark();
|
||||
electronSocket.emit("clipboard-readBookmark-completed", bookmark);
|
||||
});
|
||||
|
||||
socket.on("clipboard-writeBookmark", (title, url, type) => {
|
||||
clipboard.writeBookmark(title, url, type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-readFindText", () => {
|
||||
const content = clipboard.readFindText();
|
||||
electronSocket.emit("clipboard-readFindText-completed", content);
|
||||
});
|
||||
|
||||
socket.on("clipboard-writeFindText", (text) => {
|
||||
clipboard.writeFindText(text);
|
||||
});
|
||||
|
||||
socket.on("clipboard-clear", (type) => {
|
||||
clipboard.clear(type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-availableFormats", (type) => {
|
||||
const formats = clipboard.availableFormats(type);
|
||||
electronSocket.emit("clipboard-availableFormats-completed", formats);
|
||||
});
|
||||
|
||||
socket.on("clipboard-write", (data, type) => {
|
||||
clipboard.write(data, type);
|
||||
});
|
||||
|
||||
socket.on("clipboard-readImage", (type) => {
|
||||
const image = clipboard.readImage(type);
|
||||
electronSocket.emit("clipboard-readImage-completed", {
|
||||
1: image.toPNG().toString("base64"),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeText', (text, type) => {
|
||||
clipboard.writeText(text, type);
|
||||
});
|
||||
socket.on("clipboard-writeImage", (data, type) => {
|
||||
const dataContent = JSON.parse(data);
|
||||
const image = nativeImage.createEmpty();
|
||||
|
||||
socket.on('clipboard-readHTML', (type) => {
|
||||
const content = clipboard.readHTML(type);
|
||||
electronSocket.emit('clipboard-readHTML-completed', content);
|
||||
});
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in dataContent) {
|
||||
const scaleFactor = key;
|
||||
const bytes = data[key];
|
||||
const buffer = Buffer.from(bytes, "base64");
|
||||
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
|
||||
}
|
||||
|
||||
socket.on('clipboard-writeHTML', (markup, type) => {
|
||||
clipboard.writeHTML(markup, type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-readRTF', (type) => {
|
||||
const content = clipboard.readRTF(type);
|
||||
electronSocket.emit('clipboard-readRTF-completed', content);
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeRTF', (text, type) => {
|
||||
clipboard.writeHTML(text, type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-readBookmark', () => {
|
||||
const bookmark = clipboard.readBookmark();
|
||||
electronSocket.emit('clipboard-readBookmark-completed', bookmark);
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeBookmark', (title, url, type) => {
|
||||
clipboard.writeBookmark(title, url, type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-readFindText', () => {
|
||||
const content = clipboard.readFindText();
|
||||
electronSocket.emit('clipboard-readFindText-completed', content);
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeFindText', (text) => {
|
||||
clipboard.writeFindText(text);
|
||||
});
|
||||
|
||||
socket.on('clipboard-clear', (type) => {
|
||||
clipboard.clear(type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-availableFormats', (type) => {
|
||||
const formats = clipboard.availableFormats(type);
|
||||
electronSocket.emit('clipboard-availableFormats-completed', formats);
|
||||
});
|
||||
|
||||
socket.on('clipboard-write', (data, type) => {
|
||||
clipboard.write(data, type);
|
||||
});
|
||||
|
||||
socket.on('clipboard-readImage', (type) => {
|
||||
const image = clipboard.readImage(type);
|
||||
electronSocket.emit('clipboard-readImage-completed', { 1: image.toPNG().toString('base64') });
|
||||
});
|
||||
|
||||
socket.on('clipboard-writeImage', (data, type) => {
|
||||
const dataContent = JSON.parse(data);
|
||||
const image = nativeImage.createEmpty();
|
||||
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in dataContent) {
|
||||
const scaleFactor = key;
|
||||
const bytes = data[key];
|
||||
const buffer = Buffer.from(bytes, 'base64');
|
||||
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
|
||||
}
|
||||
|
||||
clipboard.writeImage(image, type);
|
||||
});
|
||||
clipboard.writeImage(image, type);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
let electronSocket;
|
||||
module.exports = (socket, app) => {
|
||||
electronSocket = socket;
|
||||
socket.on('appCommandLineAppendSwitch', (the_switch, value) => {
|
||||
socket.on("appCommandLineAppendSwitch", (the_switch, value) => {
|
||||
app.commandLine.appendSwitch(the_switch, value);
|
||||
});
|
||||
socket.on('appCommandLineAppendArgument', (value) => {
|
||||
socket.on("appCommandLineAppendArgument", (value) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
socket.on('appCommandLineHasSwitch', (value) => {
|
||||
socket.on("appCommandLineHasSwitch", (value) => {
|
||||
const hasSwitch = app.commandLine.hasSwitch(value);
|
||||
electronSocket.emit('appCommandLineHasSwitchCompleted', hasSwitch);
|
||||
electronSocket.emit("appCommandLineHasSwitchCompleted", hasSwitch);
|
||||
});
|
||||
socket.on('appCommandLineGetSwitchValue', (the_switch) => {
|
||||
socket.on("appCommandLineGetSwitchValue", (the_switch) => {
|
||||
const value = app.commandLine.getSwitchValue(the_switch);
|
||||
electronSocket.emit('appCommandLineGetSwitchValueCompleted', value);
|
||||
electronSocket.emit("appCommandLineGetSwitchValueCompleted", value);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=commandLine.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"commandLine.js","sourceRoot":"","sources":["commandLine.ts"],"names":[],"mappings":";AACA,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,GAAiB,EAAE,EAAE;IAC3C,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,CAAC,UAAkB,EAAE,KAAa,EAAE,EAAE;QAC1E,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,KAAa,EAAE,EAAE;QACxD,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,CAAC,KAAa,EAAE,EAAE;QACnD,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnD,cAAc,CAAC,IAAI,CAAC,kCAAkC,EAAE,SAAS,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,UAAkB,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzD,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
{"version":3,"file":"commandLine.js","sourceRoot":"","sources":["commandLine.ts"],"names":[],"mappings":";AAEA,IAAI,cAAsB,CAAC;AAE3B,iBAAS,CAAC,MAAc,EAAE,GAAiB,EAAE,EAAE;IAC7C,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CACP,4BAA4B,EAC5B,CAAC,UAAkB,EAAE,KAAa,EAAE,EAAE;QACpC,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,KAAa,EAAE,EAAE;QAC1D,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,CAAC,KAAa,EAAE,EAAE;QACrD,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnD,cAAc,CAAC,IAAI,CAAC,kCAAkC,EAAE,SAAS,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,UAAkB,EAAE,EAAE;QAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzD,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,24 +1,28 @@
|
||||
import { Socket } from 'net';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket, app: Electron.App) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('appCommandLineAppendSwitch', (the_switch: string, value: string) => {
|
||||
app.commandLine.appendSwitch(the_switch, value);
|
||||
});
|
||||
socket.on(
|
||||
"appCommandLineAppendSwitch",
|
||||
(the_switch: string, value: string) => {
|
||||
app.commandLine.appendSwitch(the_switch, value);
|
||||
},
|
||||
);
|
||||
|
||||
socket.on('appCommandLineAppendArgument', (value: string) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
socket.on("appCommandLineAppendArgument", (value: string) => {
|
||||
app.commandLine.appendArgument(value);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineHasSwitch', (value: string) => {
|
||||
const hasSwitch = app.commandLine.hasSwitch(value);
|
||||
electronSocket.emit('appCommandLineHasSwitchCompleted', hasSwitch);
|
||||
});
|
||||
socket.on("appCommandLineHasSwitch", (value: string) => {
|
||||
const hasSwitch = app.commandLine.hasSwitch(value);
|
||||
electronSocket.emit("appCommandLineHasSwitchCompleted", hasSwitch);
|
||||
});
|
||||
|
||||
socket.on('appCommandLineGetSwitchValue', (the_switch: string) => {
|
||||
const value = app.commandLine.getSwitchValue(the_switch);
|
||||
electronSocket.emit('appCommandLineGetSwitchValueCompleted', value);
|
||||
});
|
||||
socket.on("appCommandLineGetSwitchValue", (the_switch: string) => {
|
||||
const value = app.commandLine.getSwitchValue(the_switch);
|
||||
electronSocket.emit("appCommandLineGetSwitchValueCompleted", value);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,35 +3,41 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('showMessageBox', async (browserWindow, options, guid) => {
|
||||
if ('id' in browserWindow) {
|
||||
socket.on("showMessageBox", async (browserWindow, options, guid) => {
|
||||
if ("id" in browserWindow) {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
const messageBoxReturnValue = await electron_1.dialog.showMessageBox(window, options);
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
electronSocket.emit("showMessageBoxComplete" + guid, [
|
||||
messageBoxReturnValue.response,
|
||||
messageBoxReturnValue.checkboxChecked,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
const id = guid || options;
|
||||
const messageBoxReturnValue = await electron_1.dialog.showMessageBox(browserWindow);
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
electronSocket.emit("showMessageBoxComplete" + id, [
|
||||
messageBoxReturnValue.response,
|
||||
messageBoxReturnValue.checkboxChecked,
|
||||
]);
|
||||
}
|
||||
});
|
||||
socket.on('showOpenDialog', async (browserWindow, options, guid) => {
|
||||
socket.on("showOpenDialog", async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
const openDialogReturnValue = await electron_1.dialog.showOpenDialog(window, options);
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, openDialogReturnValue.filePaths || []);
|
||||
electronSocket.emit("showOpenDialogComplete" + guid, openDialogReturnValue.filePaths || []);
|
||||
});
|
||||
socket.on('showSaveDialog', async (browserWindow, options, guid) => {
|
||||
socket.on("showSaveDialog", async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
const saveDialogReturnValue = await electron_1.dialog.showSaveDialog(window, options);
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, saveDialogReturnValue.filePath || '');
|
||||
electronSocket.emit("showSaveDialogComplete" + guid, saveDialogReturnValue.filePath || "");
|
||||
});
|
||||
socket.on('showErrorBox', (title, content) => {
|
||||
socket.on("showErrorBox", (title, content) => {
|
||||
electron_1.dialog.showErrorBox(title, content);
|
||||
});
|
||||
socket.on('showCertificateTrustDialog', async (browserWindow, options, guid) => {
|
||||
socket.on("showCertificateTrustDialog", async (browserWindow, options, guid) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
await electron_1.dialog.showCertificateTrustDialog(window, options);
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
electronSocket.emit("showCertificateTrustDialogComplete" + guid);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=dialog.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["dialog.ts"],"names":[],"mappings":";AACA,uCAAiD;AACjD,IAAI,cAAsB,CAAC;AAE3B,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC/D,IAAI,IAAI,IAAI,aAAa,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;YAEtD,MAAM,qBAAqB,GAAG,MAAM,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC3E,cAAc,CAAC,IAAI,CAAC,wBAAwB,GAAG,IAAI,EAAE,CAAC,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC,CAAC;QAClI,CAAC;aAAM,CAAC;YACJ,MAAM,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC;YAC3B,MAAM,qBAAqB,GAAG,MAAM,iBAAM,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAEzE,cAAc,CAAC,IAAI,CAAC,wBAAwB,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC,CAAC;QAChI,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,O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BAAwB,GAAG,IAAI,EAC/B,qBAAqB,CAAC,SAAS,IAAI,EAAE,CACtC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACjE,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QACtD,MAAM,qBAAqB,GAAG,MAAM,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE3E,cAAc,CAAC,IAAI,CACjB,wBAAwB,GAAG,IAAI,EAC/B,qBAAqB,CAAC,QAAQ,IAAI,EAAE,CACrC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC3C,iBAAM,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CACP,4BAA4B,EAC5B,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QACtD,MAAM,iBAAM,CAAC,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEzD,cAAc,CAAC,IAAI,CAAC,oCAAoC,GAAG,IAAI,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
|
||||
@@ -1,45 +1,64 @@
|
||||
import { Socket } from 'net';
|
||||
import { BrowserWindow, dialog } from 'electron';
|
||||
import type { Socket } from "net";
|
||||
import { BrowserWindow, dialog } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('showMessageBox', async (browserWindow, options, guid) => {
|
||||
if ('id' in browserWindow) {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
electronSocket = socket;
|
||||
socket.on("showMessageBox", async (browserWindow, options, guid) => {
|
||||
if ("id" in browserWindow) {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(window, options);
|
||||
electronSocket.emit('showMessageBoxComplete' + guid, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
} else {
|
||||
const id = guid || options;
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(browserWindow);
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(
|
||||
window,
|
||||
options,
|
||||
);
|
||||
electronSocket.emit("showMessageBoxComplete" + guid, [
|
||||
messageBoxReturnValue.response,
|
||||
messageBoxReturnValue.checkboxChecked,
|
||||
]);
|
||||
} else {
|
||||
const id = guid || options;
|
||||
const messageBoxReturnValue = await dialog.showMessageBox(browserWindow);
|
||||
|
||||
electronSocket.emit('showMessageBoxComplete' + id, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]);
|
||||
}
|
||||
});
|
||||
electronSocket.emit("showMessageBoxComplete" + id, [
|
||||
messageBoxReturnValue.response,
|
||||
messageBoxReturnValue.checkboxChecked,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('showOpenDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
const openDialogReturnValue = await dialog.showOpenDialog(window, options);
|
||||
socket.on("showOpenDialog", async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
const openDialogReturnValue = await dialog.showOpenDialog(window, options);
|
||||
|
||||
electronSocket.emit('showOpenDialogComplete' + guid, openDialogReturnValue.filePaths || []);
|
||||
});
|
||||
electronSocket.emit(
|
||||
"showOpenDialogComplete" + guid,
|
||||
openDialogReturnValue.filePaths || [],
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('showSaveDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
const saveDialogReturnValue = await dialog.showSaveDialog(window, options);
|
||||
socket.on("showSaveDialog", async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
const saveDialogReturnValue = await dialog.showSaveDialog(window, options);
|
||||
|
||||
electronSocket.emit('showSaveDialogComplete' + guid, saveDialogReturnValue.filePath || '');
|
||||
});
|
||||
electronSocket.emit(
|
||||
"showSaveDialogComplete" + guid,
|
||||
saveDialogReturnValue.filePath || "",
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('showErrorBox', (title, content) => {
|
||||
dialog.showErrorBox(title, content);
|
||||
});
|
||||
socket.on("showErrorBox", (title, content) => {
|
||||
dialog.showErrorBox(title, content);
|
||||
});
|
||||
|
||||
socket.on('showCertificateTrustDialog', async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
await dialog.showCertificateTrustDialog(window, options);
|
||||
socket.on(
|
||||
"showCertificateTrustDialog",
|
||||
async (browserWindow, options, guid) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
await dialog.showCertificateTrustDialog(window, options);
|
||||
|
||||
electronSocket.emit('showCertificateTrustDialogComplete' + guid);
|
||||
});
|
||||
electronSocket.emit("showCertificateTrustDialogComplete" + guid);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,49 +3,49 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('dock-bounce', (type) => {
|
||||
socket.on("dock-bounce", (type) => {
|
||||
const id = electron_1.app.dock.bounce(type);
|
||||
electronSocket.emit('dock-bounce-completed', id);
|
||||
electronSocket.emit("dock-bounce-completed", id);
|
||||
});
|
||||
socket.on('dock-cancelBounce', (id) => {
|
||||
socket.on("dock-cancelBounce", (id) => {
|
||||
electron_1.app.dock.cancelBounce(id);
|
||||
});
|
||||
socket.on('dock-downloadFinished', (filePath) => {
|
||||
socket.on("dock-downloadFinished", (filePath) => {
|
||||
electron_1.app.dock.downloadFinished(filePath);
|
||||
});
|
||||
socket.on('dock-setBadge', (text) => {
|
||||
socket.on("dock-setBadge", (text) => {
|
||||
electron_1.app.dock.setBadge(text);
|
||||
});
|
||||
socket.on('dock-getBadge', () => {
|
||||
socket.on("dock-getBadge", () => {
|
||||
const text = electron_1.app.dock.getBadge();
|
||||
electronSocket.emit('dock-getBadge-completed', text);
|
||||
electronSocket.emit("dock-getBadge-completed", text);
|
||||
});
|
||||
socket.on('dock-hide', () => {
|
||||
socket.on("dock-hide", () => {
|
||||
electron_1.app.dock.hide();
|
||||
});
|
||||
socket.on('dock-show', () => {
|
||||
socket.on("dock-show", () => {
|
||||
electron_1.app.dock.show();
|
||||
});
|
||||
socket.on('dock-isVisible', () => {
|
||||
socket.on("dock-isVisible", () => {
|
||||
const isVisible = electron_1.app.dock.isVisible();
|
||||
electronSocket.emit('dock-isVisible-completed', isVisible);
|
||||
electronSocket.emit("dock-isVisible-completed", isVisible);
|
||||
});
|
||||
socket.on('dock-setMenu', (menuItems) => {
|
||||
socket.on("dock-setMenu", (menuItems) => {
|
||||
let menu = null;
|
||||
if (menuItems) {
|
||||
menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('dockMenuItemClicked', id);
|
||||
electronSocket.emit("dockMenuItemClicked", id);
|
||||
});
|
||||
}
|
||||
electron_1.app.dock.setMenu(menu);
|
||||
});
|
||||
// TODO: Menu (macOS) still to be implemented
|
||||
socket.on('dock-getMenu', () => {
|
||||
socket.on("dock-getMenu", () => {
|
||||
const menu = electron_1.app.dock.getMenu();
|
||||
electronSocket.emit('dock-getMenu-completed', menu);
|
||||
electronSocket.emit("dock-getMenu-completed", menu);
|
||||
});
|
||||
socket.on('dock-setIcon', (image) => {
|
||||
socket.on("dock-setIcon", (image) => {
|
||||
electron_1.app.dock.setIcon(image);
|
||||
});
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
@@ -53,8 +53,10 @@ module.exports = (socket) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"dock.js","sourceRoot":"","sources":["dock.ts"],"names":[],"mappings":";AACA,uCAAqC;AACrC,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,EAAE,GAAG,cAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,cAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,EAAE,EAAE,EAAE;QAClC,cAAG,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC5C,cAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;QAChC,cAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC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CAAC,CAAC"}
|
||||
@@ -1,78 +1,81 @@
|
||||
import { Socket } from 'net';
|
||||
import { app, Menu } from 'electron';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { app, Menu } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('dock-bounce', (type) => {
|
||||
const id = app.dock.bounce(type);
|
||||
electronSocket.emit('dock-bounce-completed', id);
|
||||
});
|
||||
socket.on("dock-bounce", (type) => {
|
||||
const id = app.dock.bounce(type);
|
||||
electronSocket.emit("dock-bounce-completed", id);
|
||||
});
|
||||
|
||||
socket.on('dock-cancelBounce', (id) => {
|
||||
app.dock.cancelBounce(id);
|
||||
});
|
||||
socket.on("dock-cancelBounce", (id) => {
|
||||
app.dock.cancelBounce(id);
|
||||
});
|
||||
|
||||
socket.on('dock-downloadFinished', (filePath) => {
|
||||
app.dock.downloadFinished(filePath);
|
||||
});
|
||||
socket.on("dock-downloadFinished", (filePath) => {
|
||||
app.dock.downloadFinished(filePath);
|
||||
});
|
||||
|
||||
socket.on('dock-setBadge', (text) => {
|
||||
app.dock.setBadge(text);
|
||||
});
|
||||
socket.on("dock-setBadge", (text) => {
|
||||
app.dock.setBadge(text);
|
||||
});
|
||||
|
||||
socket.on('dock-getBadge', () => {
|
||||
const text = app.dock.getBadge();
|
||||
electronSocket.emit('dock-getBadge-completed', text);
|
||||
});
|
||||
socket.on("dock-getBadge", () => {
|
||||
const text = app.dock.getBadge();
|
||||
electronSocket.emit("dock-getBadge-completed", text);
|
||||
});
|
||||
|
||||
socket.on('dock-hide', () => {
|
||||
app.dock.hide();
|
||||
});
|
||||
socket.on("dock-hide", () => {
|
||||
app.dock.hide();
|
||||
});
|
||||
|
||||
socket.on('dock-show', () => {
|
||||
app.dock.show();
|
||||
});
|
||||
socket.on("dock-show", () => {
|
||||
app.dock.show();
|
||||
});
|
||||
|
||||
socket.on('dock-isVisible', () => {
|
||||
const isVisible = app.dock.isVisible();
|
||||
electronSocket.emit('dock-isVisible-completed', isVisible);
|
||||
});
|
||||
socket.on("dock-isVisible", () => {
|
||||
const isVisible = app.dock.isVisible();
|
||||
electronSocket.emit("dock-isVisible-completed", isVisible);
|
||||
});
|
||||
|
||||
socket.on('dock-setMenu', (menuItems) => {
|
||||
let menu = null;
|
||||
socket.on("dock-setMenu", (menuItems) => {
|
||||
let menu = null;
|
||||
|
||||
if (menuItems) {
|
||||
menu = Menu.buildFromTemplate(menuItems);
|
||||
if (menuItems) {
|
||||
menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('dockMenuItemClicked', id);
|
||||
});
|
||||
}
|
||||
|
||||
app.dock.setMenu(menu);
|
||||
});
|
||||
|
||||
// TODO: Menu (macOS) still to be implemented
|
||||
socket.on('dock-getMenu', () => {
|
||||
const menu = app.dock.getMenu();
|
||||
electronSocket.emit('dock-getMenu-completed', menu);
|
||||
});
|
||||
|
||||
socket.on('dock-setIcon', (image) => {
|
||||
app.dock.setIcon(image);
|
||||
});
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
}
|
||||
});
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit("dockMenuItemClicked", id);
|
||||
});
|
||||
}
|
||||
|
||||
app.dock.setMenu(menu);
|
||||
});
|
||||
|
||||
// TODO: Menu (macOS) still to be implemented
|
||||
socket.on("dock-getMenu", () => {
|
||||
const menu = app.dock.getMenu();
|
||||
electronSocket.emit("dock-getMenu-completed", menu);
|
||||
});
|
||||
|
||||
socket.on("dock-setIcon", (image) => {
|
||||
app.dock.setIcon(image);
|
||||
});
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,19 +3,19 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('globalShortcut-register', (accelerator) => {
|
||||
socket.on("globalShortcut-register", (accelerator) => {
|
||||
electron_1.globalShortcut.register(accelerator, () => {
|
||||
electronSocket.emit('globalShortcut-pressed', accelerator);
|
||||
electronSocket.emit("globalShortcut-pressed", accelerator);
|
||||
});
|
||||
});
|
||||
socket.on('globalShortcut-isRegistered', (accelerator) => {
|
||||
socket.on("globalShortcut-isRegistered", (accelerator) => {
|
||||
const isRegistered = electron_1.globalShortcut.isRegistered(accelerator);
|
||||
electronSocket.emit('globalShortcut-isRegisteredCompleted', isRegistered);
|
||||
electronSocket.emit("globalShortcut-isRegisteredCompleted", isRegistered);
|
||||
});
|
||||
socket.on('globalShortcut-unregister', (accelerator) => {
|
||||
socket.on("globalShortcut-unregister", (accelerator) => {
|
||||
electron_1.globalShortcut.unregister(accelerator);
|
||||
});
|
||||
socket.on('globalShortcut-unregisterAll', () => {
|
||||
socket.on("globalShortcut-unregisterAll", () => {
|
||||
try {
|
||||
electron_1.globalShortcut.unregisterAll();
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"globalShortcut.js","sourceRoot":"","sources":["globalShortcut.ts"],"names":[],"mappings":";AAAA,uCAA0C;AAE1C,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAA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6BAA6B,EAAE,CAAC,WAAW,EAAE,EAAE;QACvD,MAAM,YAAY,GAAG,yBAAc,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAE9D,cAAc,CAAC,IAAI,CAAC,sCAAsC,EAAE,YAAY,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,2BAA2B,EAAE,CAAC,WAAW,EAAE,EAAE;QACrD,yBAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QAC7C,IAAI,CAAC;YACH,yBAAc,CAAC,aAAa,EAAE,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC,CAAA,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,28 +1,29 @@
|
||||
import { globalShortcut } from 'electron';
|
||||
import { Socket } from 'net';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { globalShortcut } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('globalShortcut-register', (accelerator) => {
|
||||
globalShortcut.register(accelerator, () => {
|
||||
electronSocket.emit('globalShortcut-pressed', accelerator);
|
||||
});
|
||||
electronSocket = socket;
|
||||
socket.on("globalShortcut-register", (accelerator) => {
|
||||
globalShortcut.register(accelerator, () => {
|
||||
electronSocket.emit("globalShortcut-pressed", accelerator);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('globalShortcut-isRegistered', (accelerator) => {
|
||||
const isRegistered = globalShortcut.isRegistered(accelerator);
|
||||
socket.on("globalShortcut-isRegistered", (accelerator) => {
|
||||
const isRegistered = globalShortcut.isRegistered(accelerator);
|
||||
|
||||
electronSocket.emit('globalShortcut-isRegisteredCompleted', isRegistered);
|
||||
});
|
||||
electronSocket.emit("globalShortcut-isRegisteredCompleted", isRegistered);
|
||||
});
|
||||
|
||||
socket.on('globalShortcut-unregister', (accelerator) => {
|
||||
globalShortcut.unregister(accelerator);
|
||||
});
|
||||
socket.on("globalShortcut-unregister", (accelerator) => {
|
||||
globalShortcut.unregister(accelerator);
|
||||
});
|
||||
|
||||
socket.on('globalShortcut-unregisterAll', () => {
|
||||
try {
|
||||
globalShortcut.unregisterAll();
|
||||
} catch (error) { }
|
||||
});
|
||||
socket.on("globalShortcut-unregisterAll", () => {
|
||||
try {
|
||||
globalShortcut.unregisterAll();
|
||||
} catch (error) {}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,40 +3,41 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('registerIpcMainChannel', (channel) => {
|
||||
socket.on("registerIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.on(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
socket.on('registerSyncIpcMainChannel', (channel) => {
|
||||
socket.on("registerSyncIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.on(channel, (event, args) => {
|
||||
const x = socket;
|
||||
x.removeAllListeners(channel + 'Sync');
|
||||
socket.on(channel + 'Sync', (result) => {
|
||||
x.removeAllListeners(channel + "Sync");
|
||||
socket.on(channel + "Sync", (result) => {
|
||||
event.returnValue = result;
|
||||
});
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
socket.on('registerOnceIpcMainChannel', (channel) => {
|
||||
socket.on("registerOnceIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.once(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
socket.on('removeAllListenersIpcMainChannel', (channel) => {
|
||||
socket.on("removeAllListenersIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.removeAllListeners(channel);
|
||||
});
|
||||
socket.on('sendToIpcRenderer', (browserWindow, channel, data) => {
|
||||
socket.on("sendToIpcRenderer", (browserWindow, channel, data) => {
|
||||
const window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
if (window) {
|
||||
window.webContents.send(channel, ...data);
|
||||
}
|
||||
});
|
||||
socket.on('sendToIpcRendererBrowserView', (id, channel, data) => {
|
||||
const browserViews = (global['browserViews'] = global['browserViews'] || []);
|
||||
socket.on("sendToIpcRendererBrowserView", (id, channel, data) => {
|
||||
const browserViews = (global["browserViews"] =
|
||||
global["browserViews"] || []);
|
||||
let view = null;
|
||||
for (let i = 0; i < browserViews.length; i++) {
|
||||
if (browserViews[i]['id'] === id) {
|
||||
if (browserViews[i]["id"] === id) {
|
||||
view = browserViews[i];
|
||||
break;
|
||||
}
|
||||
@@ -45,29 +46,58 @@ module.exports = (socket) => {
|
||||
view.webContents.send(channel, ...data);
|
||||
}
|
||||
});
|
||||
socket.on("registerHandleIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.handle(channel, (event, args) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
socket.removeAllListeners(channel + "Handle");
|
||||
socket.on(channel + "Handle", (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
});
|
||||
socket.on("registerHandleOnceIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.handleOnce(channel, (event, args) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
socket.removeAllListeners(channel + "HandleOnce");
|
||||
socket.once(channel + "HandleOnce", (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
});
|
||||
socket.on("removeHandlerIpcMainChannel", (channel) => {
|
||||
electron_1.ipcMain.removeHandler(channel);
|
||||
});
|
||||
// Integration helpers: programmatically click menu items from renderer tests
|
||||
electron_1.ipcMain.on('integration-click-application-menu', (event, id) => {
|
||||
electron_1.ipcMain.on("integration-click-application-menu", (event, id) => {
|
||||
try {
|
||||
const menu = electron_1.Menu.getApplicationMenu();
|
||||
const mi = menu ? menu.getMenuItemById(id) : null;
|
||||
if (mi && typeof mi.click === 'function') {
|
||||
if (mi && typeof mi.click === "function") {
|
||||
const bw = electron_1.BrowserWindow.fromWebContents(event.sender);
|
||||
mi.click(undefined, bw, undefined);
|
||||
}
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
catch {
|
||||
/* ignore */
|
||||
}
|
||||
});
|
||||
electron_1.ipcMain.on('integration-click-context-menu', (event, windowId, id) => {
|
||||
electron_1.ipcMain.on("integration-click-context-menu", (event, windowId, id) => {
|
||||
try {
|
||||
const entries = global['contextMenuItems'] || [];
|
||||
const entries = global["contextMenuItems"] || [];
|
||||
const entry = entries.find((x) => x.browserWindowId === windowId);
|
||||
const mi = entry?.menu?.items?.find((i) => i.id === id);
|
||||
if (mi && typeof mi.click === 'function') {
|
||||
if (mi && typeof mi.click === "function") {
|
||||
const bw = electron_1.BrowserWindow.fromId(windowId);
|
||||
mi.click(undefined, bw, undefined);
|
||||
}
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
catch {
|
||||
/* ignore */
|
||||
}
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=ipc.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["ipc.ts"],"names":[],"mappings":";AAAA,uCAAqE;AAErE,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;QAC5C,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,E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} from 'net';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { ipcMain, BrowserWindow, BrowserView, Menu } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('registerIpcMainChannel', (channel) => {
|
||||
ipcMain.on(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
electronSocket = socket;
|
||||
socket.on("registerIpcMainChannel", (channel) => {
|
||||
ipcMain.on(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("registerSyncIpcMainChannel", (channel) => {
|
||||
ipcMain.on(channel, (event, args) => {
|
||||
const x = <any>socket;
|
||||
x.removeAllListeners(channel + "Sync");
|
||||
socket.on(channel + "Sync", (result) => {
|
||||
event.returnValue = result;
|
||||
});
|
||||
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("registerOnceIpcMainChannel", (channel) => {
|
||||
ipcMain.once(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("removeAllListenersIpcMainChannel", (channel) => {
|
||||
ipcMain.removeAllListeners(channel);
|
||||
});
|
||||
|
||||
socket.on("sendToIpcRenderer", (browserWindow, channel, data) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
|
||||
if (window) {
|
||||
window.webContents.send(channel, ...data);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("sendToIpcRendererBrowserView", (id, channel, data) => {
|
||||
const browserViews: BrowserView[] = (global["browserViews"] =
|
||||
global["browserViews"] || []) as BrowserView[];
|
||||
let view: BrowserView = null;
|
||||
for (let i = 0; i < browserViews.length; i++) {
|
||||
if (browserViews[i]["id"] === id) {
|
||||
view = browserViews[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (view) {
|
||||
view.webContents.send(channel, ...data);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("registerHandleIpcMainChannel", (channel) => {
|
||||
ipcMain.handle(channel, (event, args) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
socket.removeAllListeners(channel + "Handle");
|
||||
socket.on(channel + "Handle", (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('registerSyncIpcMainChannel', (channel) => {
|
||||
ipcMain.on(channel, (event, args) => {
|
||||
const x = <any>socket;
|
||||
x.removeAllListeners(channel + 'Sync');
|
||||
socket.on(channel + 'Sync', (result) => {
|
||||
event.returnValue = result;
|
||||
});
|
||||
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
socket.on("registerHandleOnceIpcMainChannel", (channel) => {
|
||||
ipcMain.handleOnce(channel, (event, args) => {
|
||||
return new Promise((resolve, _reject) => {
|
||||
socket.removeAllListeners(channel + "HandleOnce");
|
||||
socket.once(channel + "HandleOnce", (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('registerOnceIpcMainChannel', (channel) => {
|
||||
ipcMain.once(channel, (event, args) => {
|
||||
electronSocket.emit(channel, [event.preventDefault(), args]);
|
||||
});
|
||||
});
|
||||
socket.on("removeHandlerIpcMainChannel", (channel) => {
|
||||
ipcMain.removeHandler(channel);
|
||||
});
|
||||
|
||||
socket.on('removeAllListenersIpcMainChannel', (channel) => {
|
||||
ipcMain.removeAllListeners(channel);
|
||||
});
|
||||
// Integration helpers: programmatically click menu items from renderer tests
|
||||
ipcMain.on("integration-click-application-menu", (event, id: string) => {
|
||||
try {
|
||||
const menu = Menu.getApplicationMenu();
|
||||
const mi = menu ? menu.getMenuItemById(id) : null;
|
||||
if (mi && typeof (mi as any).click === "function") {
|
||||
const bw = BrowserWindow.fromWebContents(event.sender);
|
||||
(mi as any).click(undefined, bw, undefined);
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('sendToIpcRenderer', (browserWindow, channel, data) => {
|
||||
const window = BrowserWindow.fromId(browserWindow.id);
|
||||
|
||||
if (window) {
|
||||
window.webContents.send(channel, ...data);
|
||||
ipcMain.on(
|
||||
"integration-click-context-menu",
|
||||
(event, windowId: number, id: string) => {
|
||||
try {
|
||||
const entries = (global as any)["contextMenuItems"] || [];
|
||||
const entry = entries.find((x: any) => x.browserWindowId === windowId);
|
||||
const mi = entry?.menu?.items?.find((i: any) => i.id === id);
|
||||
if (mi && typeof (mi as any).click === "function") {
|
||||
const bw = BrowserWindow.fromId(windowId);
|
||||
(mi as any).click(undefined, bw, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('sendToIpcRendererBrowserView', (id, channel, data) => {
|
||||
const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[];
|
||||
let view: BrowserView = null;
|
||||
for (let i = 0; i < browserViews.length; i++) {
|
||||
if (browserViews[i]['id'] === id) {
|
||||
view = browserViews[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (view) {
|
||||
view.webContents.send(channel, ...data);
|
||||
}
|
||||
});
|
||||
|
||||
// Integration helpers: programmatically click menu items from renderer tests
|
||||
ipcMain.on('integration-click-application-menu', (event, id: string) => {
|
||||
try {
|
||||
const menu = Menu.getApplicationMenu();
|
||||
const mi = menu ? menu.getMenuItemById(id) : null;
|
||||
if (mi && typeof (mi as any).click === 'function') {
|
||||
const bw = BrowserWindow.fromWebContents(event.sender);
|
||||
(mi as any).click(undefined, bw, undefined);
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
});
|
||||
|
||||
ipcMain.on('integration-click-context-menu', (event, windowId: number, id: string) => {
|
||||
try {
|
||||
const entries = (global as any)['contextMenuItems'] || [];
|
||||
const entry = entries.find((x: any) => x.browserWindowId === windowId);
|
||||
const mi = entry?.menu?.items?.find((i: any) => i.id === id);
|
||||
if (mi && typeof (mi as any).click === 'function') {
|
||||
const bw = BrowserWindow.fromId(windowId);
|
||||
(mi as any).click(undefined, bw, undefined);
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
});
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
"use strict";
|
||||
const electron_1 = require("electron");
|
||||
const contextMenuItems = (global['contextMenuItems'] = global['contextMenuItems'] || []);
|
||||
const contextMenuItems = (global["contextMenuItems"] =
|
||||
global["contextMenuItems"] || []);
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('menu-setContextMenu', (browserWindowId, menuItems) => {
|
||||
socket.on("menu-setContextMenu", (browserWindowId, menuItems) => {
|
||||
const menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addContextMenuItemClickConnector(menu.items, browserWindowId, (id, windowId) => {
|
||||
electronSocket.emit('contextMenuItemClicked', [id, windowId]);
|
||||
electronSocket.emit("contextMenuItemClicked", [id, windowId]);
|
||||
});
|
||||
const index = contextMenuItems.findIndex(contextMenu => contextMenu.browserWindowId === browserWindowId);
|
||||
const index = contextMenuItems.findIndex((contextMenu) => contextMenu.browserWindowId === browserWindowId);
|
||||
const contextMenuItem = {
|
||||
menu: menu,
|
||||
browserWindowId: browserWindowId
|
||||
browserWindowId: browserWindowId,
|
||||
};
|
||||
if (index === -1) {
|
||||
contextMenuItems.push(contextMenuItem);
|
||||
@@ -26,23 +27,25 @@ module.exports = (socket) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addContextMenuItemClickConnector(item.submenu.items, browserWindowId, callback);
|
||||
}
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id, browserWindowId); };
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id, browserWindowId);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
socket.on('menu-contextMenuPopup', (browserWindowId) => {
|
||||
contextMenuItems.forEach(x => {
|
||||
socket.on("menu-contextMenuPopup", (browserWindowId) => {
|
||||
contextMenuItems.forEach((x) => {
|
||||
if (x.browserWindowId === browserWindowId) {
|
||||
const browserWindow = electron_1.BrowserWindow.fromId(browserWindowId);
|
||||
x.menu.popup(browserWindow);
|
||||
}
|
||||
});
|
||||
});
|
||||
socket.on('menu-setApplicationMenu', (menuItems) => {
|
||||
socket.on("menu-setApplicationMenu", (menuItems) => {
|
||||
const menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('menuItemClicked', id);
|
||||
electronSocket.emit("menuItemClicked", id);
|
||||
});
|
||||
electron_1.Menu.setApplicationMenu(menu);
|
||||
});
|
||||
@@ -51,8 +54,10 @@ module.exports = (socket) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"menu.js","sourceRoot":"","sources":["menu.ts"],"names":[],"mappings":";AACA,uCAA+C;AAC/C,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;AACzF,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,eAAe,EAAE,SAAS,EAAE,EAAE;QAC5D,MAAM,IAAI,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AE;YACzB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClD,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC1D,CAAC;YAED,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBAC5B,IAAI,CAAC,KAAK,GAAG,GAAG,EAAE;oBAChB,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACpB,CAAC,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
||||
@@ -1,71 +1,92 @@
|
||||
import { Socket } from 'net';
|
||||
import { Menu, BrowserWindow } from 'electron';
|
||||
const contextMenuItems = (global['contextMenuItems'] = global['contextMenuItems'] || []);
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { Menu, BrowserWindow } from "electron";
|
||||
|
||||
const contextMenuItems = (global["contextMenuItems"] =
|
||||
global["contextMenuItems"] || []);
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('menu-setContextMenu', (browserWindowId, menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
electronSocket = socket;
|
||||
socket.on("menu-setContextMenu", (browserWindowId, menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addContextMenuItemClickConnector(menu.items, browserWindowId, (id, windowId) => {
|
||||
electronSocket.emit('contextMenuItemClicked', [id, windowId]);
|
||||
});
|
||||
addContextMenuItemClickConnector(
|
||||
menu.items,
|
||||
browserWindowId,
|
||||
(id, windowId) => {
|
||||
electronSocket.emit("contextMenuItemClicked", [id, windowId]);
|
||||
},
|
||||
);
|
||||
|
||||
const index = contextMenuItems.findIndex(contextMenu => contextMenu.browserWindowId === browserWindowId);
|
||||
const index = contextMenuItems.findIndex(
|
||||
(contextMenu) => contextMenu.browserWindowId === browserWindowId,
|
||||
);
|
||||
|
||||
const contextMenuItem = {
|
||||
menu: menu,
|
||||
browserWindowId: browserWindowId
|
||||
const contextMenuItem = {
|
||||
menu: menu,
|
||||
browserWindowId: browserWindowId,
|
||||
};
|
||||
|
||||
if (index === -1) {
|
||||
contextMenuItems.push(contextMenuItem);
|
||||
} else {
|
||||
contextMenuItems[index] = contextMenuItem;
|
||||
}
|
||||
});
|
||||
|
||||
function addContextMenuItemClickConnector(
|
||||
menuItems,
|
||||
browserWindowId,
|
||||
callback,
|
||||
) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addContextMenuItemClickConnector(
|
||||
item.submenu.items,
|
||||
browserWindowId,
|
||||
callback,
|
||||
);
|
||||
}
|
||||
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id, browserWindowId);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (index === -1) {
|
||||
contextMenuItems.push(contextMenuItem);
|
||||
} else {
|
||||
contextMenuItems[index] = contextMenuItem;
|
||||
}
|
||||
socket.on("menu-contextMenuPopup", (browserWindowId) => {
|
||||
contextMenuItems.forEach((x) => {
|
||||
if (x.browserWindowId === browserWindowId) {
|
||||
const browserWindow = BrowserWindow.fromId(browserWindowId);
|
||||
x.menu.popup(browserWindow);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("menu-setApplicationMenu", (menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit("menuItemClicked", id);
|
||||
});
|
||||
|
||||
function addContextMenuItemClickConnector(menuItems, browserWindowId, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addContextMenuItemClickConnector(item.submenu.items, browserWindowId, callback);
|
||||
}
|
||||
Menu.setApplicationMenu(menu);
|
||||
});
|
||||
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id, browserWindowId); };
|
||||
}
|
||||
});
|
||||
}
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
socket.on('menu-contextMenuPopup', (browserWindowId) => {
|
||||
contextMenuItems.forEach(x => {
|
||||
if (x.browserWindowId === browserWindowId) {
|
||||
const browserWindow = BrowserWindow.fromId(browserWindowId);
|
||||
x.menu.popup(browserWindow);
|
||||
}
|
||||
});
|
||||
if ("id" in item && item.id) {
|
||||
item.click = () => {
|
||||
callback(item.id);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('menu-setApplicationMenu', (menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('menuItemClicked', id);
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
});
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if ('id' in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,28 +3,28 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('nativeTheme-shouldUseDarkColors', () => {
|
||||
socket.on("nativeTheme-shouldUseDarkColors", () => {
|
||||
const shouldUseDarkColors = electron_1.nativeTheme.shouldUseDarkColors;
|
||||
electronSocket.emit('nativeTheme-shouldUseDarkColors-completed', shouldUseDarkColors);
|
||||
electronSocket.emit("nativeTheme-shouldUseDarkColors-completed", shouldUseDarkColors);
|
||||
});
|
||||
socket.on('nativeTheme-shouldUseHighContrastColors', () => {
|
||||
socket.on("nativeTheme-shouldUseHighContrastColors", () => {
|
||||
const shouldUseHighContrastColors = electron_1.nativeTheme.shouldUseHighContrastColors;
|
||||
electronSocket.emit('nativeTheme-shouldUseHighContrastColors-completed', shouldUseHighContrastColors);
|
||||
electronSocket.emit("nativeTheme-shouldUseHighContrastColors-completed", shouldUseHighContrastColors);
|
||||
});
|
||||
socket.on('nativeTheme-shouldUseInvertedColorScheme', () => {
|
||||
socket.on("nativeTheme-shouldUseInvertedColorScheme", () => {
|
||||
const shouldUseInvertedColorScheme = electron_1.nativeTheme.shouldUseInvertedColorScheme;
|
||||
electronSocket.emit('nativeTheme-shouldUseInvertedColorScheme-completed', shouldUseInvertedColorScheme);
|
||||
electronSocket.emit("nativeTheme-shouldUseInvertedColorScheme-completed", shouldUseInvertedColorScheme);
|
||||
});
|
||||
socket.on('nativeTheme-getThemeSource', () => {
|
||||
socket.on("nativeTheme-getThemeSource", () => {
|
||||
const themeSource = electron_1.nativeTheme.themeSource;
|
||||
electronSocket.emit('nativeTheme-getThemeSource-completed', themeSource);
|
||||
electronSocket.emit("nativeTheme-getThemeSource-completed", themeSource);
|
||||
});
|
||||
socket.on('nativeTheme-themeSource', (themeSource) => {
|
||||
socket.on("nativeTheme-themeSource", (themeSource) => {
|
||||
electron_1.nativeTheme.themeSource = themeSource;
|
||||
});
|
||||
socket.on('register-nativeTheme-updated', (id) => {
|
||||
electron_1.nativeTheme.on('updated', () => {
|
||||
electronSocket.emit('nativeTheme-updated' + id);
|
||||
socket.on("register-nativeTheme-updated", (id) => {
|
||||
electron_1.nativeTheme.on("updated", () => {
|
||||
electronSocket.emit("nativeTheme-updated" + id);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"nativeTheme.js","sourceR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AAM,CAAC,EAAE,CAAC,8BAA8B,EAAE,CAAC,EAAE,EAAE,EAAE;QAC/C,sBAAW,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC7B,cAAc,CAAC,IAAI,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,41 +1,52 @@
|
||||
import { Socket } from 'net';
|
||||
import { nativeTheme } from 'electron';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { nativeTheme } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
electronSocket = socket;
|
||||
|
||||
socket.on('nativeTheme-shouldUseDarkColors', () => {
|
||||
const shouldUseDarkColors = nativeTheme.shouldUseDarkColors;
|
||||
socket.on("nativeTheme-shouldUseDarkColors", () => {
|
||||
const shouldUseDarkColors = nativeTheme.shouldUseDarkColors;
|
||||
|
||||
electronSocket.emit('nativeTheme-shouldUseDarkColors-completed', shouldUseDarkColors);
|
||||
});
|
||||
|
||||
socket.on('nativeTheme-shouldUseHighContrastColors', () => {
|
||||
const shouldUseHighContrastColors = nativeTheme.shouldUseHighContrastColors;
|
||||
|
||||
electronSocket.emit('nativeTheme-shouldUseHighContrastColors-completed', shouldUseHighContrastColors);
|
||||
});
|
||||
|
||||
socket.on('nativeTheme-shouldUseInvertedColorScheme', () => {
|
||||
const shouldUseInvertedColorScheme = nativeTheme.shouldUseInvertedColorScheme;
|
||||
|
||||
electronSocket.emit('nativeTheme-shouldUseInvertedColorScheme-completed', shouldUseInvertedColorScheme);
|
||||
});
|
||||
|
||||
socket.on('nativeTheme-getThemeSource', () => {
|
||||
const themeSource = nativeTheme.themeSource;
|
||||
|
||||
electronSocket.emit('nativeTheme-getThemeSource-completed', themeSource);
|
||||
});
|
||||
|
||||
socket.on('nativeTheme-themeSource', (themeSource) => {
|
||||
nativeTheme.themeSource = themeSource;
|
||||
});
|
||||
|
||||
socket.on('register-nativeTheme-updated', (id) => {
|
||||
nativeTheme.on('updated', () => {
|
||||
electronSocket.emit('nativeTheme-updated' + id);
|
||||
});
|
||||
electronSocket.emit(
|
||||
"nativeTheme-shouldUseDarkColors-completed",
|
||||
shouldUseDarkColors,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("nativeTheme-shouldUseHighContrastColors", () => {
|
||||
const shouldUseHighContrastColors = nativeTheme.shouldUseHighContrastColors;
|
||||
|
||||
electronSocket.emit(
|
||||
"nativeTheme-shouldUseHighContrastColors-completed",
|
||||
shouldUseHighContrastColors,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("nativeTheme-shouldUseInvertedColorScheme", () => {
|
||||
const shouldUseInvertedColorScheme =
|
||||
nativeTheme.shouldUseInvertedColorScheme;
|
||||
|
||||
electronSocket.emit(
|
||||
"nativeTheme-shouldUseInvertedColorScheme-completed",
|
||||
shouldUseInvertedColorScheme,
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("nativeTheme-getThemeSource", () => {
|
||||
const themeSource = nativeTheme.themeSource;
|
||||
|
||||
electronSocket.emit("nativeTheme-getThemeSource-completed", themeSource);
|
||||
});
|
||||
|
||||
socket.on("nativeTheme-themeSource", (themeSource) => {
|
||||
nativeTheme.themeSource = themeSource;
|
||||
});
|
||||
|
||||
socket.on("register-nativeTheme-updated", (id) => {
|
||||
nativeTheme.on("updated", () => {
|
||||
electronSocket.emit("nativeTheme-updated" + id);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
"use strict";
|
||||
const electron_1 = require("electron");
|
||||
const notifications = (global['notifications'] = global['notifications'] || []);
|
||||
const notifications = (global["notifications"] =
|
||||
global["notifications"] || []);
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('createNotification', (options) => {
|
||||
socket.on("createNotification", (options) => {
|
||||
const notification = new electron_1.Notification(options);
|
||||
let haveEvent = false;
|
||||
if (options.showID) {
|
||||
haveEvent = true;
|
||||
notification.on('show', () => {
|
||||
electronSocket.emit('NotificationEventShow', options.showID);
|
||||
notification.on("show", () => {
|
||||
electronSocket.emit("NotificationEventShow", options.showID);
|
||||
});
|
||||
}
|
||||
if (options.clickID) {
|
||||
haveEvent = true;
|
||||
notification.on('click', () => {
|
||||
electronSocket.emit('NotificationEventClick', options.clickID);
|
||||
notification.on("click", () => {
|
||||
electronSocket.emit("NotificationEventClick", options.clickID);
|
||||
});
|
||||
}
|
||||
if (options.closeID) {
|
||||
haveEvent = true;
|
||||
notification.on('close', () => {
|
||||
electronSocket.emit('NotificationEventClose', options.closeID);
|
||||
notification.on("close", () => {
|
||||
electronSocket.emit("NotificationEventClose", options.closeID);
|
||||
});
|
||||
}
|
||||
if (options.replyID) {
|
||||
haveEvent = true;
|
||||
notification.on('reply', (event, value) => {
|
||||
electronSocket.emit('NotificationEventReply', [options.replyID, value]);
|
||||
notification.on("reply", (event, value) => {
|
||||
electronSocket.emit("NotificationEventReply", [options.replyID, value]);
|
||||
});
|
||||
}
|
||||
if (options.actionID) {
|
||||
haveEvent = true;
|
||||
notification.on('action', (event, value) => {
|
||||
electronSocket.emit('NotificationEventAction', [options.actionID, value]);
|
||||
notification.on("action", (event, value) => {
|
||||
electronSocket.emit("NotificationEventAction", [
|
||||
options.actionID,
|
||||
value,
|
||||
]);
|
||||
});
|
||||
}
|
||||
if (haveEvent) {
|
||||
@@ -42,9 +46,9 @@ module.exports = (socket) => {
|
||||
}
|
||||
notification.show();
|
||||
});
|
||||
socket.on('notificationIsSupported', () => {
|
||||
socket.on("notificationIsSupported", () => {
|
||||
const isSupported = electron_1.Notification.isSupported();
|
||||
electronSocket.emit('notificationIsSupportedCompleted', isSupported);
|
||||
electronSocket.emit("notificationIsSupportedCompleted", isSupported);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=notification.js.map
|
||||
@@ -1 +1 @@
|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E;gBACzC,cAAc,CAAC,IAAI,CAAC,yBAAyB,EAAE;oBAC7C,OAAO,CAAC,QAAQ;oBAChB,KAAK;iBACN,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;QAED,YAAY,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACxC,MAAM,WAAW,GAAG,uBAAY,CAAC,WAAW,EAAE,CAAC;QAC/C,cAAc,CAAC,IAAI,CAAC,kCAAkC,EAAE,WAAW,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,58 +1,64 @@
|
||||
import { Socket } from 'net';
|
||||
import { Notification } from 'electron';
|
||||
const notifications: Electron.Notification[] = (global['notifications'] = global['notifications'] || []) as Electron.Notification[];
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { Notification } from "electron";
|
||||
|
||||
const notifications: Electron.Notification[] = (global["notifications"] =
|
||||
global["notifications"] || []) as Electron.Notification[];
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('createNotification', (options) => {
|
||||
const notification = new Notification(options);
|
||||
let haveEvent = false;
|
||||
electronSocket = socket;
|
||||
socket.on("createNotification", (options) => {
|
||||
const notification = new Notification(options);
|
||||
let haveEvent = false;
|
||||
|
||||
if (options.showID) {
|
||||
haveEvent = true;
|
||||
notification.on('show', () => {
|
||||
electronSocket.emit('NotificationEventShow', options.showID);
|
||||
});
|
||||
}
|
||||
if (options.showID) {
|
||||
haveEvent = true;
|
||||
notification.on("show", () => {
|
||||
electronSocket.emit("NotificationEventShow", options.showID);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.clickID) {
|
||||
haveEvent = true;
|
||||
notification.on('click', () => {
|
||||
electronSocket.emit('NotificationEventClick', options.clickID);
|
||||
});
|
||||
}
|
||||
if (options.clickID) {
|
||||
haveEvent = true;
|
||||
notification.on("click", () => {
|
||||
electronSocket.emit("NotificationEventClick", options.clickID);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.closeID) {
|
||||
haveEvent = true;
|
||||
notification.on('close', () => {
|
||||
electronSocket.emit('NotificationEventClose', options.closeID);
|
||||
});
|
||||
}
|
||||
if (options.closeID) {
|
||||
haveEvent = true;
|
||||
notification.on("close", () => {
|
||||
electronSocket.emit("NotificationEventClose", options.closeID);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.replyID) {
|
||||
haveEvent = true;
|
||||
notification.on('reply', (event, value) => {
|
||||
electronSocket.emit('NotificationEventReply', [options.replyID, value]);
|
||||
});
|
||||
}
|
||||
if (options.replyID) {
|
||||
haveEvent = true;
|
||||
notification.on("reply", (event, value) => {
|
||||
electronSocket.emit("NotificationEventReply", [options.replyID, value]);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.actionID) {
|
||||
haveEvent = true;
|
||||
notification.on('action', (event, value) => {
|
||||
electronSocket.emit('NotificationEventAction', [options.actionID, value]);
|
||||
});
|
||||
}
|
||||
if (options.actionID) {
|
||||
haveEvent = true;
|
||||
notification.on("action", (event, value) => {
|
||||
electronSocket.emit("NotificationEventAction", [
|
||||
options.actionID,
|
||||
value,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
if (haveEvent) {
|
||||
notifications.push(notification);
|
||||
}
|
||||
if (haveEvent) {
|
||||
notifications.push(notification);
|
||||
}
|
||||
|
||||
notification.show();
|
||||
});
|
||||
notification.show();
|
||||
});
|
||||
|
||||
socket.on('notificationIsSupported', () => {
|
||||
const isSupported = Notification.isSupported();
|
||||
electronSocket.emit('notificationIsSupportedCompleted', isSupported);
|
||||
});
|
||||
socket.on("notificationIsSupported", () => {
|
||||
const isSupported = Notification.isSupported();
|
||||
electronSocket.emit("notificationIsSupportedCompleted", isSupported);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,39 +3,39 @@ const electron_1 = require("electron");
|
||||
let electronSocket;
|
||||
module.exports = (socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('register-powerMonitor-lock-screen', () => {
|
||||
electron_1.powerMonitor.on('lock-screen', () => {
|
||||
electronSocket.emit('powerMonitor-lock-screen');
|
||||
socket.on("register-powerMonitor-lock-screen", () => {
|
||||
electron_1.powerMonitor.on("lock-screen", () => {
|
||||
electronSocket.emit("powerMonitor-lock-screen");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-unlock-screen', () => {
|
||||
electron_1.powerMonitor.on('unlock-screen', () => {
|
||||
electronSocket.emit('powerMonitor-unlock-screen');
|
||||
socket.on("register-powerMonitor-unlock-screen", () => {
|
||||
electron_1.powerMonitor.on("unlock-screen", () => {
|
||||
electronSocket.emit("powerMonitor-unlock-screen");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-suspend', () => {
|
||||
electron_1.powerMonitor.on('suspend', () => {
|
||||
electronSocket.emit('powerMonitor-suspend');
|
||||
socket.on("register-powerMonitor-suspend", () => {
|
||||
electron_1.powerMonitor.on("suspend", () => {
|
||||
electronSocket.emit("powerMonitor-suspend");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-resume', () => {
|
||||
electron_1.powerMonitor.on('resume', () => {
|
||||
electronSocket.emit('powerMonitor-resume');
|
||||
socket.on("register-powerMonitor-resume", () => {
|
||||
electron_1.powerMonitor.on("resume", () => {
|
||||
electronSocket.emit("powerMonitor-resume");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-ac', () => {
|
||||
electron_1.powerMonitor.on('on-ac', () => {
|
||||
electronSocket.emit('powerMonitor-ac');
|
||||
socket.on("register-powerMonitor-ac", () => {
|
||||
electron_1.powerMonitor.on("on-ac", () => {
|
||||
electronSocket.emit("powerMonitor-ac");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-battery', () => {
|
||||
electron_1.powerMonitor.on('on-battery', () => {
|
||||
electronSocket.emit('powerMonitor-battery');
|
||||
socket.on("register-powerMonitor-battery", () => {
|
||||
electron_1.powerMonitor.on("on-battery", () => {
|
||||
electronSocket.emit("powerMonitor-battery");
|
||||
});
|
||||
});
|
||||
socket.on('register-powerMonitor-shutdown', () => {
|
||||
electron_1.powerMonitor.on('shutdown', () => {
|
||||
electronSocket.emit('powerMonitor-shutdown');
|
||||
socket.on("register-powerMonitor-shutdown", () => {
|
||||
electron_1.powerMonitor.on("shutdown", () => {
|
||||
electronSocket.emit("powerMonitor-shutdown");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"powerMonitor.js","sourceRoot":"","sources":["powerMonitor.ts"],"names":[],"mappings":";AACA,uCAAwC;AACxC,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAChD,uBAAY,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;YAChC,cAAc,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAClD,uBAAY,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;YAClC,cAAc,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC5C,uBAAY,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC5B,cAAc,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAA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BAAuB,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
||||
@@ -1,42 +1,43 @@
|
||||
import { Socket } from 'net';
|
||||
import { powerMonitor } from 'electron';
|
||||
let electronSocket;
|
||||
import type { Socket } from "net";
|
||||
import { powerMonitor } from "electron";
|
||||
|
||||
let electronSocket: Socket;
|
||||
|
||||
export = (socket: Socket) => {
|
||||
electronSocket = socket;
|
||||
socket.on('register-powerMonitor-lock-screen', () => {
|
||||
powerMonitor.on('lock-screen', () => {
|
||||
electronSocket.emit('powerMonitor-lock-screen');
|
||||
});
|
||||
electronSocket = socket;
|
||||
socket.on("register-powerMonitor-lock-screen", () => {
|
||||
powerMonitor.on("lock-screen", () => {
|
||||
electronSocket.emit("powerMonitor-lock-screen");
|
||||
});
|
||||
socket.on('register-powerMonitor-unlock-screen', () => {
|
||||
powerMonitor.on('unlock-screen', () => {
|
||||
electronSocket.emit('powerMonitor-unlock-screen');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-unlock-screen", () => {
|
||||
powerMonitor.on("unlock-screen", () => {
|
||||
electronSocket.emit("powerMonitor-unlock-screen");
|
||||
});
|
||||
socket.on('register-powerMonitor-suspend', () => {
|
||||
powerMonitor.on('suspend', () => {
|
||||
electronSocket.emit('powerMonitor-suspend');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-suspend", () => {
|
||||
powerMonitor.on("suspend", () => {
|
||||
electronSocket.emit("powerMonitor-suspend");
|
||||
});
|
||||
socket.on('register-powerMonitor-resume', () => {
|
||||
powerMonitor.on('resume', () => {
|
||||
electronSocket.emit('powerMonitor-resume');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-resume", () => {
|
||||
powerMonitor.on("resume", () => {
|
||||
electronSocket.emit("powerMonitor-resume");
|
||||
});
|
||||
socket.on('register-powerMonitor-ac', () => {
|
||||
powerMonitor.on('on-ac', () => {
|
||||
electronSocket.emit('powerMonitor-ac');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-ac", () => {
|
||||
powerMonitor.on("on-ac", () => {
|
||||
electronSocket.emit("powerMonitor-ac");
|
||||
});
|
||||
socket.on('register-powerMonitor-battery', () => {
|
||||
powerMonitor.on('on-battery', () => {
|
||||
electronSocket.emit('powerMonitor-battery');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-battery", () => {
|
||||
powerMonitor.on("on-battery", () => {
|
||||
electronSocket.emit("powerMonitor-battery");
|
||||
});
|
||||
socket.on('register-powerMonitor-shutdown', () => {
|
||||
powerMonitor.on('shutdown', () => {
|
||||
electronSocket.emit('powerMonitor-shutdown');
|
||||
});
|
||||
});
|
||||
socket.on("register-powerMonitor-shutdown", () => {
|
||||
powerMonitor.on("shutdown", () => {
|
||||
electronSocket.emit("powerMonitor-shutdown");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user