本文整理汇总了TypeScript中electron.webContents.fromId方法的典型用法代码示例。如果您正苦于以下问题:TypeScript webContents.fromId方法的具体用法?TypeScript webContents.fromId怎么用?TypeScript webContents.fromId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.webContents
的用法示例。
在下文中一共展示了webContents.fromId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
Object.keys(global.backgroundPages).forEach(key => {
const bgPage = global.backgroundPages[key];
if (e.sender.id !== bgPage.webContentsId) {
const contents = webContents.fromId(bgPage.webContentsId);
contents.send(API_PORT_POSTMESSAGE + portId, msg);
}
});
示例2: 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;
};
示例3: if
(e: Electron.IpcMessageEvent, data: any) => {
const contents = webContents.fromId(e.sender.id);
const storage = global.databases[data.extensionId];
const msg = API_STORAGE_OPERATION + data.id;
if (data.type === 'get') {
storage[data.area].get(data.arg, d => {
for (const key in d) {
if (Buffer.isBuffer(d[key])) {
d[key] = JSON.parse(d[key].toString());
}
}
contents.send(msg, d);
});
} else if (data.type === 'set') {
storage[data.area].set(data.arg, () => {
contents.send(msg);
});
} else if (data.type === 'clear') {
storage[data.area].clear(() => {
contents.send(msg);
});
} else if (data.type === 'remove') {
storage[data.area].set(data.arg, () => {
contents.send(msg);
});
}
},
示例4: async
async (e: Electron.IpcMessageEvent, data: any) => {
const { extensionId, portId, sender, name } = data;
const bgPage = global.backgroundPages[extensionId];
if (e.sender.id !== bgPage.webContentsId) {
const contents = webContents.fromId(bgPage.webContentsId);
contents.send(API_RUNTIME_CONNECT, { portId, sender, name });
}
},
示例5: async
watcher.on(actions.tabGotWebContents, async (store, action) => {
const { wind, tab, webContentsId } = action.payload;
const rs = store.getState();
const initialURL = rs.winds[wind].tabInstances[tab].location.url;
const wc = webContents.fromId(webContentsId);
storeWebContents(wind, tab, wc);
logger.debug(`Loading url '${initialURL}'`);
await hookWebContents(store, wind, tab, wc as ExtendedWebContents);
loadURL(wc, initialURL);
});
示例6: deleteAccount
export async function deleteAccount(id: number, accountId: string, partitionId?: string) {
// Delete session data
try {
const webviewWebcontent = webContents.fromId(id);
if (!webviewWebcontent) {
throw new Error(`Unable to find webview content id "${id}"`);
}
if (!webviewWebcontent.hostWebContents) {
throw new Error('Only a webview can have its storage wiped');
}
logger.log(`Deleting session data for account "${accountId}"...`);
await clearStorage(webviewWebcontent.session);
logger.log(`Deleted session data for account "${accountId}".`);
} catch (error) {
logger.error(`Failed to delete session data for account "${accountId}", reason: "${error.message}".`);
}
// Delete the webview partition
// Note: The first account always uses the default session,
// therefore partitionId is optional
// ToDo: Move the first account to a partition
if (partitionId) {
try {
if (!ValidationUtil.isUUIDv4(partitionId)) {
throw new Error('Partition is not an UUID');
}
const partitionDir = path.join(USER_DATA_DIR, 'Partitions', partitionId);
await fs.remove(partitionDir);
logger.log(`Deleted partition "${partitionId}" for account "${accountId}".`);
} catch (error) {
logger.log(`Unable to delete partition "${partitionId}" for account "${accountId}", reason: "${error.message}".`);
}
}
// Delete logs for this account
try {
if (!ValidationUtil.isUUIDv4(accountId)) {
throw new Error('Account is not an UUID');
}
const sessionFolder = path.join(LOG_DIR, accountId);
await fs.remove(sessionFolder);
logger.log(`Deleted logs folder for account "${accountId}".`);
} catch (error) {
logger.error(`Failed to delete logs folder for account "${accountId}", reason: "${error.message}".`);
}
}
示例7: setTimeout
ipcMain.on(API_ALARMS_OPERATION, (e: Electron.IpcMessageEvent, data: any) => {
const { extensionId, type } = data;
const contents = webContents.fromId(e.sender.id);
if (type === 'create') {
const { name, alarmInfo } = data;
const alarms = global.extensionsAlarms[extensionId];
const exists = alarms.findIndex(e => e.name === name) !== -1;
e.returnValue = null;
if (exists) return;
let scheduledTime = 0;
if (alarmInfo.when != null) {
scheduledTime = alarmInfo.when;
}
if (alarmInfo.delayInMinutes != null) {
if (alarmInfo.delayInMinutes < 1) {
return console.error(
`Alarm delay is less than minimum of 1 minutes. In released .crx, alarm "${name}" will fire in approximately 1 minutes.`,
);
}
scheduledTime = Date.now() + alarmInfo.delayInMinutes * 60000;
}
const alarm: ExtensionsAlarm = {
periodInMinutes: alarmInfo.periodInMinutes,
scheduledTime,
name,
};
global.extensionsAlarms[extensionId].push(alarm);
if (!alarm.periodInMinutes) {
setTimeout(() => {
contents.send(`api-emit-event-alarms-onAlarm`, alarm);
}, alarm.scheduledTime - Date.now());
}
}
});
示例8: cb
function withWebContents<T>(
store: IStore,
window: string,
tab: string,
cb: WebContentsCallback<T>
): T | null {
const sp = Space.fromStore(store, window, tab);
const { webContentsId } = sp.web();
if (!webContentsId) {
return null;
}
const wc = webContents.fromId(webContentsId);
if (!wc || wc.isDestroyed()) {
return null;
}
return cb(wc as ExtendedWebContents);
}