fix: resolve Antigravity visibility issue on account switch
This commit is contained in:
1 parent
bc43cc101c
commit
1336de679f
3 files changed
+88
-29
No files matched your search
@@ -6,7 +6,7 @@ import { logger } from '../../utils/logger';
|
|||||||
|
|
||||||
import { shell } from 'electron';
|
import { shell } from 'electron';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { closeAntigravity, startAntigravity } from '../../ipc/process/handler';
|
import { closeAntigravity, startAntigravity, _waitForProcessExit } from '../../ipc/process/handler';
|
||||||
import { updateTrayMenu } from '../../ipc/tray/handler';
|
import { updateTrayMenu } from '../../ipc/tray/handler';
|
||||||
import { getAntigravityDbPaths } from '../../utils/paths';
|
import { getAntigravityDbPaths } from '../../utils/paths';
|
||||||
|
|
||||||
@@ -189,7 +189,12 @@ export async function switchCloudAccount(accountId: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Stop Antigravity Process
|
// 2. Stop Antigravity Process
|
||||||
await closeAntigravity(); // This waits for it to close
|
await closeAntigravity();
|
||||||
|
try {
|
||||||
|
await _waitForProcessExit(10000); // Wait up to 10s for it to truly vanish
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn('Process did not exit cleanly within timeout, but proceeding...', e);
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Backup Database (New Logic)
|
// 3. Backup Database (New Logic)
|
||||||
const dbPaths = getAntigravityDbPaths();
|
const dbPaths = getAntigravityDbPaths();
|
||||||
@@ -214,7 +219,7 @@ export async function switchCloudAccount(accountId: string): Promise<void> {
|
|||||||
|
|
||||||
// 3. Inject Token
|
// 3. Inject Token
|
||||||
// injectedCloudToken uses direct DB/FS access which is sync better-sqlite3.
|
// injectedCloudToken uses direct DB/FS access which is sync better-sqlite3.
|
||||||
CloudAccountRepo.injectCloudToken(account.token);
|
CloudAccountRepo.injectCloudToken(account);
|
||||||
|
|
||||||
// 4. Update usage and active status
|
// 4. Update usage and active status
|
||||||
CloudAccountRepo.updateLastUsed(account.id);
|
CloudAccountRepo.updateLastUsed(account.id);
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ export class CloudAccountRepo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static injectCloudToken(token: CloudAccount['token']): void {
|
static injectCloudToken(account: CloudAccount): void {
|
||||||
const dbPaths = getAntigravityDbPaths();
|
const dbPaths = getAntigravityDbPaths();
|
||||||
let dbPath: string | null = null;
|
let dbPath: string | null = null;
|
||||||
|
|
||||||
@@ -325,9 +325,9 @@ export class CloudAccountRepo {
|
|||||||
|
|
||||||
// 3. Create New Field 6
|
// 3. Create New Field 6
|
||||||
const newField = ProtobufUtils.createOAuthTokenInfo(
|
const newField = ProtobufUtils.createOAuthTokenInfo(
|
||||||
token.access_token,
|
account.token.access_token,
|
||||||
token.refresh_token,
|
account.token.refresh_token,
|
||||||
token.expiry_timestamp,
|
account.token.expiry_timestamp,
|
||||||
);
|
);
|
||||||
|
|
||||||
// 4. Concatenate
|
// 4. Concatenate
|
||||||
@@ -344,13 +344,33 @@ export class CloudAccountRepo {
|
|||||||
'jetskiStateSync.agentManagerInitState',
|
'jetskiStateSync.agentManagerInitState',
|
||||||
);
|
);
|
||||||
|
|
||||||
// 7. Inject Onboarding Flag (Missing in initial port)
|
// 7. Inject Onboarding Flag
|
||||||
db.prepare('INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)').run(
|
db.prepare('INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)').run(
|
||||||
'antigravityOnboarding',
|
'antigravityOnboarding',
|
||||||
'true',
|
'true',
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info(`Successfully injected cloud token into Antigravity database at ${dbPath}.`);
|
// 8. Update Auth Status (Fix for switching issue)
|
||||||
|
// This ensures the UI reflects the user we just switched to
|
||||||
|
const authStatus = {
|
||||||
|
name: account.name || account.email,
|
||||||
|
email: account.email,
|
||||||
|
apiKey: account.token.access_token, // Critical for session recognition
|
||||||
|
// userStatusProtoBinaryBase64: ... // We cannot generate this easily, hoping IDE fetches it
|
||||||
|
};
|
||||||
|
|
||||||
|
db.prepare('INSERT OR REPLACE INTO ItemTable (key, value) VALUES (?, ?)').run(
|
||||||
|
'antigravityAuthStatus',
|
||||||
|
JSON.stringify(authStatus),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 9. Remove google.antigravity to prevent conflicts
|
||||||
|
// This key often holds old state that might override our injected state
|
||||||
|
db.prepare('DELETE FROM ItemTable WHERE key = ?').run('google.antigravity');
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Successfully injected cloud token and identity for ${account.email} into Antigravity database at ${dbPath}.`,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-20
@@ -108,33 +108,67 @@ export async function closeAntigravity(): Promise<void> {
|
|||||||
// Helper to list processes
|
// Helper to list processes
|
||||||
const getProcesses = (): { pid: number; name: string; cmd: string }[] => {
|
const getProcesses = (): { pid: number; name: string; cmd: string }[] => {
|
||||||
try {
|
try {
|
||||||
let cmd = '';
|
let output = '';
|
||||||
if (platform === 'win32') {
|
if (platform === 'win32') {
|
||||||
// Use wmic to get process info
|
const psCommand = (cmdlet: string) =>
|
||||||
cmd = 'wmic process get ProcessId,Name,CommandLine /FORMAT:CSV';
|
`powershell -NoProfile -Command "${cmdlet} Win32_Process -Filter \\"Name like 'Antigravity%'\\" | Select-Object ProcessId, Name, CommandLine | ConvertTo-Csv -NoTypeInformation"`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
output = execSync(psCommand('Get-CimInstance'), {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
maxBuffer: 1024 * 1024 * 10,
|
||||||
|
stdio: ['pipe', 'pipe', 'ignore'],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// CIM failed (likely older OS), try WMI
|
||||||
|
try {
|
||||||
|
output = execSync(psCommand('Get-WmiObject'), {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
maxBuffer: 1024 * 1024 * 10,
|
||||||
|
});
|
||||||
|
} catch (innerE) {
|
||||||
|
// Both failed, throw original or log? Throwing lets the outer catch handle it (returning empty list)
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unix/Linux/macOS
|
// Unix/Linux/macOS
|
||||||
cmd = 'ps -A -o pid,comm,args';
|
output = execSync('ps -A -o pid,comm,args', {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
maxBuffer: 1024 * 1024 * 10,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = execSync(cmd, { encoding: 'utf-8' });
|
const processList: { pid: number; name: string; cmd: string }[] = [];
|
||||||
const lines = output.split('\n');
|
|
||||||
const processList = [];
|
|
||||||
|
|
||||||
for (const line of lines) {
|
if (platform === 'win32') {
|
||||||
const parts = line.trim().split(/\s+/);
|
// Parse CSV Output
|
||||||
if (parts.length < 2) continue;
|
const lines = output.trim().split(/\r?\n/);
|
||||||
|
// First line is headers "ProcessId","Name","CommandLine"
|
||||||
if (platform === 'win32') {
|
// We start from index 1
|
||||||
// CSV format parsing would be better, but simple check for now
|
for (let i = 1; i < lines.length; i++) {
|
||||||
if (line.includes('Antigravity')) {
|
const line = lines[i];
|
||||||
// Extract PID (usually last or second to last in CSV)
|
if (!line) {
|
||||||
const match = line.match(/(\d+)(?:\s*$)/);
|
continue;
|
||||||
if (match) {
|
|
||||||
processList.push({ pid: parseInt(match[1]), name: 'Antigravity', cmd: line });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
// Regex to match CSV fields: "val1","val2","val3"
|
||||||
|
const match = line.match(/^"(\d+)","(.*?)","(.*?)"$/);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const pid = parseInt(match[1]);
|
||||||
|
const name = match[2];
|
||||||
|
const cmdLine = match[3];
|
||||||
|
|
||||||
|
processList.push({ pid, name, cmd: cmdLine || name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const lines = output.split('\n');
|
||||||
|
for (const line of lines) {
|
||||||
|
const parts = line.trim().split(/\s+/);
|
||||||
|
if (parts.length < 2) continue;
|
||||||
|
|
||||||
const pid = parseInt(parts[0]);
|
const pid = parseInt(parts[0]);
|
||||||
if (isNaN(pid)) continue;
|
if (isNaN(pid)) continue;
|
||||||
const rest = parts.slice(1).join(' ');
|
const rest = parts.slice(1).join(' ');
|
||||||
|
|||||||
Reference in new issue
Block a user