Z ZPI 文档 v0.3.8
介绍页

源码

tests/interactive/window-focus.spec.ts

typescript24 行查看原文
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { launchDesktop } from "../helpers/desktop.ts";
import { expect, test } from "../helpers/test.ts";

test("interactive: native window activation and focus after hiding", async () => {
  const dir = await mkdtemp(join(tmpdir(), "zpi-visible-"));
  const app = await launchDesktop({ dir, url: "" });
  await app.firstWindow();
  await app.evaluate(({ app, BrowserWindow }) => {
    BrowserWindow.getAllWindows()[0].hide();
    app.emit("activate", {}, false);
  });
  await expect
    .poll(() =>
      app.evaluate(({ BrowserWindow }) => {
        const window = BrowserWindow.getAllWindows()[0];
        return window.isVisible() && window.isFocused();
      }),
    )
    .toBe(true);
});