Skip to content

Commit 9abf5a2

Browse files
committed
Fix macOS 顶层无响应 bug
1 parent 06edab5 commit 9abf5a2

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
Open-source, free **Paste.app alternative**.
66

7+
中文提示:别再找 Paste 破解版了,直接用我们的 `paste` 开源版本吧。
8+
免费可用、代码透明,还支持按需自建同步服务。
9+
710
`paste` is a local-first clipboard manager for macOS (Paste-style), with an optional Cloudflare backend for cross-device sync.
811

912
- macOS: tray app, no main window, Quick Paste panel

apps/macos/electron/main.cjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,49 @@ const path = require("node:path");
1818
const { execFile, execFileSync } = require("node:child_process");
1919
const { autoUpdater } = require("electron-updater");
2020

21+
// Electron main process can crash with "write EPIPE" if stdout/stderr is a closed pipe
22+
// (common when launched via certain parent processes). Ignore broken-pipe writes so
23+
// transient logging doesn't bring down the app.
24+
const isIgnorablePipeWriteError = (err) =>
25+
Boolean(err) &&
26+
typeof err === "object" &&
27+
(err.code === "EPIPE" || err.code === "ERR_STREAM_DESTROYED" || err.code === "ERR_IPC_CHANNEL_CLOSED");
28+
29+
const patchBrokenPipeWrites = (stream) => {
30+
if (!stream) return;
31+
32+
try {
33+
if (typeof stream.on === "function") {
34+
stream.on("error", (err) => {
35+
if (isIgnorablePipeWriteError(err)) return;
36+
});
37+
}
38+
} catch {
39+
// ignore
40+
}
41+
42+
try {
43+
if (typeof stream.write !== "function") return;
44+
if (stream.write.__paste_patched) return;
45+
const origWrite = stream.write.bind(stream);
46+
const wrapped = (...args) => {
47+
try {
48+
return origWrite(...args);
49+
} catch (err) {
50+
if (isIgnorablePipeWriteError(err)) return false;
51+
throw err;
52+
}
53+
};
54+
wrapped.__paste_patched = true;
55+
stream.write = wrapped;
56+
} catch {
57+
// ignore
58+
}
59+
};
60+
61+
patchBrokenPipeWrites(process.stdout);
62+
patchBrokenPipeWrites(process.stderr);
63+
2164
const isDev = !app.isPackaged;
2265
const parsePort = (raw, fallback) => {
2366
const n = Number.parseInt(String(raw ?? ""), 10);

apps/macos/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const parsePort = (raw: unknown, fallback: number) => {
1212
const devPort = parsePort(process.env.PASTE_DEV_PORT ?? process.env.VITE_PORT, 5174);
1313

1414
export default defineConfig({
15+
base: "./",
1516
plugins: [react()],
1617
resolve: {
1718
alias: {

0 commit comments

Comments
 (0)