import { execFile } from 'child_process';
import { platform } from 'os';
export class OSNotificationChannel {
    name = 'os';
    async send(event) {
        const os = platform();
        if (os === 'darwin') {
            await this.macosNotify(event.title, event.body);
        }
        else if (os === 'linux') {
            await this.linuxNotify(event.title, event.body);
        }
        else {
            console.warn(`[OSNotification] Unsupported platform: ${os}`);
        }
    }
    macosNotify(title, body) {
        // 使用 execFile 避免 shell 注入，参数作为数组传递不经过 shell 解析
        const script = `display notification "${body.replace(/"/g, '\\"')}" with title "${title.replace(/"/g, '\\"')}" sound name "default"`;
        return new Promise((resolve) => {
            execFile('osascript', ['-e', script], (err) => {
                if (err)
                    console.error('[OSNotification] macOS notification failed:', err.message);
                resolve();
            });
        });
    }
    linuxNotify(title, body) {
        return new Promise((resolve) => {
            execFile('notify-send', [title, body], (err) => {
                if (err)
                    console.error('[OSNotification] Linux notification failed:', err.message);
                resolve();
            });
        });
    }
}
//# sourceMappingURL=os-channel.js.map