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


TypeScript webContents.fromId方法代码示例

本文整理汇总了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);
   }
 });
开发者ID:laquereric,项目名称:wexond,代码行数:7,代码来源:extensions-service.ts

示例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;
};
开发者ID:laquereric,项目名称:wexond,代码行数:35,代码来源:web-request.ts

示例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);
        });
      }
    },
开发者ID:laquereric,项目名称:wexond,代码行数:28,代码来源:extensions-service.ts

示例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 });
      }
    },
开发者ID:laquereric,项目名称:wexond,代码行数:9,代码来源:extensions-service.ts

示例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);
  });
开发者ID:itchio,项目名称:itch,代码行数:12,代码来源:web-contents.ts

示例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}".`);
  }
}
开发者ID:wireapp,项目名称:wire-desktop,代码行数:46,代码来源:LocalAccountDeletion.ts

示例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());
      }
    }
  });
开发者ID:laquereric,项目名称:wexond,代码行数:43,代码来源:extensions-service.ts

示例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);
}
开发者ID:HorrerGames,项目名称:itch,代码行数:20,代码来源:web-contents.ts


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