mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 13:44:47 +00:00
fixed bug: X and Y options to not work #193
This commit is contained in:
@@ -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 window’s current position.
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user