Fix: Add Windows support for SQLite database access (Issue #23)
Replace CLI-based sqlite3 extraction with better-sqlite3 library: - Create shared src/db/database.js module for cross-platform SQLite access - Remove duplicate extractTokenFromDB functions from token-extractor.js and account-manager.js - Add better-sqlite3 dependency with prebuilt Windows/Mac/Linux binaries - Improve error handling with specific messages for common issues Fixes #23 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import { readFile, writeFile, mkdir, access } from 'fs/promises';
|
||||
import { constants as fsConstants } from 'fs';
|
||||
import { dirname } from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import {
|
||||
ACCOUNT_CONFIG_PATH,
|
||||
ANTIGRAVITY_DB_PATH,
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
} from './constants.js';
|
||||
import { refreshAccessToken } from './oauth.js';
|
||||
import { formatDuration } from './utils/helpers.js';
|
||||
import { getAuthStatus } from './db/database.js';
|
||||
|
||||
export class AccountManager {
|
||||
#accounts = [];
|
||||
@@ -92,7 +92,7 @@ export class AccountManager {
|
||||
*/
|
||||
async #loadDefaultAccount() {
|
||||
try {
|
||||
const authData = this.#extractTokenFromDB();
|
||||
const authData = getAuthStatus();
|
||||
if (authData?.apiKey) {
|
||||
this.#accounts = [{
|
||||
email: authData.email || 'default@antigravity',
|
||||
@@ -115,22 +115,6 @@ export class AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract token from Antigravity's SQLite database
|
||||
*/
|
||||
#extractTokenFromDB(dbPath = ANTIGRAVITY_DB_PATH) {
|
||||
const result = execSync(
|
||||
`sqlite3 "${dbPath}" "SELECT value FROM ItemTable WHERE key = 'antigravityAuthStatus';"`,
|
||||
{ encoding: 'utf-8', timeout: 5000 }
|
||||
);
|
||||
|
||||
if (!result || !result.trim()) {
|
||||
throw new Error('No auth status found in database');
|
||||
}
|
||||
|
||||
return JSON.parse(result.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of accounts
|
||||
* @returns {number} Number of configured accounts
|
||||
@@ -453,7 +437,7 @@ export class AccountManager {
|
||||
} else {
|
||||
// Extract from database
|
||||
const dbPath = account.dbPath || ANTIGRAVITY_DB_PATH;
|
||||
const authData = this.#extractTokenFromDB(dbPath);
|
||||
const authData = getAuthStatus(dbPath);
|
||||
token = authData.apiKey;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user