This commit is contained in:
rafael-aero
2021-09-15 10:58:45 +02:00
11 changed files with 174 additions and 46 deletions

View File

@@ -570,9 +570,9 @@ namespace ElectronNET.API
public Task<string> GetNameAsync() => BridgeConnector.OnResult<string>("appGetName", "appGetNameCompleted");
internal App()
private App()
{
CommandLine = new CommandLine();
CommandLine = CommandLine.Instance;
}
internal static App Instance
@@ -1369,6 +1369,13 @@ namespace ElectronNET.API
/// <param name="fn">The handler</param>
public void Once(string eventName, Action<object> fn) => Events.Instance.Once(ModuleName, eventName, fn);
/// <summary>
/// If you're using a splashscreen in the electron.manifest.json, the window will ony be fully destroyed once you call this method once.
/// You should only do this after creating another window, to avoid a bug where the Electron renderer process frezees till any window interaction.
/// </summary>
public void DestroySplashScreen() => BridgeConnector.Emit("splashscreen-destroy");
private readonly JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()

View File

@@ -1075,6 +1075,14 @@ namespace ElectronNET.API
{
BridgeConnector.Emit("browserWindowSetFullScreen", Id, flag);
}
/// <summary>
/// Sets whether the background color of the window
/// </summary>
public void SetBackgroundColor(string color)
{
BridgeConnector.Emit("browserWindowSetBackgroundColor", Id, color);
}
/// <summary>
/// Whether the window is in fullscreen mode.

View File

