build: enable JS semicolons (#22783)
This commit is contained in:
parent
24e21467b9
commit
5d657dece4
354 changed files with 21512 additions and 21510 deletions
|
@ -1,29 +1,29 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const clipboard = process.electronBinding('clipboard')
|
||||
const clipboard = process.electronBinding('clipboard');
|
||||
|
||||
if (process.type === 'renderer') {
|
||||
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils')
|
||||
const typeUtils = require('@electron/internal/common/type-utils')
|
||||
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils');
|
||||
const typeUtils = require('@electron/internal/common/type-utils');
|
||||
|
||||
const makeRemoteMethod = function (method) {
|
||||
return (...args) => {
|
||||
args = typeUtils.serialize(args)
|
||||
const result = ipcRendererUtils.invokeSync('ELECTRON_BROWSER_CLIPBOARD', method, ...args)
|
||||
return typeUtils.deserialize(result)
|
||||
}
|
||||
}
|
||||
args = typeUtils.serialize(args);
|
||||
const result = ipcRendererUtils.invokeSync('ELECTRON_BROWSER_CLIPBOARD', method, ...args);
|
||||
return typeUtils.deserialize(result);
|
||||
};
|
||||
};
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
// On Linux we could not access clipboard in renderer process.
|
||||
for (const method of Object.keys(clipboard)) {
|
||||
clipboard[method] = makeRemoteMethod(method)
|
||||
clipboard[method] = makeRemoteMethod(method);
|
||||
}
|
||||
} else if (process.platform === 'darwin') {
|
||||
// Read/write to find pasteboard over IPC since only main process is notified of changes
|
||||
clipboard.readFindText = makeRemoteMethod('readFindText')
|
||||
clipboard.writeFindText = makeRemoteMethod('writeFindText')
|
||||
clipboard.readFindText = makeRemoteMethod('readFindText');
|
||||
clipboard.writeFindText = makeRemoteMethod('writeFindText');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = clipboard
|
||||
module.exports = clipboard;
|
||||
|
|
|
@ -1,95 +1,95 @@
|
|||
let deprecationHandler: ElectronInternal.DeprecationHandler | null = null
|
||||
let deprecationHandler: ElectronInternal.DeprecationHandler | null = null;
|
||||
|
||||
function warnOnce (oldName: string, newName?: string) {
|
||||
let warned = false
|
||||
let warned = false;
|
||||
const msg = newName
|
||||
? `'${oldName}' is deprecated and will be removed. Please use '${newName}' instead.`
|
||||
: `'${oldName}' is deprecated and will be removed.`
|
||||
: `'${oldName}' is deprecated and will be removed.`;
|
||||
return () => {
|
||||
if (!warned && !process.noDeprecation) {
|
||||
warned = true
|
||||
deprecate.log(msg)
|
||||
warned = true;
|
||||
deprecate.log(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const deprecate: ElectronInternal.DeprecationUtil = {
|
||||
warnOnce,
|
||||
setHandler: (handler) => { deprecationHandler = handler },
|
||||
setHandler: (handler) => { deprecationHandler = handler; },
|
||||
getHandler: () => deprecationHandler,
|
||||
warn: (oldName, newName) => {
|
||||
if (!process.noDeprecation) {
|
||||
deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`)
|
||||
deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`);
|
||||
}
|
||||
},
|
||||
log: (message) => {
|
||||
if (typeof deprecationHandler === 'function') {
|
||||
deprecationHandler(message)
|
||||
deprecationHandler(message);
|
||||
} else if (process.throwDeprecation) {
|
||||
throw new Error(message)
|
||||
throw new Error(message);
|
||||
} else if (process.traceDeprecation) {
|
||||
return console.trace(message)
|
||||
return console.trace(message);
|
||||
} else {
|
||||
return console.warn(`(electron) ${message}`)
|
||||
return console.warn(`(electron) ${message}`);
|
||||
}
|
||||
},
|
||||
|
||||
// remove a function with no replacement
|
||||
removeFunction: (fn, removedName) => {
|
||||
if (!fn) { throw Error(`'${removedName} function' is invalid or does not exist.`) }
|
||||
if (!fn) { throw Error(`'${removedName} function' is invalid or does not exist.`); }
|
||||
|
||||
// wrap the deprecated function to warn user
|
||||
const warn = warnOnce(`${fn.name} function`)
|
||||
const warn = warnOnce(`${fn.name} function`);
|
||||
return function (this: any) {
|
||||
warn()
|
||||
fn.apply(this, arguments)
|
||||
}
|
||||
warn();
|
||||
fn.apply(this, arguments);
|
||||
};
|
||||
},
|
||||
|
||||
// change the name of a function
|
||||
renameFunction: (fn, newName) => {
|
||||
const warn = warnOnce(`${fn.name} function`, `${newName} function`)
|
||||
const warn = warnOnce(`${fn.name} function`, `${newName} function`);
|
||||
return function (this: any) {
|
||||
warn()
|
||||
return fn.apply(this, arguments)
|
||||
}
|
||||
warn();
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
},
|
||||
|
||||
moveAPI: (fn: Function, oldUsage: string, newUsage: string) => {
|
||||
const warn = warnOnce(oldUsage, newUsage)
|
||||
const warn = warnOnce(oldUsage, newUsage);
|
||||
return function (this: any) {
|
||||
warn()
|
||||
return fn.apply(this, arguments)
|
||||
}
|
||||
warn();
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
},
|
||||
|
||||
// change the name of an event
|
||||
event: (emitter, oldName, newName) => {
|
||||
const warn = newName.startsWith('-') /* internal event */
|
||||
? warnOnce(`${oldName} event`)
|
||||
: warnOnce(`${oldName} event`, `${newName} event`)
|
||||
: warnOnce(`${oldName} event`, `${newName} event`);
|
||||
return emitter.on(newName, function (this: NodeJS.EventEmitter, ...args) {
|
||||
if (this.listenerCount(oldName) !== 0) {
|
||||
warn()
|
||||
this.emit(oldName, ...args)
|
||||
warn();
|
||||
this.emit(oldName, ...args);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
// deprecate a getter/setter function pair in favor of a property
|
||||
fnToProperty: (prototype: any, prop: string, getter: string, setter?: string) => {
|
||||
const withWarnOnce = function (obj: any, key: any, oldName: string, newName: string) {
|
||||
const warn = warnOnce(oldName, newName)
|
||||
const method = obj[key]
|
||||
const warn = warnOnce(oldName, newName);
|
||||
const method = obj[key];
|
||||
return function (this: any, ...args: any) {
|
||||
warn()
|
||||
return method.apply(this, args)
|
||||
}
|
||||
}
|
||||
warn();
|
||||
return method.apply(this, args);
|
||||
};
|
||||
};
|
||||
|
||||
prototype[getter.substr(1)] = withWarnOnce(prototype, getter, `${getter.substr(1)} function`, `${prop} property`)
|
||||
prototype[getter.substr(1)] = withWarnOnce(prototype, getter, `${getter.substr(1)} function`, `${prop} property`);
|
||||
if (setter) {
|
||||
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`)
|
||||
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -98,55 +98,55 @@ const deprecate: ElectronInternal.DeprecationUtil = {
|
|||
// if the property's already been removed, warn about it
|
||||
const info = Object.getOwnPropertyDescriptor((o as any).__proto__, removedName) // eslint-disable-line
|
||||
if (!info) {
|
||||
deprecate.log(`Unable to remove property '${removedName}' from an object that lacks it.`)
|
||||
return o
|
||||
deprecate.log(`Unable to remove property '${removedName}' from an object that lacks it.`);
|
||||
return o;
|
||||
}
|
||||
if (!info.get || !info.set) {
|
||||
deprecate.log(`Unable to remove property '${removedName}' from an object does not have a getter / setter`)
|
||||
return o
|
||||
deprecate.log(`Unable to remove property '${removedName}' from an object does not have a getter / setter`);
|
||||
return o;
|
||||
}
|
||||
|
||||
// wrap the deprecated property in an accessor to warn
|
||||
const warn = warnOnce(removedName)
|
||||
const warn = warnOnce(removedName);
|
||||
return Object.defineProperty(o, removedName, {
|
||||
configurable: true,
|
||||
get: () => {
|
||||
warn()
|
||||
return info.get!.call(o)
|
||||
warn();
|
||||
return info.get!.call(o);
|
||||
},
|
||||
set: newVal => {
|
||||
if (!onlyForValues || onlyForValues.includes(newVal)) {
|
||||
warn()
|
||||
warn();
|
||||
}
|
||||
return info.set!.call(o, newVal)
|
||||
return info.set!.call(o, newVal);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
// change the name of a property
|
||||
renameProperty: (o, oldName, newName) => {
|
||||
const warn = warnOnce(oldName, newName)
|
||||
const warn = warnOnce(oldName, newName);
|
||||
|
||||
// if the new property isn't there yet,
|
||||
// inject it and warn about it
|
||||
if ((oldName in o) && !(newName in o)) {
|
||||
warn()
|
||||
o[newName] = (o as any)[oldName]
|
||||
warn();
|
||||
o[newName] = (o as any)[oldName];
|
||||
}
|
||||
|
||||
// wrap the deprecated property in an accessor to warn
|
||||
// and redirect to the new property
|
||||
return Object.defineProperty(o, oldName, {
|
||||
get: () => {
|
||||
warn()
|
||||
return o[newName]
|
||||
warn();
|
||||
return o[newName];
|
||||
},
|
||||
set: value => {
|
||||
warn()
|
||||
o[newName] = value
|
||||
warn();
|
||||
o[newName] = value;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default deprecate
|
||||
export default deprecate;
|
||||
|
|
|
@ -5,4 +5,4 @@ export const commonModuleList: ElectronInternal.ModuleEntry[] = [
|
|||
{ name: 'shell', loader: () => require('./shell') },
|
||||
// The internal modules, invisible unless you know their names.
|
||||
{ name: 'deprecate', loader: () => require('./deprecate'), private: true }
|
||||
]
|
||||
];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const { nativeImage } = process.electronBinding('native_image')
|
||||
const { nativeImage } = process.electronBinding('native_image');
|
||||
|
||||
module.exports = nativeImage
|
||||
module.exports = nativeImage;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
module.exports = process.electronBinding('shell')
|
||||
module.exports = process.electronBinding('shell');
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
/* global require */
|
||||
|
||||
// Monkey-patch the fs module.
|
||||
require('electron/js2c/asar').wrapFsWithAsar(require('fs'))
|
||||
require('electron/js2c/asar').wrapFsWithAsar(require('fs'));
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const binding = process.electronBinding('crash_reporter')
|
||||
const binding = process.electronBinding('crash_reporter');
|
||||
|
||||
class CrashReporter {
|
||||
constructor () {
|
||||
this.productName = null
|
||||
this.crashesDirectory = null
|
||||
this.productName = null;
|
||||
this.crashesDirectory = null;
|
||||
}
|
||||
|
||||
init (options) {
|
||||
throw new Error('Not implemented')
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
start (options) {
|
||||
if (options == null) options = {}
|
||||
if (options == null) options = {};
|
||||
|
||||
const {
|
||||
productName,
|
||||
|
@ -22,77 +22,77 @@ class CrashReporter {
|
|||
ignoreSystemCrashHandler = false,
|
||||
submitURL,
|
||||
uploadToServer = true
|
||||
} = options
|
||||
} = options;
|
||||
|
||||
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start')
|
||||
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start')
|
||||
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start');
|
||||
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start');
|
||||
|
||||
const ret = this.init({
|
||||
submitURL,
|
||||
productName
|
||||
})
|
||||
});
|
||||
|
||||
this.productName = ret.productName
|
||||
this.crashesDirectory = ret.crashesDirectory
|
||||
this.productName = ret.productName;
|
||||
this.crashesDirectory = ret.crashesDirectory;
|
||||
|
||||
if (extra._productName == null) extra._productName = ret.productName
|
||||
if (extra._companyName == null) extra._companyName = companyName
|
||||
if (extra._version == null) extra._version = ret.appVersion
|
||||
if (extra._productName == null) extra._productName = ret.productName;
|
||||
if (extra._companyName == null) extra._companyName = companyName;
|
||||
if (extra._version == null) extra._version = ret.appVersion;
|
||||
|
||||
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra)
|
||||
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra);
|
||||
}
|
||||
|
||||
getLastCrashReport () {
|
||||
const reports = this.getUploadedReports()
|
||||
.sort((a, b) => {
|
||||
const ats = (a && a.date) ? new Date(a.date).getTime() : 0
|
||||
const bts = (b && b.date) ? new Date(b.date).getTime() : 0
|
||||
return bts - ats
|
||||
})
|
||||
const ats = (a && a.date) ? new Date(a.date).getTime() : 0;
|
||||
const bts = (b && b.date) ? new Date(b.date).getTime() : 0;
|
||||
return bts - ats;
|
||||
});
|
||||
|
||||
return (reports.length > 0) ? reports[0] : null
|
||||
return (reports.length > 0) ? reports[0] : null;
|
||||
}
|
||||
|
||||
getUploadedReports () {
|
||||
const crashDir = this.getCrashesDirectory()
|
||||
const crashDir = this.getCrashesDirectory();
|
||||
if (!crashDir) {
|
||||
throw new Error('crashReporter has not been started')
|
||||
throw new Error('crashReporter has not been started');
|
||||
}
|
||||
|
||||
return binding.getUploadedReports(crashDir)
|
||||
return binding.getUploadedReports(crashDir);
|
||||
}
|
||||
|
||||
getCrashesDirectory () {
|
||||
return this.crashesDirectory
|
||||
return this.crashesDirectory;
|
||||
}
|
||||
|
||||
getUploadToServer () {
|
||||
if (process.type === 'browser') {
|
||||
return binding.getUploadToServer()
|
||||
return binding.getUploadToServer();
|
||||
} else {
|
||||
throw new Error('getUploadToServer can only be called from the main process')
|
||||
throw new Error('getUploadToServer can only be called from the main process');
|
||||
}
|
||||
}
|
||||
|
||||
setUploadToServer (uploadToServer) {
|
||||
if (process.type === 'browser') {
|
||||
return binding.setUploadToServer(uploadToServer)
|
||||
return binding.setUploadToServer(uploadToServer);
|
||||
} else {
|
||||
throw new Error('setUploadToServer can only be called from the main process')
|
||||
throw new Error('setUploadToServer can only be called from the main process');
|
||||
}
|
||||
}
|
||||
|
||||
addExtraParameter (key, value) {
|
||||
binding.addExtraParameter(key, value)
|
||||
binding.addExtraParameter(key, value);
|
||||
}
|
||||
|
||||
removeExtraParameter (key) {
|
||||
binding.removeExtraParameter(key)
|
||||
binding.removeExtraParameter(key);
|
||||
}
|
||||
|
||||
getParameters () {
|
||||
return binding.getParameters()
|
||||
return binding.getParameters();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CrashReporter
|
||||
module.exports = CrashReporter;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
const handleESModule = (loader: ElectronInternal.ModuleLoader) => () => {
|
||||
const value = loader()
|
||||
if (value.__esModule && value.default) return value.default
|
||||
return value
|
||||
}
|
||||
const value = loader();
|
||||
if (value.__esModule && value.default) return value.default;
|
||||
return value;
|
||||
};
|
||||
|
||||
// Attaches properties to |targetExports|.
|
||||
export function defineProperties (targetExports: Object, moduleList: ElectronInternal.ModuleEntry[]) {
|
||||
const descriptors: PropertyDescriptorMap = {}
|
||||
const descriptors: PropertyDescriptorMap = {};
|
||||
for (const module of moduleList) {
|
||||
descriptors[module.name] = {
|
||||
enumerable: !module.private,
|
||||
get: handleESModule(module.loader)
|
||||
}
|
||||
};
|
||||
}
|
||||
return Object.defineProperties(targetExports, descriptors)
|
||||
return Object.defineProperties(targetExports, descriptors);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
export function electronBindingSetup (binding: typeof process['_linkedBinding'], processType: typeof process['type']): typeof process['electronBinding'] {
|
||||
return function electronBinding (name: string) {
|
||||
try {
|
||||
return binding(`electron_${processType}_${name}`)
|
||||
return binding(`electron_${processType}_${name}`);
|
||||
} catch (error) {
|
||||
if (/No such module/.test(error.message)) {
|
||||
return binding(`electron_common_${name}`)
|
||||
return binding(`electron_common_${name}`);
|
||||
} else {
|
||||
throw error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import * as util from 'util'
|
||||
import * as util from 'util';
|
||||
|
||||
import { electronBindingSetup } from '@electron/internal/common/electron-binding-setup'
|
||||
import { electronBindingSetup } from '@electron/internal/common/electron-binding-setup';
|
||||
|
||||
const timers = require('timers')
|
||||
const timers = require('timers');
|
||||
|
||||
process.electronBinding = electronBindingSetup(process._linkedBinding, process.type)
|
||||
process.electronBinding = electronBindingSetup(process._linkedBinding, process.type);
|
||||
|
||||
type AnyFn = (...args: any[]) => any
|
||||
|
||||
|
@ -17,11 +17,11 @@ type AnyFn = (...args: any[]) => any
|
|||
const wrapWithActivateUvLoop = function <T extends AnyFn> (func: T): T {
|
||||
return wrap(func, function (func) {
|
||||
return function (this: any, ...args: any[]) {
|
||||
process.activateUvLoop()
|
||||
return func.apply(this, args)
|
||||
}
|
||||
}) as T
|
||||
}
|
||||
process.activateUvLoop();
|
||||
return func.apply(this, args);
|
||||
};
|
||||
}) as T;
|
||||
};
|
||||
|
||||
/**
|
||||
* Casts to any below for func are due to Typescript not supporting symbols
|
||||
|
@ -30,41 +30,41 @@ const wrapWithActivateUvLoop = function <T extends AnyFn> (func: T): T {
|
|||
* Refs: https://github.com/Microsoft/TypeScript/issues/1863
|
||||
*/
|
||||
function wrap <T extends AnyFn> (func: T, wrapper: (fn: AnyFn) => T) {
|
||||
const wrapped = wrapper(func)
|
||||
const wrapped = wrapper(func);
|
||||
if ((func as any)[util.promisify.custom]) {
|
||||
(wrapped as any)[util.promisify.custom] = wrapper((func as any)[util.promisify.custom])
|
||||
(wrapped as any)[util.promisify.custom] = wrapper((func as any)[util.promisify.custom]);
|
||||
}
|
||||
return wrapped
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
process.nextTick = wrapWithActivateUvLoop(process.nextTick)
|
||||
process.nextTick = wrapWithActivateUvLoop(process.nextTick);
|
||||
|
||||
global.setImmediate = timers.setImmediate = wrapWithActivateUvLoop(timers.setImmediate)
|
||||
global.clearImmediate = timers.clearImmediate
|
||||
global.setImmediate = timers.setImmediate = wrapWithActivateUvLoop(timers.setImmediate);
|
||||
global.clearImmediate = timers.clearImmediate;
|
||||
|
||||
// setTimeout needs to update the polling timeout of the event loop, when
|
||||
// called under Chromium's event loop the node's event loop won't get a chance
|
||||
// to update the timeout, so we have to force the node's event loop to
|
||||
// recalculate the timeout in browser process.
|
||||
timers.setTimeout = wrapWithActivateUvLoop(timers.setTimeout)
|
||||
timers.setInterval = wrapWithActivateUvLoop(timers.setInterval)
|
||||
timers.setTimeout = wrapWithActivateUvLoop(timers.setTimeout);
|
||||
timers.setInterval = wrapWithActivateUvLoop(timers.setInterval);
|
||||
|
||||
// Only override the global setTimeout/setInterval impls in the browser process
|
||||
if (process.type === 'browser') {
|
||||
global.setTimeout = timers.setTimeout
|
||||
global.setInterval = timers.setInterval
|
||||
global.setTimeout = timers.setTimeout;
|
||||
global.setInterval = timers.setInterval;
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Always returns EOF for stdin stream.
|
||||
const { Readable } = require('stream')
|
||||
const stdin = new Readable()
|
||||
stdin.push(null)
|
||||
const { Readable } = require('stream');
|
||||
const stdin = new Readable();
|
||||
stdin.push(null);
|
||||
Object.defineProperty(process, 'stdin', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get () {
|
||||
return stdin
|
||||
return stdin;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
'use strict'
|
||||
'use strict';
|
||||
|
||||
// parses a feature string that has the format used in window.open()
|
||||
// - `features` input string
|
||||
// - `emit` function(key, value) - called for each parsed KV
|
||||
module.exports = function parseFeaturesString (features, emit) {
|
||||
features = `${features}`.trim()
|
||||
features = `${features}`.trim();
|
||||
// split the string by ','
|
||||
features.split(/\s*,\s*/).forEach((feature) => {
|
||||
// expected form is either a key by itself or a key/value pair in the form of
|
||||
// 'key=value'
|
||||
let [key, value] = feature.split(/\s*=\s*/)
|
||||
if (!key) return
|
||||
let [key, value] = feature.split(/\s*=\s*/);
|
||||
if (!key) return;
|
||||
|
||||
// interpret the value as a boolean, if possible
|
||||
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
|
||||
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value;
|
||||
|
||||
// emit the parsed pair
|
||||
emit(key, value)
|
||||
})
|
||||
}
|
||||
emit(key, value);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
import * as path from 'path'
|
||||
import * as path from 'path';
|
||||
|
||||
const Module = require('module')
|
||||
const Module = require('module');
|
||||
|
||||
// Clear Node's global search paths.
|
||||
Module.globalPaths.length = 0
|
||||
Module.globalPaths.length = 0;
|
||||
|
||||
// Prevent Node from adding paths outside this app to search paths.
|
||||
const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep
|
||||
const originalNodeModulePaths = Module._nodeModulePaths
|
||||
const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep;
|
||||
const originalNodeModulePaths = Module._nodeModulePaths;
|
||||
Module._nodeModulePaths = function (from: string) {
|
||||
const paths: string[] = originalNodeModulePaths(from)
|
||||
const fromPath = path.resolve(from) + path.sep
|
||||
const paths: string[] = originalNodeModulePaths(from);
|
||||
const fromPath = path.resolve(from) + path.sep;
|
||||
// If "from" is outside the app then we do nothing.
|
||||
if (fromPath.startsWith(resourcesPathWithTrailingSlash)) {
|
||||
return paths.filter(function (candidate) {
|
||||
return candidate.startsWith(resourcesPathWithTrailingSlash)
|
||||
})
|
||||
return candidate.startsWith(resourcesPathWithTrailingSlash);
|
||||
});
|
||||
} else {
|
||||
return paths
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Make a fake Electron module that we will insert into the module cache
|
||||
const electronModule = new Module('electron', null)
|
||||
electronModule.id = 'electron'
|
||||
electronModule.loaded = true
|
||||
electronModule.filename = 'electron'
|
||||
const electronModule = new Module('electron', null);
|
||||
electronModule.id = 'electron';
|
||||
electronModule.loaded = true;
|
||||
electronModule.filename = 'electron';
|
||||
Object.defineProperty(electronModule, 'exports', {
|
||||
get: () => require('electron')
|
||||
})
|
||||
});
|
||||
|
||||
Module._cache.electron = electronModule
|
||||
Module._cache.electron = electronModule;
|
||||
|
||||
const originalResolveFilename = Module._resolveFilename
|
||||
const originalResolveFilename = Module._resolveFilename;
|
||||
Module._resolveFilename = function (request: string, parent: NodeModule, isMain: boolean) {
|
||||
if (request === 'electron') {
|
||||
return 'electron'
|
||||
return 'electron';
|
||||
} else {
|
||||
return originalResolveFilename(request, parent, isMain)
|
||||
return originalResolveFilename(request, parent, isMain);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { nativeImage, NativeImage } = process.electronBinding('native_image')
|
||||
const { nativeImage, NativeImage } = process.electronBinding('native_image');
|
||||
|
||||
export function isPromise (val: any) {
|
||||
return (
|
||||
|
@ -10,7 +10,7 @@ export function isPromise (val: any) {
|
|||
val.constructor.reject instanceof Function &&
|
||||
val.constructor.resolve &&
|
||||
val.constructor.resolve instanceof Function
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const serializableTypes = [
|
||||
|
@ -21,17 +21,17 @@ const serializableTypes = [
|
|||
Error,
|
||||
RegExp,
|
||||
ArrayBuffer
|
||||
]
|
||||
];
|
||||
|
||||
export function isSerializableObject (value: any) {
|
||||
return value === null || ArrayBuffer.isView(value) || serializableTypes.some(type => value instanceof type)
|
||||
return value === null || ArrayBuffer.isView(value) || serializableTypes.some(type => value instanceof type);
|
||||
}
|
||||
|
||||
const objectMap = function (source: Object, mapper: (value: any) => any) {
|
||||
const sourceEntries = Object.entries(source)
|
||||
const targetEntries = sourceEntries.map(([key, val]) => [key, mapper(val)])
|
||||
return Object.fromEntries(targetEntries)
|
||||
}
|
||||
const sourceEntries = Object.entries(source);
|
||||
const targetEntries = sourceEntries.map(([key, val]) => [key, mapper(val)]);
|
||||
return Object.fromEntries(targetEntries);
|
||||
};
|
||||
|
||||
export function serialize (value: any): any {
|
||||
if (value instanceof NativeImage) {
|
||||
|
@ -39,28 +39,28 @@ export function serialize (value: any): any {
|
|||
buffer: value.toBitmap(),
|
||||
size: value.getSize(),
|
||||
__ELECTRON_SERIALIZED_NativeImage__: true
|
||||
}
|
||||
};
|
||||
} else if (Array.isArray(value)) {
|
||||
return value.map(serialize)
|
||||
return value.map(serialize);
|
||||
} else if (isSerializableObject(value)) {
|
||||
return value
|
||||
return value;
|
||||
} else if (value instanceof Object) {
|
||||
return objectMap(value, serialize)
|
||||
return objectMap(value, serialize);
|
||||
} else {
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
export function deserialize (value: any): any {
|
||||
if (value && value.__ELECTRON_SERIALIZED_NativeImage__) {
|
||||
return nativeImage.createFromBitmap(value.buffer, value.size)
|
||||
return nativeImage.createFromBitmap(value.buffer, value.size);
|
||||
} else if (Array.isArray(value)) {
|
||||
return value.map(deserialize)
|
||||
return value.map(deserialize);
|
||||
} else if (isSerializableObject(value)) {
|
||||
return value
|
||||
return value;
|
||||
} else if (value instanceof Object) {
|
||||
return objectMap(value, deserialize)
|
||||
return objectMap(value, deserialize);
|
||||
} else {
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export const syncMethods = new Set([
|
|||
'getZoomLevel',
|
||||
'setZoomFactor',
|
||||
'setZoomLevel'
|
||||
])
|
||||
]);
|
||||
|
||||
export const properties = new Set([
|
||||
'audioMuted',
|
||||
|
@ -56,7 +56,7 @@ export const properties = new Set([
|
|||
'zoomLevel',
|
||||
'zoomFactor',
|
||||
'frameRate'
|
||||
])
|
||||
]);
|
||||
|
||||
export const asyncMethods = new Set([
|
||||
'loadURL',
|
||||
|
@ -70,4 +70,4 @@ export const asyncMethods = new Set([
|
|||
'setVisualZoomLevelLimits',
|
||||
'print',
|
||||
'printToPDF'
|
||||
])
|
||||
]);
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
//
|
||||
// Will mutate this captured one as well and that is OK.
|
||||
|
||||
export const Promise = global.Promise
|
||||
export const Promise = global.Promise;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue