本文整理汇总了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
}
}
示例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);
}
};
示例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()
})
示例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}`);
}
}
}
示例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);
});
}
}
示例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';
示例7: it
it('returns the overridden path', () => {
app.setPath('music', __dirname)
expect(app.getPath('music')).to.equal(__dirname)
})
示例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());
}
示例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();
示例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')
}
示例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') {