当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript app.setPath方法代码示例

本文整理汇总了TypeScript中electron.app.setPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript app.setPath方法的具体用法?TypeScript app.setPath怎么用?TypeScript app.setPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在electron.app的用法示例。


在下文中一共展示了app.setPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
  }
}
开发者ID:malept,项目名称:electron,代码行数:49,代码来源:main.ts

示例2:

const handlePortableFlags = () => {
  if (argv.portable || argv.user_data_dir) {
    const USER_PATH = argv.user_data_dir || path.join(process.env.APPIMAGE || process.execPath, '../Data');

    console.log(`Saving user data to ${USER_PATH}`);
    app.setPath('userData', USER_PATH);
  }
};
开发者ID:wireapp,项目名称:wire-desktop,代码行数:8,代码来源:main.ts

示例3: it

    it('does not create a new directory by default', () => {
      const badPath = path.join(__dirname, 'music')

      expect(fs.existsSync(badPath)).to.be.false
      app.setPath('music', badPath)
      expect(fs.existsSync(badPath)).to.be.false

      expect(() => { app.getPath(badPath) }).to.throw()
    })
开发者ID:electron,项目名称:electron,代码行数:9,代码来源:api-app-spec.ts

示例4: setup

export function setup() {
  const base = "./tmp/prefix";

  for (const name of electronLocations) {
    const location = resolve(base, name);
    try {
      mkdirp(location);
      app.setPath(name, location);
    } catch (e) {
      console.warn(`Could not set location ${name} to ${location}: ${e.stack}`);
    }
  }
}
开发者ID:HorrerGames,项目名称:itch,代码行数:13,代码来源:test-paths.ts

示例5: applyCLIArgs

/**
 * If we are running functional tests with spectron, we need to expose more of the app to
 * outside control.
 *
 * First, we need to be able to override the directory in Chromium will be storing data.
 * This is “--user-data-dir”. We need it so tests will not store data in the same folder where the
 * regular apps stores it, and tests should not share data amongst themselves, so each test case
 * will provide a different directory, and clean it up afterwards.
 *
 * We also need a possibility to override some modules in the app.
 * For example, we don't want to do actual HTTP requests. We instead need a way to mock
 * modules on per-test basis.
 *
 */
function applyCLIArgs() {
    const dirArgName             = "--user-data-dir=";
    const moduleOverridesArgName = "--override-modules=";

    // Find if arguments are present in the command line
    const userDataDirArg     = process.argv.find(arg => arg.startsWith(dirArgName));
    const moduleOverridesArg = process.argv.find(arg => arg.startsWith(moduleOverridesArgName));

    // If we're given an alternate userData directory, override the default one
    if (userDataDirArg) {
        const userDir = userDataDirArg.slice(dirArgName.length);
        app.setPath("userData", userDir);
    }

    // If we're given module overrides, we're given a string through the command line
    // so we need to unpack it
    if (moduleOverridesArg) {
        // Take the argument value
        const serializedOverrides = moduleOverridesArg.slice(moduleOverridesArgName.length);

        // Deserialize it in such way that everything that is not an object goes through eval
        // We serialized function as strings beforehand, so we need to bring them back to life
        const overrides: { module: string, override: Object }[] = JSON.parse(serializedOverrides, (key, val) => {
            if (typeof val === "string" && (val.startsWith("(") || val.startsWith("function"))) {
                return eval(`(${val})`);
            }

            return val;
        }) || [];

        // For all modules that should be mocked, provide given mocks to the module loader now,
        // before anybody else requires them.
        // That way, they will get mocks from cache.
        overrides.forEach(override => {
            mock(override.module, override.override);
        });
    }
}
开发者ID:hmenager,项目名称:composer,代码行数:52,代码来源:main.common.ts

示例6: resolve

import { platform, homedir } from 'os';
import { mkdirSync, existsSync, writeFileSync } from 'fs';

import { runAutoUpdaterService, runExtensionsService } from './services';
import { Global } from './interfaces';
import {
  createWindow,
  getPath,
  registerProtocols,
  loadExtensions,
} from './utils';
import { defaultPaths, filesContent } from '~/defaults';
import { matchesPattern } from '~/utils/url';
import { runWebRequestService } from '~/main/services/web-request';

app.setPath('userData', resolve(homedir(), '.wexond'));

declare const global: Global;

let mainWindow: Electron.BrowserWindow;

global.extensions = {};
global.backgroundPages = {};
global.databases = {};
global.extensionsLocales = {};
global.extensionsAlarms = {};
global.locale = 'en-US';

