使用过Electron的同鞋都知道,在主进程中打开一个渲染进程窗口需要实例化一个BrowserWindow对象, 即:
let mainWindow = new BrowserWindow({
width: 1366,
height: 768
});
这是 一个最基本的实例化一个窗口的代码片段。在这个过程中,我们可以对即将打开的窗口进行各种设置,不过文档中似乎并没有对相关的设置项进行说明。没办法,只能看源码了。。。
功夫不负有心人,终于在源码中找到以下片段,注释写的很全,供各位参考:
interface BrowserWindowConstructorOptions {
/**
* Window's width in pixels. Default is 800.
*/
width?: number;
/**
* Window's height in pixels. Default is 600.
*/
height?: number;
/**
* ( if y is used) Window's left offset from screen. Default is to center the
* window.
*/
x?: number;
/**
* ( if x is used) Window's top offset from screen. Default is to center the
* window.
*/
y?: number;
/**
* The width and height would be used as web page's size, which means the actual
* window's size will include window frame's size and be slightly larger. Default
* is false.
*/
useContentSize?: boolean;
/**
* Show window in the center of the screen.
*/
center?: boolean;
/**
* Window's minimum width. Default is 0.
*/
minWidth?: number;
/**
* Window's minimum height. Default is 0.
*/
minHeight?: number;
/**
* Window's maximum width. Default is no limit.
*/
maxWidth?: number;
/**
* Window's maximum height. Default is no limit.
*/
maxHeight?: number;
/**
* Whether window is resizable. Default is true.
*/
resizable?: boolean;
/**
* Whether window is movable. This is not implemented on Linux. Default is true.
*/
movable?: boolean;
/**
* Whether window is minimizable. This is not implemented on Linux. Default is
* true.
*/
minimizable?: boolean;
/**
* Whether window is maximizable. This is not implemented on Linux. Default is
* true.
*/
maximizable?: boolean;
/**
* Whether window is closable. This is not implemented on Linux. Default is true.
*/
closable?: boolean;
/**
* Whether the window can be focused. Default is true. On Windows setting
* focusable: false also implies setting skipTaskbar: true. On Linux setting
* focusable: false makes the window stop interacting with wm, so the window will
* always stay on top in all workspaces.
*/
focusable?: boolean;
/**
* Whether the window should always stay on top of other windows. Default is false.
*/
alwaysOnTop?: boolean;
/**
* 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.
*/
fullscreen?: boolean;
/**
* 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.
*/
fullscreenable?: boolean;
/**
* Whether to show the window in taskbar. Default is false.
*/
skipTaskbar?: boolean;
/**
* The kiosk mode. Default is false.
*/
kiosk?: boolean;
/**
* Default window title. Default is "Electron".
*/
title?: string;
/**
* The window icon. On Windows it is recommended to use ICO icons to get best
* visual effects, you can also leave it undefined so the executable's icon will be
* used.
*/
icon?: NativeImage | string;
/**
* Whether window should be shown when created. Default is true.
*/
show?: boolean;
/**
* Specify false to create a . Default is true.
*/
frame?: boolean;
/**
* Specify parent window. Default is null.
*/
parent?: BrowserWindow;
/**
* Whether this is a modal window. This only works when the window is a child
* window. Default is false.
*/
modal?: boolean;
/**
* Whether the web view accepts a single mouse-down event that simultaneously
* activates the window. Default is false.
*/
acceptFirstMouse?: boolean;
/**
* Whether to hide cursor when typing. Default is false.
*/
disableAutoHideCursor?: boolean;
/**
* Auto hide the menu bar unless the Alt key is pressed. Default is false.
*/
autoHideMenuBar?: boolean;
/**
* Enable the window to be resized larger than screen. Default is false.
*/
enableLargerThanScreen?: boolean;
/**
* Window's background color as Hexadecimal value, like #66CD00 or #FFF or
* #80FFFFFF (alpha is supported). Default is #FFF (white).
*/
backgroundColor?: string;
/**
* Whether window should have a shadow. This is only implemented on macOS. Default
* is true.
*/
hasShadow?: boolean;
/**
* Forces using dark theme for the window, only works on some GTK+3 desktop
* environments. Default is false.
*/
darkTheme?: boolean;
/**
* Makes the window . Default is false.
*/
transparent?: boolean;
/**
* The type of window, default is normal window. See more about this below.
*/
type?: string;
/**
* The style of window title bar. Default is default. Possible values are:
*/
titleBarStyle?: ('default' | 'hidden' | 'hidden-inset' | 'hiddenInset' | 'customButtonsOnHover');
/**
* Shows the title in the tile bar in full screen mode on macOS for all
* titleBarStyle options. Default is false.
*/
fullscreenWindowTitle?: boolean;
/**
* Use WS_THICKFRAME style for frameless windows on Windows, which adds standard
* window frame. Setting it to false will remove window shadow and window
* animations. Default is true.
*/
thickFrame?: boolean;
/**
* Add a type of vibrancy effect to the window, only on macOS. Can be
* appearance-based, light, dark, titlebar, selection, menu, popover, sidebar,
* medium-light or ultra-dark.
*/
vibrancy?: ('appearance-based' | 'light' | 'dark' | 'titlebar' | 'selection' | 'menu' | 'popover' | 'sidebar' | 'medium-light' | 'ultra-dark');
/**
* Controls the behavior on macOS when option-clicking the green stoplight button
* on the toolbar or by clicking the Window > Zoom menu item. If true, the window
* will grow to the preferred width of the web page when zoomed, false will cause
* it to zoom to the width of the screen. This will also affect the behavior when
* calling maximize() directly. Default is false.
*/
zoomToPageWidth?: boolean;
/**
* Tab group name, allows opening the window as a native tab on macOS 10.12+.
* Windows with the same tabbing identifier will be grouped together. This also
* adds a native new tab button to your window's tab bar and allows your app and
* window to receive the new-window-for-tab event.
*/
tabbingIdentifier?: string;
/**
* Settings of web page's features.
*/
webPreferences?: WebPreferences;
}