Skip to content

Commit

Permalink
Merge branch 'master' into bug/578
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorBiswanger committed Jul 1, 2021
2 parents 476cc9e + fdd643b commit 78d9d60
Show file tree
Hide file tree
Showing 33 changed files with 496 additions and 219 deletions.
6 changes: 4 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Not released

# 11.5.2

# Released

# 11.5.1

ElectronNET.CLI:
Expand Down Expand Up @@ -45,8 +49,6 @@ Example for consuming the activate event (MacOs only)
* Fixed bug: Maintain references between socket.io connection events (thanks [danatcofo](https://github.com/danatcofo )) [\#468](https://github.com/ElectronNET/Electron.NET/pull/486)
* Fixed bug: Set default WebPreferences.DefaultFontSize (thanks [duncanawoods](https://github.com/duncanawoods)) [\#468](https://github.com/ElectronNET/Electron.NET/pull/468)

# Released

# 9.31.2

* Electron-Builder fixed for Windows builds.
Expand Down
18 changes: 18 additions & 0 deletions ElectronNET.API/Entities/Blob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Blob : IPostData
{
/// <summary>
/// The object represents a Blob
/// </summary>
public string Type { get; } = "blob";

/// <summary>
/// The UUID of the Blob being uploaded
/// </summary>
public string BlobUUID { get; set; }
}
}
12 changes: 12 additions & 0 deletions ElectronNET.API/Entities/BrowserViewConstructorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ public class BrowserViewConstructorOptions
/// See BrowserWindow.
/// </summary>
public WebPreferences WebPreferences { get; set; }

/// <summary>
/// A proxy to set on creation in the format host:port.
/// The proxy can be alternatively set using the BrowserView.WebContents.SetProxyAsync function.
/// </summary>
public string Proxy { get; set; }

/// <summary>
/// The credentials of the Proxy in the format username:password.
/// These will only be used if the Proxy field is also set.
/// </summary>
public string ProxyCredentials { get; set; }
}
}
12 changes: 12 additions & 0 deletions ElectronNET.API/Entities/BrowserWindowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,17 @@ public class BrowserWindowOptions
/// Settings of web page's features.
/// </summary>
public WebPreferences WebPreferences { get; set; }

/// <summary>
/// A proxy to set on creation in the format host:port.
/// The proxy can be alternatively set using the BrowserWindow.WebContents.SetProxyAsync function.
/// </summary>
public string Proxy { get; set; }

/// <summary>
/// The credentials of the Proxy in the format username:password.
/// These will only be used if the Proxy field is also set.
/// </summary>
public string ProxyCredentials { get; set; }
}
}
16 changes: 16 additions & 0 deletions ElectronNET.API/Entities/IPostData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ElectronNET.API.Entities
{
/// <summary>
/// Interface to use Electrons PostData Object
/// </summary>
public interface IPostData
{
/// <summary>
/// One of the following:
/// rawData - <see cref="UploadRawData"/> The data is available as a Buffer, in the rawData field.
/// file - <see cref="UploadFile"/> The object represents a file. The filePath, offset, length and modificationTime fields will be used to describe the file.
/// blob - <see cref="Blob"/> The object represents a Blob. The blobUUID field will be used to describe the Blob.
/// </summary>
public string Type { get; }
}
}
6 changes: 6 additions & 0 deletions ElectronNET.API/Entities/LoadURLOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public class LoadURLOptions
/// Extra headers for the request.
/// </summary>
public string ExtraHeaders { get; set; }

/// <summary>
/// PostData Object for the request.
/// Can be <see cref="UploadRawData"/>, <see cref="UploadFile"/> or <see cref="Blob"/>
/// </summary>
public IPostData[] PostData { get; set; }
}
}
34 changes: 34 additions & 0 deletions ElectronNET.API/Entities/UploadFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class UploadFile : IPostData
{
/// <summary>
/// The object represents a file.
/// </summary>
public string Type { get; } = "file";

/// <summary>
/// The path of the file being uploaded.
/// </summary>
public string FilePath { get; set; }

/// <summary>
/// The offset from the beginning of the file being uploaded, in bytes. Defaults to 0.
/// </summary>
public long Offset { get; set; } = 0;

/// <summary>
/// The length of the file being uploaded, <see cref="Offset"/>. Defaults to 0.
/// If set to -1, the whole file will be uploaded.
/// </summary>
public long Length { get; set; } = 0;

/// <summary>
/// The modification time of the file represented by a double, which is the number of seconds since the UNIX Epoch (Jan 1, 1970)
/// </summary>
public double ModificationTime { get; set; }
}
}
18 changes: 18 additions & 0 deletions ElectronNET.API/Entities/UploadRawData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class UploadRawData : IPostData
{
/// <summary>
/// The data is available as a Buffer, in the rawData field.
/// </summary>
public string Type { get; } = "rawData";

/// <summary>
/// The raw bytes of the post data in a Buffer.
/// </summary>
public byte[] Bytes { get; set; }
}
}
8 changes: 4 additions & 4 deletions ElectronNET.API/Entities/Vibrancy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;

namespace ElectronNET.API.Entities
{
Expand All @@ -10,7 +10,7 @@ public enum Vibrancy
/// <summary>
/// The appearance based
/// </summary>
[JsonProperty("appearance-based")]
[EnumMember(Value = "appearance-based")]
appearanceBased,

/// <summary>
Expand Down Expand Up @@ -51,13 +51,13 @@ public enum Vibrancy
/// <summary>
/// The medium light
/// </summary>
[JsonProperty("medium-light")]
[EnumMember(Value = "medium-light")]
mediumLight,

/// <summary>
/// The ultra dark
/// </summary>
[JsonProperty("ultra-dark")]
[EnumMember(Value = "ultra-dark")]
ultraDark
}
}
39 changes: 39 additions & 0 deletions ElectronNET.API/IpcMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ public void Send(BrowserWindow browserWindow, string channel, params object[] da
}
}

