Example #1
0
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
  }
}
Example #2
0
 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);
Example #3
0
  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')
}