本文整理匯總了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()
}
示例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
}
示例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)
})
示例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");
示例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')!;
}
//.........這裏部分代碼省略.........