fixed bug: X and Y options to not work #193

This commit is contained in:
Gregor Biswanger
2019-01-03 20:20:21 +01:00
parent 17e4646d11
commit f4efad299a
3 changed files with 61 additions and 5 deletions

View File

@@ -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
/// <param name="y"></param>
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
/// <param name="animate"></param>
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");
}
/// <summary>
/// Contains the windows current position.
/// </summary>

View File

@@ -12,24 +12,24 @@ namespace ElectronNET.API.Entities
/// <summary>
/// Window's width in pixels. Default is 800.
/// </summary>
public int Width { get; set; }
public int Width { get; set; } = 800;
/// <summary>
/// Window's height in pixels. Default is 600.
/// </summary>
public int Height { get; set; }
public int Height { get; set; } = 600;
/// <summary>
/// ( if y is used) Window's left offset from screen. Default is to center the
/// window.
/// </summary>
public int X { get; set; }
public int X { get; set; } = -1;
/// <summary>
/// ( if x is used) Window's top offset from screen. Default is to center the
/// window.
/// </summary>
public int Y { get; set; }
public int Y { get; set; } = -1;
/// <summary>
/// The width and height would be used as web page's size, which means the actual

View File

@@ -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(),