@@ -8,7 +8,7 @@ namespace ElectronNET.API
/// </summary>
public sealed class CommandLine
{
internal CommandLine() { }
private CommandLine() { }
internal static CommandLine Instance
{

View File

@@ -37,62 +37,62 @@ namespace ElectronNET.API.Entities
/// window's size will include window frame's size and be slightly larger. Default
/// is false.
/// </summary>
public bool UseContentSize { get; set; }
public bool? UseContentSize { get; set; }
/// <summary>
/// Show window in the center of the screen.
/// </summary>
public bool Center { get; set; }
public bool? Center { get; set; }
/// <summary>
/// Window's minimum width. Default is 0.
/// </summary>
public int MinWidth { get; set; }
public int? MinWidth { get; set; }
/// <summary>
/// Window's minimum height. Default is 0.
/// </summary>
public int MinHeight { get; set; }
public int? MinHeight { get; set; }
/// <summary>
/// Window's maximum width. Default is no limit.
/// </summary>
public int MaxWidth { get; set; }
public int? MaxWidth { get; set; }
/// <summary>
/// Window's maximum height. Default is no limit.
/// </summary>
public int MaxHeight { get; set; }
public int? MaxHeight { get; set; }
/// <summary>
/// Whether window is resizable. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Resizable { get; set; } = true;
public bool? Resizable { get; set; } = true;
/// <summary>
/// Whether window is movable. This is not implemented on Linux. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Movable { get; set; } = true;
public bool? Movable { get; set; } = true;
/// <summary>
/// Whether window is minimizable. This is not implemented on Linux. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Minimizable { get; set; } = true;
public bool? Minimizable { get; set; } = true;
/// <summary>
/// Whether window is maximizable. This is not implemented on Linux. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Maximizable { get; set; } = true;
public bool? Maximizable { get; set; } = true;
/// <summary>
/// Whether window is closable. This is not implemented on Linux. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Closable { get; set; } = true;
public bool? Closable { get; set; } = true;
/// <summary>
/// Whether the window can be focused. Default is true. On Windows setting
@@ -101,35 +101,35 @@ namespace ElectronNET.API.Entities
/// always stay on top in all workspaces.
/// </summary>
[DefaultValue(true)]
public bool Focusable { get; set; } = true;
public bool? Focusable { get; set; } = true;
/// <summary>
/// Whether the window should always stay on top of other windows. Default is false.
/// </summary>
public bool AlwaysOnTop { get; set; }
public bool? AlwaysOnTop { get; set; }
/// <summary>
/// Whether the window should show in fullscreen. When explicitly set to false the
/// fullscreen button will be hidden or disabled on macOS.Default is false.
/// </summary>
public bool Fullscreen { get; set; }
public bool? Fullscreen { get; set; }
/// <summary>
/// Whether the window can be put into fullscreen mode. On macOS, also whether the
/// maximize/zoom button should toggle full screen mode or maximize window.Default
/// is true.
/// </summary>
public bool Fullscreenable { get; set; }
public bool? Fullscreenable { get; set; }
/// <summary>
/// Whether to show the window in taskbar. Default is false.
/// </summary>
public bool SkipTaskbar { get; set; }
public bool? SkipTaskbar { get; set; }
/// <summary>
/// The kiosk mode. Default is false.
/// </summary>
public bool Kiosk { get; set; }
public bool? Kiosk { get; set; }
/// <summary>
/// Default window title. Default is "Electron.NET".
@@ -146,40 +146,40 @@ namespace ElectronNET.API.Entities
/// Whether window should be shown when created. Default is true.
/// </summary>
[DefaultValue(true)]
public bool Show { get; set; } = true;
public bool? Show { get; set; } = true;
/// <summary>
/// Specify false to create a . Default is true.
/// </summary>
[DefaultValue(true)]
public bool Frame { get; set; } = true;
public bool? Frame { get; set; } = true;
/// <summary>
/// Whether this is a modal window. This only works when the window is a child
/// window.Default is false.
/// </summary>
public bool Modal { get; set; }
public bool? Modal { get; set; }
/// <summary>
/// Whether the web view accepts a single mouse-down event that simultaneously
/// activates the window.Default is false.
/// </summary>
public bool AcceptFirstMouse { get; set; }
public bool? AcceptFirstMouse { get; set; }
/// <summary>
/// Whether to hide cursor when typing. Default is false.
/// </summary>
public bool DisableAutoHideCursor { get; set; }
public bool? DisableAutoHideCursor { get; set; }
/// <summary>
/// Auto hide the menu bar unless the Alt key is pressed. Default is false.
/// </summary>
public bool AutoHideMenuBar { get; set; }
public bool? AutoHideMenuBar { get; set; }
/// <summary>
/// Enable the window to be resized larger than screen. Default is false.
/// </summary>
public bool EnableLargerThanScreen { get; set; }
public bool? EnableLargerThanScreen { get; set; }
/// <summary>
/// Window's background color as Hexadecimal value, like #66CD00 or #FFF or
@@ -191,18 +191,18 @@ namespace ElectronNET.API.Entities
/// Whether window should have a shadow. This is only implemented on macOS. Default
/// is true.
/// </summary>
public bool HasShadow { get; set; }
public bool? HasShadow { get; set; }
/// <summary>
/// Forces using dark theme for the window, only works on some GTK+3 desktop
/// environments.Default is false.
/// </summary>
public bool DarkTheme { get; set; }
public bool? DarkTheme { get; set; }
/// <summary>
/// Makes the window . Default is false.
/// </summary>
public bool Transparent { get; set; }
public bool? Transparent { get; set; }
/// <summary>
/// The type of window, default is normal window.
@@ -214,13 +214,20 @@ namespace ElectronNET.API.Entities
/// 'default' | 'hidden' | 'hiddenInset' | 'customButtonsOnHover'
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleBarStyle TitleBarStyle { get; set; }
public TitleBarStyle? TitleBarStyle { get; set; }
/// <summary>
/// Shows the title in the tile bar in full screen mode on macOS for all
/// titleBarStyle options.Default is false.
/// </summary>
public bool FullscreenWindowTitle { get; set; }
public bool? FullscreenWindowTitle { get; set; }
/// <summary>
/// Activate the Window Controls Overlay on Windows, when combined with <see cref="TitleBarStyle"/> = <see cref="TitleBarStyle.Hidden"/>
/// </summary>
[SupportedOSPlatform("win")]
[DefaultValue(null)]
public TitleBarOverlayConfig TitleBarOverlay { get; set; }
/// <summary>
/// Use WS_THICKFRAME style for frameless windows on Windows, which adds standard
@@ -228,7 +235,7 @@ namespace ElectronNET.API.Entities
/// animations. Default is true.
/// </summary>
[DefaultValue(true)]
public bool ThickFrame { get; set; } = true;
public bool? ThickFrame { get; set; } = true;
/// <summary>
/// Add a type of vibrancy effect to the window, only on macOS. Can be
@@ -236,7 +243,7 @@ namespace ElectronNET.API.Entities
/// medium-light or ultra-dark.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public Vibrancy Vibrancy { get; set; }
public Vibrancy? Vibrancy { get; set; }
/// <summary>
/// Controls the behavior on macOS when option-clicking the green stoplight button
@@ -245,7 +252,7 @@ namespace ElectronNET.API.Entities
/// it to zoom to the width of the screen.This will also affect the behavior when
/// calling maximize() directly.Default is false.
/// </summary>
public bool ZoomToPageWidth { get; set; }
public bool? ZoomToPageWidth { get; set; }
/// <summary>
/// Tab group name, allows opening the window as a native tab on macOS 10.12+.

View File

@@ -28,4 +28,10 @@ namespace ElectronNET.API.Entities
/// </summary>
customButtonsOnHover
}
public class TitleBarOverlayConfig
{
public string Color { get; set; }
public string SymbolColor { get; set; }
}
}

