base-window.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { EventEmitter } from 'events';
  2. import type { BaseWindow as TLWT } from 'electron/main';
  3. const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT };
  4. Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype);
  5. BaseWindow.prototype._init = function () {
  6. // Avoid recursive require.
  7. const { app } = require('electron');
  8. // Simulate the application menu on platforms other than macOS.
  9. if (process.platform !== 'darwin') {
  10. const menu = app.applicationMenu;
  11. if (menu) this.setMenu(menu);
  12. }
  13. };
  14. // Properties
  15. Object.defineProperty(BaseWindow.prototype, 'autoHideMenuBar', {
  16. get: function () { return this.isMenuBarAutoHide(); },
  17. set: function (autoHide) { this.setAutoHideMenuBar(autoHide); }
  18. });
  19. Object.defineProperty(BaseWindow.prototype, 'visibleOnAllWorkspaces', {
  20. get: function () { return this.isVisibleOnAllWorkspaces(); },
  21. set: function (visible) { this.setVisibleOnAllWorkspaces(visible); }
  22. });
  23. Object.defineProperty(BaseWindow.prototype, 'fullScreen', {
  24. get: function () { return this.isFullScreen(); },
  25. set: function (full) { this.setFullScreen(full); }
  26. });
  27. Object.defineProperty(BaseWindow.prototype, 'simpleFullScreen', {
  28. get: function () { return this.isSimpleFullScreen(); },
  29. set: function (simple) { this.setSimpleFullScreen(simple); }
  30. });
  31. Object.defineProperty(BaseWindow.prototype, 'focusable', {
  32. get: function () { return this.isFocusable(); },
  33. set: function (focusable) { this.setFocusable(focusable); }
  34. });
  35. Object.defineProperty(BaseWindow.prototype, 'kiosk', {
  36. get: function () { return this.isKiosk(); },
  37. set: function (kiosk) { this.setKiosk(kiosk); }
  38. });
  39. Object.defineProperty(BaseWindow.prototype, 'documentEdited', {
  40. get: function () { return this.isDocumentEdited(); },
  41. set: function (edited) { this.setDocumentEdited(edited); }
  42. });
  43. Object.defineProperty(BaseWindow.prototype, 'shadow', {
  44. get: function () { return this.hasShadow(); },
  45. set: function (shadow) { this.setHasShadow(shadow); }
  46. });
  47. Object.defineProperty(BaseWindow.prototype, 'representedFilename', {
  48. get: function () { return this.getRepresentedFilename(); },
  49. set: function (filename) { this.setRepresentedFilename(filename); }
  50. });
  51. Object.defineProperty(BaseWindow.prototype, 'minimizable', {
  52. get: function () { return this.isMinimizable(); },
  53. set: function (min) { this.setMinimizable(min); }
  54. });
  55. Object.defineProperty(BaseWindow.prototype, 'title', {
  56. get: function () { return this.getTitle(); },
  57. set: function (title) { this.setTitle(title); }
  58. });
  59. Object.defineProperty(BaseWindow.prototype, 'maximizable', {
  60. get: function () { return this.isMaximizable(); },
  61. set: function (max) { this.setMaximizable(max); }
  62. });
  63. Object.defineProperty(BaseWindow.prototype, 'resizable', {
  64. get: function () { return this.isResizable(); },
  65. set: function (res) { this.setResizable(res); }
  66. });
  67. Object.defineProperty(BaseWindow.prototype, 'menuBarVisible', {
  68. get: function () { return this.isMenuBarVisible(); },
  69. set: function (visible) { this.setMenuBarVisibility(visible); }
  70. });
  71. Object.defineProperty(BaseWindow.prototype, 'fullScreenable', {
  72. get: function () { return this.isFullScreenable(); },
  73. set: function (full) { this.setFullScreenable(full); }
  74. });
  75. Object.defineProperty(BaseWindow.prototype, 'closable', {
  76. get: function () { return this.isClosable(); },
  77. set: function (close) { this.setClosable(close); }
  78. });
  79. Object.defineProperty(BaseWindow.prototype, 'movable', {
  80. get: function () { return this.isMovable(); },
  81. set: function (move) { this.setMovable(move); }
  82. });
  83. BaseWindow.getFocusedWindow = () => {
  84. return BaseWindow.getAllWindows().find((win) => win.isFocused());
  85. };
  86. module.exports = BaseWindow;