Skip to content

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

Batch transcription tombstone pushes into one request (#638)

Gabriel Stein079ee98b3351
diff --git a/electron-builder.json b/electron-builder.json
index 6fb53562c..d766dd142 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -124,7 +124,6 @@
]
}
],
- "afterSign": "scripts/afterSign.js",
"mac": {
"category": "public.app-category.productivity",
"target": ["dmg", "zip"],
diff --git a/scripts/afterPack.js b/scripts/afterPack.js
index 99f902409..6b45f7ce6 100644
--- a/scripts/afterPack.js
+++ b/scripts/afterPack.js
@@ -11,8 +11,95 @@
const fs = require("fs");
const path = require("path");
+const { execFileSync } = require("child_process");
const { Arch } = require("app-builder-lib");
+// ---------------------------------------------------------------------------
+// macOS resource binary signing
+// ---------------------------------------------------------------------------
+
+function resolveAppPath(context) {
+ if (context.electronPlatformName !== "darwin") {
+ return context.appOutDir;
+ }
+
+ if (context.appOutDir.endsWith(".app")) {
+ return context.appOutDir;
+ }
+
+ return path.join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`);
+}
+
+function resolveResourcesDir(context) {
+ return context.electronPlatformName === "darwin"
+ ? path.join(resolveAppPath(context), "Contents", "Resources")
+ : path.join(context.appOutDir, "resources");
+}
+
+function collectFiles(rootDir) {
+ if (!fs.existsSync(rootDir)) {
+ return [];
+ }
+
+ const files = [];
+ const queue = [rootDir];
+
+ while (queue.length > 0) {
+ const currentDir = queue.pop();
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
+
+ for (const entry of entries) {
+ const fullPath = path.join(currentDir, entry.name);
+
+ if (entry.isDirectory()) {
+ queue.push(fullPath);
+ continue;
+ }
+
+ if (entry.isFile()) {
+ files.push(fullPath);
+ }
+ }
+ }
+
+ return files;
+}
+
+function isMachOBinary(filePath) {
+ try {
+ const description = execFileSync("file", ["-b", filePath], {
+ encoding: "utf8",
+ stdio: ["ignore", "pipe", "ignore"],
+ });
+
+ return description.includes("Mach-O");
+ } catch {
+ return false;
+ }
+}
+
+function registerMacResourceBinariesForSigning(context) {
+ if (context.electronPlatformName !== "darwin") {
+ return;
+ }
+
+ const resourcesDir = resolveResourcesDir(context);
+ const machOFiles = collectFiles(resourcesDir).filter(isMachOBinary);
+
+ if (machOFiles.length === 0) {
+ return;
+ }
+
+ const macConfig = context.packager.platformSpecificBuildOptions;
+ const existingBinaries = Array.isArray(macConfig.binaries) ? macConfig.binaries : [];
+
+ macConfig.binaries = [...new Set([...existingBinaries, ...machOFiles])];
+
+ console.log(
+ ` afterPack: registered ${machOFiles.length} Mach-O files under Contents/Resources for signing`
+ );
+}
+
// ---------------------------------------------------------------------------
// onnxruntime-node binary stripping
// ---------------------------------------------------------------------------
@@ -22,15 +109,7 @@ function stripOnnxruntimeBinaries(context) {
const archName = Arch[context.arch]; // x64 | arm64 | ia32 | universal
// Resolve the resources directory inside the packed output
- const resourcesDir =
- platform === "darwin"
- ? path.join(
- context.appOutDir,
- `${context.packager.appInfo.productFilename}.app`,
- "Contents",
- "Resources"
- )
- : path.join(context.appOutDir, "resources");
+ const resourcesDir = resolveResourcesDir(context);
const onnxBinDir = path.join(
resourcesDir,
@@ -44,8 +123,7 @@ function stripOnnxruntimeBinaries(context) {
if (!fs.existsSync(onnxBinDir)) return;
// For universal macOS builds keep both arm64 and x64 under darwin/
- const keepArchs =
- archName === "universal" ? ["arm64", "x64"] : [archName];
+ const keepArchs = archName === "universal" ? ["arm64", "x64"] : [archName];
const platformDirs = fs.readdirSync(onnxBinDir);
let totalRemoved = 0;
@@ -130,15 +208,7 @@ function verifyMeetingAecHelper(context) {
}
const binaryName = `meeting-aec-helper-${platform}-${archName}${platform === "win32" ? ".exe" : ""}`;
- const resourcesDir =
- platform === "darwin"
- ? path.join(
- context.appOutDir,
- `${context.packager.appInfo.productFilename}.app`,
- "Contents",
- "Resources"
- )
- : path.join(context.appOutDir, "resources");
+ const resourcesDir = resolveResourcesDir(context);
const binaryPath = path.join(resourcesDir, "bin", binaryName);
if (!fs.existsSync(binaryPath)) {
@@ -159,4 +229,5 @@ exports.default = async function (context) {
stripOnnxruntimeBinaries(context);
wrapLinuxBinary(context);
verifyMeetingAecHelper(context);
+ registerMacResourceBinariesForSigning(context);
};
diff --git a/scripts/afterSign.js b/scripts/afterSign.js
deleted file mode 100644
index 57f91b376..000000000
--- a/scripts/afterSign.js
+++ /dev/null
@@ -1,104 +0,0 @@
-const fs = require("fs/promises");
-const path = require("path");
-const { execFileSync } = require("child_process");
-
-function resolveSigningIdentity(context) {
- const identity =
- context.packager?.platformSpecificBuildOptions?.identity ||
- context.packager?.config?.mac?.identity ||
- process.env.CSC_NAME ||
- null;
-
- if (!identity) {
- return null;
- }
-
- if (identity.includes(":")) {
- return identity;
- }
-
- return `Developer ID Application: ${identity}`;
-}
-
-async function collectFiles(rootDir) {
- const files = [];
- const queue = [rootDir];
-
- while (queue.length > 0) {
- const currentDir = queue.pop();
- const entries = await fs.readdir(currentDir, { withFileTypes: true });
-
- for (const entry of entries) {
- const fullPath = path.join(currentDir, entry.name);
-
- if (entry.isDirectory()) {
- queue.push(fullPath);
- continue;
- }
-
- if (entry.isFile()) {
- files.push(fullPath);
- }
- }
- }
-
- return files;
-}
-
-function isMachOBinary(filePath) {
- try {
- const description = execFileSync("file", ["-b", filePath], {
- encoding: "utf8",
- stdio: ["ignore", "pipe", "ignore"],
- });
- return description.includes("Mach-O");
- } catch {
- return false;
- }
-}
-
-function codesign(targetPath, identity, entitlementsPath = null) {
- const args = ["--force", "--timestamp", "--options", "runtime", "--sign", identity];
-
- if (entitlementsPath) {
- args.push("--entitlements", entitlementsPath);
- }
-
- args.push(targetPath);
- execFileSync("codesign", args, { stdio: "inherit" });
-}
-
-exports.default = async function afterSign(context) {
- if (context.electronPlatformName !== "darwin") {
- return;
- }
-
- if (process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false") {
- return;
- }
-
- const identity = resolveSigningIdentity(context);
- if (!identity) {
- console.warn("afterSign: skipping macOS re-sign because no signing identity was resolved");
- return;
- }
-
- const appName = context.packager.appInfo.productFilename;
- const appPath = path.join(context.appOutDir, `${appName}.app`);
- const resourcesPath = path.join(appPath, "Contents", "Resources");
- const entitlementsPath = path.join(__dirname, "..", "resources", "mac", "entitlements.mac.plist");
-
- const resourceFiles = await collectFiles(resourcesPath);
- const machOFiles = resourceFiles.filter(isMachOBinary);
-
- if (machOFiles.length > 0) {
- console.log(`afterSign: re-signing ${machOFiles.length} Mach-O files under Contents/Resources`);
- }
-
- for (const targetPath of machOFiles) {
- codesign(targetPath, identity);
- }
-
- console.log("afterSign: re-signing app bundle");
- codesign(appPath, identity, entitlementsPath);
-};
diff --git a/src/services/SyncService.ts b/src/services/SyncService.ts
index 4a873666e..78d431e50 100644
--- a/src/services/SyncService.ts
+++ b/src/services/SyncService.ts
@@ -450,13 +450,19 @@ class SyncService {
private async pushTranscriptionDeletes(): Promise<void> {
const deletes = (await window.electronAPI.getPendingTranscriptionDeletes?.()) ?? [];
- for (const t of deletes) {
- if (!t.cloud_id) continue;
+ const withCloudId = deletes.filter((t) => t.cloud_id);
+ if (withCloudId.length === 0) return;
+
+ for (let i = 0; i < withCloudId.length; i += TRANSCRIPTION_BATCH_SIZE) {
+ const chunk = withCloudId.slice(i, i + TRANSCRIPTION_BATCH_SIZE);
try {
- await TranscriptionsService.delete(t.cloud_id);
- await window.electronAPI.hardDeleteTranscription?.(t.id);
+ const { deleted } = await TranscriptionsService.batchDelete(chunk.map((t) => t.cloud_id!));
+ for (const cloudId of deleted) {
+ const local = chunk.find((t) => t.cloud_id === cloudId);
+ if (local) await window.electronAPI.hardDeleteTranscription?.(local.id);
+ }
} catch (err) {
- console.error("Transcription delete sync failed:", err);
+ console.error("Transcription batch delete failed:", err);
}
}
}
diff --git a/src/services/TranscriptionsService.ts b/src/services/TranscriptionsService.ts
index dd80a9e8a..589fb1d86 100644
--- a/src/services/TranscriptionsService.ts
+++ b/src/services/TranscriptionsService.ts
@@ -57,11 +57,16 @@ async function deleteTranscription(id: string): Promise<void> {
await cloudDelete("/api/transcriptions/delete", { id });
}
-export { create, batchCreate, list, deleteTranscription };
+async function batchDelete(ids: string[]): Promise<{ deleted: string[] }> {
+ return cloudPost<{ deleted: string[] }>("/api/transcriptions/batch-delete", { ids });
+}
+
+export { create, batchCreate, list, deleteTranscription, batchDelete };
export const TranscriptionsService = {
create,
batchCreate,
list,
delete: deleteTranscription,
+ batchDelete,
};