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


TypeScript butlerd.Client类代码示例

本文整理汇总了TypeScript中butlerd.Client的典型用法代码示例。如果您正苦于以下问题:TypeScript Client类的具体用法?TypeScript Client怎么用?TypeScript Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: refreshButlerd

async function refreshButlerd(store: IStore) {
  logger.info(`Refreshing butlerd! Spinning up new instance...`);
  let instance = await makeButlerInstance();
  instance.promise().catch(e => {
    console.error(`butlerd instance threw:`);
    console.error(e.stack);
    refreshButlerd(store).catch(() => {});
  });
  const endpoint = await instance.getEndpoint();

  logger.info(`Connecting client...`);
  const nextClient = new Client(endpoint);
  await nextClient.connect();

  if (masterClient) {
    // instances exit gracefully when all clients have closed
    logger.info(`Closing old master client...`);
    masterClient.close();
    masterClient = null;
  }
  masterClient = nextClient;
  logger.info(`Got new endpoint`);
  store.dispatch(actions.gotButlerdEndpoint({ endpoint }));
  initialButlerdResolve();
}
开发者ID:HorrerGames,项目名称:itch,代码行数:25,代码来源:setup.ts

示例2: setupLogging

export function setupLogging(client: Client, logger: Logger) {
  client.onWarning(msg => {
    logger.warn(`(butlerd) ${msg}`);
  });

  client.onNotification(messages.Log, ({ params }) => {
    switch (params.level) {
      case "debug":
        logger.debug(params.message);
        break;
      case "info":
        logger.info(params.message);
        break;
      case "warning":
        logger.warn(params.message);
        break;
      case "error":
        logger.error(params.message);
        break;
      default:
        logger.info(`[${params.level}] ${params.message}`);
        break;
    }
  });
}
开发者ID:HorrerGames,项目名称:itch,代码行数:25,代码来源:utils.ts

示例3: async

  sanityCheck: async (ctx, logger, versionPrefix) => {
    const instance = await makeButlerInstance({ ctx, versionPrefix });
    // we're awaiting it later, avoid 'unhandledRejection'
    instance.promise().catch(() => {});

    const client = new Client(await instance.getEndpoint());
    await client.call(messages.VersionGet, {});
  },
开发者ID:itchio,项目名称:itch,代码行数:8,代码来源:formulas.ts

示例4: async

 sanityCheck: async (versionPrefix: string) => {
   const instance = await makeButlerInstanceWithPrefix(versionPrefix);
   // we're awaiting it later, avoid 'unhandledRejection'
   instance.promise().catch(() => {});
   try {
     const client = new Client(await instance.getEndpoint());
     await client.connect();
     await client.call(messages.VersionGet, {});
     client.close();
   } finally {
     await instance.promise();
   }
 },
开发者ID:HorrerGames,项目名称:itch,代码行数:13,代码来源:formulas.ts

示例5: makeClient

async function makeClient(store: Store, parentLogger: Logger): Promise<Client> {
  const logger = parentLogger.childWithName("butlerd/make-client");

  while (true) {
    const { endpoint } = store.getState().butlerd;
    if (endpoint) {
      const client = new Client(endpoint);
      client.onWarning(msg => {
        logger.warn(`(butlerd) ${msg}`);
      });
      return client;
    }

    logger.info(`Waiting for butlerd endpoint...`);
    await delay(1000);
  }
}
开发者ID:itchio,项目名称:itch,代码行数:17,代码来源:utils.ts

示例6: getRootState

