From cdf874ee2dd5f34066546f3cc96be40cbe06ba3a Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 21 Aug 2023 15:58:09 +0200 Subject: [PATCH] chore: remove deprecated `getTrafficLightPosition()` / `setTrafficLightPosition()` (#39479) chore: remove deprecated getTrafficLightPosition() / setTrafficLightPosition() --- docs/api/browser-window.md | 19 ---------------- docs/breaking-changes.md | 40 +++++++++++++++++++++++++++++++++ lib/browser/api/base-window.ts | 20 ----------------- spec/api-browser-window-spec.ts | 40 --------------------------------- 4 files changed, 40 insertions(+), 79 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index d5d61e47e963a..6e829db202ed7 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1595,25 +1595,6 @@ Passing `null` will reset the position to default. 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.setTrafficLightPosition(position)` _macOS_ _Deprecated_ - -* `position` [Point](structures/point.md) - -Set a custom position for the traffic light buttons in frameless window. -Passing `{ x: 0, y: 0 }` will reset the position to default. - -> **Note** -> This function is deprecated. Use [setWindowButtonPosition](#winsetwindowbuttonpositionposition-macos) instead. - -#### `win.getTrafficLightPosition()` _macOS_ _Deprecated_ - -Returns `Point` - The custom position for the traffic light buttons in -frameless window, `{ x: 0, y: 0 }` will be returned when there is no custom -position. - -> **Note** -> This function is deprecated. Use [getWindowButtonPosition](#wingetwindowbuttonposition-macos) instead. - #### `win.setTouchBar(touchBar)` _macOS_ * `touchBar` TouchBar | null diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index e71bb5690d76b..7a15b66b1fd40 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -12,6 +12,46 @@ This document uses the following convention to categorize breaking changes: * **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release. * **Removed:** An API or feature was removed, and is no longer supported by Electron. +## Planned Breaking API Changes (28.0) + +### Removed: `BrowserWindow.setTrafficLightPosition(position)` + +`BrowserWindow.setTrafficLightPosition(position)` has been removed, the +`BrowserWindow.setWindowButtonPosition(position)` API should be used instead +which accepts `null` instead of `{ x: 0, y: 0 }` to reset the position to +system default. + +```js +// Removed in Electron 28 +win.setTrafficLightPosition({ x: 10, y: 10 }) +win.setTrafficLightPosition({ x: 0, y: 0 }) + +// Replace with +win.setWindowButtonPosition({ x: 10, y: 10 }) +win.setWindowButtonPosition(null) +``` + +### Removed: `BrowserWindow.getTrafficLightPosition()` + +`BrowserWindow.getTrafficLightPosition()` has been removed, the +`BrowserWindow.getWindowButtonPosition()` API should be used instead +which returns `null` instead of `{ x: 0, y: 0 }` when there is no custom +position. + +```js +// Removed in Electron 28 +const pos = win.getTrafficLightPosition() +if (pos.x === 0 && pos.y === 0) { + // No custom position. +} + +// Replace with +const ret = win.getWindowButtonPosition() +if (ret === null) { + // No custom position. +} +``` + ## Planned Breaking API Changes (27.0) ### Removed: macOS 10.13 / 10.14 support diff --git a/lib/browser/api/base-window.ts b/lib/browser/api/base-window.ts index 45a200e125d67..28671d7c1de7c 100644 --- a/lib/browser/api/base-window.ts +++ b/lib/browser/api/base-window.ts @@ -1,6 +1,5 @@ import { EventEmitter } from 'events'; import type { BaseWindow as TLWT } from 'electron/main'; -import * as deprecate from '@electron/internal/common/deprecate'; const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT }; Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype); @@ -16,25 +15,6 @@ BaseWindow.prototype._init = function () { } }; -// Deprecation. -const setTrafficLightPositionDeprecated = deprecate.warnOnce('setTrafficLightPosition', 'setWindowButtonPosition'); -// Converting to any as the methods are defined under BrowserWindow in our docs. -(BaseWindow as any).prototype.setTrafficLightPosition = function (pos: Electron.Point) { - setTrafficLightPositionDeprecated(); - if (typeof pos === 'object' && pos.x === 0 && pos.y === 0) { - this.setWindowButtonPosition(null); - } else { - this.setWindowButtonPosition(pos); - } -}; - -const getTrafficLightPositionDeprecated = deprecate.warnOnce('getTrafficLightPosition', 'getWindowButtonPosition'); -(BaseWindow as any).prototype.getTrafficLightPosition = function () { - getTrafficLightPositionDeprecated(); - const pos = this.getWindowButtonPosition(); - return pos === null ? { x: 0, y: 0 } : pos; -}; - // Properties Object.defineProperty(BaseWindow.prototype, 'autoHideMenuBar', { diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index c2057bce7b32a..05fff05840651 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -2580,46 +2580,6 @@ describe('BrowserWindow module', () => { expect(w.getWindowButtonPosition()).to.deep.equal(newPos); }); }); - - // The set/getTrafficLightPosition APIs are deprecated. - describe('BrowserWindow.getTrafficLightPosition(pos)', () => { - it('returns { x: 0, y: 0 } when there is no custom position', () => { - const w = new BrowserWindow({ show: false }); - expect(w.getTrafficLightPosition()).to.deep.equal({ x: 0, y: 0 }); - }); - - it('gets position property for "hidden" titleBarStyle', () => { - const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos }); - expect(w.getTrafficLightPosition()).to.deep.equal(pos); - }); - - it('gets position property for "customButtonsOnHover" titleBarStyle', () => { - const w = new BrowserWindow({ show: false, titleBarStyle: 'customButtonsOnHover', trafficLightPosition: pos }); - expect(w.getTrafficLightPosition()).to.deep.equal(pos); - }); - }); - - describe('BrowserWindow.setTrafficLightPosition(pos)', () => { - it('resets the position when { x: 0, y: 0 } is passed', () => { - const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos }); - w.setTrafficLightPosition({ x: 0, y: 0 }); - expect(w.getTrafficLightPosition()).to.deep.equal({ x: 0, y: 0 }); - }); - - it('sets position property for "hidden" titleBarStyle', () => { - const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos }); - const newPos = { x: 20, y: 20 }; - w.setTrafficLightPosition(newPos); - expect(w.getTrafficLightPosition()).to.deep.equal(newPos); - }); - - it('sets position property for "customButtonsOnHover" titleBarStyle', () => { - const w = new BrowserWindow({ show: false, titleBarStyle: 'customButtonsOnHover', trafficLightPosition: pos }); - const newPos = { x: 20, y: 20 }; - w.setTrafficLightPosition(newPos); - expect(w.getTrafficLightPosition()).to.deep.equal(newPos); - }); - }); }); ifdescribe(process.platform === 'win32')('BrowserWindow.setAppDetails(options)', () => {