Skip to content

Commit 3b062b8

Browse files
authored
chore: support props/fns for BrowserWindow (electron#24074) (electron#24162)
1 parent bcd0250 commit 3b062b8

File tree

4 files changed

+316
-296
lines changed

4 files changed

+316
-296
lines changed

docs/api/browser-window.md

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,98 +1092,70 @@ Returns `Integer[]` - Contains the window's maximum width and height.
10921092

10931093
* `resizable` Boolean
10941094

1095-
Sets whether the window can be manually resized by user.
1096-
1097-
**[Deprecated](modernization/property-updates.md)**
1095+
Sets whether the window can be manually resized by the user.
10981096

10991097
#### `win.isResizable()`
11001098

1101-
Returns `Boolean` - Whether the window can be manually resized by user.
1102-
1103-
**[Deprecated](modernization/property-updates.md)**
1099+
Returns `Boolean` - Whether the window can be manually resized by the user.
11041100

11051101
#### `win.setMovable(movable)` _macOS_ _Windows_
11061102

11071103
* `movable` Boolean
11081104

11091105
Sets whether the window can be moved by user. On Linux does nothing.
11101106

1111-
**[Deprecated](modernization/property-updates.md)**
1112-
11131107
#### `win.isMovable()` _macOS_ _Windows_
11141108

11151109
Returns `Boolean` - Whether the window can be moved by user.
11161110

11171111
On Linux always returns `true`.
11181112

1119-
**[Deprecated](modernization/property-updates.md)**
1120-
11211113
#### `win.setMinimizable(minimizable)` _macOS_ _Windows_
11221114

11231115
* `minimizable` Boolean
11241116

1125-
Sets whether the window can be manually minimized by user. On Linux does
1126-
nothing.
1127-
1128-
**[Deprecated](modernization/property-updates.md)**
1117+
Sets whether the window can be manually minimized by user. On Linux does nothing.
11291118

11301119
#### `win.isMinimizable()` _macOS_ _Windows_
11311120

1132-
Returns `Boolean` - Whether the window can be manually minimized by user
1121+
Returns `Boolean` - Whether the window can be manually minimized by the user.
11331122

11341123
On Linux always returns `true`.
11351124

1136-
**[Deprecated](modernization/property-updates.md)**
1137-
11381125
#### `win.setMaximizable(maximizable)` _macOS_ _Windows_
11391126

11401127
* `maximizable` Boolean
11411128

1142-
Sets whether the window can be manually maximized by user. On Linux does
1143-
nothing.
1144-
1145-
**[Deprecated](modernization/property-updates.md)**
1129+
Sets whether the window can be manually maximized by user. On Linux does nothing.
11461130

11471131
#### `win.isMaximizable()` _macOS_ _Windows_
11481132

11491133
Returns `Boolean` - Whether the window can be manually maximized by user.
11501134

11511135
On Linux always returns `true`.
11521136

1153-
**[Deprecated](modernization/property-updates.md)**
1154-
11551137
#### `win.setFullScreenable(fullscreenable)`
11561138

11571139
* `fullscreenable` Boolean
11581140

1159-
Sets whether the maximize/zoom window button toggles fullscreen mode or
1160-
maximizes the window.
1161-
1162-
**[Deprecated](modernization/property-updates.md)**
1141+
Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
11631142

11641143
#### `win.isFullScreenable()`
11651144

1166-
Returns `Boolean` - Whether the maximize/zoom window button toggles fullscreen mode or
1167-
maximizes the window.
1168-
1169-
**[Deprecated](modernization/property-updates.md)**
1145+
Returns `Boolean` - Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
11701146

11711147
#### `win.setClosable(closable)` _macOS_ _Windows_
11721148

11731149
* `closable` Boolean
11741150

11751151
Sets whether the window can be manually closed by user. On Linux does nothing.
11761152

1177-
**[Deprecated](modernization/property-updates.md)**
1178-
11791153
#### `win.isClosable()` _macOS_ _Windows_
11801154

11811155
Returns `Boolean` - Whether the window can be manually closed by user.
11821156

11831157
On Linux always returns `true`.
11841158

1185-
**[Deprecated](modernization/property-updates.md)**
1186-
11871159
#### `win.setAlwaysOnTop(flag[, level][, relativeLevel])`
11881160

11891161
* `flag` Boolean
@@ -1578,23 +1550,17 @@ This cannot be called when `titleBarStyle` is set to `customButtonsOnHover`.
15781550
Sets whether the window menu bar should hide itself automatically. Once set the
15791551
menu bar will only show when users press the single `Alt` key.
15801552

1581-
If the menu bar is already visible, calling `setAutoHideMenuBar(true)` won't
1582-
hide it immediately.
1583-
1584-
**[Deprecated](modernization/property-updates.md)**
1553+
If the menu bar is already visible, calling `setAutoHideMenuBar(true)` won't hide it immediately.
15851554

15861555
#### `win.isMenuBarAutoHide()`
15871556

15881557
Returns `Boolean` - Whether menu bar automatically hides itself.
15891558

1590-
**[Deprecated](modernization/property-updates.md)**
1591-
15921559
#### `win.setMenuBarVisibility(visible)` _Windows_ _Linux_
15931560

15941561
* `visible` Boolean
15951562

1596-
Sets whether the menu bar should be visible. If the menu bar is auto-hide, users
1597-
can still bring up the menu bar by pressing the single `Alt` key.
1563+
Sets whether the menu bar should be visible. If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single `Alt` key.
15981564

15991565
#### `win.isMenuBarVisible()`
16001566

lib/browser/api/browser-window.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,43 @@ BrowserWindow.prototype._init = function () {
9292
return this.webContents.devToolsWebContents;
9393
}
9494
});
95+
96+
// Properties
97+
98+
Object.defineProperty(this, 'autoHideMenuBar', {
99+
get: () => this.isMenuBarAutoHide(),
100+
set: (autoHide) => this.setAutoHideMenuBar(autoHide)
101+
});
102+
103+
Object.defineProperty(this, 'minimizable', {
104+
get: () => this.isMinimizable(),
105+
set: (min) => this.setMinimizable(min)
106+
});
107+
108+
Object.defineProperty(this, 'maximizable', {
109+
get: () => this.isMaximizable(),
110+
set: (max) => this.setMaximizable(max)
111+
});
112+
113+
Object.defineProperty(this, 'resizable', {
114+
get: () => this.isResizable(),
115+
set: (res) => this.setResizable(res)
116+
});
117+
118+
Object.defineProperty(this, 'fullScreenable', {
119+
get: () => this.isFullScreenable(),
120+
set: (full) => this.setFullScreenable(full)
121+
});
122+
123+
Object.defineProperty(this, 'closable', {
124+
get: () => this.isClosable(),
125+
set: (close) => this.setClosable(close)
126+
});
127+
128+
Object.defineProperty(this, 'movable', {
129+
get: () => this.isMovable(),
130+
set: (move) => this.setMovable(move)
131+
});
95132
};
96133

97134
const isBrowserWindow = (win) => {
@@ -183,13 +220,4 @@ Object.assign(BrowserWindow.prototype, {
183220
}
184221
});
185222

186-
// Deprecations
187-
deprecate.fnToProperty(BrowserWindow.prototype, 'autoHideMenuBar', '_isMenuBarAutoHide', '_setAutoHideMenuBar');
188-
deprecate.fnToProperty(BrowserWindow.prototype, 'minimizable', '_isMinimizable', '_setMinimizable');
189-
deprecate.fnToProperty(BrowserWindow.prototype, 'maximizable', '_isMaximizable', '_setMaximizable');
190-
deprecate.fnToProperty(BrowserWindow.prototype, 'resizable', '_isResizable', '_setResizable');
191-
deprecate.fnToProperty(BrowserWindow.prototype, 'fullScreenable', '_isFullScreenable', '_setFullScreenable');
192-
deprecate.fnToProperty(BrowserWindow.prototype, 'closable', '_isClosable', '_setClosable');
193-
deprecate.fnToProperty(BrowserWindow.prototype, 'movable', '_isMovable', '_setMovable');
194-
195223
module.exports = BrowserWindow;

shell/browser/api/atom_api_top_level_window.cc

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,30 +1087,18 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
10871087
.SetMethod("getMaximumSize", &TopLevelWindow::GetMaximumSize)
10881088
.SetMethod("setSheetOffset", &TopLevelWindow::SetSheetOffset)
10891089
.SetMethod("moveTop", &TopLevelWindow::MoveTop)
1090-
.SetMethod("_setResizable", &TopLevelWindow::SetResizable)
1091-
.SetMethod("_isResizable", &TopLevelWindow::IsResizable)
1092-
.SetProperty("resizable", &TopLevelWindow::IsResizable,
1093-
&TopLevelWindow::SetResizable)
1094-
.SetMethod("_setMovable", &TopLevelWindow::SetMovable)
1095-
.SetMethod("_isMovable", &TopLevelWindow::IsMovable)
1096-
.SetProperty("movable", &TopLevelWindow::IsMovable,
1097-
&TopLevelWindow::SetMovable)
1098-
.SetMethod("_setMinimizable", &TopLevelWindow::SetMinimizable)
1099-
.SetMethod("_isMinimizable", &TopLevelWindow::IsMinimizable)
1100-
.SetProperty("minimizable", &TopLevelWindow::IsMinimizable,
1101-
&TopLevelWindow::SetMinimizable)
1102-
.SetMethod("_setMaximizable", &TopLevelWindow::SetMaximizable)
1103-
.SetMethod("_isMaximizable", &TopLevelWindow::IsMaximizable)
1104-
.SetProperty("maximizable", &TopLevelWindow::IsMaximizable,
1105-
&TopLevelWindow::SetMaximizable)
1106-
.SetMethod("_setFullScreenable", &TopLevelWindow::SetFullScreenable)
1107-
.SetMethod("_isFullScreenable", &TopLevelWindow::IsFullScreenable)
1108-
.SetProperty("fullScreenable", &TopLevelWindow::IsFullScreenable,
1109-
&TopLevelWindow::SetFullScreenable)
1110-
.SetMethod("_setClosable", &TopLevelWindow::SetClosable)
1111-
.SetMethod("_isClosable", &TopLevelWindow::IsClosable)
1112-
.SetProperty("closable", &TopLevelWindow::IsClosable,
1113-
&TopLevelWindow::SetClosable)
1090+
.SetMethod("setResizable", &TopLevelWindow::SetResizable)
1091+
.SetMethod("isResizable", &TopLevelWindow::IsResizable)
1092+
.SetMethod("setMovable", &TopLevelWindow::SetMovable)
1093+
.SetMethod("isMovable", &TopLevelWindow::IsMovable)
1094+
.SetMethod("setMinimizable", &TopLevelWindow::SetMinimizable)
1095+
.SetMethod("isMinimizable", &TopLevelWindow::IsMinimizable)
1096+
.SetMethod("setMaximizable", &TopLevelWindow::SetMaximizable)
1097+
.SetMethod("isMaximizable", &TopLevelWindow::IsMaximizable)
1098+
.SetMethod("setFullScreenable", &TopLevelWindow::SetFullScreenable)
1099+
.SetMethod("isFullScreenable", &TopLevelWindow::IsFullScreenable)
1100+
.SetMethod("setClosable", &TopLevelWindow::SetClosable)
1101+
.SetMethod("isClosable", &TopLevelWindow::IsClosable)
11141102
.SetMethod("setAlwaysOnTop", &TopLevelWindow::SetAlwaysOnTop)
11151103
.SetMethod("isAlwaysOnTop", &TopLevelWindow::IsAlwaysOnTop)
11161104
.SetMethod("center", &TopLevelWindow::Center)
@@ -1174,10 +1162,8 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
11741162
&TopLevelWindow::IsExcludedFromShownWindowsMenu,
11751163
&TopLevelWindow::SetExcludedFromShownWindowsMenu)
11761164
#endif
1177-
.SetMethod("_setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
1178-
.SetMethod("_isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)
1179-
.SetProperty("autoHideMenuBar", &TopLevelWindow::IsMenuBarAutoHide,
1180-
&TopLevelWindow::SetAutoHideMenuBar)
1165+
.SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
1166+
.SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)
11811167
.SetMethod("setMenuBarVisibility", &TopLevelWindow::SetMenuBarVisibility)
11821168
.SetMethod("isMenuBarVisible", &TopLevelWindow::IsMenuBarVisible)
11831169
.SetMethod("setAspectRatio", &TopLevelWindow::SetAspectRatio)

0 commit comments

Comments
 (0)