feat: add BrowserWindow.set/getWindowButtonPosition APIs (#37094)

This commit is contained in:
Cheng Zhao 2023-02-17 19:06:32 +09:00 committed by GitHub
parent 0a5e634736
commit 0de1012280
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 188 additions and 26 deletions

View file

@ -1,5 +1,6 @@
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);
@ -15,6 +16,25 @@ 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', {