1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-03 09:03:32 +00:00

[PM-8292] Fixup ForegroundSyncService (#9292)

* Change `object` to `Record<string, unknown>`

* Change `object` to `Record<string, unknown>` Pt. 2

* Update ForegroundSyncService

- Manage finish message in the listener to more gaurantee a message back
- Make the timeout much longer
- Allow it to throw if the background sync service threw

---------

Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com>
This commit is contained in:
Justin Baur
2024-05-29 12:12:58 -04:00
committed by GitHub
parent beb930902a
commit a6df923416
23 changed files with 328 additions and 86 deletions

View File

@@ -151,7 +151,7 @@ const safeProviders: SafeProvider[] = [
}),
safeProvider({
provide: MessageSender,
useFactory: (subject: Subject<Message<object>>) =>
useFactory: (subject: Subject<Message<Record<string, unknown>>>) =>
MessageSender.combine(
new ElectronRendererMessageSender(), // Communication with main process
new SubjectMessageSender(subject), // Communication with ourself
@@ -160,7 +160,7 @@ const safeProviders: SafeProvider[] = [
}),
safeProvider({
provide: MessageListener,
useFactory: (subject: Subject<Message<object>>) =>
useFactory: (subject: Subject<Message<Record<string, unknown>>>) =>
new MessageListener(
merge(
subject.asObservable(), // For messages from the same context

View File

@@ -223,7 +223,7 @@ export class Main {
this.updaterMain = new UpdaterMain(this.i18nService, this.windowMain);
this.trayMain = new TrayMain(this.windowMain, this.i18nService, this.desktopSettingsService);
const messageSubject = new Subject<Message<object>>();
const messageSubject = new Subject<Message<Record<string, unknown>>>();
this.messagingService = MessageSender.combine(
new SubjectMessageSender(messageSubject), // For local messages
new ElectronMainMessagingService(this.windowMain),

View File

@@ -2,9 +2,9 @@ import { MessageSender, CommandDefinition } from "@bitwarden/common/platform/mes
import { getCommand } from "@bitwarden/common/platform/messaging/internal";
export class ElectronRendererMessageSender implements MessageSender {
send<T extends object>(
send<T extends Record<string, unknown>>(
commandDefinition: CommandDefinition<T> | string,
payload: object | T = {},
payload: Record<string, unknown> | T = {},
): void {
const command = getCommand(commandDefinition);
ipc.platform.sendMessage(Object.assign({}, { command: command }, payload));

View File

@@ -8,8 +8,8 @@ import { tagAsExternal } from "@bitwarden/common/platform/messaging/internal";
* @returns An observable stream of messages.
*/
export const fromIpcMessaging = () => {
return fromEventPattern<Message<object>>(
return fromEventPattern<Message<Record<string, unknown>>>(
(handler) => ipc.platform.onMessage.addListener(handler),
(handler) => ipc.platform.onMessage.removeListener(handler),
).pipe(tagAsExternal, share());
).pipe(tagAsExternal(), share());
};

View File

@@ -87,7 +87,10 @@ export class ElectronMainMessagingService implements MessageSender {
});
}
send<T extends object>(commandDefinition: CommandDefinition<T> | string, arg: T | object = {}) {
send<T extends Record<string, unknown>>(
commandDefinition: CommandDefinition<T> | string,
arg: T | Record<string, unknown> = {},
) {
const command = getCommand(commandDefinition);
const message = Object.assign({}, { command: command }, arg);
if (this.windowMain.win != null) {