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';
|
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-06-29 07:06:20 +00:00
|
|
|
(BaseWindow.prototype as any)._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') {
|
2020-03-20 20:28:31 +00:00
|
|
|
const menu = app.applicationMenu;
|
|
|
|
if (menu) this.setMenu(menu);
|
2018-04-17 07:46:32 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2018-04-17 07:46:32 +00:00
|
|
|
|
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); }
|
|
|
|
});
|
|
|
|
|
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', {
|
2020-04-01 15:22:32 +00:00
|
|
|
get: function () { return this.isFullscreen(); },
|
|
|
|
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());
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2018-04-17 08:14:49 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
module.exports = BaseWindow;
|