export async function withButlerClient<T>(
  parentLogger: Logger,
  cb: WithCB<T>
): Promise<T> {
  const { endpoint } = getRootState().butlerd;
  if (!endpoint) {
    throw new Error(`no butlerd endpoint yet`);
  }
  const client = new Client(endpoint);
  await client.connect();
  setupLogging(client, parentLogger);

  let res: T;
  let err: Error;
  try {
    res = await cb(client);
  } catch (e) {
    if (getRootState().system.quitting) {
      // ignore butlerd error when quitting
    } else {
      console.error(`Caught butler error:`);
      if (isInternalError(e)) {
        const ed = getRpcErrorData(e);
        if (ed) {
          console.error(`butler version: ${ed.butlerVersion}`);
          console.error(`Golang stack:\n${ed.stack}`);
        }
        console.error(`JavaScript stack: ${e.stack}`);
      } else {
        console.error(`${e.message}`);
      }
      err = e;
    }
  } finally {
    client.close();
  }

  if (err) {
    throw err;
  }
  return res;
}
开发者ID:HorrerGames,项目名称:itch,代码行数:42,代码来源:utils.ts

示例7: setupClient

export function setupClient(
  client: Client,
  parentLogger: Logger,
  ctx: MinimalContext
) {
  client.onNotification(messages.Progress, ({ params }) => {
    ctx.emitProgress(params);
  });

  setupLogging(client, parentLogger);
}
开发者ID:HorrerGames,项目名称:itch,代码行数:11,代码来源:utils.ts

示例8: async

    work: async () => {
      client = new Client(store.getState().butlerd.endpoint);
      await client.connect();
      try {
        setupClient(client, logger, ctx);

        client.on(messages.PickManifestAction, async ({ actions }) => {
          const index = await pickManifestAction(store, actions, game);
          return { index };
        });

        client.on(messages.HTMLLaunch, async params => {
          return await performHTMLLaunch({
            ctx,
            logger,
            game,
            params,
          });
        });

        client.on(messages.ShellLaunch, async ({ itemPath }) => {
          shell.openItem(itemPath);
          return {};
        });

        client.on(messages.URLLaunch, async ({ url }) => {
          store.dispatch(actions.navigate({ window: "root", url }));
          return {};
        });

        client.on(messages.PrereqsStarted, async ({ tasks }) => {
          prereqsStateParams = {
            gameTitle: game.title,
            tasks: {},
          };

          for (const name of Object.keys(tasks)) {
            const task = tasks[name];
            prereqsStateParams.tasks[name] = {
              fullName: task.fullName,
              order: task.order,
              status: PrereqStatus.Pending,
              progress: 0,
              eta: 0,
              bps: 0,
            };
          }

          prereqsModal = modalWidgets.prereqsState.make({
            window: "root",
            title: ["grid.item.installing"],
            message: "",
            widgetParams: prereqsStateParams,
            buttons: [
              {
                id: "modal-cancel",
                label: ["prompt.action.cancel"],
                action: actions.abortTask({ id: ctx.getTaskId() }),
                className: "secondary",
              },
            ],
            unclosable: true,
          });
          store.dispatch(actions.openModal(prereqsModal));
        });

        client.on(
          messages.PrereqsTaskState,
          async ({ name, status, progress, eta, bps }) => {
            if (!prereqsModal) {
              return;
            }

            let state = {
              ...prereqsStateParams.tasks[name],
              status,
              progress,
              eta,
              bps,
            };

            let tasks = {
              ...prereqsStateParams.tasks,
              [name]: state,
            };

            prereqsStateParams = { ...prereqsStateParams, tasks };

            store.dispatch(
              actions.updateModalWidgetParams(
                modalWidgets.prereqsState.update({
                  id: prereqsModal.id,
                  widgetParams: prereqsStateParams,
                })
              )
            );
          }
        );

        client.on(messages.PrereqsFailed, async ({ errorStack, error }) => {
//.........这里部分代码省略.........
开发者ID:HorrerGames,项目名称:itch,代码行数:101,代码来源:perform-launch.ts

示例9: cancel

 async cancel() {
   this.setPhase(Phase.CANCELLING);
   await this.client.call(messages.DownloadsDriveCancel, {});
   this.client = null;
 }
开发者ID:HorrerGames,项目名称:itch,代码行数:5,代码来源:driver-persistent-state.ts


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