mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-28 03:05:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccd9f0a436 |
@@ -96,6 +96,7 @@ jobs:
|
||||
publish-macos:
|
||||
needs: [create-release]
|
||||
if: ${{ always() && (needs.create-release.result == 'success' || needs.create-release.result == 'skipped') && ((github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'macos')) || (github.event_name == 'push' && (startsWith(github.ref_name, 'v') || startsWith(github.ref_name, 'desktop-v') || startsWith(github.ref_name, 'desktop-macos-v')))) }}
|
||||
timeout-minutes: 45
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -181,7 +182,7 @@ jobs:
|
||||
npm run build:desktop "${build_args[@]}"
|
||||
|
||||
- name: Upload packaged smoke diagnostics
|
||||
if: failure()
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: desktop-smoke-macos-${{ matrix.electron_arch }}
|
||||
|
||||
@@ -11,6 +11,8 @@ const assert = require("node:assert/strict");
|
||||
|
||||
const EXECUTABLE_NAME = "Paseo";
|
||||
const SMOKE_TIMEOUT_MS = 60_000;
|
||||
const DAEMON_STATUS_CALL_TIMEOUT_MS = 10_000;
|
||||
const ARTIFACT_PAGE_TIMEOUT_MS = 5_000;
|
||||
const EXIT_TIMEOUT_MS = 10_000;
|
||||
const TERMINAL_CAPTURE_ATTEMPTS = 20;
|
||||
const TERMINAL_CAPTURE_INTERVAL_MS = 500;
|
||||
@@ -291,14 +293,122 @@ function readIfExists(filePath) {
|
||||
return fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : null;
|
||||
}
|
||||
|
||||
function formatLogs({ stdout, stderr, userData, daemonHome }) {
|
||||
function captureProcessList() {
|
||||
if (process.platform === "win32") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = spawnSync("ps", ["-axo", "pid,ppid,%cpu,%mem,rss,state,comm,args"], {
|
||||
encoding: "utf8",
|
||||
timeout: 10_000,
|
||||
});
|
||||
if (result.error) {
|
||||
return `<ps error: ${result.error.message}>`;
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
return `<ps exited ${result.status}: ${result.stderr.trim() || "<empty>"}>`;
|
||||
}
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
function captureVmStat() {
|
||||
if (process.platform !== "darwin") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = spawnSync("vm_stat", [], {
|
||||
encoding: "utf8",
|
||||
timeout: 10_000,
|
||||
});
|
||||
if (result.error) {
|
||||
return `<vm_stat error: ${result.error.message}>`;
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
return `<vm_stat exited ${result.status}: ${result.stderr.trim() || "<empty>"}>`;
|
||||
}
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
function extractPaseoElectronPids(processList) {
|
||||
if (!processList) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const pids = [];
|
||||
for (const line of processList.split(/\r?\n/).slice(1)) {
|
||||
if (!line.includes("Paseo.app/Contents/")) {
|
||||
continue;
|
||||
}
|
||||
const match = line.trim().match(/^(\d+)\s+/);
|
||||
if (match) {
|
||||
pids.push(Number(match[1]));
|
||||
}
|
||||
}
|
||||
return pids.slice(0, 6);
|
||||
}
|
||||
|
||||
function captureDarwinSamples(artifactDir, processList) {
|
||||
if (process.platform !== "darwin") {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const pid of extractPaseoElectronPids(processList)) {
|
||||
const result = spawnSync("sample", [String(pid), "1"], {
|
||||
encoding: "utf8",
|
||||
timeout: 10_000,
|
||||
});
|
||||
const output = result.error
|
||||
? `<sample error for pid ${pid}: ${result.error.message}>`
|
||||
: [result.stdout, result.stderr].filter(Boolean).join("\n");
|
||||
fs.writeFileSync(path.join(artifactDir, `sample-${pid}.txt`), `${output}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
function filterRelevantProcesses(processList) {
|
||||
if (!processList) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lines = processList.split(/\r?\n/);
|
||||
const header = lines[0] ?? "";
|
||||
const matching = lines.slice(1).filter((line) => /paseo|node/i.test(line));
|
||||
return [header, ...matching].filter(Boolean).join("\n") || "<none>";
|
||||
}
|
||||
|
||||
function raceWithTimeout(promise, timeoutMs, label) {
|
||||
// Prevent unhandled rejections if the inner promise rejects after the timeout wins.
|
||||
promise.catch(() => undefined);
|
||||
let timer = null;
|
||||
const timeoutPromise = new Promise((_, reject) => {
|
||||
timer = setTimeout(() => {
|
||||
reject(new Error(`${label} timed out after ${timeoutMs}ms`));
|
||||
}, timeoutMs);
|
||||
});
|
||||
return Promise.race([promise, timeoutPromise]).finally(() => {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function formatLogs({
|
||||
stdout,
|
||||
stderr,
|
||||
userData,
|
||||
daemonHome,
|
||||
processList = captureProcessList(),
|
||||
vmStat = captureVmStat(),
|
||||
}) {
|
||||
const desktopLog = readIfExists(path.join(userData, "logs", "main.log"));
|
||||
const daemonLog = readIfExists(path.join(daemonHome, "daemon.log"));
|
||||
const relevantProcesses = filterRelevantProcesses(processList);
|
||||
return [
|
||||
`App stdout:\n${stdout.join("").trim() || "<empty>"}`,
|
||||
`App stderr:\n${stderr.join("").trim() || "<empty>"}`,
|
||||
`Desktop log:\n${desktopLog?.trim() || "<missing>"}`,
|
||||
`Daemon log:\n${daemonLog?.trim() || "<missing>"}`,
|
||||
`Live processes (paseo|node):\n${relevantProcesses || "<unavailable>"}`,
|
||||
...(vmStat !== null ? [`vm_stat:\n${vmStat}`] : []),
|
||||
].join("\n\n");
|
||||
}
|
||||
|
||||
@@ -308,6 +418,8 @@ async function writeSmokeArtifacts({ page, stdout, stderr, userData, daemonHome,
|
||||
return;
|
||||
}
|
||||
|
||||
const processList = captureProcessList();
|
||||
const vmStat = captureVmStat();
|
||||
fs.mkdirSync(artifactDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(artifactDir, error ? "failure.txt" : "success.txt"),
|
||||
@@ -317,10 +429,21 @@ async function writeSmokeArtifacts({ page, stdout, stderr, userData, daemonHome,
|
||||
stderr,
|
||||
userData,
|
||||
daemonHome,
|
||||
processList,
|
||||
vmStat,
|
||||
},
|
||||
)}\n`,
|
||||
);
|
||||
|
||||
if (processList !== null) {
|
||||
fs.writeFileSync(path.join(artifactDir, "ps.txt"), `${processList}\n`);
|
||||
}
|
||||
if (vmStat !== null) {
|
||||
fs.writeFileSync(path.join(artifactDir, "vm_stat.txt"), `${vmStat}\n`);
|
||||
}
|
||||
if (error) {
|
||||
captureDarwinSamples(artifactDir, processList);
|
||||
}
|
||||
const desktopLog = readIfExists(path.join(userData, "logs", "main.log"));
|
||||
if (desktopLog !== null) {
|
||||
fs.writeFileSync(path.join(artifactDir, "desktop-main.log"), desktopLog);
|
||||
@@ -331,8 +454,8 @@ async function writeSmokeArtifacts({ page, stdout, stderr, userData, daemonHome,
|
||||
}
|
||||
|
||||
if (page) {
|
||||
const renderer = await page
|
||||
.evaluate(() => ({
|
||||
const renderer = await raceWithTimeout(
|
||||
page.evaluate(() => ({
|
||||
url: window.location.href,
|
||||
title: document.title,
|
||||
rootChildCount: document.querySelector("#root")?.childElementCount ?? 0,
|
||||
@@ -341,15 +464,19 @@ async function writeSmokeArtifacts({ page, stdout, stderr, userData, daemonHome,
|
||||
typeof window.paseoDesktop === "object" && window.paseoDesktop !== null
|
||||
? Object.keys(window.paseoDesktop)
|
||||
: [],
|
||||
}))
|
||||
.catch((evaluationError) => ({ evaluationError: String(evaluationError) }));
|
||||
})),
|
||||
ARTIFACT_PAGE_TIMEOUT_MS,
|
||||
"renderer artifact capture",
|
||||
).catch((evaluationError) => ({ evaluationError: String(evaluationError) }));
|
||||
fs.writeFileSync(
|
||||
path.join(artifactDir, "renderer.json"),
|
||||
`${JSON.stringify(renderer, null, 2)}\n`,
|
||||
);
|
||||
await page
|
||||
.screenshot({ path: path.join(artifactDir, "renderer.png"), fullPage: true })
|
||||
.catch(() => undefined);
|
||||
await raceWithTimeout(
|
||||
page.screenshot({ path: path.join(artifactDir, "renderer.png"), fullPage: true }),
|
||||
ARTIFACT_PAGE_TIMEOUT_MS,
|
||||
"renderer screenshot capture",
|
||||
).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,10 +632,24 @@ async function waitForRendererStartedDaemon({
|
||||
}) {
|
||||
let lastStatus = null;
|
||||
let lastError = null;
|
||||
let loggedFirstOutcome = false;
|
||||
let attempt = 0;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
attempt += 1;
|
||||
const callTimeoutMs = Math.min(DAEMON_STATUS_CALL_TIMEOUT_MS, remainingTime(deadline));
|
||||
try {
|
||||
lastStatus = await page.evaluate(() => window.paseoDesktop.invoke("desktop_daemon_status"));
|
||||
lastStatus = await raceWithTimeout(
|
||||
page.evaluate(() => window.paseoDesktop.invoke("desktop_daemon_status")),
|
||||
callTimeoutMs,
|
||||
"desktop_daemon_status",
|
||||
);
|
||||
if (!loggedFirstOutcome) {
|
||||
loggedFirstOutcome = true;
|
||||
console.log(
|
||||
`Packaged desktop smoke: first desktop_daemon_status response (attempt ${attempt}): ${JSON.stringify(lastStatus)}`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
lastStatus?.status === "running" &&
|
||||
lastStatus.desktopManaged === true &&
|
||||
@@ -522,8 +663,16 @@ async function waitForRendererStartedDaemon({
|
||||
}
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
if (!loggedFirstOutcome || String(error).includes("timed out")) {
|
||||
loggedFirstOutcome = true;
|
||||
console.warn(
|
||||
`Packaged desktop smoke: desktop_daemon_status attempt ${attempt} failed: ${error}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (Date.now() < deadline) {
|
||||
await delay(Math.min(250, remainingTime(deadline)));
|
||||
}
|
||||
await delay(250);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
|
||||
@@ -88,4 +88,34 @@ describe("external CLI", () => {
|
||||
localDaemon: "running",
|
||||
});
|
||||
});
|
||||
|
||||
it("terminates and rejects when an external CLI subprocess hangs past the timeout", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const kill = vi.fn();
|
||||
const child = new EventEmitter() as EventEmitter & {
|
||||
stdout: EventEmitter;
|
||||
stderr: EventEmitter;
|
||||
kill: typeof kill;
|
||||
};
|
||||
child.stdout = new EventEmitter();
|
||||
child.stderr = new EventEmitter();
|
||||
child.kill = kill;
|
||||
mocks.spawnProcess.mockReturnValueOnce(child);
|
||||
|
||||
const pending = runExternalCliJsonCommand(["daemon", "status", "--json"]);
|
||||
const assertion = expect(pending).rejects.toThrow(
|
||||
"CLI command timed out after 15000ms: daemon status --json",
|
||||
);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(15_000);
|
||||
await assertion;
|
||||
expect(kill).toHaveBeenCalledWith("SIGTERM");
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(kill).toHaveBeenCalledWith("SIGKILL");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,8 +38,13 @@ function createExternalCliInvocation(args: string[]): NodeEntrypointInvocation {
|
||||
});
|
||||
}
|
||||
|
||||
const DEFAULT_EXTERNAL_CLI_TIMEOUT_MS = 15_000;
|
||||
const EXTERNAL_CLI_KILL_GRACE_MS = 2_000;
|
||||
|
||||
function spawnExternalCli(
|
||||
invocation: NodeEntrypointInvocation,
|
||||
args: string[],
|
||||
timeoutMs = DEFAULT_EXTERNAL_CLI_TIMEOUT_MS,
|
||||
): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawnProcess(invocation.command, invocation.args, {
|
||||
@@ -50,6 +55,44 @@ function spawnExternalCli(
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
let settled = false;
|
||||
let killTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const cleanupTimers = () => {
|
||||
clearTimeout(timeoutTimer);
|
||||
if (killTimer !== null) {
|
||||
clearTimeout(killTimer);
|
||||
killTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const timeoutTimer = setTimeout(() => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
log.warn("[desktop external-cli]", "CLI command timed out", {
|
||||
args,
|
||||
timeoutMs,
|
||||
command: invocation.command,
|
||||
stdout: stdout.trim().slice(0, 500),
|
||||
stderr: stderr.trim().slice(0, 500),
|
||||
});
|
||||
try {
|
||||
child.kill("SIGTERM");
|
||||
} catch {
|
||||
// Ignore kill failures if the process already exited.
|
||||
}
|
||||
killTimer = setTimeout(() => {
|
||||
try {
|
||||
child.kill("SIGKILL");
|
||||
} catch {
|
||||
// Ignore kill failures if the process already exited.
|
||||
}
|
||||
}, EXTERNAL_CLI_KILL_GRACE_MS);
|
||||
killTimer.unref?.();
|
||||
reject(new Error(`CLI command timed out after ${timeoutMs}ms: ${args.join(" ")}`));
|
||||
}, timeoutMs);
|
||||
|
||||
child.stdout!.on("data", (data: Buffer) => {
|
||||
stdout += data.toString();
|
||||
@@ -58,8 +101,21 @@ function spawnExternalCli(
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
child.on("error", reject);
|
||||
child.on("error", (error) => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
cleanupTimers();
|
||||
reject(error);
|
||||
});
|
||||
child.on("close", (exitCode) => {
|
||||
if (settled) {
|
||||
cleanupTimers();
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
cleanupTimers();
|
||||
resolve({ stdout, stderr, exitCode });
|
||||
});
|
||||
});
|
||||
@@ -79,7 +135,7 @@ function externalCliFailureMessage(
|
||||
|
||||
export async function runExternalCliTextCommand(args: string[]): Promise<string> {
|
||||
const invocation = createExternalCliInvocation(args);
|
||||
const result = await spawnExternalCli(invocation);
|
||||
const result = await spawnExternalCli(invocation, args);
|
||||
|
||||
if (result.exitCode !== 0) {
|
||||
const stderr = result.stderr.trim();
|
||||
@@ -98,7 +154,7 @@ export async function runExternalCliTextCommand(args: string[]): Promise<string>
|
||||
|
||||
export async function runExternalCliJsonCommand(args: string[]): Promise<unknown> {
|
||||
const invocation = createExternalCliInvocation(args);
|
||||
const result = await spawnExternalCli(invocation);
|
||||
const result = await spawnExternalCli(invocation, args);
|
||||
|
||||
if (result.exitCode !== 0) {
|
||||
const stderr = result.stderr.trim();
|
||||
|
||||
@@ -84,6 +84,7 @@ import {
|
||||
resolveStagingUserId,
|
||||
runElectronQuitAndInstall,
|
||||
shouldInstallAppUpdateOnQuit,
|
||||
shouldUseWindowProgressBar,
|
||||
} from "./auto-updater";
|
||||
|
||||
describe("checkForAppUpdate", () => {
|
||||
@@ -160,43 +161,109 @@ describe("checkForAppUpdate", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("forwards download-progress to window progress bars and renderer events", async () => {
|
||||
it("forwards download-progress to window progress bars on non-darwin platforms and avoids idle clears", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("linux");
|
||||
const setProgressBar = vi.fn();
|
||||
const send = vi.fn();
|
||||
getAllWindowsMock.mockReturnValue([
|
||||
{ isDestroyed: () => false, setProgressBar, webContents: { send } },
|
||||
]);
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: { version: "1.2.6" },
|
||||
});
|
||||
try {
|
||||
getAllWindowsMock.mockReturnValue([
|
||||
{ isDestroyed: () => false, setProgressBar, webContents: { send } },
|
||||
]);
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: { version: "1.2.6" },
|
||||
});
|
||||
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "stable",
|
||||
intent: "automatic",
|
||||
autoDownload: true,
|
||||
});
|
||||
autoUpdaterMock.handlers.get("download-progress")?.({
|
||||
percent: 42,
|
||||
transferred: 420,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "stable",
|
||||
intent: "automatic",
|
||||
autoDownload: true,
|
||||
});
|
||||
expect(setProgressBar).not.toHaveBeenCalled();
|
||||
|
||||
expect(setProgressBar).toHaveBeenCalledWith(0.42);
|
||||
expect(send).toHaveBeenCalledWith("paseo:event:app-update-download-progress", {
|
||||
version: "1.2.6",
|
||||
percent: 42,
|
||||
transferred: 420,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
autoUpdaterMock.handlers.get("download-progress")?.({
|
||||
percent: 42,
|
||||
transferred: 420,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
|
||||
autoUpdaterMock.handlers.get("update-downloaded")?.({ version: "1.2.6" });
|
||||
expect(setProgressBar).toHaveBeenLastCalledWith(-1);
|
||||
expect(send).toHaveBeenLastCalledWith("paseo:event:app-update-download-progress", null);
|
||||
getAllWindowsMock.mockReturnValue([]);
|
||||
expect(setProgressBar).toHaveBeenCalledWith(0.42);
|
||||
expect(send).toHaveBeenCalledWith("paseo:event:app-update-download-progress", {
|
||||
version: "1.2.6",
|
||||
percent: 42,
|
||||
transferred: 420,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
|
||||
autoUpdaterMock.handlers.get("update-downloaded")?.({ version: "1.2.6" });
|
||||
expect(setProgressBar).toHaveBeenLastCalledWith(-1);
|
||||
expect(setProgressBar).toHaveBeenCalledTimes(2);
|
||||
expect(send).toHaveBeenLastCalledWith("paseo:event:app-update-download-progress", null);
|
||||
|
||||
// A subsequent idle clear (e.g., switching channels) must not call setProgressBar(-1) again.
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: false,
|
||||
updateInfo: { version: "1.2.3" },
|
||||
});
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "beta",
|
||||
intent: "manual",
|
||||
});
|
||||
expect(setProgressBar).toHaveBeenCalledTimes(2);
|
||||
} finally {
|
||||
getAllWindowsMock.mockReturnValue([]);
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("skips window progress bars on darwin while still forwarding renderer events", async () => {
|
||||
expect(shouldUseWindowProgressBar("darwin")).toBe(false);
|
||||
expect(shouldUseWindowProgressBar("win32")).toBe(true);
|
||||
expect(shouldUseWindowProgressBar("linux")).toBe(true);
|
||||
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("darwin");
|
||||
const setProgressBar = vi.fn();
|
||||
const send = vi.fn();
|
||||
try {
|
||||
getAllWindowsMock.mockReturnValue([
|
||||
{ isDestroyed: () => false, setProgressBar, webContents: { send } },
|
||||
]);
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: { version: "1.2.11" },
|
||||
});
|
||||
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "stable",
|
||||
intent: "automatic",
|
||||
autoDownload: true,
|
||||
});
|
||||
autoUpdaterMock.handlers.get("download-progress")?.({
|
||||
percent: 55,
|
||||
transferred: 550,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
autoUpdaterMock.handlers.get("update-downloaded")?.({ version: "1.2.11" });
|
||||
|
||||
expect(setProgressBar).not.toHaveBeenCalled();
|
||||
expect(send).toHaveBeenCalledWith("paseo:event:app-update-download-progress", {
|
||||
version: "1.2.11",
|
||||
percent: 55,
|
||||
transferred: 550,
|
||||
total: 1000,
|
||||
bytesPerSecond: 100,
|
||||
});
|
||||
expect(send).toHaveBeenLastCalledWith("paseo:event:app-update-download-progress", null);
|
||||
} finally {
|
||||
getAllWindowsMock.mockReturnValue([]);
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("gates automatic checks and autoDownload from desktop settings and falls back to automatic on read failure", async () => {
|
||||
@@ -253,40 +320,45 @@ describe("checkForAppUpdate", () => {
|
||||
});
|
||||
|
||||
it("does not fail update events when setProgressBar throws", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("linux");
|
||||
const send = vi.fn();
|
||||
getAllWindowsMock.mockReturnValue([
|
||||
{
|
||||
isDestroyed: () => false,
|
||||
setProgressBar: () => {
|
||||
throw new Error("unsupported desktop environment");
|
||||
try {
|
||||
getAllWindowsMock.mockReturnValue([
|
||||
{
|
||||
isDestroyed: () => false,
|
||||
setProgressBar: () => {
|
||||
throw new Error("unsupported desktop environment");
|
||||
},
|
||||
webContents: { send },
|
||||
},
|
||||
webContents: { send },
|
||||
},
|
||||
]);
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: { version: "1.2.7" },
|
||||
});
|
||||
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "stable",
|
||||
intent: "automatic",
|
||||
autoDownload: true,
|
||||
});
|
||||
expect(() => {
|
||||
autoUpdaterMock.handlers.get("download-progress")?.({
|
||||
percent: 50,
|
||||
transferred: 50,
|
||||
total: 100,
|
||||
bytesPerSecond: 10,
|
||||
]);
|
||||
autoUpdaterMock.checkForUpdates.mockResolvedValueOnce({
|
||||
isUpdateAvailable: true,
|
||||
updateInfo: { version: "1.2.7" },
|
||||
});
|
||||
}).not.toThrow();
|
||||
expect(send).toHaveBeenCalledWith(
|
||||
"paseo:event:app-update-download-progress",
|
||||
expect.objectContaining({ version: "1.2.7", percent: 50 }),
|
||||
);
|
||||
getAllWindowsMock.mockReturnValue([]);
|
||||
|
||||
await checkForAppUpdate({
|
||||
currentVersion: "1.2.3",
|
||||
releaseChannel: "stable",
|
||||
intent: "automatic",
|
||||
autoDownload: true,
|
||||
});
|
||||
expect(() => {
|
||||
autoUpdaterMock.handlers.get("download-progress")?.({
|
||||
percent: 50,
|
||||
transferred: 50,
|
||||
total: 100,
|
||||
bytesPerSecond: 10,
|
||||
});
|
||||
}).not.toThrow();
|
||||
expect(send).toHaveBeenCalledWith(
|
||||
"paseo:event:app-update-download-progress",
|
||||
expect.objectContaining({ version: "1.2.7", percent: 50 }),
|
||||
);
|
||||
} finally {
|
||||
getAllWindowsMock.mockReturnValue([]);
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("reports a failure when quitAndInstall emits an installer error and returns normally", async () => {
|
||||
|
||||
@@ -132,6 +132,14 @@ export function shouldInstallAppUpdateOnQuit(input: {
|
||||
}
|
||||
|
||||
const APP_UPDATE_DOWNLOAD_PROGRESS_EVENT = "paseo:event:app-update-download-progress";
|
||||
const activeProgressBarWindows = new WeakSet<BrowserWindow>();
|
||||
|
||||
// macOS 26 Intel under Electron 44 wedges the main process and leaks gigabytes of
|
||||
// IOSurfaces in VizCompositorThread when BrowserWindow.setProgressBar() touches the
|
||||
// Dock tile. In-app download progress still updates via APP_UPDATE_DOWNLOAD_PROGRESS_EVENT.
|
||||
export function shouldUseWindowProgressBar(platform: NodeJS.Platform): boolean {
|
||||
return platform !== "darwin";
|
||||
}
|
||||
|
||||
function resolveProgressBarValue(progress: AppUpdateDownloadProgress | null): number {
|
||||
if (progress === null) return -1;
|
||||
@@ -141,12 +149,22 @@ function resolveProgressBarValue(progress: AppUpdateDownloadProgress | null): nu
|
||||
|
||||
function broadcastDownloadProgress(progress: AppUpdateDownloadProgress | null): void {
|
||||
const normalizedBar = resolveProgressBarValue(progress);
|
||||
const useWindowProgressBar = shouldUseWindowProgressBar(process.platform);
|
||||
for (const win of BrowserWindow.getAllWindows()) {
|
||||
if (win.isDestroyed()) continue;
|
||||
try {
|
||||
win.setProgressBar(normalizedBar);
|
||||
} catch {
|
||||
// Progress bar support is optional across desktop environments.
|
||||
const shouldUpdateProgressBar =
|
||||
useWindowProgressBar && (progress !== null || activeProgressBarWindows.has(win));
|
||||
if (shouldUpdateProgressBar) {
|
||||
try {
|
||||
win.setProgressBar(normalizedBar);
|
||||
if (progress === null) {
|
||||
activeProgressBarWindows.delete(win);
|
||||
} else {
|
||||
activeProgressBarWindows.add(win);
|
||||
}
|
||||
} catch {
|
||||
// Progress bar support is optional across desktop environments.
|
||||
}
|
||||
}
|
||||
try {
|
||||
win.webContents.send(APP_UPDATE_DOWNLOAD_PROGRESS_EVENT, progress);
|
||||
|
||||
Reference in New Issue
Block a user