Browse Source
* [PM-3685] Remove ipcRenderer from renderer-storage * Break out storage and keytar into separate functionspull/6672/head
3 changed files with 32 additions and 42 deletions
@ -1,41 +1,22 @@
@@ -1,41 +1,22 @@
|
||||
import { ipcRenderer } from "electron"; |
||||
|
||||
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; |
||||
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options"; |
||||
|
||||
export class ElectronRendererSecureStorageService implements AbstractStorageService { |
||||
async get<T>(key: string, options?: StorageOptions): Promise<T> { |
||||
const val = await ipcRenderer.invoke("keytar", { |
||||
action: "getPassword", |
||||
key: key, |
||||
keySuffix: options?.keySuffix ?? "", |
||||
}); |
||||
const val = await ipc.platform.passwords.get(key, options?.keySuffix ?? ""); |
||||
return val != null ? (JSON.parse(val) as T) : null; |
||||
} |
||||
|
||||
async has(key: string, options?: StorageOptions): Promise<boolean> { |
||||
const val = await ipcRenderer.invoke("keytar", { |
||||
action: "hasPassword", |
||||
key: key, |
||||
keySuffix: options?.keySuffix ?? "", |
||||
}); |
||||
const val = await ipc.platform.passwords.has(key, options?.keySuffix ?? ""); |
||||
return !!val; |
||||
} |
||||
|
||||
async save(key: string, obj: any, options?: StorageOptions): Promise<any> { |
||||
await ipcRenderer.invoke("keytar", { |
||||
action: "setPassword", |
||||
key: key, |
||||
keySuffix: options?.keySuffix ?? "", |
||||
value: JSON.stringify(obj), |
||||
}); |
||||
await ipc.platform.passwords.set(key, options?.keySuffix ?? "", JSON.stringify(obj)); |
||||
} |
||||
|
||||
async remove(key: string, options?: StorageOptions): Promise<any> { |
||||
await ipcRenderer.invoke("keytar", { |
||||
action: "deletePassword", |
||||
key: key, |
||||
keySuffix: options?.keySuffix ?? "", |
||||
}); |
||||
await ipc.platform.passwords.delete(key, options?.keySuffix ?? ""); |
||||
} |
||||
} |
||||
|
||||
@ -1,34 +1,19 @@
@@ -1,34 +1,19 @@
|
||||
import { ipcRenderer } from "electron"; |
||||
|
||||
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; |
||||
|
||||
export class ElectronRendererStorageService implements AbstractStorageService { |
||||
get<T>(key: string): Promise<T> { |
||||
return ipcRenderer.invoke("storageService", { |
||||
action: "get", |
||||
key: key, |
||||
}); |
||||
return ipc.platform.storage.get(key); |
||||
} |
||||
|
||||
has(key: string): Promise<boolean> { |
||||
return ipcRenderer.invoke("storageService", { |
||||
action: "has", |
||||
key: key, |
||||
}); |
||||
return ipc.platform.storage.has(key); |
||||
} |
||||
|
||||
save(key: string, obj: any): Promise<any> { |
||||
return ipcRenderer.invoke("storageService", { |
||||
action: "save", |
||||
key: key, |
||||
obj: obj, |
||||
}); |
||||
return ipc.platform.storage.save(key, obj); |
||||
} |
||||
|
||||
remove(key: string): Promise<any> { |
||||
return ipcRenderer.invoke("storageService", { |
||||
action: "remove", |
||||
key: key, |
||||
}); |
||||
return ipc.platform.storage.remove(key); |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue