build: allow use of BUILDFLAG directives from within JS code (#20328)
This commit is contained in:
		
					parent
					
						
							
								f9c04449f4
							
						
					
				
			
			
				commit
				
					
						392ea320cf
					
				
			
		
					 16 changed files with 132 additions and 74 deletions
				
			
		| 
						 | 
				
			
			@ -1,47 +0,0 @@
 | 
			
		|||
'use strict';
 | 
			
		||||
 | 
			
		||||
// TODO: Figure out a way to not duplicate this information between here and module-list
 | 
			
		||||
// It is currently duplicated as module-list "require"s all the browser API file and the
 | 
			
		||||
// remote module in the renderer process depends on that file.  As a result webpack
 | 
			
		||||
// includes all the browser API files in the renderer process as well and we want to avoid that
 | 
			
		||||
 | 
			
		||||
const features = process.electronBinding('features');
 | 
			
		||||
 | 
			
		||||
// Browser side modules, please sort alphabetically.
 | 
			
		||||
module.exports = [
 | 
			
		||||
  { name: 'app' },
 | 
			
		||||
  { name: 'autoUpdater' },
 | 
			
		||||
  { name: 'BrowserView' },
 | 
			
		||||
  { name: 'BrowserWindow' },
 | 
			
		||||
  { name: 'contentTracing' },
 | 
			
		||||
  { name: 'crashReporter' },
 | 
			
		||||
  { name: 'dialog' },
 | 
			
		||||
  { name: 'globalShortcut' },
 | 
			
		||||
  { name: 'ipcMain' },
 | 
			
		||||
  { name: 'inAppPurchase' },
 | 
			
		||||
  { name: 'Menu' },
 | 
			
		||||
  { name: 'MenuItem' },
 | 
			
		||||
  { name: 'nativeTheme' },
 | 
			
		||||
  { name: 'net' },
 | 
			
		||||
  { name: 'netLog' },
 | 
			
		||||
  { name: 'MessageChannelMain' },
 | 
			
		||||
  { name: 'Notification' },
 | 
			
		||||
  { name: 'powerMonitor' },
 | 
			
		||||
  { name: 'powerSaveBlocker' },
 | 
			
		||||
  { name: 'protocol' },
 | 
			
		||||
  { name: 'screen' },
 | 
			
		||||
  { name: 'session' },
 | 
			
		||||
  { name: 'systemPreferences' },
 | 
			
		||||
  { name: 'TopLevelWindow' },
 | 
			
		||||
  { name: 'TouchBar' },
 | 
			
		||||
  { name: 'Tray' },
 | 
			
		||||
  { name: 'View' },
 | 
			
		||||
  { name: 'webContents' },
 | 
			
		||||
  { name: 'WebContentsView' }
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
if (features.isViewApiEnabled()) {
 | 
			
		||||
  module.exports.push(
 | 
			
		||||
    { name: 'ImageView' }
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,5 @@
 | 
			
		|||
// TODO: Updating this file also required updating the module-keys file
 | 
			
		||||
 | 
			
		||||
const features = process.electronBinding('features');
 | 
			
		||||
 | 
			
		||||
// Browser side modules, please sort alphabetically.
 | 
			
		||||
export const browserModuleList: ElectronInternal.ModuleEntry[] = [
 | 
			
		||||
  { name: 'app', loader: () => require('./app') },
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +33,7 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [
 | 
			
		|||
  { name: 'WebContentsView', loader: () => require('./web-contents-view') }
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
if (features.isViewApiEnabled()) {
 | 
			
		||||
if (BUILDFLAG(ENABLE_VIEWS_API)) {
 | 
			
		||||
  browserModuleList.push(
 | 
			
		||||
    { name: 'ImageView', loader: () => require('./views/image-view') }
 | 
			
		||||
  );
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										43
									
								
								lib/browser/api/module-names.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								lib/browser/api/module-names.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
// TODO: Figure out a way to not duplicate this information between here and module-list
 | 
			
		||||
// It is currently duplicated as module-list "require"s all the browser API file and the
 | 
			
		||||
// remote module in the renderer process depends on that file.  As a result webpack
 | 
			
		||||
// includes all the browser API files in the renderer process as well and we want to avoid that
 | 
			
		||||
 | 
			
		||||
// Browser side modules, please sort alphabetically.
 | 
			
		||||
export const browserModuleNames = [
 | 
			
		||||
  'app',
 | 
			
		||||
  'autoUpdater',
 | 
			
		||||
  'BrowserView',
 | 
			
		||||
  'BrowserWindow',
 | 
			
		||||
  'contentTracing',
 | 
			
		||||
  'crashReporter',
 | 
			
		||||
  'dialog',
 | 
			
		||||
  'globalShortcut',
 | 
			
		||||
  'ipcMain',
 | 
			
		||||
  'inAppPurchase',
 | 
			
		||||
  'Menu',
 | 
			
		||||
  'MenuItem',
 | 
			
		||||
  'nativeTheme',
 | 
			
		||||
  'net',
 | 
			
		||||
  'netLog',
 | 
			
		||||
  'MessageChannelMain',
 | 
			
		||||
  'Notification',
 | 
			
		||||
  'powerMonitor',
 | 
			
		||||
  'powerSaveBlocker',
 | 
			
		||||
  'protocol',
 | 
			
		||||
  'screen',
 | 
			
		||||
  'session',
 | 
			
		||||
  'systemPreferences',
 | 
			
		||||
  'TopLevelWindow',
 | 
			
		||||
  'TouchBar',
 | 
			
		||||
  'Tray',
 | 
			
		||||
  'View',
 | 
			
		||||
  'webContents',
 | 
			
		||||
  'WebContentsView'
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
if (BUILDFLAG(ENABLE_VIEWS_API)) {
 | 
			
		||||
  browserModuleNames.push(
 | 
			
		||||
    'ImageView'
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
'use strict';
 | 
			
		||||
 | 
			
		||||
const features = process.electronBinding('features');
 | 
			
		||||
const { EventEmitter } = require('events');
 | 
			
		||||
const electron = require('electron');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
| 
						 | 
				
			
			@ -341,7 +340,7 @@ WebContents.prototype.printToPDF = function (options) {
 | 
			
		|||
  printSettings.scaleFactor = Math.ceil(printSettings.scaleFactor) % 100;
 | 
			
		||||
  // PrinterType enum from //printing/print_job_constants.h
 | 
			
		||||
  printSettings.printerType = 2;
 | 
			
		||||
  if (features.isPrintingEnabled()) {
 | 
			
		||||
  if (this._printToPDF) {
 | 
			
		||||
    return this._printToPDF(printSettings);
 | 
			
		||||
  } else {
 | 
			
		||||
    const error = new Error('Printing feature is disabled');
 | 
			
		||||
| 
						 | 
				
			
			@ -375,7 +374,7 @@ WebContents.prototype.print = function (options = {}, callback) {
 | 
			
		|||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (features.isPrintingEnabled()) {
 | 
			
		||||
  if (this._print) {
 | 
			
		||||
    if (callback) {
 | 
			
		||||
      this._print(options, callback);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -387,7 +386,7 @@ WebContents.prototype.print = function (options = {}, callback) {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
WebContents.prototype.getPrinters = function () {
 | 
			
		||||
  if (features.isPrintingEnabled()) {
 | 
			
		||||
  if (this._getPrinters) {
 | 
			
		||||
    return this._getPrinters();
 | 
			
		||||
  } else {
 | 
			
		||||
    console.error('Error: Printing feature is disabled.');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue