本文整理汇总了TypeScript中module._load函数的典型用法代码示例。如果您正苦于以下问题:TypeScript _load函数的具体用法?TypeScript _load怎么用?TypeScript _load使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_load函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: loadApplicationPackage
function loadApplicationPackage (packagePath: string) {
// Add a flag indicating app is started from default app.
Object.defineProperty(process, 'defaultApp', {
configurable: false,
enumerable: true,
value: true
})
try {
// Override app name and version.
packagePath = path.resolve(packagePath)
const packageJsonPath = path.join(packagePath, 'package.json')
if (fs.existsSync(packageJsonPath)) {
let packageJson
try {
packageJson = require(packageJsonPath)
} catch (e) {
showErrorMessage(`Unable to parse ${packageJsonPath}\n\n${e.message}`)
return
}
if (packageJson.version) {
app.setVersion(packageJson.version)
}
if (packageJson.productName) {
app.setName(packageJson.productName)
} else if (packageJson.name) {
app.setName(packageJson.name)
}
app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
app.setAppPath(packagePath)
}
try {
Module._resolveFilename(packagePath, module, true)
} catch (e) {
showErrorMessage(`Unable to find Electron app at ${packagePath}\n\n${e.message}`)
return
}
// Run the app.
Module._load(packagePath, module, true)
} catch (e) {
console.error('App threw an error during load')
console.error(e.stack || e)
throw e
}
}
示例2: join
const DISCORD_APP_ROOT = process.env.DISCORD_APP_ROOT || join(__dirname, "../app.asar")
PatchModule("electron", {
// Injector for the renderer thread
// Based on the injector in https://github.com/DiscordInjections/DiscordInjections
BrowserWindow: Object.assign(function(userOptions: BrowserWindowConstructorOptions) {
const options = Object.assign({}, userOptions);
options.webPreferences = Object.assign({}, options.webPreferences)
options.webPreferences.preload = join(dirname(DISCORD_APP_ROOT), "app");
options.webPreferences.webSecurity = false;
options.webPreferences.experimentalFeatures = true;
const win = new BrowserWindow(options);
// Allow the renderer process to act on the options
win.__options = userOptions
return win;
}, BrowserWindow)
}, {
BrowserWindow: "../../browser-window.js"
})
// Starting the application
const Module = require("module");
const AppPath = DISCORD_APP_ROOT;
const AppPackage = require(join(AppPath, "package.json"));
// Adjust electron root
app.getAppPath = () => AppPath;
// Load Discord
Module._load(join(AppPath, AppPackage.main || "index.js"), null, true);
示例3: import
return false
}
// Workaround for electron/electron#5050 and electron/electron#9046
if (currentPlatformSupportsAppIndicator()) {
process.env.XDG_CURRENT_DESKTOP = 'Unity'
}
// Quit when all windows are closed and no other one is listening to this.
app.on('window-all-closed', () => {
if (app.listenerCount('window-all-closed') === 1) {
app.quit()
}
})
Promise.all([
import('@electron/internal/browser/default-menu'),
app.whenReady
]).then(([{ setDefaultApplicationMenu }]) => {
// Create default menu
setDefaultApplicationMenu()
})
if (packagePath) {
// Finally load app's main.js and transfer control to C++.
Module._load(path.join(packagePath, mainStartupScript), Module, true)
} else {
console.error('Failed to locate a valid package to load (app, app.asar or default_app.asar)')
console.error('This normally means you\'ve damaged the Electron package somehow')
}