mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 05:34:51 +00:00
Compare commits
57 Commits
0.3.0-pre.
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
456135a562 | ||
|
|
300f52510c | ||
|
|
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 | ||
|
|
e854451043 | ||
|
|
331c2f548c | ||
|
|
b00adcbd38 | ||
|
|
ed6d24dbb1 | ||
|
|
bbc7c79d5a | ||
|
|
2389ae32bd | ||
|
|
42fecbdc98 | ||
|
|
d95b41fbae |
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
|
||||
|
||||
28
Changelog.md
28
Changelog.md
@@ -1,10 +1,38 @@
|
||||
# 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();
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ A `package.json` file **is allowed** in the `ElectronHostHook` folder if you're
|
||||
|
||||
```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>
|
||||
|
||||
@@ -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.0" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
<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>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -165,13 +165,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))
|
||||
|
||||
@@ -61,6 +61,11 @@
|
||||
{
|
||||
ElectronNetRuntime.OnAppReadyCallback = onAppReadyCallback;
|
||||
|
||||
// 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);
|
||||
|
||||
var webPort = PortHelper.GetFreePort(ElectronNetRuntime.AspNetWebPort ?? ElectronNetRuntime.DefaultWebPort);
|
||||
ElectronNetRuntime.AspNetWebPort = webPort;
|
||||
|
||||
|
||||
@@ -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.0" 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>
|
||||
|
||||
@@ -50,11 +50,7 @@ module.exports = (socket) => {
|
||||
const trayIcon = electron_1.nativeImage.createFromPath(image);
|
||||
tray.value = new electron_1.Tray(trayIcon);
|
||||
if (menuItems) {
|
||||
const menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('trayMenuItemClicked', id);
|
||||
});
|
||||
tray.value.setContextMenu(menu);
|
||||
applyContextMenu(menuItems);
|
||||
}
|
||||
});
|
||||
socket.on('tray-destroy', () => {
|
||||
@@ -62,6 +58,11 @@ module.exports = (socket) => {
|
||||
tray.value.destroy();
|
||||
}
|
||||
});
|
||||
socket.on('set-contextMenu', (menuItems) => {
|
||||
if (menuItems && tray.value) {
|
||||
applyContextMenu(menuItems);
|
||||
}
|
||||
});
|
||||
socket.on('tray-setImage', (image) => {
|
||||
if (tray.value) {
|
||||
tray.value.setImage(image);
|
||||
@@ -118,6 +119,13 @@ module.exports = (socket) => {
|
||||
});
|
||||
}
|
||||
});
|
||||
function applyContextMenu(menuItems) {
|
||||
const menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('trayMenuItemClicked', id);
|
||||
});
|
||||
tray.value.setContextMenu(menu);
|
||||
}
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -59,12 +59,7 @@ export = (socket: Socket) => {
|
||||
tray.value = new Tray(trayIcon);
|
||||
|
||||
if (menuItems) {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('trayMenuItemClicked', id);
|
||||
});
|
||||
tray.value.setContextMenu(menu);
|
||||
applyContextMenu(menuItems);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,6 +69,12 @@ export = (socket: Socket) => {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('set-contextMenu', (menuItems) => {
|
||||
if (menuItems && tray.value) {
|
||||
applyContextMenu(menuItems);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('tray-setImage', (image) => {
|
||||
if (tray.value) {
|
||||
tray.value.setImage(image);
|
||||
@@ -136,6 +137,14 @@ export = (socket: Socket) => {
|
||||
}
|
||||
});
|
||||
|
||||
function applyContextMenu(menuItems) {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
electronSocket.emit('trayMenuItemClicked', id);
|
||||
});
|
||||
tray.value.setContextMenu(menu);
|
||||
}
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
|
||||
@@ -5,14 +5,13 @@ const path = require('path');
|
||||
const cProcess = require('child_process').spawn;
|
||||
const portscanner = require('portscanner');
|
||||
const { imageSize } = require('image-size');
|
||||
const { HookService } = require('electron-host-hook');
|
||||
let io, server, browserWindows, ipc, apiProcess, loadURL;
|
||||
let appApi, menu, dialogApi, notification, tray, webContents;
|
||||
let globalShortcut, shellApi, screen, clipboard, autoUpdater;
|
||||
let commandLine, browserView;
|
||||
let powerMonitor;
|
||||
let processInfo;
|
||||
let splashScreen, hostHook;
|
||||
let splashScreen;
|
||||
let nativeTheme;
|
||||
let dock;
|
||||
let launchFile;
|
||||
@@ -94,7 +93,7 @@ app.on('will-finish-launching', () => {
|
||||
|
||||
const manifestJsonFile = require(manifestJsonFilePath);
|
||||
|
||||
if (manifestJsonFile.singleInstance === "yes") {
|
||||
if (manifestJsonFile.singleInstance) {
|
||||
const mainInstance = app.requestSingleInstanceLock();
|
||||
app.on('second-instance', (events, args = []) => {
|
||||
args.forEach((parameter) => {
|
||||
@@ -263,6 +262,7 @@ function startSocketApiBridge(port) {
|
||||
console.log('Electron Socket: starting...');
|
||||
server = require('http').createServer();
|
||||
const { Server } = require('socket.io');
|
||||
let hostHook;
|
||||
io = new Server({
|
||||
pingTimeout: 60000, // in ms, default is 5000
|
||||
pingInterval: 10000, // in ms, default is 25000
|
||||
@@ -359,6 +359,8 @@ function startSocketApiBridge(port) {
|
||||
});
|
||||
|
||||
try {
|
||||
const { HookService } = require('electron-host-hook');
|
||||
|
||||
if (hostHook === undefined) {
|
||||
hostHook = new HookService(socket, app);
|
||||
hostHook.onHostReady();
|
||||
@@ -366,6 +368,7 @@ function startSocketApiBridge(port) {
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
|
||||
console.log('Electron Socket: startup complete.');
|
||||
});
|
||||
}
|
||||
@@ -373,7 +376,7 @@ function startSocketApiBridge(port) {
|
||||
function startAspCoreBackend(electronPort) {
|
||||
startBackend();
|
||||
|
||||
function startBackend() {
|
||||
function startBackend() {
|
||||
loadURL = `about:blank`;
|
||||
const envParam = getEnvironmentParameter();
|
||||
const parameters = [
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using ElectronNET.API;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.Samples.ElectronHostHook.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
string message = "Electron not active";
|
||||
if (HybridSupport.IsElectronActive)
|
||||
{
|
||||
// Call the HostHook defined in ElectronHostHook/index.ts
|
||||
var result = await Electron.HostHook.CallAsync<string>("ping", "Hello from C#");
|
||||
message = $"Sent 'Hello from C#', Received: '{result}'";
|
||||
}
|
||||
|
||||
return View("Index", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
src/ElectronNET.Samples.ElectronHostHook/ElectronHostHook/.gitignore
vendored
Normal file
3
src/ElectronNET.Samples.ElectronHostHook/ElectronHostHook/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
*.js
|
||||
*.js.map
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Socket } from "socket.io";
|
||||
|
||||
export class Connector {
|
||||
constructor(private socket: Socket, public app: any) {
|
||||
}
|
||||
|
||||
on(key: string, javaScriptCode: Function): void {
|
||||
this.socket.on(key, (...args: any[]) => {
|
||||
const id: string = args.pop();
|
||||
try {
|
||||
javaScriptCode(...args, (data) => {
|
||||
if (data) {
|
||||
this.socket.emit(`${key}Complete${id}`, data);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.socket.emit(`${key}Error${id}`, `Host Hook Exception`, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Connector } from "./connector";
|
||||
import { Socket } from "socket.io";
|
||||
|
||||
export class HookService extends Connector {
|
||||
constructor(socket: Socket, public app: any) {
|
||||
super(socket, app);
|
||||
}
|
||||
|
||||
onHostReady(): void {
|
||||
// execute your own JavaScript Host logic here
|
||||
this.on("ping", (msg, done) => {
|
||||
console.log("Received ping from C#:", msg);
|
||||
done("pong: " + msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "electron-host-hook",
|
||||
"version": "1.0.0",
|
||||
"description": "Connector for Electron.NET projects.",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"socket.io": "^4.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2019",
|
||||
"sourceMap": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<ElectronNetDevMode>true</ElectronNetDevMode>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\ElectronNET\build\ElectronNET.Core.props" Condition="$(ElectronNetDevMode)" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
|
||||
<AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
|
||||
<IsPackable>false</IsPackable>
|
||||
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
|
||||
<TypeScriptUseNodeJS>true</TypeScriptUseNodeJS>
|
||||
<TypeScriptTSConfig>ElectronHostHook/tsconfig.json</TypeScriptTSConfig>
|
||||
<TypeScriptCompileOnSaveEnabled>true</TypeScriptCompileOnSaveEnabled>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<TypeScriptCompile Remove="**\node_modules\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ElectronNET.API\ElectronNET.API.csproj" Condition="$(ElectronNetDevMode)" />
|
||||
<ProjectReference Include="..\ElectronNET.AspNet\ElectronNET.AspNet.csproj" Condition="$(ElectronNetDevMode)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.2.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="ElectronNET.Core.AspNet" Version="0.2.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.9.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\ElectronNET\build\ElectronNET.Core.targets" Condition="$(ElectronNetDevMode)" />
|
||||
</Project>
|
||||
33
src/ElectronNET.Samples.ElectronHostHook/Program.cs
Normal file
33
src/ElectronNET.Samples.ElectronHostHook/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using ElectronNET.API;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ElectronNET.Samples.ElectronHostHook
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.WebHost.UseElectron(args, async () =>
|
||||
{
|
||||
var window = await Electron.WindowManager.CreateWindowAsync();
|
||||
});
|
||||
|
||||
builder.Services.AddElectron();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ElectronNET.Samples.ElectronHostHook": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
@model string
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>ElectronHostHook Sample</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 20px; }
|
||||
.result { padding: 10px; background-color: #f0f0f0; border: 1px solid #ccc; margin-top: 10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ElectronHostHook Sample</h1>
|
||||
<p>This sample demonstrates bidirectional communication between C# and the Electron Host process.</p>
|
||||
|
||||
<div class="result">
|
||||
<strong>Result:</strong> @Model
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,7 +8,7 @@
|
||||
<Import Project="..\ElectronNET\build\ElectronNET.Core.props" Condition="$(ElectronNetDevMode)" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
|
||||
<AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
|
||||
</PropertyGroup>
|
||||
@@ -76,8 +76,8 @@
|
||||
<ProjectReference Include="..\ElectronNET.AspNet\ElectronNET.AspNet.csproj" Condition="$(ElectronNetDevMode)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.3.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="ElectronNET.Core.AspNet" Version="0.3.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="ElectronNET.Core" Version="0.4.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="ElectronNET.Core.AspNet" Version="0.4.0" Condition="'$(ElectronNetDevMode)' != 'true'" />
|
||||
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.9.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<ProjectGuid>6ea447d9-343f-46b8-b456-66557bddbb9f</ProjectGuid>
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<ProjectGuid>6ea447d9-343f-46b8-b456-66557bddbb9f</ProjectGuid>
|
||||
<SelfContained>true</SelfContained>
|
||||
|
||||
@@ -41,10 +41,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test Apps", "Test Apps", "{
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{985D39A7-5216-4945-8167-2FD0CB387BD8}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml
|
||||
..\.github\workflows\Build and Publish.yml = ..\.github\workflows\Build and Publish.yml
|
||||
..\.github\workflows\integration-tests.yml = ..\.github\workflows\integration-tests.yml
|
||||
..\.github\workflows\PR Validation.yml = ..\.github\workflows\PR Validation.yml
|
||||
..\.github\workflows\pr-comment.yml = ..\.github\workflows\pr-comment.yml
|
||||
..\.github\workflows\publish-wiki.yml = ..\.github\workflows\publish-wiki.yml
|
||||
..\.github\workflows\retry-test-jobs.yml = ..\.github\workflows\retry-test-jobs.yml
|
||||
..\.github\workflows\trailing-whitespace-check.yml = ..\.github\workflows\trailing-whitespace-check.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -66,6 +68,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectronNET.IntegrationTest
|
||||
EndProject
|
||||
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "ElectronNET.Host", "ElectronNET.Host\ElectronNET.Host.esproj", "{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronNET.Samples.ElectronHostHook", "ElectronNET.Samples.ElectronHostHook\ElectronNET.Samples.ElectronHostHook.csproj", "{B8D65F3A-7E54-4632-9F1C-46679237B312}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6} = {1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6}
|
||||
{8860606D-6847-F22A-5AED-DF4E0984DD24} = {8860606D-6847-F22A-5AED-DF4E0984DD24}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -109,6 +117,10 @@ Global
|
||||
{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{B8D65F3A-7E54-4632-9F1C-46679237B312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B8D65F3A-7E54-4632-9F1C-46679237B312}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B8D65F3A-7E54-4632-9F1C-46679237B312}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B8D65F3A-7E54-4632-9F1C-46679237B312}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -124,6 +136,7 @@ Global
|
||||
{06CAADC7-DE5B-47B4-AB2A-E9501459A2D1} = {D36CDFFD-3438-42E4-A7FF-88BA19AC4964}
|
||||
{AE877E48-6B44-63C2-8EA0-DB58D096B553} = {75129C45-FC6F-41B0-A485-07F4A7E031ED}
|
||||
{1C5FD66E-A1C6-C436-DF7C-3ECE4FEDDFE6} = {1BB6F634-2831-4496-83A6-BC6761DCEC8D}
|
||||
{B8D65F3A-7E54-4632-9F1C-46679237B312} = {EDCBFC49-2AEE-4BAF-9368-4409298C52FC}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {81A62E71-9E04-4EFE-AD5C-23165375F8EF}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<ElectronSplashScreen></ElectronSplashScreen>
|
||||
<ElectronIcon></ElectronIcon>
|
||||
<PackageIcon></PackageIcon>
|
||||
<PackageId>$(MSBuildProjectName.Replace(".", "-").ToLower())</PackageId>
|
||||
<ElectronPackageId>$(MSBuildProjectName.Replace(".", "-").ToLower())</ElectronPackageId>
|
||||
<ElectronBuilderJson>electron-builder.json</ElectronBuilderJson>
|
||||
<Title>$(MSBuildProjectName)</Title>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup Condition="'$(ElectronExecutable)' == ''">
|
||||
<WinPrefix>win</WinPrefix>
|
||||
<ElectronExecutable Condition="'$(RuntimeIdentifier.StartsWith($(WinPrefix)))' == 'true'">$(Title)</ElectronExecutable>
|
||||
<ElectronExecutable Condition="'$(RuntimeIdentifier.StartsWith($(WinPrefix)))' != 'true'">$(PackageId)</ElectronExecutable>
|
||||
<ElectronExecutable Condition="'$(RuntimeIdentifier.StartsWith($(WinPrefix)))' != 'true'">$(ElectronPackageId)</ElectronExecutable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -12,6 +12,10 @@
|
||||
<_IsMsAspNetProject Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true'">True</_IsMsAspNetProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PackageId Condition="'$(PackageId)' == ''">$(ElectronPackageId)</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyMetadata Include="ElectronExecutable" Value="$(ElectronExecutable)" />
|
||||
<AssemblyMetadata Include="ElectronVersion" Value="$(ElectronVersion)" />
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<TemplateProperty Include="PackageId" Value="$(PackageId)" />
|
||||
<TemplateProperty Include="ElectronPackageId" Value="$(ElectronPackageId)" />
|
||||
<TemplateProperty Include="Title" Value="$(Title)" />
|
||||
<TemplateProperty Include="ElectronTitle" Value="$(ElectronTitle)" />
|
||||
<TemplateProperty Include="Version" Value="$(Version)" />
|
||||
@@ -135,7 +135,7 @@
|
||||
<TemplateProperty Include="ElectronSplashScreen" Value="$(ElectronSplashScreenFileName)" />
|
||||
<TemplateProperty Include="ElectronVersion" Value="$(ElectronVersion)" />
|
||||
<TemplateProperty Include="TargetName" Value="$(ElectronTargetName)" />
|
||||
<TemplateProperty Include="ElectronSingleInstance" Value="$(ElectronSingleInstance)" />
|
||||
<TemplateProperty Include="ElectronSingleInstance" Value="$(ElectronSingleInstance.ToLower())" />
|
||||
</ItemGroup>
|
||||
|
||||
<MakeDir Directories="$(ElectronIntermediateOutputPath)" />
|
||||
@@ -297,12 +297,58 @@
|
||||
<RemoveDir Directories="$(ElectronHookTargetModuleDir)" Condition="Exists($(ElectronHookTargetModuleDir))" />
|
||||
</Target>
|
||||
|
||||
<Target Name="ElectronCheckVersionMismatch">
|
||||
|
||||
<PropertyGroup>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x86'">ia32</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-arm64'">arm64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm'">armv7l</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">arm64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">arm64</ElectronArch>
|
||||
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'win-x64' OR '$(RuntimeIdentifier)' == 'win-x86' OR '$(RuntimeIdentifier)' == 'win-arm64'">win</ElectronPlatform>
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm' OR '$(RuntimeIdentifier)' == 'linux-arm64'">linux</ElectronPlatform>
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'osx-x64' OR '$(RuntimeIdentifier)' == 'osx-arm64'">mac</ElectronPlatform>
|
||||
|
||||
<!-- npm uses different OS names than Electron -->
|
||||
<NpmOs Condition="'$(ElectronPlatform)' == 'win'">win32</NpmOs>
|
||||
<NpmOs Condition="'$(ElectronPlatform)' == 'linux'">linux</NpmOs>
|
||||
<NpmOs Condition="'$(ElectronPlatform)' == 'mac'">darwin</NpmOs>
|
||||
|
||||
<!-- npm CPU is same as ElectronArch except for linux-arm -->
|
||||
<NpmCpu>$(ElectronArch)</NpmCpu>
|
||||
<NpmCpu Condition="'$(RuntimeIdentifier)' == 'linux-arm'">arm</NpmCpu>
|
||||
|
||||
<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</_CurrentOSPlatform>
|
||||
<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</_CurrentOSPlatform>
|
||||
<_CurrentOSPlatform Condition="$([MSBuild]::IsOSPlatform('OSX'))">mac</_CurrentOSPlatform>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Validate that the target platform matches the current OS -->
|
||||
<PropertyGroup>
|
||||
<IsLinuxWsl>false</IsLinuxWsl>
|
||||
<IsLinuxWsl Condition="'$(ElectronPlatform)' == 'linux' AND '$(_CurrentOSPlatform)' == 'win'">true</IsLinuxWsl>
|
||||
|
||||
<_IsCrossCompileAllowed>false</_IsCrossCompileAllowed>
|
||||
<!-- Allow Linux builds on Windows via WSL -->
|
||||
<_IsCrossCompileAllowed Condition="'$(_CurrentOSPlatform)' == 'win' AND '$(ElectronPlatform)' == 'linux' AND '$(IsLinuxWsl)' == 'true'">true</_IsCrossCompileAllowed>
|
||||
|
||||
<_IsPlatformMismatch>false</_IsPlatformMismatch>
|
||||
<_IsPlatformMismatch Condition="'$(_CurrentOSPlatform)' != '$(ElectronPlatform)' AND '$(_IsCrossCompileAllowed)' != 'true'">true</_IsPlatformMismatch>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
|
||||
<Target Name="ElectronConfigureApp"
|
||||
Inputs="@(ElectronPackageJsonFiles)"
|
||||
Outputs="@(ElectronPackageJsonFiles->'$(OutDir)%(TargetPath)')"
|
||||
AfterTargets="CopyFilesToOutputDirectory"
|
||||
DependsOnTargets="ElectronResetHostHook"
|
||||
DependsOnTargets="ElectronResetHostHook;ElectronCheckVersionMismatch"
|
||||
>
|
||||
|
||||
<Copy SourceFiles="@(ElectronPackageJsonFiles)" DestinationFiles="@(ElectronPackageJsonFiles->'$(OutDir)%(TargetPath)')" >
|
||||
@@ -316,10 +362,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<ElectronOutputPath>$([System.IO.Path]::GetFullPath('$(ElectronOutDir)'))</ElectronOutputPath>
|
||||
<LinuxPrefix>linux</LinuxPrefix>
|
||||
<IsLinuxWsl>false</IsLinuxWsl>
|
||||
<IsLinuxWsl Condition="'$(RuntimeIdentifier.StartsWith($(LinuxPrefix)))' == 'true'AND $([MSBuild]::IsOSPlatform('Windows'))">true</IsLinuxWsl>
|
||||
<_NpmCmd>npm install --no-bin-links</_NpmCmd>
|
||||
<!-- Add cross-platform parameters when there's a platform mismatch (for remote debugging preparation) -->
|
||||
<_NpmCmd Condition="'$(_IsPlatformMismatch)' == 'true'">$(_NpmCmd) --os=$(NpmOs) --cpu=$(NpmCpu) --arch=$(NpmCpu) --platform=$(NpmOs)</_NpmCmd>
|
||||
<_NpmCmd Condition="'$(IsLinuxWsl)' == 'true'">wsl bash -ic '$(_NpmCmd)'</_NpmCmd>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -335,6 +380,23 @@
|
||||
|
||||
<Message Importance="High" Text="Electron setup failed!" Condition="'$(ExecExitCode)' != '0'" />
|
||||
|
||||
<!-- Fix up incorrect symlinks created by npm on Windows when targeting macOS -->
|
||||
<PropertyGroup>
|
||||
<_ElectronFrameworksDir>$(ElectronOutDir)node_modules\electron\dist\Electron.app\Contents\Frameworks</_ElectronFrameworksDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Electron Framework.framework" />
|
||||
<_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Mantle.framework" />
|
||||
<_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\ReactiveObjC.framework" />
|
||||
<_ElectronFrameworkDirs Include="$(_ElectronFrameworksDir)\Squirrel.framework" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Only execute on Windows host when targeting macOS -->
|
||||
<Message Importance="High" Text="Fixing macOS framework Resources symlinks" Condition="'$(ElectronPlatform)' == 'mac' AND '$(_CurrentOSPlatform)' == 'win'" />
|
||||
|
||||
<Exec Command="cmd /c del Resources && mklink /D Resources "Versions\Current\Resources"" WorkingDirectory="%(_ElectronFrameworkDirs.Identity)" Condition="'$(ElectronPlatform)' == 'mac' AND '$(_CurrentOSPlatform)' == 'win'" />
|
||||
|
||||
</Target>
|
||||
|
||||
<Target Name="BeforePublishElectronApp" BeforeTargets="PrepareForPublish">
|
||||
@@ -367,7 +429,7 @@
|
||||
<_ElectronPublishAppAfterTarget Condition="'$(UsingMicrosoftNETSdkWeb)' != 'true'">Publish</_ElectronPublishAppAfterTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="ElectronPublishApp" AfterTargets="$(_ElectronPublishAppAfterTarget)">
|
||||
<Target Name="ElectronPublishApp" AfterTargets="$(_ElectronPublishAppAfterTarget)" DependsOnTargets="ElectronCheckVersionMismatch">
|
||||
|
||||
<PropertyGroup>
|
||||
<PublishDir>$(_OriginalPublishDir)</PublishDir>
|
||||
@@ -376,21 +438,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Default values -->
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-x86'">ia32</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'win-arm64'">arm64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm'">armv7l</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">arm64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-x64'">x64</ElectronArch>
|
||||
<ElectronArch Condition="'$(RuntimeIdentifier)' == 'osx-arm64'">arm64</ElectronArch>
|
||||
<Error Condition="'$(_IsPlatformMismatch)' == 'true'"
|
||||
Code="ELECTRON100"
|
||||
Text="The target RuntimeIdentifier '$(RuntimeIdentifier)' (platform: $(ElectronPlatform)) does not match the current operating system ($(_CurrentOSPlatform)).
|
||||
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'win-x64' OR '$(RuntimeIdentifier)' == 'win-x86' OR '$(RuntimeIdentifier)' == 'win-arm64'">win</ElectronPlatform>
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm' OR '$(RuntimeIdentifier)' == 'linux-arm64'">linux</ElectronPlatform>
|
||||
<ElectronPlatform Condition="'$(RuntimeIdentifier)' == 'osx-x64' OR '$(RuntimeIdentifier)' == 'osx-arm64'">mac</ElectronPlatform>
|
||||
</PropertyGroup>
|
||||
Electron applications must be built on the target operating system:
|
||||
- Windows targets (win-x64, win-x86, win-arm64) must be built on Windows
|
||||
- Linux targets (linux-x64, linux-arm, linux-arm64) must be built on Linux (or Windows with WSL)
|
||||
- macOS targets (osx-x64, osx-arm64) must be built on macOS
|
||||
|
||||
EXCEPTION: Linux targets can be built on Windows using WSL (Windows Subsystem for Linux).
|
||||
|
||||
For more information, see: https://github.com/ElectronNET/Electron.NET/wiki/Migration-Checks#8-cross-platform-build-validation" />
|
||||
|
||||
<RemoveEnvironmentVariables Variables="BUILD_BUILDNUMBER;BUILD_NUMBER;TRAVIS_BUILD_NUMBER;APPVEYOR_BUILD_NUMBER;CIRCLE_BUILD_NUM;CI_PIPELINE_IID" />
|
||||
|
||||
@@ -452,7 +511,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<ElectronPaParams></ElectronPaParams>
|
||||
<ElectronPaParams Condition="'$(PackageId)' != ''">$(ElectronPaParams) -c.appId "$(PackageId)"</ElectronPaParams>
|
||||
<ElectronPaParams Condition="'$(ElectronPackageId)' != ''">$(ElectronPaParams) -c.appId "$(ElectronPackageId)"</ElectronPaParams>
|
||||
<ElectronPaParams Condition="'$(Version)' != ''">$(ElectronPaParams) -c.buildVersion "$(Version)"</ElectronPaParams>
|
||||
<ElectronPaParams Condition="'$(Copyright)' != ''">$(ElectronPaParams) -c.copyright "$(Copyright)"</ElectronPaParams>
|
||||
<ElectronPaParams>$(ElectronPaParams) -c.extraResources "bin/**/*"</ElectronPaParams>
|
||||
|
||||
@@ -479,7 +479,7 @@
|
||||
Description="The version of the app, following the major.minor.patch pattern. Version numbers may include a pre-release suffix."
|
||||
Category="AppInfo" />
|
||||
|
||||
<StringProperty Name="PackageId"
|
||||
<StringProperty Name="ElectronPackageId"
|
||||
DisplayName="App Identifier"
|
||||
Category="AppInfo">
|
||||
</StringProperty>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "$(PackageId)",
|
||||
"name": "$(ElectronPackageId)",
|
||||
"productName": "$(ElectronTitle)",
|
||||
"build": {
|
||||
"appId": "$(PackageId)",
|
||||
"appId": "$(ElectronPackageId)",
|
||||
"linux": {
|
||||
"desktop": {
|
||||
"entry": { "Name": "$(Title)" }
|
||||
},
|
||||
"executableName": "$(PackageId)"
|
||||
"executableName": "$(ElectronPackageId)"
|
||||
},
|
||||
"deb": {
|
||||
"desktop": {
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"license": "$(License)",
|
||||
"executable": "$(TargetName)",
|
||||
"singleInstance": "$(ElectronSingleInstance)",
|
||||
"singleInstance": $(ElectronSingleInstance),
|
||||
"homepage": "$(ProjectUrl)",
|
||||
"splashscreen": {
|
||||
"imageFile": "$(ElectronSplashScreen)"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>0.3.0</Version>
|
||||
<Version>0.4.0</Version>
|
||||
<PackageNamePrefix>ElectronNET.Core</PackageNamePrefix>
|
||||
<Authors>Gregor Biswanger, Florian Rappl, softworkz</Authors>
|
||||
<Product>Electron.NET</Product>
|
||||
|
||||
Reference in New Issue
Block a user