View File

@@ -171,6 +171,12 @@ namespace ElectronNET.API.Entities
/// </summary>
public bool Offscreen { get; set; }
/// <summary>
/// Whether to enable built-in spellcheck
/// </summary>
[DefaultValue(true)]
public bool Spellcheck { get; set; } = true;
/// <summary>
/// Whether to run Electron APIs and the specified preload script in a separate
/// JavaScript context. Defaults to false. The context that the preload script runs

View File

@@ -126,10 +126,10 @@ namespace ElectronNET.API
if (options.X == -1 && options.Y == -1)
{
options.X = 0;
options.X = 0; //This is manually removed by the browserWindows.js code before creating the window
options.Y = 0;
BridgeConnector.Emit("createBrowserWindow", guid, JObject.FromObject(options, _jsonSerializer), loadUrl);
BridgeConnector.Emit("createBrowserWindow", guid, JObject.FromObject(options, _keepDefaultValuesSerializer), loadUrl);
}
else
{
@@ -218,6 +218,19 @@ namespace ElectronNET.API
return await taskCompletionSource.Task;
}
/// <summary>
/// Destroy all windows.
/// </summary>
/// <returns>Number of windows destroyed</returns>
public async Task<int> DestroyAllWindows()
{
var destroyed = await BridgeConnector.OnResult<int>("browserWindowDestroyAll", "browserWindowDestroyAll-completed");
_browserViews.Clear();
_browserWindows.Clear();
return destroyed;
}
private static JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -182,6 +182,12 @@ module.exports = (socket, app) => {
else if (!options.webPreferences) {
options = { ...options, webPreferences: { nodeIntegration: true, contextIsolation: false } };
}
if (options.x && options.y && options.x == 0 && options.y == 0) {
delete options.x;
delete options.y;
}
// we dont want to recreate the window when watch is ready.
if (app.commandLine.hasSwitch('watch') && app['mainWindowURL'] === loadUrl) {
window = app['mainWindow'];
@@ -256,6 +262,25 @@ module.exports = (socket, app) => {
socket.on('browserWindowDestroy', (id) => {
getWindowById(id)?.destroy();
});
socket.on('browserWindowDestroyAll', () => {
const windows = electron_1.BrowserWindow.getAllWindows();
let count = 0;
if (windows.length) {
windows.forEach(w => {
try {
w.hide();
w.destroy();
count++;
}
catch {
//ignore, probably already destroyed
}
});
}
electronSocket.emit('browserWindowDestroyAll-completed', count);
});
socket.on('browserWindowClose', (id) => {
getWindowById(id)?.close();
});
@@ -318,6 +343,9 @@ module.exports = (socket, app) => {
socket.on('browserWindowSetFullScreen', (id, fullscreen) => {
getWindowById(id)?.setFullScreen(fullscreen);
});
socket.on('browserWindowSetBackgroundColor', (id, color) => {
getWindowById(id)?.setBackgroundColor(color);
});
socket.on('browserWindowIsFullScreen', (id) => {
const isFullScreen = getWindowById(id)?.isFullScreen() ?? null;
electronSocket.emit('browserWindow-isFullScreen-completed' + id, isFullScreen);
@@ -628,4 +656,4 @@ module.exports = (socket, app) => {
return null;
}
};
//# sourceMappingURL=browserWindows.js.map
//# sourceMappingURL=browserWindows.js.map

View File

@@ -288,6 +288,24 @@ export = (socket: Socket, app: Electron.App) => {
getWindowById(id)?.destroy();
});
socket.on('browserWindowDestroyAll', () => {
const windows = BrowserWindow.getAllWindows();
let count = 0;
if (windows.length) {
windows.forEach(w => {
try {
w.hide();
w.destroy();
count++;
}
catch {
//ignore, probably already destroyed
}
});
}
electronSocket.emit('browserWindowDestroyAll-completed', count);
});
socket.on('browserWindowClose', (id) => {
getWindowById(id)?.close();
});
@@ -371,7 +389,11 @@ export = (socket: Socket, app: Electron.App) => {
socket.on('browserWindowSetFullScreen', (id, fullscreen) => {
getWindowById(id)?.setFullScreen(fullscreen);
});
socket.on('browserWindowSetBackgroundColor', (id, color) => {
getWindowById(id)?.setBackgroundColor(color);
});
socket.on('browserWindowIsFullScreen', (id) => {
const isFullScreen = getWindowById(id)?.isFullScreen() ?? null;

View File

@@ -51,9 +51,23 @@ app.on('will-finish-launching', () => {
app.on('before-quit-for-update', () => {
ignoreApiProcessClosed = true;
const windows = BrowserWindow.getAllWindows();
if (windows.length) {
windows.forEach(w => {
try {
w.hide();
w.destroy();
}
catch {
//ignore, probably already destroyed
}
});
}
});
const manifestJsonFile = require(manifestJsonFilePath);
if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
const mainInstance = app.requestSingleInstanceLock();
app.on('second-instance', (events, args = []) => {
@@ -88,6 +102,14 @@ if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
}
}
//Some flags need to be set before app is ready
if (manifestJsonFile.hasOwnProperty('cliFlags') && manifestJsonFile.cliFlags.length > 0) {
manifestJsonFile.cliFlags.forEach(flag => {
app.commandLine.appendSwitch(flag);
});
}
app.on('ready', () => {
// Fix ERR_UNKNOWN_URL_SCHEME using file protocol
@@ -170,12 +192,13 @@ function startSplashScreen() {
}
}
splashScreen.setIgnoreMouseEvents(true);
//Removed as we want to be able to drag the splash screen: splashScreen.setIgnoreMouseEvents(true);
app.once('browser-window-created', () => {
splashScreen.destroy();
splashScreen = null;
if (splashScreen) {
splashScreen.hide();
}
//We cannot destroy the window here as this triggers an electron freeze bug (https://github.com/electron/electron/issues/29050)
});
const loadSplashscreenUrl = path.join(__dirname, 'splashscreen', 'index.html') + '?imgPath=' + imageFile;
@@ -269,6 +292,13 @@ function startSocketApiBridge(port) {
}
});
socket.on('splashscreen-destroy', () => {
if(splashScreen) {
splashScreen.destroy();
splashScreen = null;
}
});
socket.on('register-app-open-url-event', (id) => {
global['electronsocket'] = socket;

View File

@@ -10,9 +10,10 @@
<body>
<style>
body {
overflow: hidden;
}
body {
overflow: hidden;
-webkit-app-region: drag;
}
</style>
<img draggable="false" alt="splashscreen" style="width: 100%; height: 100%;">