Browse Source

[PM-3677] Remove ipcRenderer from desktop utils (#6477)

* [PM-3677] Remove ipcRenderer from utils

* Fix typo
pull/6737/head
Daniel García 2 years ago committed by GitHub
parent
commit
7f7700f5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/desktop/src/auth/accessibility-cookie.component.ts
  2. 6
      apps/desktop/src/auth/preload.ts
  3. 7
      apps/desktop/src/platform/preload.ts
  4. 2
      apps/desktop/src/preload.ts
  5. 8
      apps/desktop/src/utils.ts

4
apps/desktop/src/auth/accessibility-cookie.component.ts

@ -8,8 +8,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic @@ -8,8 +8,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { getCookie } from "../utils";
const BroadcasterSubscriptionId = "AccessibilityCookieComponent";
@Component({
@ -55,7 +53,7 @@ export class AccessibilityCookieComponent { @@ -55,7 +53,7 @@ export class AccessibilityCookieComponent {
async checkForCookie() {
this.hCaptchaWindow.close();
const [cookie] = await getCookie("https://www.hcaptcha.com/", "hc_accessibility");
const [cookie] = await ipc.auth.getHcaptchaAccessibilityCookie();
if (cookie) {
this.onCookieSavedSuccess();
} else {

6
apps/desktop/src/auth/preload.ts

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
import { ipcRenderer } from "electron";
export default {
getHcaptchaAccessibilityCookie: (): Promise<[string]> =>
ipcRenderer.invoke("getCookie", { url: "https://www.hcaptcha.com/", name: "hc_accessibility" }),
};

7
apps/desktop/src/platform/preload.ts

@ -60,6 +60,13 @@ export default { @@ -60,6 +60,13 @@ export default {
isWindowsStore: isWindowsStore(),
reloadProcess: () => ipcRenderer.send("reload-process"),
openContextMenu: (
menu: {
label?: string;
type?: "normal" | "separator" | "submenu" | "checkbox" | "radio";
}[]
): Promise<number> => ipcRenderer.invoke("openContextMenu", { menu }),
getSystemTheme: (): Promise<ThemeType> => ipcRenderer.invoke("systemTheme"),
onSystemThemeUpdated: (callback: (theme: ThemeType) => void) => {
ipcRenderer.on("systemThemeUpdated", (_event, theme: ThemeType) => callback(theme));

2
apps/desktop/src/preload.ts

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
// import { contextBridge } from "electron";
import auth from "./auth/preload";
import platform from "./platform/preload";
/**
@ -13,6 +14,7 @@ import platform from "./platform/preload"; @@ -13,6 +14,7 @@ import platform from "./platform/preload";
// Each team owns a subspace of the `ipc` global variable in the renderer.
export const ipc = {
auth,
platform,
};

8
apps/desktop/src/utils.ts

@ -1,5 +1,3 @@ @@ -1,5 +1,3 @@
import { ipcRenderer } from "electron";
export type RendererMenuItem = {
label?: string;
type?: "normal" | "separator" | "submenu" | "checkbox" | "radio";
@ -10,7 +8,7 @@ export function invokeMenu(menu: RendererMenuItem[]) { @@ -10,7 +8,7 @@ export function invokeMenu(menu: RendererMenuItem[]) {
const menuWithoutClick = menu.map((m) => {
return { label: m.label, type: m.type };
});
ipcRenderer.invoke("openContextMenu", { menu: menuWithoutClick }).then((i: number) => {
ipc.platform.openContextMenu(menuWithoutClick).then((i: number) => {
if (i !== -1) {
menu[i].click();
}
@ -82,7 +80,3 @@ export function cleanUserAgent(userAgent: string): string { @@ -82,7 +80,3 @@ export function cleanUserAgent(userAgent: string): string {
.replace(userAgentItem("Bitwarden", " "), "")
.replace(userAgentItem("Electron", " "), "");
}
export async function getCookie(url: string, name: string): Promise<Electron.Cookie[]> {
return await ipcRenderer.invoke("getCookie", { url: url, name: name });
}

Loading…
Cancel
Save