Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename TopLevelWindow to BaseWindow #24305

Merged
merged 1 commit into from Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion filenames.auto.gni
Expand Up @@ -190,6 +190,7 @@ auto_filenames = {
"lib/browser/api/auto-updater/auto-updater-native.js",
"lib/browser/api/auto-updater/auto-updater-win.js",
"lib/browser/api/auto-updater/squirrel-update-win.js",
"lib/browser/api/base-window.ts",
"lib/browser/api/browser-view.ts",
"lib/browser/api/browser-window.ts",
"lib/browser/api/content-tracing.ts",
Expand All @@ -216,7 +217,6 @@ auto_filenames = {
"lib/browser/api/screen.ts",
"lib/browser/api/session.ts",
"lib/browser/api/system-preferences.ts",
"lib/browser/api/top-level-window.ts",
"lib/browser/api/touch-bar.js",
"lib/browser/api/tray.ts",
"lib/browser/api/view.ts",
Expand Down
4 changes: 2 additions & 2 deletions filenames.gni
Expand Up @@ -44,6 +44,8 @@ filenames = {
"shell/browser/api/electron_api_app_mac.mm",
"shell/browser/api/electron_api_auto_updater.cc",
"shell/browser/api/electron_api_auto_updater.h",
"shell/browser/api/electron_api_base_window.cc",
"shell/browser/api/electron_api_base_window.h",
"shell/browser/api/electron_api_browser_view.cc",
"shell/browser/api/electron_api_browser_view.h",
"shell/browser/api/electron_api_browser_window.cc",
Expand Down Expand Up @@ -102,8 +104,6 @@ filenames = {
"shell/browser/api/electron_api_system_preferences.h",
"shell/browser/api/electron_api_system_preferences_mac.mm",
"shell/browser/api/electron_api_system_preferences_win.cc",
"shell/browser/api/electron_api_top_level_window.cc",
"shell/browser/api/electron_api_top_level_window.h",
"shell/browser/api/electron_api_tray.cc",
"shell/browser/api/electron_api_tray.h",
"shell/browser/api/electron_api_url_loader.cc",
Expand Down
@@ -1,10 +1,10 @@
import { EventEmitter } from 'events';
import type { TopLevelWindow as TLWT } from 'electron';
const { TopLevelWindow } = process._linkedBinding('electron_browser_top_level_window') as { TopLevelWindow: typeof TLWT };
import type { BaseWindow as TLWT } from 'electron';
const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT };

Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype);
Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype);

(TopLevelWindow.prototype as any)._init = function () {
(BaseWindow.prototype as any)._init = function () {
// Avoid recursive require.
const { app } = require('electron');

Expand All @@ -17,88 +17,88 @@ Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype);

// Properties

Object.defineProperty(TopLevelWindow.prototype, 'autoHideMenuBar', {
Object.defineProperty(BaseWindow.prototype, 'autoHideMenuBar', {
get: function () { return this.isMenuBarAutoHide(); },
set: function (autoHide) { this.setAutoHideMenuBar(autoHide); }
});

Object.defineProperty(TopLevelWindow.prototype, 'visibleOnAllWorkspaces', {
Object.defineProperty(BaseWindow.prototype, 'visibleOnAllWorkspaces', {
get: function () { return this.isVisibleOnAllWorkspaces(); },
set: function (visible) { this.setVisibleOnAllWorkspaces(visible); }
});

Object.defineProperty(TopLevelWindow.prototype, 'fullScreen', {
Object.defineProperty(BaseWindow.prototype, 'fullScreen', {
get: function () { return this.isFullScreen(); },
set: function (full) { this.setFullScreen(full); }
});

Object.defineProperty(TopLevelWindow.prototype, 'simpleFullScreen', {
Object.defineProperty(BaseWindow.prototype, 'simpleFullScreen', {
get: function () { return this.isSimpleFullScreen(); },
set: function (simple) { this.setSimpleFullScreen(simple); }
});

Object.defineProperty(TopLevelWindow.prototype, 'kiosk', {
Object.defineProperty(BaseWindow.prototype, 'kiosk', {
get: function () { return this.isKiosk(); },
set: function (kiosk) { this.setKiosk(kiosk); }
});

Object.defineProperty(TopLevelWindow.prototype, 'documentEdited', {
Object.defineProperty(BaseWindow.prototype, 'documentEdited', {
get: function () { return this.isFullscreen(); },
set: function (edited) { this.setDocumentEdited(edited); }
});

Object.defineProperty(TopLevelWindow.prototype, 'shadow', {
Object.defineProperty(BaseWindow.prototype, 'shadow', {
get: function () { return this.hasShadow(); },
set: function (shadow) { this.setHasShadow(shadow); }
});

Object.defineProperty(TopLevelWindow.prototype, 'representedFilename', {
Object.defineProperty(BaseWindow.prototype, 'representedFilename', {
get: function () { return this.getRepresentedFilename(); },
set: function (filename) { this.setRepresentedFilename(filename); }
});

Object.defineProperty(TopLevelWindow.prototype, 'minimizable', {
Object.defineProperty(BaseWindow.prototype, 'minimizable', {
get: function () { return this.isMinimizable(); },
set: function (min) { this.setMinimizable(min); }
});

Object.defineProperty(TopLevelWindow.prototype, 'title', {
Object.defineProperty(BaseWindow.prototype, 'title', {
get: function () { return this.getTitle(); },
set: function (title) { this.setTitle(title); }
});

Object.defineProperty(TopLevelWindow.prototype, 'maximizable', {
Object.defineProperty(BaseWindow.prototype, 'maximizable', {
get: function () { return this.isMaximizable(); },
set: function (max) { this.setMaximizable(max); }
});

Object.defineProperty(TopLevelWindow.prototype, 'resizable', {
Object.defineProperty(BaseWindow.prototype, 'resizable', {
get: function () { return this.isResizable(); },
set: function (res) { this.setResizable(res); }
});

Object.defineProperty(TopLevelWindow.prototype, 'menuBarVisible', {
Object.defineProperty(BaseWindow.prototype, 'menuBarVisible', {
get: function () { return this.isMenuBarVisible(); },
set: function (visible) { this.setMenuBarVisibility(visible); }
});

Object.defineProperty(TopLevelWindow.prototype, 'fullScreenable', {
Object.defineProperty(BaseWindow.prototype, 'fullScreenable', {
get: function () { return this.isFullScreenable(); },
set: function (full) { this.setFullScreenable(full); }
});

Object.defineProperty(TopLevelWindow.prototype, 'closable', {
Object.defineProperty(BaseWindow.prototype, 'closable', {
get: function () { return this.isClosable(); },
set: function (close) { this.setClosable(close); }
});

Object.defineProperty(TopLevelWindow.prototype, 'movable', {
Object.defineProperty(BaseWindow.prototype, 'movable', {
get: function () { return this.isMovable(); },
set: function (move) { this.setMovable(move); }
});

TopLevelWindow.getFocusedWindow = () => {
return TopLevelWindow.getAllWindows().find((win) => win.isFocused());
BaseWindow.getFocusedWindow = () => {
return BaseWindow.getAllWindows().find((win) => win.isFocused());
};

module.exports = TopLevelWindow;
module.exports = BaseWindow;
10 changes: 5 additions & 5 deletions lib/browser/api/browser-window.ts
@@ -1,12 +1,12 @@
import { TopLevelWindow, WebContents, Event, BrowserView, TouchBar } from 'electron';
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron';
import type { BrowserWindow as BWT } from 'electron';
const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT };

Object.setPrototypeOf(BrowserWindow.prototype, TopLevelWindow.prototype);
Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype);

(BrowserWindow.prototype as any)._init = function (this: BWT) {
// Call parent class's _init.
(TopLevelWindow.prototype as any)._init.call(this);
(BaseWindow.prototype as any)._init.call(this);

// Avoid recursive require.
const { app } = require('electron');
Expand Down Expand Up @@ -74,12 +74,12 @@ const isBrowserWindow = (win: any) => {
};

BrowserWindow.fromId = (id: number) => {
const win = TopLevelWindow.fromId(id);
const win = BaseWindow.fromId(id);
return isBrowserWindow(win) ? win as any as BWT : null;
};

BrowserWindow.getAllWindows = () => {
return TopLevelWindow.getAllWindows().filter(isBrowserWindow) as any[] as BWT[];
return BaseWindow.getAllWindows().filter(isBrowserWindow) as any[] as BWT[];
};

BrowserWindow.getFocusedWindow = () => {
Expand Down
14 changes: 7 additions & 7 deletions lib/browser/api/menu.js
@@ -1,6 +1,6 @@
'use strict';

const { TopLevelWindow, MenuItem, webContents } = require('electron');
const { BaseWindow, MenuItem, webContents } = require('electron');
const { sortMenuItems } = require('@electron/internal/browser/api/menu-utils');
const EventEmitter = require('events').EventEmitter;
const v8Util = process._linkedBinding('electron_common_v8_util');
Expand Down Expand Up @@ -46,7 +46,7 @@ Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) {
Menu.prototype._executeCommand = function (event, id) {
const command = this.commandsMap[id];
if (!command) return;
command.click(event, TopLevelWindow.getFocusedWindow(), webContents.getFocusedWebContents());
command.click(event, BaseWindow.getFocusedWindow(), webContents.getFocusedWebContents());
};

Menu.prototype._menuWillShow = function () {
Expand All @@ -72,14 +72,14 @@ Menu.prototype.popup = function (options = {}) {
if (typeof positioningItem !== 'number') positioningItem = -1;

// find which window to use
const wins = TopLevelWindow.getAllWindows();
const wins = BaseWindow.getAllWindows();
if (!wins || wins.indexOf(window) === -1) {
window = TopLevelWindow.getFocusedWindow();
window = BaseWindow.getFocusedWindow();
if (!window && wins && wins.length > 0) {
window = wins[0];
}
if (!window) {
throw new Error('Cannot open Menu without a TopLevelWindow present');
throw new Error('Cannot open Menu without a BaseWindow present');
}
}

Expand All @@ -88,7 +88,7 @@ Menu.prototype.popup = function (options = {}) {
};

Menu.prototype.closePopup = function (window) {
if (window instanceof TopLevelWindow) {
if (window instanceof BaseWindow) {
this.closePopupAt(window.id);
} else {
// Passing -1 (invalid) would make closePopupAt close the all menu runners
Expand Down Expand Up @@ -168,7 +168,7 @@ Menu.setApplicationMenu = function (menu) {
menu._callMenuWillShow();
bindings.setApplicationMenu(menu);
} else {
const windows = TopLevelWindow.getAllWindows();
const windows = BaseWindow.getAllWindows();
return windows.map(w => w.setMenu(menu));
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/module-list.ts
Expand Up @@ -4,6 +4,7 @@
export const browserModuleList: ElectronInternal.ModuleEntry[] = [
{ name: 'app', loader: () => require('./app') },
{ name: 'autoUpdater', loader: () => require('./auto-updater') },
{ name: 'BaseWindow', loader: () => require('./base-window') },
{ name: 'BrowserView', loader: () => require('./browser-view') },
{ name: 'BrowserWindow', loader: () => require('./browser-window') },
{ name: 'contentTracing', loader: () => require('./content-tracing') },
Expand All @@ -25,7 +26,6 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [
{ name: 'screen', loader: () => require('./screen') },
{ name: 'session', loader: () => require('./session') },
{ name: 'systemPreferences', loader: () => require('./system-preferences') },
{ name: 'TopLevelWindow', loader: () => require('./top-level-window') },
{ name: 'TouchBar', loader: () => require('./touch-bar') },
{ name: 'Tray', loader: () => require('./tray') },
{ name: 'View', loader: () => require('./view') },
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/module-names.ts
Expand Up @@ -7,6 +7,7 @@
export const browserModuleNames = [
'app',
'autoUpdater',
'BaseWindow',
'BrowserView',
'BrowserWindow',
'contentTracing',
Expand All @@ -28,7 +29,6 @@ export const browserModuleNames = [
'screen',
'session',
'systemPreferences',
'TopLevelWindow',
'TouchBar',
'Tray',
'View',
Expand Down