diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs
index 169800d..36bb5d6 100644
--- a/ElectronNET.API/BrowserWindow.cs
+++ b/ElectronNET.API/BrowserWindow.cs
@@ -6,6 +6,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -1657,6 +1658,13 @@ namespace ElectronNET.API
///
public void SetPosition(int x, int y)
{
+ // Workaround Windows 10 / Electron Bug
+ // https://github.com/electron/electron/issues/4045
+ if (isWindows10())
+ {
+ x = x - 7;
+ }
+
BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y);
}
@@ -1668,9 +1676,21 @@ namespace ElectronNET.API
///
public void SetPosition(int x, int y, bool animate)
{
+ // Workaround Windows 10 / Electron Bug
+ // https://github.com/electron/electron/issues/4045
+ if (isWindows10())
+ {
+ x = x - 7;
+ }
+
BridgeConnector.Socket.Emit("browserWindowSetPosition", Id, x, y, animate);
}
+ private bool isWindows10()
+ {
+ return RuntimeInformation.OSDescription.Contains("Windows 10");
+ }
+
///
/// Contains the window’s current position.
///
diff --git a/ElectronNET.API/Entities/BrowserWindowOptions.cs b/ElectronNET.API/Entities/BrowserWindowOptions.cs
index e72c29f..df66a57 100644
--- a/ElectronNET.API/Entities/BrowserWindowOptions.cs
+++ b/ElectronNET.API/Entities/BrowserWindowOptions.cs
@@ -12,24 +12,24 @@ namespace ElectronNET.API.Entities
///
/// Window's width in pixels. Default is 800.
///
- public int Width { get; set; }
+ public int Width { get; set; } = 800;
///
/// Window's height in pixels. Default is 600.
///
- public int Height { get; set; }
+ public int Height { get; set; } = 600;
///
/// ( if y is used) Window's left offset from screen. Default is to center the
/// window.
///
- public int X { get; set; }
+ public int X { get; set; } = -1;
///
/// ( if x is used) Window's top offset from screen. Default is to center the
/// window.
///
- public int Y { get; set; }
+ public int Y { get; set; } = -1;
///
/// The width and height would be used as web page's size, which means the actual
diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs
index 9b1fbfb..ffd1dca 100644
--- a/ElectronNET.API/WindowManager.cs
+++ b/ElectronNET.API/WindowManager.cs
@@ -5,6 +5,7 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -114,11 +115,46 @@ namespace ElectronNET.API
loadUrl = $"{loadUrl}:{BridgeSettings.WebPort}";
}
- BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl);
+ // Workaround Windows 10 / Electron Bug
+ // https://github.com/electron/electron/issues/4045
+ if (isWindows10())
+ {
+ options.Width = options.Width + 14;
+ options.Height = options.Height + 7;
+ }
+
+ if (options.X == -1 && options.Y == -1)
+ {
+ options.X = 0;
+ options.Y = 0;
+
+ BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl);
+ }
+ else
+ {
+ // Workaround Windows 10 / Electron Bug
+ // https://github.com/electron/electron/issues/4045
+ if (isWindows10())
+ {
+ options.X = options.X - 7;
+ }
+
+ var ownjsonSerializer = new JsonSerializer()
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver(),
+ NullValueHandling = NullValueHandling.Ignore
+ };
+ BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, ownjsonSerializer), loadUrl);
+ }
return taskCompletionSource.Task;
}
+ private bool isWindows10()
+ {
+ return RuntimeInformation.OSDescription.Contains("Windows 10");
+ }
+
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),