Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

1.3 KB
Raw Blame
const fs = require("fs");
const path = require("path");
const { app } = require("electron");

const SUBDIR = "sidecar-pids";

function pidDir() {
  return path.join(app.getPath("userData"), SUBDIR);
}

function pidPath(name) {
  return path.join(pidDir(), `${name}.pid`);
}

function write(name, pid) {
  if (!Number.isInteger(pid)) return;
  try {
    fs.mkdirSync(pidDir(), { recursive: true });
    fs.writeFileSync(pidPath(name), String(pid), "utf-8");
  } catch {
    // Best-effort; the registry is the primary shutdown path.
  }
}

function clear(name) {
  try {
    fs.unlinkSync(pidPath(name));
  } catch {
    // Already gone.
  }
}

function readAll() {
  const dir = pidDir();
  let files;
  try {
    files = fs.readdirSync(dir);
  } catch {
    return [];
  }

  const entries = [];
  for (const file of files) {
    if (!file.endsWith(".pid")) continue;
    try {
      const name = path.basename(file, ".pid");
      const raw = fs.readFileSync(path.join(dir, file), "utf-8").trim();
      const pid = Number(raw);
      if (!Number.isInteger(pid) || pid <= 0) continue;
      entries.push({ name, pid });
    } catch {
      // Best-effort recovery metadata; skip entries that vanished or cannot be read.
    }
  }
  return entries;
}

module.exports = { write, clear, readAll };