/// <summary>
/// Send a message to the BrowserView renderer process asynchronously via channel, you can also send
/// arbitrary arguments. Arguments will be serialized in JSON internally and hence
/// no functions or prototype chain will be included. The renderer process handles it by
/// listening for channel with ipcRenderer module.
/// </summary>
/// <param name="browserView">BrowserView with channel.</param>
/// <param name="channel">Channelname.</param>
/// <param name="data">Arguments data.</param>
public void Send(BrowserView browserView, string channel, params object[] data)
{
List<JObject> jobjects = new List<JObject>();
List<JArray> jarrays = new List<JArray>();
List<object> objects = new List<object>();

foreach (var parameterObject in data)
{
if(parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable)
{
jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer));
} else if(parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string))
{
jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer));
} else if(parameterObject.GetType().IsPrimitive || (parameterObject is string))
{
objects.Add(parameterObject);
}
}

if(jobjects.Count > 0 || jarrays.Count > 0)
{
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray());
}
else
{
BridgeConnector.Socket.Emit("sendToIpcRendererBrowserView", browserView.Id, channel, data);
}
}

private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Expand Down
12 changes: 12 additions & 0 deletions ElectronNET.API/WebContents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ public Task LoadURLAsync(string url, LoadURLOptions options)
return taskCompletionSource.Task;
}

/// <summary>
/// Inserts CSS into the web page.
/// See: https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options
/// Works for both BrowserWindows and BrowserViews.
/// </summary>
/// <param name="isBrowserWindow">Whether the webContents belong to a BrowserWindow or not (the other option is a BrowserView)</param>
/// <param name="path">Absolute path to the CSS file location</param>
public void InsertCSS(bool isBrowserWindow, string path)
{
BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path);
}

private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Expand Down
81 changes: 60 additions & 21 deletions ElectronNET.CLI/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class BuildCommand : ICommand
"Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine +
"Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine +
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
"Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine +
"Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine +
"Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \"";

public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
Expand All @@ -43,6 +45,7 @@ public BuildCommand(string[] args)
private string _manifest = "manifest";
private string _paramPublishReadyToRun = "PublishReadyToRun";
private string _paramPublishSingleFile = "PublishSingleFile";
private string _paramVersion = "Version";

public Task<bool> ExecuteAsync()
{
Expand All @@ -53,6 +56,11 @@ public Task<bool> ExecuteAsync()
SimpleCommandLineParser parser = new SimpleCommandLineParser();
parser.Parse(_args);
//This version will be shared between the dotnet publish and electron-builder commands
string version = null;
if (parser.Arguments.ContainsKey(_paramVersion))
version = parser.Arguments[_paramVersion][0];
if (!parser.Arguments.ContainsKey(_paramTarget))
{
Console.WriteLine($"Error: missing '{_paramTarget}' argument.");
Expand Down Expand Up @@ -95,28 +103,18 @@ public Task<bool> ExecuteAsync()
string tempBinPath = Path.Combine(tempPath, "bin");
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");
var dotNetPublishFlags = GetDotNetPublishFlags(parser);
string publishReadyToRun = "/p:PublishReadyToRun=";
if (parser.Arguments.ContainsKey(_paramPublishReadyToRun))
{
publishReadyToRun += parser.Arguments[_paramPublishReadyToRun][0];
}
else
{
publishReadyToRun += "true";
}
string publishSingleFile = "/p:PublishSingleFile=";
if (parser.Arguments.ContainsKey(_paramPublishSingleFile))
{
publishSingleFile += parser.Arguments[_paramPublishSingleFile][0];
}
else
{
publishSingleFile += "true";
}
var command =
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
// output the command
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(command);
Console.ResetColor();
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --self-contained", Directory.GetCurrentDirectory());
var resultCode = ProcessHelper.CmdExecute(command, Directory.GetCurrentDirectory());
if (resultCode != 0)
{
Expand Down Expand Up @@ -194,7 +192,10 @@ public Task<bool> ExecuteAsync()
manifestFileName = parser.Arguments[_manifest].First();
}
ProcessHelper.CmdExecute($"node build-helper.js " + manifestFileName, tempPath);
ProcessHelper.CmdExecute(
string.IsNullOrWhiteSpace(version)
? $"node build-helper.js {manifestFileName}"
: $"node build-helper.js {manifestFileName} {version}", tempPath);
Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=12.0.12 {electronParams}", tempPath);
Expand All @@ -204,5 +205,43 @@ public Task<bool> ExecuteAsync()
return true;
});
}

private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser parser)
{
var dotNetPublishFlags = new Dictionary<string, string>
{
{"/p:PublishReadyToRun", parser.TryGet(_paramPublishReadyToRun, out var rtr) ? rtr[0] : "true"},
{"/p:PublishSingleFile", parser.TryGet(_paramPublishSingleFile, out var psf) ? psf[0] : "true"},
};

foreach (var parm in parser.Arguments.Keys.Where(key => key.StartsWith("p:") || key.StartsWith("property:")))
{
var split = parm.IndexOf('=');
if (split < 0)
{
continue;
}

var key = $"/{parm.Substring(0, split)}";
// normalize the key
if (key.StartsWith("/property:"))
{
key = key.Replace("/property:", "/p:");
}

var value = parm.Substring(split + 1);

if (dotNetPublishFlags.ContainsKey(key))
{
dotNetPublishFlags[key] = value;
}
else
{
dotNetPublishFlags.Add(key, value);
}
}

return dotNetPublishFlags;
}
}
}

0 comments on commit 78d9d60

Please sign in to comment.