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


TypeScript app.whenReady方法代码示例

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


在下文中一共展示了app.whenReady方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

export const load = async (appUrl: string) => {
  await app.whenReady()

  const options: BrowserWindowConstructorOptions = {
    width: 900,
    height: 600,
    autoHideMenuBar: true,
    backgroundColor: '#FFFFFF',
    webPreferences: {
      contextIsolation: true,
      preload: path.resolve(__dirname, 'renderer.js'),
      webviewTag: false
    },
    useContentSize: true,
    show: false
  }

  if (process.platform === 'linux') {
    options.icon = path.join(__dirname, 'icon.png')
  }

  mainWindow = new BrowserWindow(options)

  mainWindow.on('ready-to-show', () => mainWindow!.show())

  mainWindow.loadURL(appUrl)
  mainWindow.focus()
}
开发者ID:vwvww,项目名称:electron,代码行数:28,代码来源:default_app.ts

示例2: createWindow

async function createWindow () {
  await app.whenReady()

  const options: Electron.BrowserWindowConstructorOptions = {
    width: 900,
    height: 600,
    autoHideMenuBar: true,
    backgroundColor: '#FFFFFF',
    webPreferences: {
      preload: path.resolve(__dirname, 'preload.js'),
      contextIsolation: true,
      sandbox: true,
      enableRemoteModule: false
    },
    useContentSize: true,
    show: false
  }

  if (process.platform === 'linux') {
    options.icon = path.join(__dirname, 'icon.png')
  }

  mainWindow = new BrowserWindow(options)
  mainWindow.on('ready-to-show', () => mainWindow!.show())

  mainWindow.webContents.on('new-window', (event, url) => {
    event.preventDefault()
    shell.openExternal(decorateURL(url))
  })

  mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, done) => {
    const parsedUrl = new URL(webContents.getURL())

    const options: Electron.MessageBoxOptions = {
      title: 'Permission Request',
      message: `Allow '${parsedUrl.origin}' to access '${permission}'?`,
      buttons: ['OK', 'Cancel'],
      cancelId: 1
    }

    dialog.showMessageBox(mainWindow!, options).then(response => {
      done(response === 0)
    })
  })

  return mainWindow
}
开发者ID:malept,项目名称:electron,代码行数:47,代码来源:default_app.ts

示例3: it

 it('becomes fulfilled if the app is already ready', async () => {
   expect(app.isReady()).to.equal(true)
   await expect(app.whenReady()).to.be.eventually.fulfilled.equal(undefined)
 })
开发者ID:malept,项目名称:electron,代码行数:4,代码来源:api-app-spec.ts

示例4: done

import { session, app, BrowserWindow, BrowserWindowConstructorOptions } from "electron";
import { PatchModule } from "./util";
import { join, dirname } from "path";

// TODO: Find a way to detect when we are in the overlay process, and execute there

  // Remove all csp headers so we can load our own scripts
  app.whenReady().then(() => {
    session.defaultSession.webRequest.onHeadersReceived((details, done) => {
      const responseHeaders = details.responseHeaders as {
        [key: string]: string;
      };
  
      for (const header in responseHeaders)
        if (header.toLowerCase().startsWith("content-security-policy"))
          delete responseHeaders[header];
  
      done({ cancel: false, responseHeaders });
    });
  });
  
  // Environment variable for development in typescript
  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");
开发者ID:devpixel12,项目名称:twitchcord-1,代码行数:31,代码来源:main.ts

示例5: updateAppMenu

(async () => {
	await Promise.all([ensureOnline(), app.whenReady()]);

	const trackingUrlPrefix = `https://l.${domain}/l.php`;

	await updateAppMenu();
	mainWindow = createMainWindow();
	tray.create(mainWindow);

	if (is.macos) {
		const firstItem: MenuItemConstructorOptions = {
			label: 'Mute Notifications',
			type: 'checkbox',
			checked: config.get('notificationsMuted'),
			click() {
				mainWindow.webContents.send('toggle-mute-notifications');
			}
		};

		dockMenu = Menu.buildFromTemplate([firstItem]);
		app.dock.setMenu(dockMenu);

		ipcMain.on('conversations', (_event: ElectronEvent, conversations: Conversation[]) => {
			if (conversations.length === 0) {
				return;
			}

			const items = conversations.map(({label, icon}, index) => {
				return {
					label: `${label}`,
					icon: nativeImage.createFromDataURL(icon),
					click: () => {
						mainWindow.show();
						sendAction('jump-to-conversation', index + 1);
					}
				};
			});
			app.dock.setMenu(Menu.buildFromTemplate([firstItem, {type: 'separator'}, ...items]));
		});
	}

	// Update badge on conversations change
	ipcMain.on('conversations', (_event: ElectronEvent, conversations: Conversation[]) => {
		updateBadge(conversations);
	});

	enableHiresResources();

	const {webContents} = mainWindow;

	webContents.on('dom-ready', async () => {
		await updateAppMenu();

		webContents.insertCSS(readFileSync(path.join(__dirname, '..', 'css', 'browser.css'), 'utf8'));
		webContents.insertCSS(readFileSync(path.join(__dirname, '..', 'css', 'dark-mode.css'), 'utf8'));
		webContents.insertCSS(readFileSync(path.join(__dirname, '..', 'css', 'vibrancy.css'), 'utf8'));
		webContents.insertCSS(
			readFileSync(path.join(__dirname, '..', 'css', 'code-blocks.css'), 'utf8')
		);

		if (config.get('useWorkChat')) {
			webContents.insertCSS(
				readFileSync(path.join(__dirname, '..', 'css', 'workchat.css'), 'utf8')
			);
		}

		if (existsSync(path.join(app.getPath('userData'), 'custom.css'))) {
			webContents.insertCSS(readFileSync(path.join(app.getPath('userData'), 'custom.css'), 'utf8'));
		}

		if (config.get('launchMinimized') || app.getLoginItemSettings().wasOpenedAsHidden) {
			mainWindow.hide();
		} else {
			mainWindow.show();
		}

		webContents.send('toggle-mute-notifications', config.get('notificationsMuted'));
		webContents.send('toggle-message-buttons', config.get('showMessageButtons'));

		webContents.executeJavaScript(
			readFileSync(path.join(__dirname, 'notifications-isolated.js'), 'utf8')
		);
	});

	webContents.on('new-window', (event: Event, url, frameName, _disposition, options) => {
		event.preventDefault();

		if (url === 'about:blank') {
			if (frameName !== 'about:blank') {
				// Voice/video call popup
				options.show = true;
				options.titleBarStyle = 'default';
				options.webPreferences.nodeIntegration = false;
				options.webPreferences.preload = path.join(__dirname, 'browser-call.js');
				(event as any).newGuest = new BrowserWindow(options);
			}
		} else {
			if (url.startsWith(trackingUrlPrefix)) {
				url = new URL(url).searchParams.get('u')!;
			}
//.........这里部分代码省略.........
开发者ID:kusamakura,项目名称:caprine,代码行数:101,代码来源:index.ts


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