Skip to content

Commit 9f98b5c

Browse files
committed
Modernized the host bridge
1 parent 77b7141 commit 9f98b5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4512
-7400
lines changed

src/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,30 @@ public static class DeployEmbeddedElectronFiles
66
{
77
public static void Do(string tempPath)
88
{
9-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
10-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
11-
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "build-helper.js");
12-
13-
string vscodeFolder = Path.Combine(tempPath, ".vscode");
14-
if (Directory.Exists(vscodeFolder) == false)
9+
var hostDistFolder = Path.Combine(tempPath, "dist");
10+
var vscodeFolder = Path.Combine(tempPath, ".vscode");
11+
var splashscreenFolder = Path.Combine(tempPath, "splashscreen");
12+
13+
if (!Directory.Exists(hostDistFolder))
1514
{
16-
Directory.CreateDirectory(vscodeFolder);
15+
Directory.CreateDirectory(hostDistFolder);
1716
}
18-
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "launch.json", ".vscode.");
19-
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "tasks.json", ".vscode.");
2017

21-
string hostApiFolder = Path.Combine(tempPath, "api");
22-
if (Directory.Exists(hostApiFolder) == false)
18+
if (!Directory.Exists(vscodeFolder))
2319
{
24-
Directory.CreateDirectory(hostApiFolder);
20+
Directory.CreateDirectory(vscodeFolder);
2521
}
2622

27-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
28-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
29-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
30-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "commandLine.js", "api.");
31-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
32-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dock.js", "api.");
33-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
34-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
35-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
36-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
37-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
38-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
39-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
40-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
41-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "autoUpdater.js", "api.");
42-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserView.js", "api.");
43-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "powerMonitor.js", "api.");
44-
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "nativeTheme.js", "api.");
45-
46-
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
47-
if (Directory.Exists(splashscreenFolder) == false)
23+
if (!Directory.Exists(splashscreenFolder))
4824
{
4925
Directory.CreateDirectory(splashscreenFolder);
5026
}
27+
28+
EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
29+
EmbeddedFileHelper.DeployEmbeddedFile(hostDistFolder, "main.js", "dist.");
30+
EmbeddedFileHelper.DeployEmbeddedFile(hostDistFolder, "build-helper.js", "dist.");
31+
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "launch.json", ".vscode.");
32+
EmbeddedFileHelper.DeployEmbeddedFile(vscodeFolder, "tasks.json", ".vscode.");
5133
EmbeddedFileHelper.DeployEmbeddedFile(splashscreenFolder, "index.html", "splashscreen.");
5234
}
5335
}

src/ElectronNET.CLI/Commands/AddCommand.cs

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,51 @@ public AddCommand(string[] args)
2323
_args = args;
2424
}
2525

26-
private static string ElectronHostHookFolderName = "ElectronHostHook";
27-
2826
public Task<bool> ExecuteAsync()
2927
{
3028
return Task.Run(() =>
3129
{
32-
if(_args.Length == 0)
30+
if (_args.Length == 0)
3331
{
3432
Console.WriteLine("Specify 'hosthook' to add custom npm packages.");
3533
return false;
3634
}
3735

38-
if(_args[0].ToLowerInvariant() != "hosthook")
36+
if (_args[0].ToLowerInvariant() != "hosthook")
3937
{
4038
Console.WriteLine("Specify 'hosthook' to add custom npm packages.");
4139
return false;
4240
}
4341

44-
string aspCoreProjectPath = "";
45-
4642
// Maybe ToDo: Adding the possiblity to specify a path (like we did in the InitCommand, but this would require a better command args parser)
47-
aspCoreProjectPath = Directory.GetCurrentDirectory();
48-
49-
var currentDirectory = aspCoreProjectPath;
50-
51-
var targetFilePath = Path.Combine(currentDirectory, ElectronHostHookFolderName);
52-
53-
if(Directory.Exists(targetFilePath))
43+
var currentDirectory = Directory.GetCurrentDirectory();
44+
var hostDistFolder = Path.Combine(currentDirectory, "dist");
45+
46+
if (!Directory.Exists(hostDistFolder))
5447
{
55-
Console.WriteLine("ElectronHostHook directory already in place. If you want to start over, delete the folder and invoke this command again.");
56-
return false;
48+
Directory.CreateDirectory(hostDistFolder);
5749
}
5850

59-
Console.WriteLine("Adding the ElectronHostHook folder to your project...");
60-
61-
Directory.CreateDirectory(targetFilePath);
62-
6351
// Deploy related files
64-
EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "index.ts", "ElectronHostHook.");
65-
EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "connector.ts", "ElectronHostHook.");
66-
EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "package.json", "ElectronHostHook.");
67-
EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "tsconfig.json", "ElectronHostHook.");
68-
EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, ".gitignore", "ElectronHostHook.");
69-
70-
// npm for typescript compiler etc.
71-
Console.WriteLine("Start npm install...");
72-
ProcessHelper.CmdExecute("npm install", targetFilePath);
73-
74-
// run typescript compiler
75-
// ToDo: Not sure if this runs under linux/macos
76-
ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);
52+
EmbeddedFileHelper.DeployEmbeddedFile(hostDistFolder, "host-hook.js", "dist.");
7753