global.userAgent =
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36';
开发者ID:laquereric,项目名称:wexond,代码行数:30,代码来源:index.ts

示例7: it

 it('returns the overridden path', () => {
   app.setPath('music', __dirname)
   expect(app.getPath('music')).to.equal(__dirname)
 })
开发者ID:malept,项目名称:electron,代码行数:4,代码来源:api-app-spec.ts

示例8: setConfigProps

import { join } from 'path';
import { getConfig, setConfigProps } from './config';

import { BackgroundApp } from './model/background-app';

// Special module holding environment variables which you declared
// in config/env_xxx.json file.
import env from './env';

// Save userData in separate folders for each environment.
// Thanks to this you can use production and development versions of the app
// on same machine like those are two separate apps.
if (env.name !== 'production') {
  var userDataPath = app.getPath('userData');
  app.setPath('userData', userDataPath + ' (' + env.name + ')');
}

const onThemeChange = (theme: string) => setConfigProps({ theme });

const onAngularToggle = () => {
  const config = getConfig();
  const showLibs = !config.showLibs;
  setConfigProps({ showLibs });
};

const menuItems = [applicationMenuTemplate(onThemeChange, onAngularToggle)];
if (env.name !== 'production') {
  menuItems.push(devMenuTemplate());
}
开发者ID:chauey,项目名称:ngrev,代码行数:29,代码来源:app.ts

示例9: require

import * as mock from "mock-require";
import * as path from "path";
import * as acceleratorProxy from "./accelerator-proxy";
import * as openExternalFileProxy from "./open-external-file-proxy";

require("fix-path")();

const {app, Menu, BrowserWindow} = require("electron");
const {registerProtocolForLinux} = require("./register-protocols");
const deepLinkingController      = require("./controllers/open-external-file/deep-linking-protocol-controller");
const localFileController        = require("./controllers/open-external-file/open-file-handler-controller");

const isSpectronRun       = ~process.argv.indexOf("--spectron");
const defaultUserDataPath = app.getPath("home") + path.sep + ".sevenbridges/rabix-composer";

app.setPath("userData", defaultUserDataPath);

process.on("unhandledRejection", (reason, p) => {
    console.log("Unhandled Rejection at: Promise", p, "reason:", reason);
});

applyCLIArgs();

const router = require("./ipc-router");

let win = null;
let splash;

function start(config: { devTools: boolean, url: string }) {
    router.start();
开发者ID:hmenager,项目名称:composer,代码行数:30,代码来源:main.common.ts

示例10: require

}

// Set application's desktop name.
if (packageJson.desktopName != null) {
  app.setDesktopName(packageJson.desktopName)
} else {
  app.setDesktopName((app.getName()) + '.desktop')
}

// Set v8 flags
if (packageJson.v8Flags != null) {
  v8.setFlagsFromString(packageJson.v8Flags)
}

// Set the user path according to application's name.
app.setPath('userData', path.join(app.getPath('appData'), app.getName()))
app.setPath('userCache', path.join(app.getPath('cache'), app.getName()))
app.setAppPath(packagePath)

// Load the chrome devtools support.
require('@electron/internal/browser/chrome-devtools')

// Load the chrome extension support.
require('@electron/internal/browser/chrome-extension')

const features = process.atomBinding('features')
if (features.isDesktopCapturerEnabled()) {
  // Load internal desktop-capturer module.
  require('@electron/internal/browser/desktop-capturer')
}
开发者ID:vwvww,项目名称:electron,代码行数:30,代码来源:init.ts

示例11: setApplicationMenu

import env from './env';

const setApplicationMenu = () => {
  const menus = [editMenuTemplate];
  if (env.name !== 'production') {
    menus.push(devMenuTemplate);
  }
  Menu.setApplicationMenu(Menu.buildFromTemplate(menus));
};

// Save userData in separate folders for each environment.
// Thanks to this you can use production and development versions of the app
// on same machine like those are two separate apps.
if (env.name !== 'production') {
  const userDataPath = app.getPath('userData');
  app.setPath('userData', `${userDataPath} (${env.name})`);
}

app.on('ready', () => {
  setApplicationMenu();

  const mainWindow = createWindow('main', {
    width: 1000,
    height: 600,
  });

//setTimeout(() => {
    mainWindow.loadURL('file://' + __dirname + '/app.html');
//}, 2000); // 1 second wasn't enough lol

  if (env.name === 'development') {
开发者ID:Dorokhov,项目名称:azure-tools,代码行数:31,代码来源:background.ts


注:本文中的electron.app.setPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。