@freely01/opencode-notify 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -38
- package/cli.ts +27 -15
- package/config.ts +298 -37
- package/delayed-dispatcher.ts +135 -0
- package/dispatcher.ts +11 -6
- package/events.ts +35 -43
- package/index.ts +115 -62
- package/log.ts +90 -0
- package/message.ts +39 -2
- package/package.json +1 -1
- package/senders/screen-flash/index.ts +32 -0
- package/senders/screen-flash/linux.ts +29 -0
- package/senders/screen-flash/win32.ts +129 -0
- package/senders/system/darwin.ts +17 -0
- package/senders/system/index.ts +67 -0
- package/senders/system/linux.ts +16 -0
- package/senders/system/win32.ts +51 -0
- package/session-tracker.ts +133 -0
- package/store.ts +5 -4
- package/terminator-detect.ts +164 -0
- package/senders/screen-flash.ts +0 -42
- package/senders/system.ts +0 -88
package/senders/system.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 系统通知发送器
|
|
3
|
-
*
|
|
4
|
-
* 平台适配:
|
|
5
|
-
* - macOS: osascript(内置,无需额外安装)
|
|
6
|
-
* - Linux: notify-send(需 libnotify)
|
|
7
|
-
* - Windows: PowerShell Toast(需 BurntToast 模块)
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { execSync } from "node:child_process"
|
|
11
|
-
import type { Message } from "../message.js"
|
|
12
|
-
import type { Sender } from "./types.js"
|
|
13
|
-
|
|
14
|
-
export class SystemSender implements Sender {
|
|
15
|
-
readonly name = "system_message"
|
|
16
|
-
|
|
17
|
-
async send(msg: Message): Promise<void> {
|
|
18
|
-
const { title, body } = escapeForShell(msg.title, msg.body)
|
|
19
|
-
const platform = process.platform
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
if (platform === "darwin") {
|
|
23
|
-
this.sendMacOS(title, body)
|
|
24
|
-
} else if (platform === "linux") {
|
|
25
|
-
this.sendLinux(title, body)
|
|
26
|
-
} else if (platform === "win32") {
|
|
27
|
-
this.sendWindows(title, body)
|
|
28
|
-
}
|
|
29
|
-
// 其他平台静默忽略
|
|
30
|
-
} catch (err) {
|
|
31
|
-
throw new Error(`系统通知失败: ${err}`)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private sendMacOS(title: string, body: string): void {
|
|
36
|
-
// 使用 osascript 显示原生通知
|
|
37
|
-
const script = `display notification "${body}" with title "${title}" sound name "default"`
|
|
38
|
-
execSync(`osascript -e ${JSON.stringify(script)}`, {
|
|
39
|
-
timeout: 5000,
|
|
40
|
-
stdio: "ignore",
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private sendLinux(title: string, body: string): void {
|
|
45
|
-
execSync(`notify-send "${title}" "${body}"`, {
|
|
46
|
-
timeout: 5000,
|
|
47
|
-
stdio: "ignore",
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private sendWindows(title: string, body: string): void {
|
|
52
|
-
// 尝试使用 BurntToast,失败则用简单 MessageBox
|
|
53
|
-
const psScript = `
|
|
54
|
-
try {
|
|
55
|
-
New-BurntToastNotification -Text '${title}', '${body}' -ErrorAction Stop
|
|
56
|
-
} catch {
|
|
57
|
-
Add-Type -AssemblyName System.Windows.Forms
|
|
58
|
-
[System.Windows.Forms.MessageBox]::Show('${body}', '${title}')
|
|
59
|
-
}`
|
|
60
|
-
execSync(`powershell -NoProfile -Command ${JSON.stringify(psScript)}`, {
|
|
61
|
-
timeout: 10000,
|
|
62
|
-
stdio: "ignore",
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 转义标题和正文中的特殊字符,防止 shell 注入
|
|
69
|
-
*/
|
|
70
|
-
function escapeForShell(
|
|
71
|
-
title: string,
|
|
72
|
-
body: string,
|
|
73
|
-
): { title: string; body: string } {
|
|
74
|
-
return {
|
|
75
|
-
title: sanitize(title),
|
|
76
|
-
body: sanitize(body),
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function sanitize(s: string): string {
|
|
81
|
-
return s
|
|
82
|
-
.replace(/"/g, '\\"')
|
|
83
|
-
.replace(/'/g, "\\'")
|
|
84
|
-
.replace(/`/g, "\\`")
|
|
85
|
-
.replace(/\$/g, "\\$")
|
|
86
|
-
.replace(/\n/g, " ")
|
|
87
|
-
.replace(/\r/g, "")
|
|
88
|
-
}
|