mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
fix: resolve Windows Electron build failures for missing native modules (#8959)
Validated in local merge-train (devbox-vm-06-dev002) @ combined-tip (FAST gates green: static + changed tests + vitest — only pre-existing audit.test.ts flake). Evidence: /home/diegosouzapw/dev/proxys/OmniRoute/.claude/worktrees/merge-train-20260805-213228-suite.log
This commit is contained in:
@@ -43,7 +43,8 @@
|
||||
"appId": "online.omniroute.desktop",
|
||||
"productName": "OmniRoute",
|
||||
"copyright": "Copyright © 2025 OmniRoute",
|
||||
"buildDependenciesFromSource": true,
|
||||
"buildDependenciesFromSource": false,
|
||||
"npmRebuild": false,
|
||||
"directories": {
|
||||
"output": "dist-electron",
|
||||
"buildResources": "assets"
|
||||
|
||||
@@ -207,7 +207,10 @@ function toString(value: unknown): string {
|
||||
}
|
||||
|
||||
async function openBetterSqliteAuditDb(dbPath: string): Promise<AuditDatabase> {
|
||||
const Database = (await import("better-sqlite3")).default as unknown as new (
|
||||
const { createRequire } = await import("node:module");
|
||||
const _require = createRequire(import.meta.url);
|
||||
const mod = _require("better-sqlite3");
|
||||
const Database = (mod?.default || mod) as unknown as new (
|
||||
dbPath: string
|
||||
) => AuditDatabase;
|
||||
return new Database(dbPath);
|
||||
|
||||
@@ -3,6 +3,16 @@ import path from "path";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const _require = createRequire(import.meta.url);
|
||||
function getDatabaseClass() {
|
||||
try {
|
||||
if (process.versions.bun) {
|
||||
return _require("bun:sqlite").Database;
|
||||
}
|
||||
return _require("better-sqlite3");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const Database = process.versions.bun
|
||||
? (_require("bun:sqlite").Database as typeof import("better-sqlite3"))
|
||||
: (_require("better-sqlite3") as typeof import("better-sqlite3"));
|
||||
@@ -15,6 +25,8 @@ const getOmpDir = () => path.join(os.homedir(), ".omp", "agent");
|
||||
const getOmpDbPath = () => path.join(getOmpDir(), "agent.db");
|
||||
|
||||
export function getOmpCredentials(providerId: string) {
|
||||
const Database = getDatabaseClass();
|
||||
if (!Database) return { hasOmniRoute: false, baseUrl: null, apiKey: null };
|
||||
const dbPath = getOmpDbPath();
|
||||
try {
|
||||
const db = new Database(dbPath, databaseOptions(true));
|
||||
@@ -36,6 +48,8 @@ export function getOmpCredentials(providerId: string) {
|
||||
}
|
||||
|
||||
export function saveOmpCredentials(providerId: string, apiKey: string, baseUrl: string) {
|
||||
const Database = getDatabaseClass();
|
||||
if (!Database) return;
|
||||
const dbPath = getOmpDbPath();
|
||||
const db = new Database(dbPath, databaseOptions());
|
||||
|
||||
@@ -54,6 +68,8 @@ export function saveOmpCredentials(providerId: string, apiKey: string, baseUrl:
|
||||
}
|
||||
|
||||
export function deleteOmpCredentials(providerId: string) {
|
||||
const Database = getDatabaseClass();
|
||||
if (!Database) return;
|
||||
const dbPath = getOmpDbPath();
|
||||
const db = new Database(dbPath, databaseOptions());
|
||||
db.prepare("DELETE FROM auth_credentials WHERE provider = ?").run(providerId);
|
||||
|
||||
Reference in New Issue
Block a user