BaseWindow
Create and control windows.
Process: Main
Note
BaseWindow
provides a flexible way to compose multiple web views in a single window. For windows with only a single, full-size web view, theBrowserWindow
class may be a simpler option.
This module cannot be used until the ready
event of the app
module is emitted.
// In the main process.
const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 600 })
const leftView = new WebContentsView()
leftView.webContents.loadURL('https://electronjs.org')
win.contentView.addChildView(leftView)
const rightView = new WebContentsView()
rightView.webContents.loadURL('https://github.com/electron/electron')
win.contentView.addChildView(rightView)
leftView.setBounds({ x: 0, y: 0, width: 400, height: 600 })
rightView.setBounds({ x: 400, y: 0, width: 400, height: 600 })
親ウィンドウと子ウィンドウ
By using parent
option, you can create child windows:
const { BaseWindow } = require('electron')
const parent = new BaseWindow()
const child = new BaseWindow({ parent })
The child
window will always show on top of the parent
window.
モーダルウィンドウ
A modal window is a child window that disables parent window. To create a modal
window, you have to set both the parent
and modal
options:
const { BaseWindow } = require('electron')
const parent = new BaseWindow()
const child = new BaseWindow({ parent, modal: true })
プラットフォームに関する注意事項
- macOSでは、モーダルウインドウは親ウインドウに付随したシートとして表示されます。
- On macOS the child windows will keep the relative position to parent window when parent window moves, while on Windows and Linux child windows will not move.
- On Linux the type of modal windows will be changed to
dialog
. - Linuxでは、多くのデスクトップ環境は、モーダルウインドウを非表示にすることをサポートしていません。
Class: BaseWindow
Create and control windows.
Process: Main
BaseWindow
is an EventEmitter.
It creates a new BaseWindow
with native properties as set by the options
.
new BaseWindow([options])
When setting minimum or maximum window size with minWidth
/maxWidth
/
minHeight
/maxHeight
, it only constrains the users. It won't prevent you from
passing a size that does not follow size constraints to setBounds
/setSize
or
to the constructor of BrowserWindow
.
The possible values and behaviors of the type
option are platform dependent.
以下は取りうる値です。
- On Linux, possible types are
desktop
,dock
,toolbar
,splash
,notification
.- The
desktop
type places the window at the desktop background window level (kCGDesktopWindowLevel - 1). However, note that a desktop window will not receive focus, keyboard, or mouse events. You can still use globalShortcut to receive input sparingly. - The
dock
type creates a dock-like window behavior. - The
toolbar
type creates a window with a toolbar appearance. - The
splash
type behaves in a specific way. It is not draggable, even if the CSS styling of the window's body contains -webkit-app-region: drag. このタイプは主にスプラッシュスクリーンで使用されます。 - The
notification
type creates a window that behaves like a system notification.
- The
- On macOS, possible types are
desktop
,textured
,panel
.- The
textured
type adds metal gradient appearance (NSWindowStyleMaskTexturedBackground
). - The
desktop
type places the window at the desktop background window level (kCGDesktopWindowLevel - 1
). Note that desktop window will not receive focus, keyboard or mouse events, but you can useglobalShortcut
to receive input sparingly. - The
panel
type enables the window to float on top of full-screened apps by adding theNSWindowStyleMaskNonactivatingPanel
style mask,normally reserved for NSPanel, at runtime. Also, the window will appear on all spaces (desktops).
- The
- On Windows, possible type is
toolbar
.
インスタンスイベント
Objects created with new BaseWindow
emit the following events:
Note: Some events are only available on specific operating systems and are labeled as such.
イベント: 'close'
戻り値:
event
Event
ウインドウがクローズされようとするときに発生します。 It's emitted before the
beforeunload
and unload
event of the DOM. Calling event.preventDefault()
will cancel the close.
Usually you would want to use the beforeunload
handler to decide whether the
window should be closed, which will also be called when the window is
reloaded. In Electron, returning any value other than undefined
would cancel the
close. 以下がその例です。
window.onbeforeunload = (e) => {
console.log('I do not want to be closed')
// Unlike usual browsers that a message box will be prompted to users, returning
// a non-void value will silently cancel the close.
// It is recommended to use the dialog API to let the user confirm closing the
// application.
e.returnValue = false
}
Note: There is a subtle difference between the behaviors of window.onbeforeunload = handler
and window.addEventListener('beforeunload', handler)
. It is recommended to always set the event.returnValue
explicitly, instead of only returning a value, as the former works more consistently within Electron.
イベント: 'closed'
ウインドウが閉じられたときに発生します。 このイベントを受け取った後は、ウインドウへの参照を削除し、以降そのウインドウを使用しないようにしてください。
Event: 'session-end' Windows
強制的なシャットダウン、マシン再起動またはセッションのログオフによってウインドウセッションが終了されようとしたときに発生します。
イベント: 'blur'
ウインドウがフォーカスを失うときに発生します。
イベント: 'focus'
ウインドウがフォーカスを得るときに発生します。
イベント: 'show'
ウインドウが表示されるときに発生します。
イベント: 'hide'
ウインドウが非表示になるときに発生します。
イベント: 'maximize'
ウィンドウが最大化されるときに発生します。
イベント: 'unmaximize'
ウインドウが最大化状態から抜けるときに発生します。
イベント: 'minimize'
ウィンドウが最小化されるときに発生します。
イベント: 'restore'
ウインドウが最小化状態から復元されたときに発生します。
Event: 'will-resize' macOS Windows
戻り値:
event
EventnewBounds
Rectangle - Size the window is being resized to.details
Objectedge
(string) - The edge of the window being dragged for resizing. Can bebottom
,left
,right
,top-left
,top-right
,bottom-left
orbottom-right
.
ウィンドウがリサイズされる前に発生します。 Calling event.preventDefault()
will prevent the window from being resized.
このイベントは、ウィンドウが手動でリサイズされようとしているときにしか発生しません。 Resizing the window with setBounds
/setSize
will not emit this event.
The possible values and behaviors of the edge
option are platform dependent. 以下は取りうる値です。
- On Windows, possible values are
bottom
,top
,left
,right
,top-left
,top-right
,bottom-left
,bottom-right
. - On macOS, possible values are
bottom
andright
.- The value
bottom
is used to denote vertical resizing. - The value
right
is used to denote horizontal resizing.
- The value
イベント: 'resize'
ウインドウがリサイズされた後に発生します。
Event: 'resized' macOS Windows
ウインドウがリサイズされるときに一度発生します。
これは、通常、ウィンドウが手動でリサイズされようとしているときにしか発生しません。 On macOS, resizing the window with setBounds
/setSize
and setting the animate
parameter to true
will also emit this event once resizing has finished.
Event: 'will-move' macOS Windows
戻り値:
event
EventnewBounds
Rectangle - Location the window is being moved to.
ウィンドウが移動される前に発生します。 On Windows, calling event.preventDefault()
will prevent the window from being moved.
このイベントは、ウィンドウが手動で移動されようとしているときにしか発生しません。 Moving the window with setPosition
/setBounds
/center
will not emit this event.
イベント: 'move'
ウインドウが新しい位置に移動されているときに発生します。
Event: 'moved' macOS Windows
ウインドウが新しい位置に移動されるときに一回だけ、発生します。
Note: On macOS this event is an alias of move
.
イベント: 'enter-full-screen'
ウインドウがフルスクリーン状態に入るときに発生します。
イベント: 'leave-full-screen'
ウインドウがフルスクリーン状態を抜けるときに発生します。
イベント: 'always-on-top-changed'
戻り値:
event
EventisAlwaysOnTop
boolean
ウインドウが常に他のウインドウの手前に表示されるように設定またはそれが解除されたときに発生します。
Event: 'app-command' Windows Linux
戻り値:
event
Eventcommand
string
Emitted when an App Command is invoked. これらは、Windowsで幾つかのマウスに組み込まれている "Back" ボタンだけでなく、一般的にキーボードのメディアキーやブラウザコマンドとも関連付けられています。
Commands are lowercased, underscores are replaced with hyphens, and the
APPCOMMAND_
prefix is stripped off.
e.g. APPCOMMAND_BROWSER_BACKWARD
is emitted as browser-backward
.
const { BaseWindow } = require('electron')
const win = new BaseWindow()
win.on('app-command', (e, cmd) => {
// Navigate the window back when the user hits their mouse back button
if (cmd === 'browser-backward') {
// Find the appropriate WebContents to navigate.
}
})
Linux 上では以下のアプリコマンドが明示的にサポートされます。
browser-backward
browser-forward
Event: 'swipe' macOS
戻り値:
event
Eventdirection
string
3 本指でのスワイプ時に発生します。 Possible directions are up
, right
, down
, left
.
このイベントは、スワイプで画面の内容が移動しない、古い macOS スタイルのトラックパッドスワイプを元にしています。 Most macOS trackpads are not
configured to allow this kind of swiping anymore, so in order for it to emit properly the
'Swipe between pages' preference in System Preferences > Trackpad > More Gestures
must be
set to 'Swipe with two or three fingers'.
Event: 'rotate-gesture' macOS
戻り値:
event
Eventrotation
Float
トラックパッドの回転ジェスチャで発生します。 回転ジェスチャーが終了するまで継続的に発生します。 The rotation
value on each emission is the angle in degrees rotated since
the last emission. The last emitted event upon a rotation gesture will always be of
value 0
. 反時計回りの回転値は正であり、時計回りの回転値は負です。
Event: 'sheet-begin' macOS
ウインドウがシートを開くときに発生します。
Event: 'sheet-end' macOS
ウインドウがシートを閉じたときに発生します。
Event: 'new-window-for-tab' macOS
ネイティブの新規タブボタンがクリックされるときに発生します。
Event: 'system-context-menu' Windows
戻り値:
event
Eventpoint
Point - The screen coordinates the context menu was triggered at
システムコンテキストメニューがウィンドウ上でトリガーされたときに発生します。 通常ユーザーがウィンドウのクライアントエリア以外を右クリックしたときにトリガーされます。 This is the window titlebar or any area you have declared
as -webkit-app-region: drag
in a frameless window.
Calling event.preventDefault()
will prevent the menu from being displayed.
静的メソッド
The BaseWindow
class has the following static methods:
BaseWindow.getAllWindows()
Returns BaseWindow[]
- An array of all opened browser windows.
BaseWindow.getFocusedWindow()
Returns BaseWindow | null
- The window that is focused in this application, otherwise returns null
.
BaseWindow.fromId(id)
id
Integer
Returns BaseWindow | null
- The window with the given id
.
インスタンスプロパティ
Objects created with new BaseWindow
have the following properties:
const { BaseWindow } = require('electron')
// In this example `win` is our instance
const win = new BaseWindow({ width: 800, height: 600 })
win.id
Readonly
A Integer
property representing the unique ID of the window. Each ID is unique among all BaseWindow
instances of the entire Electron application.
win.contentView
A View
property for the content view of the window.
win.tabbingIdentifier
macOS Readonly
A string
(optional) property that is equal to the tabbingIdentifier
passed to the BrowserWindow
constructor or undefined
if none was set.
win.autoHideMenuBar
A boolean
property that determines whether the window menu bar should hide itself automatically. Once set, the menu bar will only show when users press the single Alt
key.
If the menu bar is already visible, setting this property to true
won't
hide it immediately.
win.simpleFullScreen
A boolean
property that determines whether the window is in simple (pre-Lion) fullscreen mode.
win.fullScreen
A boolean
property that determines whether the window is in fullscreen mode.
win.focusable
Windows macOS
A boolean
property that determines whether the window is focusable.
win.visibleOnAllWorkspaces
macOS Linux
A boolean
property that determines whether the window is visible on all workspaces.
Note: Always returns false on Windows.
win.shadow
A boolean
property that determines whether the window has a shadow.
win.menuBarVisible
Windows Linux
A boolean
property that determines whether the menu bar should be visible.
Note: If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single Alt
key.
win.kiosk
A boolean
property that determines whether the window is in kiosk mode.
win.documentEdited
macOS
A boolean
property that specifies whether the window’s document has been edited.
The icon in title bar will become gray when set to true
.
win.representedFilename
macOS
A string
property that determines the pathname of the file the window represents,
and the icon of the file will show in window's title bar.
win.title
A string
property that determines the title of the native window.
Note: The title of the web page can be different from the title of the native window.
win.minimizable
macOS Windows
A boolean
property that determines whether the window can be manually minimized by user.
On Linux the setter is a no-op, although the getter returns true
.
win.maximizable
macOS Windows
A boolean
property that determines whether the window can be manually maximized by user.
On Linux the setter is a no-op, although the getter returns true
.
win.fullScreenable
A boolean
property that determines whether the maximize/zoom window button toggles fullscreen mode or
maximizes the window.
win.resizable
A boolean
property that determines whether the window can be manually resized by user.
win.closable
macOS Windows
A boolean
property that determines whether the window can be manually closed by user.
On Linux the setter is a no-op, although the getter returns true
.
win.movable
macOS Windows
A boolean
property that determines Whether the window can be moved by user.
On Linux the setter is a no-op, although the getter returns true
.
win.excludedFromShownWindowsMenu
macOS
A boolean
property that determines whether the window is excluded from the application’s Windows menu. false
by default.
const { Menu, BaseWindow } = require('electron')
const win = new BaseWindow({ height: 600, width: 600 })
const template = [
{
role: 'windowmenu'
}
]
win.excludedFromShownWindowsMenu = true
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
win.accessibleTitle
A string
property that defines an alternative title provided only to
accessibility tools such as screen readers. この文字列はユーザに直接表示されません。
インスタンスメソッド
Objects created with new BaseWindow
have the following instance methods:
Note: Some methods are only available on specific operating systems and are labeled as such.
win.setContentView(view)
view
View
Sets the content view of the window.
win.getContentView()
Returns View - The content view of the window.
win.destroy()
Force closing the window, the unload
and beforeunload
event won't be emitted
for the web page, and close
event will also not be emitted
for this window, but it guarantees the closed
event will be emitted.
win.close()
ウインドウを閉じようとします。 これは、ユーザーが手動でウィンドウの閉じるボタンをクリックした場合と同じ効果があります。 ただし、 Web ページはウィンドウが閉じようとするのををキャンセルすることができます。 See the close event.
win.focus()
ウインドウにフォーカスを当てます。
win.blur()
ウインドウからフォーカスを外します。
win.isFocused()
Returns boolean
- Whether the window is focused.
win.isDestroyed()
Returns boolean
- Whether the window is destroyed.
win.show()
表示し、ウインドウにフォーカスを当てます。
win.showInactive()
ウインドウを表示しますが、フォーカスを当てません。
win.hide()
ウインドウを非表示にします。
win.isVisible()
Returns boolean
- Whether the window is visible to the user in the foreground of the app.
win.isModal()
Returns boolean
- Whether current window is a modal window.
win.maximize()
ウィンドウを最大化します。 ウインドウがまだ表示されていない場合、併せてウインドウを表示 (ただし、フォーカスは当たりません) します。
win.unmaximize()
ウインドウの最大化を解除します。
win.isMaximized()
Returns boolean
- Whether the window is maximized.
win.minimize()
ウィンドウを最小化します。 一部のプラットフォームでは、最小化されたウィンドウが Dock に表示されます。
win.restore()
ウインドウを最小化された状態からその前の状態に戻します。
win.isMinimized()
Returns boolean
- Whether the window is minimized.
win.setFullScreen(flag)
flag
boolean
ウインドウをフルスクリーンモードにするかどうかを設定します。
Note: On macOS, fullscreen transitions take place asynchronously. If further actions depend on the fullscreen state, use the 'enter-full-screen' or 'leave-full-screen' events.
win.isFullScreen()
Returns boolean
- Whether the window is in fullscreen mode.
win.setSimpleFullScreen(flag)
macOS
flag
boolean
簡易フルスクリーンモードに設定したり、解除したりします。
macOS Lion (10.7) より前のバージョンで見られる簡易フルスクリーンモードはネイティブのフルスクリーン動作をエミュレートします。
win.isSimpleFullScreen()
macOS
Returns boolean
- Whether the window is in simple (pre-Lion) fullscreen mode.
win.isNormal()
Returns boolean
- Whether the window is in normal state (not maximized, not minimized, not in fullscreen mode).
win.setAspectRatio(aspectRatio[, extraSize])
aspectRatio
Float - The aspect ratio to maintain for some portion of the content view.extraSize
Size (optional) macOS - The extra size not to be included while maintaining the aspect ratio.
これはウインドウのアスペクト比を維持します。 ピクセルで指定した追加のサイズによって、開発者は、アスペクト比の計算に含まれないスペースを確保することができます。 このAPIはウインドウのサイズとそのコンテンツのサイズの差異も考慮しています。
HDビデオプレーヤーと関連したコントロールを持つ通常のウインドウを考えてみましょう。 ひょっとすると、左端に15ピクセルのコントロール、右端に25ピクセルのコントロール、プレーヤーの下部に50ピクセルのコントロールがあるかもしれません。 プレーヤー内で 16:9 アスペクト比 (HD @1920x1280 の標準的なアスペクト比) を維持するためには、この関数を 16/9 と { width: 40, height: 50 } の引数で呼び出します。 2番目の引数は、追加の幅と高さがコンテンツビューの中に収まるかを気にしません。それらはただ存在しているだけです。 全体のコンテンツビュー内にある余分な幅と高さの領域を単純に足し合わせます。
The aspect ratio is not respected when window is resized programmatically with
APIs like win.setSize
.
To reset an aspect ratio, pass 0 as the aspectRatio
value: win.setAspectRatio(0)
.
win.setBackgroundColor(backgroundColor)
backgroundColor
string - Color in Hex, RGB, RGBA, HSL, HSLA or named CSS color format. 16 進数タイプの場合のアルファチャンネルは任意です。
Examples of valid backgroundColor
values:
- Hex
- #fff (略記 RGB)
- #ffff (略記 ARGB)
- #ffffff (RGB)
- #ffffffff (ARGB)
- RGB
rgb\(([\d]+),\s*([\d]+),\s*([\d]+)\)
- 例: rgb(255, 255, 255)
- RGBA
rgba\(([\d]+),\s*([\d]+),\s*([\d]+),\s*([\d.]+)\)
- 例: rgba(255, 255, 255, 1.0)
- HSL
hsl\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%\)
- 例: hsl(200, 20%, 50%)
- HSLA
hsla\((-?[\d.]+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)
- 例: hsla(200, 20%, 50%, 0.5)
- 色の名前
- Options are listed in SkParseColor.cpp
- CSS カラーモジュールレベル 3 のキーワードと似ていますが、大文字と小文字を区別します。
- e.g.
blueviolet
orred
- e.g.
ウィンドウの背景色を設定します。 See Setting backgroundColor
.
win.previewFile(path[, displayName])
macOS
path
string - The absolute path to the file to preview with QuickLook. This is important as Quick Look uses the file name and file extension on the path to determine the content type of the file to open.displayName
string (optional) - The name of the file to display on the Quick Look modal view. This is purely visual and does not affect the content type of the file. Defaults topath
.
Uses Quick Look to preview a file at a given path.
win.closeFilePreview()
macOS
Closes the currently open Quick Look panel.
win.setBounds(bounds[, animate])
bounds
Partial<Rectangle>animate
boolean (optional) macOS
指定した境界までウインドウのサイズを変更して移動します。 指定されていないプロパティは、既定で現在の値になります。
const { BaseWindow } = require('electron')
const win = new BaseWindow()
// set all bounds properties
win.setBounds({ x: 440, y: 225, width: 800, height: 600 })
// set a single bounds property
win.setBounds({ width: 100 })
// { x: 440, y: 225, width: 100, height: 600 }
console.log(win.getBounds())
Note: On macOS, the y-coordinate value cannot be smaller than the Tray height. Tray の高さは時期やオペレーティングシステムによって異なりますが、20 から 40px の間です。 Tray の高さより低い値を渡すと、Tray と同じ高さのウインドウになります。
win.getBounds()
Returns Rectangle - The bounds
of the window as Object
.
Note: On macOS, the y-coordinate value returned will be at minimum the Tray height. For example, calling win.setBounds({ x: 25, y: 20, width: 800, height: 600 })
with a tray height of 38 means that win.getBounds()
will return { x: 25, y: 38, width: 800, height: 600 }
.
win.getBackgroundColor()
Returns string
- Gets the background color of the window in Hex (#RRGGBB
) format.
Note: The alpha value is not returned alongside the red, green, and blue values.
win.setContentBounds(bounds[, animate])
bounds
Rectangleanimate
boolean (optional) macOS
指定した境界までウインドウのクライアント領域 (例えば、Webページ) のサイズを変更して移動します。
win.getContentBounds()
Returns Rectangle - The bounds
of the window's client area as Object
.
win.getNormalBounds()
Returns Rectangle - Contains the window bounds of the normal state
Note: whatever the current state of the window : maximized, minimized or in fullscreen, this function always returns the position and size of the window in normal state. In normal state, getBounds and getNormalBounds returns the same Rectangle.
win.setEnabled(enable)
enable
boolean
ウインドウを無効にするか有効にします。
win.isEnabled()
Returns boolean
- whether the window is enabled.
win.setSize(width, height[, animate])
width
Integerheight
Integeranimate
boolean (optional) macOS
Resizes the window to width
and height
. If width
or height
are below any set minimum size constraints the window will snap to its minimum size.
win.getSize()
Returns Integer[]
- Contains the window's width and height.
win.setContentSize(width, height[, animate])
width
Integerheight
Integeranimate
boolean (optional) macOS
Resizes the window's client area (e.g. the web page) to width
and height
.
win.getContentSize()
Returns Integer[]
- Contains the window's client area's width and height.
win.setMinimumSize(width, height)
width
Integerheight
Integer
Sets the minimum size of window to width
and height
.
win.getMinimumSize()
Returns Integer[]
- Contains the window's minimum width and height.
win.setMaximumSize(width, height)
width
Integerheight
Integer
Sets the maximum size of window to width
and height
.
win.getMaximumSize()
Returns Integer[]
- Contains the window's maximum width and height.
win.setResizable(resizable)
resizable
boolean
ウインドウがユーザによって手動でサイズ変更できるかどうかを設定します。
win.isResizable()
Returns boolean
- Whether the window can be manually resized by the user.
win.setMovable(movable)
macOS Windows
movable
boolean
ウインドウがユーザーによって手動で移動できるかどうかを設定します。 Linux では何もしません。
win.isMovable()
macOS Windows
Returns boolean
- Whether the window can be moved by user.
On Linux always returns true
.
win.setMinimizable(minimizable)
macOS Windows
minimizable
boolean
ウインドウがユーザーによって手動で最小化できるかどうかを設定します。 Linux では何もしません。
win.isMinimizable()
macOS Windows
Returns boolean
- Whether the window can be manually minimized by the user.
On Linux always returns true
.
win.setMaximizable(maximizable)
macOS Windows
maximizable
boolean
ウインドウがユーザーによって手動で最大化できるかどうかを設定します。 Linux では何もしません。
win.isMaximizable()
macOS Windows
Returns boolean
- Whether the window can be manually maximized by user.
On Linux always returns true
.
win.setFullScreenable(fullscreenable)
fullscreenable
boolean
ウインドウの最大化/ズームボタンでフルスクリーンモードに切り替えるか、ウインドウを最大化するかを設定します。
win.isFullScreenable()
Returns boolean
- Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
win.setClosable(closable)
macOS Windows
closable
boolean
ウインドウがユーザーによって手動で閉じられるかどうかを設定します。 Linux では何もしません。
win.isClosable()
macOS Windows
Returns boolean
- Whether the window can be manually closed by user.
On Linux always returns true
.
win.setHiddenInMissionControl(hidden)
macOS
hidden
boolean
ユーザーが Mission Control に切り替えたときに、このウインドウを隠すかどうかを設定します。
win.isHiddenInMissionControl()
macOS
Returns boolean
- Whether the window will be hidden when the user toggles into mission control.
win.setAlwaysOnTop(flag[, level][, relativeLevel])
flag
booleanlevel
string (optional) macOS Windows - Values includenormal
,floating
,torn-off-menu
,modal-panel
,main-menu
,status
,pop-up-menu
,screen-saver
, and(Deprecated). The default isdock
floating
whenflag
is true. Thelevel
is reset tonormal
when the flag is false. Note that fromfloating
tostatus
included, the window is placed below the Dock on macOS and below the taskbar on Windows. Frompop-up-menu
to a higher it is shown above the Dock on macOS and above the taskbar on Windows. See the macOS docs for more details.relativeLevel
Integer (optional) macOS - The number of layers higher to set this window relative to the givenlevel
. The default is0
. Note that Apple discourages setting levels higher than 1 abovescreen-saver
.
ウィンドウを常に他のウィンドウの上に表示するかどうかを設定します。 この設定を行った後でも、ウィンドウはまだ通常のものであり、フォーカスが当てられないツールボックスウィンドウではありません。
win.isAlwaysOnTop()
Returns boolean
- Whether the window is always on top of other windows.
win.moveAbove(mediaSourceId)
mediaSourceId
string - Window id in the format of DesktopCapturerSource's id. 例えば "window:1869:0" 。
Z オーダーの意味で、ウィンドウをソースウィンドウの上に移動します。 If the
mediaSourceId
is not of type window or if the window does not exist then
this method throws an error.
win.moveTop()
フォーカスに関係なく上 (Z順序) にウィンドウを移動します。
win.center()
ウインドウを画面の中央に移動します。
win.setPosition(x, y[, animate])
x
Integery
Integeranimate
boolean (optional) macOS
Moves window to x
and y
.
win.getPosition()
Returns Integer[]
- Contains the window's current position.
win.setTitle(title)
title
string
Changes the title of native window to title
.
win.getTitle()
Returns string
- The title of the native window.
Note: The title of the web page can be different from the title of the native window.
win.setSheetOffset(offsetY[, offsetX])
macOS
offsetY
FloatoffsetX
Float (optional)
macOS においてシートを設置する位置を変更します。 既定では、シートはウィンドウフレームのすぐ下に設置されますが、 HTML で表示されたツールバーの下に表示することもできます。 以下がその例です。
const { BaseWindow } = require('electron')
const win = new BaseWindow()
const toolbarRect = document.getElementById('toolbar').getBoundingClientRect()
win.setSheetOffset(toolbarRect.height)
win.flashFrame(flag)
flag
boolean
ユーザの注意を引きつけるためにウインドウの点滅を開始または停止します。
win.setSkipTaskbar(skip)
macOS Windows
skip
boolean
ウインドウがタスクバーに表示されなくなります。
win.setKiosk(flag)
flag
boolean
キオスクモードに入ったり出たりします。
win.isKiosk()
Returns boolean
- Whether the window is in kiosk mode.
win.isTabletMode()
Windows
Returns boolean
- Whether the window is in Windows 10 tablet mode.
Since Windows 10 users can use their PC as tablet, under this mode apps can choose to optimize their UI for tablets, such as enlarging the titlebar and hiding titlebar buttons.
This API returns whether the window is in tablet mode, and the resize
event
can be be used to listen to changes to tablet mode.
win.getMediaSourceId()
Returns string
- Window id in the format of DesktopCapturerSource's id. 例えば "window:1324:0" 。
More precisely the format is window:id:other_id
where id
is HWND
on
Windows, CGWindowID
(uint64_t
) on macOS and Window
(unsigned long
) on
Linux. other_id
is used to identify web contents (tabs) so within the same
top level window.
win.getNativeWindowHandle()
Returns Buffer
- The platform-specific handle of the window.
The native type of the handle is HWND
on Windows, NSView*
on macOS, and
Window
(unsigned long
) on Linux.
win.hookWindowMessage(message, callback)
Windows
message
Integercallback
FunctionwParam
Buffer - ThewParam
provided to the WndProclParam
Buffer - ThelParam
provided to the WndProc
ウィンドウメッセージをフックします。 The callback
is called when
the message is received in the WndProc.
win.isWindowMessageHooked(message)
Windows
message
Integer
Returns boolean
- true
or false
depending on whether the message is hooked.
win.unhookWindowMessage(message)
Windows
message
Integer
ウインドウメッセージのフックを解除します。
win.unhookAllWindowMessages()
Windows
すべてのウインドウメッセージのフックを解除します。
win.setRepresentedFilename(filename)
macOS
filename
string
ウインドウが表すファイルのパス名を設定します。ファイルのアイコンがウインドウのタイトルバーに表示されます。
win.getRepresentedFilename()
macOS
Returns string
- The pathname of the file the window represents.
win.setDocumentEdited(edited)
macOS
edited
boolean
Specifies whether the window’s document has been edited, and the icon in title
bar will become gray when set to true
.
win.isDocumentEdited()
macOS
Returns boolean
- Whether the window's document has been edited.
win.setMenu(menu)
Linux Windows
menu
Menu | null
Sets the menu
as the window's menu bar.
win.removeMenu()
Linux Windows
ウインドウのメニューバーを消去します。
win.setProgressBar(progress[, options])
progress
Double
プログレスバーの進捗を設定します。 有効な範囲は [0, 1.0] です。
進捗 < 0 の場合、プログレスバーは削除されます。進捗 > 1 の場合、不確定モードに変更します。
On Linux platform, only supports Unity desktop environment, you need to specify
the *.desktop
file name to desktopName
field in package.json
. By default,
it will assume {app.name}.desktop
.
Windowsでは、モードを渡すことができます。 Accepted values are none
, normal
,
indeterminate
, error
, and paused
. If you call setProgressBar
without a
mode set (but with a value within the valid range), normal
will be assumed.
win.setOverlayIcon(overlay, description)
Windows
overlay
NativeImage | null - the icon to display on the bottom right corner of the taskbar icon. If this parameter isnull
, the overlay is cleareddescription
string - a description that will be provided to Accessibility screen readers
現在のタスクバーアイコンの上に、通常、何らかのアプリケーションステータスを伝えたり、ユーザーに控えめに通知したりするのに使われる16 x 16ピクセルのオーバレイを設定します。
win.invalidateShadow()
macOS
ウインドウの影を現在のウインドウの形状に基づいて再計算するように更新します。
BaseWindow
s that are transparent can sometimes leave behind visual artifacts on macOS.
このメソッドは、例えばアニメーションを実行するときにこれらの残留物を消去するときに利用できます。
win.setHasShadow(hasShadow)
hasShadow
boolean
ウインドウに影を付けるべきかどうかを設定します。
win.hasShadow()
Returns boolean
- Whether the window has a shadow.
win.setOpacity(opacity)
Windows macOS
opacity
number - between 0.0 (fully transparent) and 1.0 (fully opaque)
ウィンドウの不透明度を設定します。 Linux では何もしません。 範囲外の値は [0, 1] に収められます。
win.getOpacity()
Returns number
- between 0.0 (fully transparent) and 1.0 (fully opaque). Linuxでは常に 1 を返します。
win.setShape(rects)
Windows Linux Experimental
rects
Rectangle[] - Sets a shape on the window. 空のリストを渡すと、ウィンドウが四角形に戻ります。
ウィンドウの形を設定すると、システム内で描画とユーザ操作が許可されているウィンドウ内の領域が決まります。 与えられた領域の外側のピクセルでは描画されず、マウスイベントも登録されません。 領域外のマウスイベントはそのウィンドウでは受信されませんが、ウィンドウの後ろにあるものにそのイベントがフォールスルーします。
win.setThumbarButtons(buttons)
Windows
buttons
ThumbarButton[]
Returns boolean
- Whether the buttons were added successfully
タスクバーボタンレイアウトのウインドウのサムネイルイメージに指定されたボタンのセットと一緒にサムネイルツールバーを追加します。 Returns a boolean
object indicates
whether the thumbnail has been added successfully.
限られた空間のため、サムネイルツールバーのボタン数は、7以下にしてください。 一度、サムネイルツールバーをセットアップすると、プラットフォームの制約のため、ツールバーを削除することはできません。 しかしながら、ボタンを取り除くためにAPIを空の配列で呼び出すことはできます。
The buttons
is an array of Button
objects:
Button
Objecticon
NativeImage - The icon showing in thumbnail toolbar.click
Functiontooltip
string (optional) - The text of the button's tooltip.flags
string[] (optional) - Control specific states and behaviors of the button. By default, it is['enabled']
.
The flags
is an array that can include following string
s:
enabled
- The button is active and available to the user.disabled
- The button is disabled. It is present, but has a visual state indicating it will not respond to user action.dismissonclick
- When the button is clicked, the thumbnail window closes immediately.nobackground
- Do not draw a button border, use only the image.hidden
- The button is not shown to the user.noninteractive
- The button is enabled but not interactive; no pressed button state is drawn. This value is intended for instances where the button is used in a notification.
win.setThumbnailClip(region)
Windows
region
Rectangle - Region of the window
タスクバーのウインドウの上でホバリングするときに表示されるサムネイルイメージとして表示するウインドウの領域を設定します。 You can reset the thumbnail to be
the entire window by specifying an empty region:
{ x: 0, y: 0, width: 0, height: 0 }
.
win.setThumbnailToolTip(toolTip)
Windows
toolTip
string
タスクバーのウインドウサムネイルでホバリングするときに表示されるツールチップを設定します。
win.setAppDetails(options)
Windows
ウインドウのタスクバーボタンのプロパティを設定します。
Note: relaunchCommand
and relaunchDisplayName
must always be set
together. いずれかが設定されていない場合、どちらも使用されません。
win.setIcon(icon)
Windows Linux
icon
NativeImage | string
ウインドウのアイコンを変更します。
win.setWindowButtonVisibility(visible)
macOS
visible
boolean
ウインドウの信号ボタンを表示するかどうかを設定します。
win.setAutoHideMenuBar(hide)
Windows Linux
hide
boolean
ウィンドウのメニューバーを自動的に非表示にするかどうかを設定します。 Once set the
menu bar will only show when users press the single Alt
key.
If the menu bar is already visible, calling setAutoHideMenuBar(true)
won't hide it immediately.
win.isMenuBarAutoHide()
Windows Linux
Returns boolean
- Whether menu bar automatically hides itself.
win.setMenuBarVisibility(visible)
Windows Linux
visible
boolean
メニューバーを表示するかどうかを設定します。 If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single Alt
key.
win.isMenuBarVisible()
Windows Linux
Returns boolean
- Whether the menu bar is visible.
win.setVisibleOnAllWorkspaces(visible[, options])
macOS Linux
visible
boolean
ウインドウをすべてのワークスペースで表示させるかどうかを設定します。
Note: This API does nothing on Windows.
win.isVisibleOnAllWorkspaces()
macOS Linux
Returns boolean
- Whether the window is visible on all workspaces.
Note: This API always returns false on Windows.
win.setIgnoreMouseEvents(ignore[, options])
ignore
boolean
ウインドウがすべてのマウスイベントを無視するようにします。
このウインドウで発生するすべてのマウスイベントは、このウインドウの下にあるウインドウに渡されますが、このウインドウにフォーカスがある場合、依然としてキーボードイベントは受信されます。
win.setContentProtection(enable)
macOS Windows
enable
boolean
他のアプリによってウインドウのコンテンツがキャプチャされるのを防止します。
macOS では、NSWindow の共有タイプを NSWindowSharingNone に設定します。
On Windows it calls SetWindowDisplayAffinity with WDA_EXCLUDEFROMCAPTURE
.
For Windows 10 version 2004 and up the window will be removed from capture entirely,
older Windows versions behave as if WDA_MONITOR
is applied capturing a black window.
win.setFocusable(focusable)
macOS Windows
focusable
boolean
ウインドウにフォーカスできるかどうかを変更します。
macOS ではウィンドウからフォーカスは除去されません。
win.isFocusable()
macOS Windows
Returns boolean
- Whether the window can be focused.
win.setParentWindow(parent)
parent
BaseWindow | null
Sets parent
as current window's parent window, passing null
will turn
current window into a top-level window.
win.getParentWindow()
Returns BaseWindow | null
- The parent window or null
if there is no parent.
win.getChildWindows()
Returns BaseWindow[]
- All child windows.
win.setAutoHideCursor(autoHide)
macOS
autoHide
boolean
タイプしているときにカーソルを非表示にするかどうかを制御します。
win.selectPreviousTab()
macOS
ネイティブのタブが有効で、ウインドウに他のタブがあるとき、一つ前のタブを選択します。
win.selectNextTab()
macOS
ネイティブのタブが有効で、ウインドウに他のタブがあるとき、次のタブを選択します。
win.showAllTabs()
macOS
ネイティブのタブが有効な場合に、タブの概要を表示または非表示にします。
win.mergeAllWindows()
macOS
ネイティブのタブが有効で複数の開いているウインドウがあるとき、すべてのウインドウを複数のタブで1つのウインドウにマージします。
win.moveTabToNewWindow()
macOS
ネイティブのタブが有効で現在のウインドウに複数のタブがあるとき、現在のタブを新しいウインドウに移動します。
win.toggleTabBar()
macOS
ネイティブのタブが有効で現在のウインドウにタブが1つだけしかないとき、タブバーを表示するかどうかを切り替えます。
win.addTabbedWindow(baseWindow)
macOS
baseWindow
BaseWindow
ウインドウインスタンスのタブの後ろに、このウインドウのタブとしてウインドウを追加します。
win.setVibrancy(type)
macOS
type
string | null - Can betitlebar
,selection
,menu
,popover
,sidebar
,header
,sheet
,window
,hud
,fullscreen-ui
,tooltip
,content
,under-window
, orunder-page
. See the macOS documentation for more details.
Adds a vibrancy effect to the window. Passing null
or an empty string
will remove the vibrancy effect on the window.
win.setBackgroundMaterial(material)
Windows
material
stringauto
- Let the Desktop Window Manager (DWM) automatically decide the system-drawn backdrop material for this window. これが既定値です。none
- Don't draw any system backdrop.mica
- Draw the backdrop material effect corresponding to a long-lived window.acrylic
- Draw the backdrop material effect corresponding to a transient window.tabbed
- Draw the backdrop material effect corresponding to a window with a tabbed title bar.
このメソッドは、非クライアント領域の背後を含む、ブラウザウインドウのシステム描画の背景マテリアルを設定します。
See the Windows documentation for more details.
Note: This method is only supported on Windows 11 22H2 and up.
win.setWindowButtonPosition(position)
macOS
position
Point | null
フレームレスウインドウにおける信号機ボタンのカスタム位置を設定します。
Passing null
will reset the position to default.
win.getWindowButtonPosition()
macOS
Returns Point | null
- The custom position for the traffic light buttons in
frameless window, null
will be returned when there is no custom position.
win.setTouchBar(touchBar)
macOS
touchBar
TouchBar | null
現在のウインドウのTouchBarレイアウトを設定します。 Specifying null
or
undefined
clears the touch bar. このメソッドは TouchBar 搭載マシンでのみ作用します。
Note: The TouchBar API is currently experimental and may change or be removed in future Electron releases.
win.setTitleBarOverlay(options)
Windows
ウインドウコントロールオーバーレイがすでに有効になっているウインドウに対して、このメソッドはそのタイトルバーオーバーレイのスタイルを更新します。