2020-06-29 01:22:55 +00:00
|
|
|
import { EventEmitter } from 'events';
|
2020-07-13 16:58:49 +00:00
|
|
|
import type { BaseWindow as TLWT } from 'electron/main';
|
2023-02-17 10:06:32 +00:00
|
|
|
import * as deprecate from '@electron/internal/common/deprecate';
|
2020-06-29 07:06:20 +00:00
|
|
|
const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT };
|
2018-04-17 07:29:16 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype);
|
2018-04-17 07:29:16 +00:00
|
|
|
|
2020-10-08 01:01:23 +00:00
|
|
|
BaseWindow.prototype._init = function () {
|
2018-04-17 07:46:32 +00:00
|
|
|
// Avoid recursive require.
|
2020-06-29 01:22:55 +00:00
|
|
|
const { app } = require('electron');
|
2018-04-17 07:46:32 +00:00
|
|
|
|
|
|
|
// Simulate the application menu on platforms other than macOS.
|
|
|
|
if (process.platform !== 'darwin') {
|
2019-04-02 20:36:57 +00:00
|
|
|
const menu = app.applicationMenu;
|
2018-04-17 07:46:32 +00:00
|
|
|
if (menu) this.setMenu(menu);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-17 10:06:32 +00:00
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2020-04-01 15:22:32 +00:00
|
|
|
// Properties
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'autoHideMenuBar', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isMenuBarAutoHide(); },
|
|
|
|
set: function (autoHide) { this.setAutoHideMenuBar(autoHide); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'visibleOnAllWorkspaces', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isVisibleOnAllWorkspaces(); },
|
|
|
|
set: function (visible) { this.setVisibleOnAllWorkspaces(visible); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'fullScreen', {
|
2020-04-21 03:25:18 +00:00
|
|
|
get: function () { return this.isFullScreen(); },
|
|
|
|
set: function (full) { this.setFullScreen(full); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'simpleFullScreen', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isSimpleFullScreen(); },
|
|
|
|
set: function (simple) { this.setSimpleFullScreen(simple); }
|
|
|
|
});
|
|
|
|
|
2021-04-21 10:32:19 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'focusable', {
|
|
|
|
get: function () { return this.isFocusable(); },
|
|
|
|
set: function (focusable) { this.setFocusable(focusable); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'kiosk', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isKiosk(); },
|
|
|
|
set: function (kiosk) { this.setKiosk(kiosk); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'documentEdited', {
|
2021-02-22 20:33:46 +00:00
|
|
|
get: function () { return this.isDocumentEdited(); },
|
2020-04-01 15:22:32 +00:00
|
|
|
set: function (edited) { this.setDocumentEdited(edited); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'shadow', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.hasShadow(); },
|
|
|
|
set: function (shadow) { this.setHasShadow(shadow); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'representedFilename', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.getRepresentedFilename(); },
|
|
|
|
set: function (filename) { this.setRepresentedFilename(filename); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'minimizable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isMinimizable(); },
|
|
|
|
set: function (min) { this.setMinimizable(min); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'title', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.getTitle(); },
|
|
|
|
set: function (title) { this.setTitle(title); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'maximizable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isMaximizable(); },
|
|
|
|
set: function (max) { this.setMaximizable(max); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'resizable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isResizable(); },
|
|
|
|
set: function (res) { this.setResizable(res); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'menuBarVisible', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isMenuBarVisible(); },
|
|
|
|
set: function (visible) { this.setMenuBarVisibility(visible); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'fullScreenable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isFullScreenable(); },
|
|
|
|
set: function (full) { this.setFullScreenable(full); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'closable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isClosable(); },
|
|
|
|
set: function (close) { this.setClosable(close); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
Object.defineProperty(BaseWindow.prototype, 'movable', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isMovable(); },
|
|
|
|
set: function (move) { this.setMovable(move); }
|
|
|
|
});
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow.getFocusedWindow = () => {
|
|
|
|
return BaseWindow.getAllWindows().find((win) => win.isFocused());
|
2018-04-17 08:14:49 +00:00
|
|
|
};
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
module.exports = BaseWindow;
|