本文整理匯總了TypeScript中electron.ipcMain.once方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ipcMain.once方法的具體用法?TypeScript ipcMain.once怎麽用?TypeScript ipcMain.once使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類electron.ipcMain
的用法示例。
在下文中一共展示了ipcMain.once方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getCurrentSchedule
getCurrentSchedule((schedule) => {
let posterWindow = new BrowserWindow({width: 795, height: 800, show: debug});
if (debug) {
posterWindow.webContents.openDevTools();
}
posterWindow.setMenu(null);
posterWindow.loadURL(`file://${__dirname}/poster.html`);
ipcMain.once('+main:poster-angular-up', () => {
if (debug) {
posterWindow.webContents.send('+view:debug-enabled');
}
posterWindow.webContents.send('+view:open-schedule', schedule, month);
});
ipcMain.once('+main:poster-ready', () => {
posterWindow.webContents['_printToPDF'](posterPrintingSetting, (err, data) => {
if (err) throw err;
fs.writeFile(filename, data, (err) => {
if (err) throw err;
console.log('Write PDF successfully.');
dialog.showMessageBox({
type: 'info',
title: 'PDF Saved',
message: 'Poster rendered and saved to file.',
buttons: ['OK'],
});
if (!debug) {
posterWindow.close();
}
});
});
});
});
示例2: Promise
return new Promise((resolve: (a: any) => void) => {
window.webContents.send('get-tab-by-web-contents-id', webContentsId);
ipcMain.once('get-tab-by-web-contents-id', (e: any, tab: any) => {
resolve(tab);
});
});
示例3: makeId
const interceptRequest = (
eventName: string,
details: any,
callback: any = null,
): boolean => {
let isIntercepted = false;
if (Array.isArray(eventListeners[eventName])) {
for (const event of eventListeners[eventName]) {
if (!matchesFilter(event.filters, details.url)) continue;
const id = makeId(32);
if (callback) {
ipcMain.once(
`api-webRequest-response-${eventName}-${event.id}-${id}`,
(e: any, res: any) => {
callback(res);
},
);
}
const contents = webContents.fromId(event.webContentsId);
contents.send(
`api-webRequest-intercepted-${eventName}-${event.id}`,
details,
id,
);
isIntercepted = true;
}
}
return isIntercepted;
};
示例4: createWindow
function createWindow() {
mainWindow = new BrowserWindow({height: 650, width: 900, show: debug});
if (debug) {
mainWindow.webContents.openDevTools();
}
mainWindow.loadURL(`file://${__dirname}/index.html`);
if (process.platform === 'darwin') {
Menu.setApplicationMenu(createMenu());
} else {
mainWindow.setMenu(createMenu());
}
ipcMain.once('+main:angular-up', () => {
if (debug) {
mainWindow.webContents.send('+view:debug-enabled');
}
if (startFile) {
openScheduleFromFile(startFile);
}
mainWindow.show();
});
ipcMain.on('+main:new-schedule', () => {
createNewSchedule();
});
ipcMain.on('+main:open-schedule', () => {
openScheduleFileDialog();
});
mainWindow.on('closed', () => {
mainWindow = null;
app.quit();
});
};
示例5: log
autoUpdater.addListener('update-downloaded', () => {
log('update downloaded')
const notificationWindow = new BrowserWindow(
{parent: mainWindow, width: 400, height: 600, modal: true})
notificationWindow.loadURL(
`file://${__dirname}/ui/update-notification.html`)
ipcMain.once('close-notification-window', () => {
notificationWindow.close()
})
ipcMain.once('quit-and-update', () => {
autoUpdater.quitAndInstall()
})
})
示例6: BrowserWindow
ipcMain.on('preview-invoice', (event, client, invoiceData) => {
const previewWindow = new BrowserWindow(
{parent: mainWindow, width: 800, height: 1000})
previewWindow.loadURL(
`file://${__dirname}/ui/preview-invoice.html`)
//previewWindow.webContents.openDevTools()
ipcMain.once('preview-invoice-ready', (event) => {
event.sender.send('invoice-data', client, invoiceData)
})
})
示例7: c
return new TPromise<boolean>((c) => {
let oneTimeEventToken = this.oneTimeListenerTokenGenerator++;
let oneTimeOkEvent = 'vscode:ok' + oneTimeEventToken;
let oneTimeCancelEvent = 'vscode:cancel' + oneTimeEventToken;
ipc.once(oneTimeOkEvent, () => {
c(false); // no veto
});
ipc.once(oneTimeCancelEvent, () => {
// Any cancellation also cancels a pending quit if present
if (this.pendingQuitPromiseComplete) {
this.pendingQuitPromiseComplete(true /* veto */);
delete this.pendingQuitPromiseComplete;
delete this.pendingQuitPromise;
}
c(true); // veto
});
vscodeWindow.send('vscode:beforeUnload', { okChannel: oneTimeOkEvent, cancelChannel: oneTimeCancelEvent });
});
示例8: Promise
return new Promise((resolve) => {
electron.ipcMain.once(ELECTRON_READY, (ev: any) => {
ev.returnValue = 'ok';
resolve();
});
});