7854
// search .csproj or .fsproj (.csproj has higher precedence)
7955
Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'");
80-
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
56+
57+
var projectFile = Directory
58+
.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
8159
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
8260
.FirstOrDefault();
8361

8462
var extension = Path.GetExtension(projectFile);
8563
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
8664

87-
if (!EditProjectFile(projectFile)) return false;
65+
if (!EditProjectFile(projectFile))
66+
{
67+
return false;
68+
}
8869

8970
Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!");
90-
9171
return true;
9272
});
9373
}
@@ -98,16 +78,16 @@ private static bool EditProjectFile(string projectFile)
9878
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
9979
{
10080
var xmlDocument = XDocument.Load(stream);
101-
10281
var projectElement = xmlDocument.Descendants("Project").FirstOrDefault();
82+
10383
if (projectElement == null || projectElement.Attribute("Sdk")?.Value != "Microsoft.NET.Sdk.Web")
10484
{
10585
Console.WriteLine(
10686
$"Project file is not a compatible type of 'Microsoft.NET.Sdk.Web'. Your project: {projectElement?.Attribute("Sdk")?.Value}");
10787
return false;
10888
}
10989

110-
string itemGroupXmlString = "<ItemGroup>" +
90+
var itemGroupXmlString = "<ItemGroup>" +
11191
"<Content Update=\"ElectronHostHook\\**\\*.*\">" +
11292
"<CopyToPublishDirectory>Never</CopyToPublishDirectory>" +
11393
"</Content>" +
@@ -124,6 +104,7 @@ private static bool EditProjectFile(string projectFile)
124104
OmitXmlDeclaration = true,
125105
Indent = true
126106
};
107+
127108
using (XmlWriter xw = XmlWriter.Create(stream, xws))
128109
{
129110
xmlDocument.Save(xw);

src/ElectronNET.CLI/ElectronNET.CLI.csproj

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,10 @@
4141
<ItemGroup>
4242
<EmbeddedResource Include="..\ElectronNET.Host\electron.manifest.json" Link="ElectronHost\electron.manifest.json" />
4343
<EmbeddedResource Include="..\ElectronNET.Host\package.json" Link="ElectronHost\package.json" />
44-
<EmbeddedResource Include="..\ElectronNET.Host\main.js" Link="ElectronHost\main.js" />
45-
<EmbeddedResource Include="..\ElectronNET.Host\build-helper.js" Link="ElectronHost\build-helper.js" />
46-
<EmbeddedResource Include="..\ElectronNET.Host\api\ipc.js" Link="ElectronHost\api\ipc.js" />
47-
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\index.ts" Link="ElectronHost\ElectronHostHook\index.ts" />
48-
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\connector.ts" Link="ElectronHost\ElectronHostHook\connector.ts" />
49-
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\tsconfig.json" Link="ElectronHost\ElectronHostHook\tsconfig.json" />
50-
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\package.json" Link="ElectronHost\ElectronHostHook\package.json" />
51-
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
44+
<EmbeddedResource Include="..\ElectronNET.Host\dist\main.js" Link="ElectronHost\dist\main.js" />
45+
<EmbeddedResource Include="..\ElectronNET.Host\dist\build-helper.js" Link="ElectronHost\dist\build-helper.js" />
46+
<EmbeddedResource Include="..\ElectronNET.HostHook\dist\host-hook.js" Link="ElectronHost\dist\host-hook.js" />
5247
<EmbeddedResource Include="..\ElectronNET.Host\splashscreen\index.html" Link="ElectronHost\splashscreen\index.html" />
53-
<EmbeddedResource Include="..\ElectronNET.Host\api\app.js" Link="ElectronHost\api\app.js" />
54-
<EmbeddedResource Include="..\ElectronNET.Host\api\browserWindows.js" Link="ElectronHost\api\browserWindows.js" />
55-
<EmbeddedResource Include="..\ElectronNET.Host\api\commandLine.js" Link="ElectronHost\api\commandLine.js" />
56-
<EmbeddedResource Include="..\ElectronNET.Host\api\dialog.js" Link="ElectronHost\api\dialog.js" />
57-
<EmbeddedResource Include="..\ElectronNET.Host\api\dock.js" Link="ElectronHost\api\dock.js" />
58-
<EmbeddedResource Include="..\ElectronNET.Host\api\menu.js" Link="ElectronHost\api\menu.js" />
59-
<EmbeddedResource Include="..\ElectronNET.Host\api\notification.js" Link="ElectronHost\api\notification.js" />
60-
<EmbeddedResource Include="..\ElectronNET.Host\api\tray.js" Link="ElectronHost\api\tray.js" />
61-
<EmbeddedResource Include="..\ElectronNET.Host\api\globalShortcut.js" Link="ElectronHost\api\globalShortcut.js" />
62-
<EmbeddedResource Include="..\ElectronNET.Host\api\screen.js" Link="ElectronHost\api\screen.js" />
63-
<EmbeddedResource Include="..\ElectronNET.Host\api\shell.js" Link="ElectronHost\api\shell.js" />
64-
<EmbeddedResource Include="..\ElectronNET.Host\api\webContents.js" Link="ElectronHost\api\webContents.js" />
65-
<EmbeddedResource Include="..\ElectronNET.Host\api\clipboard.js" Link="ElectronHost\api\clipboard.js" />
66-
<EmbeddedResource Include="..\ElectronNET.Host\api\autoUpdater.js" Link="ElectronHost\api\autoUpdater.js" />
67-
<EmbeddedResource Include="..\ElectronNET.Host\api\browserView.js" Link="ElectronHost\api\browserView.js" />
68-
<EmbeddedResource Include="..\ElectronNET.Host\api\powerMonitor.js" Link="ElectronHost\api\powerMonitor.js" />
69-
<EmbeddedResource Include="..\ElectronNET.Host\api\nativeTheme.js" Link="ElectronHost\api\nativeTheme.js" />
7048
<EmbeddedResource Include="..\ElectronNET.Host\.vscode\launch.json" Link="ElectronHost\.vscode\launch.json" />
7149
<EmbeddedResource Include="..\ElectronNET.Host\.vscode\tasks.json" Link="ElectronHost\.vscode\tasks.json" />
7250
</ItemGroup>

src/ElectronNET.Host/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
bin
2+
dist

src/ElectronNET.Host/.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"request": "launch",
1010
"name": "Launch Electron App",
1111
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
12-
"program": "${workspaceFolder}/main.js",
12+
"program": "${workspaceFolder}/dist/main.js",
1313
"sourceMaps": true,
1414
"args": [
1515
"--test=true",
@@ -20,7 +20,7 @@
2020
"type": "node",
2121
"request": "launch",
2222
"name": "Launch build-helper",
23-
"program": "${workspaceFolder}/build-helper.js",
23+
"program": "${workspaceFolder}/dist/build-helper.js",
2424
"skipFiles": [
2525
"<node_internals>/**"
2626
],

src/ElectronNET.Host/ElectronHostHook/.gitignore

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/ElectronNET.Host/ElectronHostHook/connector.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/ElectronNET.Host/ElectronHostHook/connector.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/ElectronNET.Host/ElectronHostHook/connector.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy