Skip to content

Commit

Permalink
refactor: convert browser window state fns to props (#18618)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 5, 2019
1 parent 164cc43 commit a0b1f4f
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 60 deletions.
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_system_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void SystemPreferences::BuildPrototype(
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
.SetMethod("getEffectiveAppearance",
&SystemPreferences::GetEffectiveAppearance)
.SetMethod("getAppLevelAppearance",
.SetMethod("_getAppLevelAppearance",
&SystemPreferences::GetAppLevelAppearance)
.SetMethod("setAppLevelAppearance",
.SetMethod("_setAppLevelAppearance",
&SystemPreferences::SetAppLevelAppearance)
.SetProperty("appLevelAppearance",
&SystemPreferences::GetAppLevelAppearance,
Expand Down
36 changes: 24 additions & 12 deletions atom/browser/api/atom_api_top_level_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1070,19 +1070,31 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setMaximumSize", &TopLevelWindow::SetMaximumSize)
.SetMethod("getMaximumSize", &TopLevelWindow::GetMaximumSize)
.SetMethod("setSheetOffset", &TopLevelWindow::SetSheetOffset)
.SetMethod("setResizable", &TopLevelWindow::SetResizable)
.SetMethod("isResizable", &TopLevelWindow::IsResizable)
.SetMethod("setMovable", &TopLevelWindow::SetMovable)
.SetMethod("moveTop", &TopLevelWindow::MoveTop)
.SetMethod("isMovable", &TopLevelWindow::IsMovable)
.SetMethod("setMinimizable", &TopLevelWindow::SetMinimizable)
.SetMethod("isMinimizable", &TopLevelWindow::IsMinimizable)
.SetMethod("setMaximizable", &TopLevelWindow::SetMaximizable)
.SetMethod("isMaximizable", &TopLevelWindow::IsMaximizable)
.SetMethod("setFullScreenable", &TopLevelWindow::SetFullScreenable)
.SetMethod("isFullScreenable", &TopLevelWindow::IsFullScreenable)
.SetMethod("setClosable", &TopLevelWindow::SetClosable)
.SetMethod("isClosable", &TopLevelWindow::IsClosable)
.SetMethod("_setResizable", &TopLevelWindow::SetResizable)
.SetMethod("_isResizable", &TopLevelWindow::IsResizable)
.SetProperty("resizable", &TopLevelWindow::IsResizable,
&TopLevelWindow::SetResizable)
.SetMethod("_setMovable", &TopLevelWindow::SetMovable)
.SetMethod("_isMovable", &TopLevelWindow::IsMovable)
.SetProperty("movable", &TopLevelWindow::IsMovable,
&TopLevelWindow::SetMovable)
.SetMethod("_setMinimizable", &TopLevelWindow::SetMinimizable)
.SetMethod("_isMinimizable", &TopLevelWindow::IsMinimizable)
.SetProperty("minimizable", &TopLevelWindow::IsMinimizable,
&TopLevelWindow::SetMinimizable)
.SetMethod("_setMaximizable", &TopLevelWindow::SetMaximizable)
.SetMethod("_isMaximizable", &TopLevelWindow::IsMaximizable)
.SetProperty("maximizable", &TopLevelWindow::IsMaximizable,
&TopLevelWindow::SetMaximizable)
.SetMethod("_setFullScreenable", &TopLevelWindow::SetFullScreenable)
.SetMethod("_isFullScreenable", &TopLevelWindow::IsFullScreenable)
.SetProperty("fullScreenable", &TopLevelWindow::IsFullScreenable,
&TopLevelWindow::SetFullScreenable)
.SetMethod("_setClosable", &TopLevelWindow::SetClosable)
.SetMethod("_isClosable", &TopLevelWindow::IsClosable)
.SetProperty("closable", &TopLevelWindow::IsClosable,
&TopLevelWindow::SetClosable)
.SetMethod("setAlwaysOnTop", &TopLevelWindow::SetAlwaysOnTop)
.SetMethod("isAlwaysOnTop", &TopLevelWindow::IsAlwaysOnTop)
.SetMethod("center", &TopLevelWindow::Center)
Expand Down
57 changes: 57 additions & 0 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -1009,72 +1009,96 @@ Returns `Integer[]` - Contains the window's maximum width and height.

Sets whether the window can be manually resized by user.

**[Deprecated](modernization/property-updates.md)**

#### `win.isResizable()`

Returns `Boolean` - Whether the window can be manually resized by user.

**[Deprecated](modernization/property-updates.md)**

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

* `movable` Boolean

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

**[Deprecated](modernization/property-updates.md)**

#### `win.isMovable()` _macOS_ _Windows_

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

On Linux always returns `true`.

**[Deprecated](modernization/property-updates.md)**

#### `win.setMinimizable(minimizable)` _macOS_ _Windows_

* `minimizable` Boolean

Sets whether the window can be manually minimized by user. On Linux does
nothing.

**[Deprecated](modernization/property-updates.md)**

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

Returns `Boolean` - Whether the window can be manually minimized by user

On Linux always returns `true`.

**[Deprecated](modernization/property-updates.md)**

#### `win.setMaximizable(maximizable)` _macOS_ _Windows_

* `maximizable` Boolean

Sets whether the window can be manually maximized by user. On Linux does
nothing.

**[Deprecated](modernization/property-updates.md)**

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

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

On Linux always returns `true`.

**[Deprecated](modernization/property-updates.md)**

#### `win.setFullScreenable(fullscreenable)`

* `fullscreenable` Boolean

Sets whether the maximize/zoom window button toggles fullscreen mode or
maximizes the window.

**[Deprecated](modernization/property-updates.md)**

#### `win.isFullScreenable()`

Returns `Boolean` - Whether the maximize/zoom window button toggles fullscreen mode or
maximizes the window.

**[Deprecated](modernization/property-updates.md)**

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

* `closable` Boolean

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

**[Deprecated](modernization/property-updates.md)**

#### `win.isClosable()` _macOS_ _Windows_

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

On Linux always returns `true`.

**[Deprecated](modernization/property-updates.md)**

#### `win.setAlwaysOnTop(flag[, level][, relativeLevel])`

* `flag` Boolean
Expand Down Expand Up @@ -1653,6 +1677,39 @@ A `Boolean` property that determines whether the window menu bar should hide its
If the menu bar is already visible, setting this property to `true` won't
hide it immediately.

#### `win.minimizable`

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`

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`

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`

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.
Expand Down
12 changes: 6 additions & 6 deletions docs/api/modernization/property-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `BrowserWindow`
* `fullscreen`
* `simpleFullscreen`
* `movable`
* `resizable`
* `maximizable`
* `minimizable`
* `fullscreenable`
* `closable`
* `alwaysOnTop`
* `title`
* `documentEdited`
Expand Down Expand Up @@ -55,6 +49,12 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `name`
* `BrowserWindow` module
* `autohideMenuBar`
* `resizable`
* `maximizable`
* `minimizable`
* `fullscreenable`
* `movable`
* `closable`
* `NativeImage`
* `isMacTemplateImage`
* `SystemPreferences` module
Expand Down
6 changes: 3 additions & 3 deletions lib/browser/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ for (const name of events) {
}

// Property Deprecations
deprecate.fnToProperty(app, 'accessibilitySupportEnabled', '_isAccessibilitySupportEnabled', '_setAccessibilitySupportEnabled')
deprecate.fnToProperty(app, 'badgeCount', '_getBadgeCount', '_setBadgeCount')
deprecate.fnToProperty(app, 'name', '_getName', '_setName')
deprecate.fnToProperty(App.prototype, 'accessibilitySupportEnabled', '_isAccessibilitySupportEnabled', '_setAccessibilitySupportEnabled')
deprecate.fnToProperty(App.prototype, 'badgeCount', '_getBadgeCount', '_setBadgeCount')
deprecate.fnToProperty(App.prototype, 'name', '_getName', '_setName')

// Wrappers for native classes.
const { DownloadItem } = process.electronBinding('download_item')
Expand Down
6 changes: 6 additions & 0 deletions lib/browser/api/browser-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,11 @@ Object.assign(BrowserWindow.prototype, {

// Deprecations
deprecate.fnToProperty(BrowserWindow.prototype, 'autoHideMenuBar', '_isMenuBarAutoHide', '_setAutoHideMenuBar')
deprecate.fnToProperty(BrowserWindow.prototype, 'minimizable', '_isMinimizable', '_setMinimizable')
deprecate.fnToProperty(BrowserWindow.prototype, 'maximizable', '_isMaximizable', '_setMaximizable')
deprecate.fnToProperty(BrowserWindow.prototype, 'resizable', '_isResizable', '_setResizable')
deprecate.fnToProperty(BrowserWindow.prototype, 'fullScreenable', '_isFullScreenable', '_setFullScreenable')
deprecate.fnToProperty(BrowserWindow.prototype, 'closable', '_isClosable', '_setClosable')
deprecate.fnToProperty(BrowserWindow.prototype, 'movable', '_isMovable', '_setMovable')

module.exports = BrowserWindow
2 changes: 1 addition & 1 deletion lib/browser/api/system-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype)
EventEmitter.call(systemPreferences)

if ('appLevelAppearance' in systemPreferences) {
deprecate.fnToProperty(systemPreferences, 'appLevelAppearance', '_getAppLevelAppearance', '_setAppLevelAppearance')
deprecate.fnToProperty(SystemPreferences.prototype, 'appLevelAppearance', '_getAppLevelAppearance', '_setAppLevelAppearance')
}

module.exports = systemPreferences
13 changes: 7 additions & 6 deletions lib/common/api/deprecate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ const deprecate: ElectronInternal.DeprecationUtil = {
},

// deprecate a getter/setter function pair in favor of a property
fnToProperty: (module: any, prop: string, getter: string, setter: string) => {
const withWarnOnce = (obj: any, key: any, oldName: string, newName: string) => {
fnToProperty: (prototype: any, prop: string, getter: string, setter: string) => {
const withWarnOnce = function (obj: any, key: any, oldName: string, newName: string) {
const warn = warnOnce(oldName, newName)
return (...args: any) => {
const method = obj[key]
return function (this: any, ...args: any) {
warn()
return obj[key](...args)
return method.apply(this, args)
}
}

module[getter.substr(1)] = withWarnOnce(module, getter, `${getter.substr(1)} function`, `${prop} property`)
module[setter.substr(1)] = withWarnOnce(module, setter, `${setter.substr(1)} function`, `${prop} property`)
prototype[getter.substr(1)] = withWarnOnce(prototype, getter, `${getter.substr(1)} function`, `${prop} property`)
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`)
},

// remove a property with no replacement
Expand Down

0 comments on commit a0b1f4f

Please sign in to comment.