diff --git a/ElectronNET.CLI/Commands/StartElectronCommand.cs b/ElectronNET.CLI/Commands/StartElectronCommand.cs
index 3573f2d..8c04e02 100644
--- a/ElectronNET.CLI/Commands/StartElectronCommand.cs
+++ b/ElectronNET.CLI/Commands/StartElectronCommand.cs
@@ -60,7 +60,25 @@ namespace ElectronNET.CLI.Commands
var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty);
string tempBinPath = Path.Combine(tempPath, "bin");
- var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\" /p:PublishReadyToRun=true --no-self-contained", aspCoreProjectPath);
+ var resultCode = 0;
+
+ if (parser != null && parser.Contains("watch"))
+ {
+
+ // if not exists then create mklink
+ if (!Directory.Exists($"{tempBinPath}")) Directory.CreateDirectory(tempBinPath);
+ if (!Directory.Exists($"{tempBinPath}\\wwwroot")) resultCode = ProcessHelper.CmdExecute($"mklink /D {tempBinPath}\\wwwroot wwwroot", aspCoreProjectPath);
+
+ if (!File.Exists($"{tempBinPath}\\electron.manifest.json"))
+ {
+ resultCode = ProcessHelper.CmdExecute($"mklink /h {tempBinPath}\\electron.manifest.json electron.manifest.json", aspCoreProjectPath);
+ }
+
+ }
+ else
+ {
+ resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} --output \"{tempBinPath}\" /p:PublishReadyToRun=true --no-self-contained", aspCoreProjectPath);
+ }
if (resultCode != 0)
{
@@ -110,6 +128,11 @@ namespace ElectronNET.CLI.Commands
arguments += " --clear-cache=true";
}
+ if (parser.Arguments.ContainsKey("watch"))
+ {
+ arguments += " --watch=true";
+ }
+
string path = Path.Combine(tempPath, "node_modules", ".bin");
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
@@ -117,6 +140,7 @@ namespace ElectronNET.CLI.Commands
{
Console.WriteLine("Invoke electron.cmd - in dir: " + path);
ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js"" " + arguments, path);
+
}
else
{
diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj
index c90d679..4f72713 100644
--- a/ElectronNET.CLI/ElectronNET.CLI.csproj
+++ b/ElectronNET.CLI/ElectronNET.CLI.csproj
@@ -3,7 +3,7 @@
Exe
- netcoreapp3.0
+ netcoreapp3.1
dotnet-electronize
electronize
@@ -29,6 +29,11 @@
Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md
PackageIcon.png
true
+
+
+
+
+ AnyCPU
@@ -37,7 +42,7 @@
-
+
diff --git a/ElectronNET.CLI/Properties/launchSettings.json b/ElectronNET.CLI/Properties/launchSettings.json
index bcce156..819d7fe 100644
--- a/ElectronNET.CLI/Properties/launchSettings.json
+++ b/ElectronNET.CLI/Properties/launchSettings.json
@@ -2,7 +2,7 @@
"profiles": {
"ElectronNET.CLI": {
"commandName": "Project",
- "commandLineArgs": "build \"C:\\Users\\Gregor\\Documents\\Visual Studio 2017\\Projects\\ElectronNET\\ElectronNET.WebApp\""
+ "commandLineArgs": "start /project-path \"C:\\Users\\Rizvi\\source\\repos\\Electron.NET\\ElectronNET.WebApp\" /watch"
}
}
}
\ No newline at end of file
diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js
index c1cd851..b4e993d 100644
--- a/ElectronNET.Host/main.js
+++ b/ElectronNET.Host/main.js
@@ -1,7 +1,7 @@
const { app } = require('electron');
const { BrowserWindow } = require('electron');
const path = require('path');
-const process = require('child_process').spawn;
+const cProcess = require('child_process').spawn;
const portscanner = require('portscanner');
const imageSize = require('image-size');
let io, server, browserWindows, ipc, apiProcess, loadURL;
@@ -11,12 +11,25 @@ let commandLine, browserView;
let splashScreen, hostHook;
let manifestJsonFileName = 'electron.manifest.json';
-if(app.commandLine.hasSwitch('manifest')) {
+let watchable = false;
+if (app.commandLine.hasSwitch('manifest')) {
manifestJsonFileName = app.commandLine.getSwitchValue('manifest');
};
-const currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
-const manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);
+if (app.commandLine.hasSwitch('watch')) {
+ watchable = true;
+};
+
+let currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
+let manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);
+
+// if watch is enabled lets change the path
+if (watchable) {
+ currentBinPath = path.join(__dirname, '../../'); // go to project directory
+ currentBinPath = currentBinPath.substr(0, currentBinPath.length - 1);
+ manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);
+}
+
const manifestJsonFile = require(manifestJsonFilePath);
if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
const mainInstance = app.requestSingleInstanceLock();
@@ -106,7 +119,11 @@ function startSocketApiBridge(port) {
server.on('listening', function () {
console.log('Electron Socket started on port %s at %s', server.address().port, server.address().address);
// Now that socket connection is established, we can guarantee port will not be open for portscanner
- startAspCoreBackend(port);
+ if (watchable) {
+ startAspCoreBackendWithWatch(port);
+ } else {
+ startAspCoreBackend(port);
+ }
});
io.on('connection', (socket) => {
@@ -153,7 +170,7 @@ function isModuleAvailable(name) {
}
function startAspCoreBackend(electronPort) {
- if(manifestJsonFile.aspCoreBackendPort) {
+ if (manifestJsonFile.aspCoreBackendPort) {
startBackend(manifestJsonFile.aspCoreBackendPort)
} else {
// hostname needs to be localhost, otherwise Windows Firewall will be triggered.
@@ -175,10 +192,40 @@ function startAspCoreBackend(electronPort) {
let binFilePath = path.join(currentBinPath, binaryFile);
var options = { cwd: currentBinPath };
- apiProcess = process(binFilePath, parameters, options);
+ apiProcess = cProcess(binFilePath, parameters, options);
apiProcess.stdout.on('data', (data) => {
console.log(`stdout: ${data.toString()}`);
});
}
}
+
+function startAspCoreBackendWithWatch(electronPort) {
+ if (manifestJsonFile.aspCoreBackendPort) {
+ startBackend(manifestJsonFile.aspCoreBackendPort)
+ } else {
+ // hostname needs to be localhost, otherwise Windows Firewall will be triggered.
+ portscanner.findAPortNotInUse(electronPort + 1, 65535, 'localhost', function (error, electronWebPort) {
+ startBackend(electronWebPort);
+ });
+ }
+
+ function startBackend(aspCoreBackendPort) {
+ console.log('ASP.NET Core Watch Port: ' + aspCoreBackendPort);
+ loadURL = `http://localhost:${aspCoreBackendPort}`;
+ const parameters = ['watch','run', `--project ${currentBinPath}`, `/electronPort=${electronPort}`, `/electronWebPort=${aspCoreBackendPort}`];
+
+ console.log(currentBinPath);
+ var options = {
+ cwd: currentBinPath,
+ env: {
+ PATH: process.env.PATH
+ }
+ };
+ apiProcess = cProcess('dotnet', parameters, options);
+
+ apiProcess.stdout.on('data', (data) => {
+ console.log(`stdout: ${data.toString()}`);
+ });
+ }
+}
\ No newline at end of file
diff --git a/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/ElectronNET.WebApp/ElectronNET.WebApp.csproj
index 09fa59e..f880723 100644
--- a/ElectronNET.WebApp/ElectronNET.WebApp.csproj
+++ b/ElectronNET.WebApp/ElectronNET.WebApp.csproj
@@ -4,7 +4,7 @@
OutOfProcess
AspNetCoreModule
win-x64
- 3.6
+ 3.8
diff --git a/ElectronNET.WebApp/erd.png b/ElectronNET.WebApp/erd.png
new file mode 100644
index 0000000..8df12c8
Binary files /dev/null and b/ElectronNET.WebApp/erd.png differ