1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

[PM-16837] Fix agent only loading when featureflag is on during startup (#12742)

* Fix ssh generation and import not being available when agent feature-flag is disabled

* Fix agent only loading when featureflag is on during startup
This commit is contained in:
Bernd Schoolmann
2025-01-08 14:25:19 +01:00
committed by GitHub
parent 1b08335245
commit 244539cc38
4 changed files with 169 additions and 152 deletions

View File

@@ -2,7 +2,7 @@
// @ts-strict-ignore // @ts-strict-ignore
import * as path from "path"; import * as path from "path";
import { app, ipcMain } from "electron"; import { app } from "electron";
import { Subject, firstValueFrom } from "rxjs"; import { Subject, firstValueFrom } from "rxjs";
import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service"; import { AccountServiceImplementation } from "@bitwarden/common/auth/services/account.service";
@@ -257,12 +257,7 @@ export class Main {
this.clipboardMain = new ClipboardMain(); this.clipboardMain = new ClipboardMain();
this.clipboardMain.init(); this.clipboardMain.init();
ipcMain.handle("sshagent.init", async (event: any, message: any) => {
if (this.sshAgentService == null) {
this.sshAgentService = new MainSshAgentService(this.logService, this.messagingService); this.sshAgentService = new MainSshAgentService(this.logService, this.messagingService);
this.sshAgentService.init();
}
});
new EphemeralValueStorageService(); new EphemeralValueStorageService();
new SSOLocalhostCallbackService(this.environmentService, this.messagingService); new SSOLocalhostCallbackService(this.environmentService, this.messagingService);

View File

@@ -40,6 +40,14 @@ export class MainSshAgentService {
return sshagent.importKey(privateKey, password); return sshagent.importKey(privateKey, password);
}, },
); );
ipcMain.handle("sshagent.init", async (event: any, message: any) => {
this.init();
});
ipcMain.handle("sshagent.isloaded", async (event: any) => {
return this.agentState != null;
});
} }
init() { init() {

View File

@@ -74,6 +74,9 @@ const sshAgent = {
}); });
return res; return res;
}, },
isLoaded(): Promise<boolean> {
return ipcRenderer.invoke("sshagent.isloaded");
},
}; };
const powermonitor = { const powermonitor = {

View File

@@ -61,8 +61,20 @@ export class SshAgentService implements OnDestroy {
) {} ) {}
async init() { async init() {
const isSshAgentFeatureEnabled = await this.configService.getFeatureFlag(FeatureFlag.SSHAgent); this.configService
if (isSshAgentFeatureEnabled) { .getFeatureFlag$(FeatureFlag.SSHAgent)
.pipe(
concatMap(async (enabled) => {
if (enabled && !(await ipc.platform.sshAgent.isLoaded())) {
return this.initSshAgent();
}
}),
takeUntil(this.destroy$),
)
.subscribe();
}
private async initSshAgent() {
await ipc.platform.sshAgent.init(); await ipc.platform.sshAgent.init();
this.messageListener this.messageListener
@@ -222,7 +234,6 @@ export class SshAgentService implements OnDestroy {
) )
.subscribe(); .subscribe();
} }
}
ngOnDestroy() { ngOnDestroy() {
this.destroy$.next(); this.destroy$.next();