feat: add imessage rpc adapter
This commit is contained in:
33
src/imessage/probe.ts
Normal file
33
src/imessage/probe.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { detectBinary } from "../commands/onboard-helpers.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { createIMessageRpcClient } from "./client.js";
|
||||
|
||||
export type IMessageProbe = {
|
||||
ok: boolean;
|
||||
error?: string | null;
|
||||
};
|
||||
|
||||
export async function probeIMessage(
|
||||
timeoutMs = 2000,
|
||||
): Promise<IMessageProbe> {
|
||||
const cfg = loadConfig();
|
||||
const cliPath = cfg.imessage?.cliPath?.trim() || "imsg";
|
||||
const dbPath = cfg.imessage?.dbPath?.trim();
|
||||
const detected = await detectBinary(cliPath);
|
||||
if (!detected) {
|
||||
return { ok: false, error: `imsg not found (${cliPath})` };
|
||||
}
|
||||
|
||||
const client = await createIMessageRpcClient({
|
||||
cliPath,
|
||||
dbPath,
|
||||
});
|
||||
try {
|
||||
await client.request("chats.list", { limit: 1 }, { timeoutMs });
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
return { ok: false, error: String(err) };
|
||||
} finally {
|
||||
await client.stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user