mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-30 17:47:44 +01:00
[PM-3685] Remove ipcRenderer from electron-renderer-storage (#6481)
* [PM-3685] Remove ipcRenderer from renderer-storage * Break out storage and keytar into separate functions
This commit is contained in:
parent
c2613af4f6
commit
55bc275f40
@ -4,6 +4,27 @@ import { DeviceType, ThemeType } from "@bitwarden/common/enums";
|
|||||||
|
|
||||||
import { isDev, isWindowsStore } from "../utils";
|
import { isDev, isWindowsStore } from "../utils";
|
||||||
|
|
||||||
|
const storage = {
|
||||||
|
get: <T>(key: string): Promise<T> => ipcRenderer.invoke("storageService", { action: "get", key }),
|
||||||
|
has: (key: string): Promise<boolean> =>
|
||||||
|
ipcRenderer.invoke("storageService", { action: "has", key }),
|
||||||
|
save: (key: string, obj: any): Promise<void> =>
|
||||||
|
ipcRenderer.invoke("storageService", { action: "save", key, obj }),
|
||||||
|
remove: (key: string): Promise<void> =>
|
||||||
|
ipcRenderer.invoke("storageService", { action: "remove", key }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const passwords = {
|
||||||
|
get: (key: string, keySuffix: string): Promise<string> =>
|
||||||
|
ipcRenderer.invoke("keytar", { action: "getPassword", key, keySuffix }),
|
||||||
|
has: (key: string, keySuffix: string): Promise<boolean> =>
|
||||||
|
ipcRenderer.invoke("keytar", { action: "hasPassword", key, keySuffix }),
|
||||||
|
set: (key: string, keySuffix: string, value: string): Promise<void> =>
|
||||||
|
ipcRenderer.invoke("keytar", { action: "setPassword", key, keySuffix, value }),
|
||||||
|
delete: (key: string, keySuffix: string): Promise<void> =>
|
||||||
|
ipcRenderer.invoke("keytar", { action: "deletePassword", key, keySuffix }),
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
versions: {
|
versions: {
|
||||||
app: (): Promise<string> => ipcRenderer.invoke("appVersion"),
|
app: (): Promise<string> => ipcRenderer.invoke("appVersion"),
|
||||||
@ -27,6 +48,9 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
storage,
|
||||||
|
passwords,
|
||||||
};
|
};
|
||||||
|
|
||||||
function deviceType(): DeviceType {
|
function deviceType(): DeviceType {
|
||||||
|
@ -1,41 +1,22 @@
|
|||||||
import { ipcRenderer } from "electron";
|
|
||||||
|
|
||||||
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
||||||
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options";
|
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options";
|
||||||
|
|
||||||
export class ElectronRendererSecureStorageService implements AbstractStorageService {
|
export class ElectronRendererSecureStorageService implements AbstractStorageService {
|
||||||
async get<T>(key: string, options?: StorageOptions): Promise<T> {
|
async get<T>(key: string, options?: StorageOptions): Promise<T> {
|
||||||
const val = await ipcRenderer.invoke("keytar", {
|
const val = await ipc.platform.passwords.get(key, options?.keySuffix ?? "");
|
||||||
action: "getPassword",
|
|
||||||
key: key,
|
|
||||||
keySuffix: options?.keySuffix ?? "",
|
|
||||||
});
|
|
||||||
return val != null ? (JSON.parse(val) as T) : null;
|
return val != null ? (JSON.parse(val) as T) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async has(key: string, options?: StorageOptions): Promise<boolean> {
|
async has(key: string, options?: StorageOptions): Promise<boolean> {
|
||||||
const val = await ipcRenderer.invoke("keytar", {
|
const val = await ipc.platform.passwords.has(key, options?.keySuffix ?? "");
|
||||||
action: "hasPassword",
|
|
||||||
key: key,
|
|
||||||
keySuffix: options?.keySuffix ?? "",
|
|
||||||
});
|
|
||||||
return !!val;
|
return !!val;
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(key: string, obj: any, options?: StorageOptions): Promise<any> {
|
async save(key: string, obj: any, options?: StorageOptions): Promise<any> {
|
||||||
await ipcRenderer.invoke("keytar", {
|
await ipc.platform.passwords.set(key, options?.keySuffix ?? "", JSON.stringify(obj));
|
||||||
action: "setPassword",
|
|
||||||
key: key,
|
|
||||||
keySuffix: options?.keySuffix ?? "",
|
|
||||||
value: JSON.stringify(obj),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(key: string, options?: StorageOptions): Promise<any> {
|
async remove(key: string, options?: StorageOptions): Promise<any> {
|
||||||
await ipcRenderer.invoke("keytar", {
|
await ipc.platform.passwords.delete(key, options?.keySuffix ?? "");
|
||||||
action: "deletePassword",
|
|
||||||
key: key,
|
|
||||||
keySuffix: options?.keySuffix ?? "",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,19 @@
|
|||||||
import { ipcRenderer } from "electron";
|
|
||||||
|
|
||||||
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
||||||
|
|
||||||
export class ElectronRendererStorageService implements AbstractStorageService {
|
export class ElectronRendererStorageService implements AbstractStorageService {
|
||||||
get<T>(key: string): Promise<T> {
|
get<T>(key: string): Promise<T> {
|
||||||
return ipcRenderer.invoke("storageService", {
|
return ipc.platform.storage.get(key);
|
||||||
action: "get",
|
|
||||||
key: key,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
has(key: string): Promise<boolean> {
|
has(key: string): Promise<boolean> {
|
||||||
return ipcRenderer.invoke("storageService", {
|
return ipc.platform.storage.has(key);
|
||||||
action: "has",
|
|
||||||
key: key,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
save(key: string, obj: any): Promise<any> {
|
save(key: string, obj: any): Promise<any> {
|
||||||
return ipcRenderer.invoke("storageService", {
|
return ipc.platform.storage.save(key, obj);
|
||||||
action: "save",
|
|
||||||
key: key,
|
|
||||||
obj: obj,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(key: string): Promise<any> {
|
remove(key: string): Promise<any> {
|
||||||
return ipcRenderer.invoke("storageService", {
|
return ipc.platform.storage.remove(key);
|
||||||
action: "remove",
|
|
||||||
key: key,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user