Skip to content

Commit a9fced8

Browse files
committed
replaced to solution local cache key
1 parent c418406 commit a9fced8

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "electron-gp",
33
"private": true,
4-
"version": "0.2.12",
4+
"version": "0.2.14",
55
"type": "module",
66
"main": "dist-main/app.js",
77
"author": "traeop",

src/main/$shared/store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ElectronStorage from "electron-store";
22

33
type TStore = {
44
updateProcess: boolean;
5+
masterKey: string;
56
};
67

78
export type TCacheResponse = {
@@ -12,7 +13,6 @@ export type TElectronStorage = {
1213
authToken: string;
1314
userId: string;
1415
twoFactorSecret: string;
15-
masterKey: string;
1616
response: TCacheResponse;
1717
};
1818

@@ -35,6 +35,10 @@ export function clearStore() {
3535
store.clear();
3636
}
3737

38+
export function deleteStore<K extends keyof TStore>(name: K) {
39+
store.delete(name);
40+
}
41+
3842
export function getElectronStorage<K extends keyof TElectronStorage>(key: K) {
3943
return electronStorage.get(key) as TElectronStorage[K] | undefined;
4044
}

src/main/master-key/ipc.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
ipcWebContentsSend,
1010
} from "../$shared/utils.js";
1111
import {
12-
setElectronStorage,
12+
setStore,
13+
getStore,
14+
deleteStore,
1315
getElectronStorage,
14-
deleteFromElectronStorage,
1516
} from "../$shared/store.js";
1617
import { restApi } from "../config.js";
1718

@@ -37,7 +38,7 @@ export class MasterKeyIpc {
3738
private ipcPostMasterKey(): void {
3839
ipcMainHandle("postMasterKey", async (payload) => {
3940
if (payload !== undefined) {
40-
setElectronStorage("masterKey", payload.key);
41+
setStore("masterKey", payload.key);
4142
}
4243

4344
this.hideMasterKeyWindow();
@@ -73,7 +74,7 @@ export class MasterKeyIpc {
7374
cacheResources !== undefined
7475
? cacheResources.find((res) => res.id + "" === payload.id)
7576
: undefined;
76-
const masterKey = getElectronStorage("masterKey");
77+
const masterKey = getStore("masterKey");
7778

7879
if (
7980
masterKey !== undefined &&
@@ -99,7 +100,7 @@ export class MasterKeyIpc {
99100

100101
private ipcGetMasterKey(): void {
101102
ipcMainOn("checkMasterKey", (event) => {
102-
const masterKey = getElectronStorage("masterKey");
103+
const masterKey = getStore("masterKey");
103104

104105
event.reply("masterKey", {
105106
isMasterKey: Boolean(masterKey),
@@ -109,18 +110,18 @@ export class MasterKeyIpc {
109110

110111
private ipcDeleteMasterKey(): void {
111112
ipcMainOn("deleteMasterKey", () => {
112-
const masterKey = getElectronStorage("masterKey");
113+
const masterKey = getStore("masterKey");
113114

114115
if (masterKey !== undefined) {
115-
deleteFromElectronStorage("masterKey");
116+
deleteStore("masterKey");
116117
this.getMasterKey();
117118
this.hideMasterKeyWindow();
118119
}
119120
});
120121
}
121122

122123
private getMasterKey(): void {
123-
const masterKey = getElectronStorage("masterKey");
124+
const masterKey = getStore("masterKey");
124125
const mainWindow = getWindows<TWindows["main"]>("window:main");
125126
if (mainWindow !== undefined) {
126127
ipcWebContentsSend("masterKey", mainWindow.webContents, {

src/main/resources/ipc/actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ResourcesService } from "../services/resources.js";
1111
import { CryptoService } from "../../crypto/service.js";
1212
import { TEncryptedVault } from "../services/types.js";
1313
import { CacheWindowsService } from "../services/cacheWindows.js";
14-
import { getElectronStorage } from "../../$shared/store.js";
14+
import { getStore, getElectronStorage } from "../../$shared/store.js";
1515
import { TrayService } from "../../tray/service.js";
1616
import { restApi } from "../../config.js";
1717

@@ -53,7 +53,7 @@ export class ResourcesActionsIpc implements TIpcHandlerInterface {
5353
const updateResourceWindow = this.cacheWindowsService.getResourceWindows(
5454
"updateResourceWindow"
5555
);
56-
const masterKey = getElectronStorage("masterKey");
56+
const masterKey = getStore("masterKey");
5757

5858
if (
5959
masterKey !== undefined &&
@@ -103,7 +103,7 @@ export class ResourcesActionsIpc implements TIpcHandlerInterface {
103103
let encryptedVault: TEncryptedVault | undefined;
104104
const addResourceWindow =
105105
this.cacheWindowsService.getResourceWindows("addResourceWindow");
106-
const masterKey = getElectronStorage("masterKey");
106+
const masterKey = getStore("masterKey");
107107

108108
if (
109109
masterKey !== undefined &&
@@ -263,7 +263,7 @@ export class ResourcesActionsIpc implements TIpcHandlerInterface {
263263
}
264264

265265
private async copyMasterKey(resource: TResource) {
266-
const masterKey = getElectronStorage("masterKey");
266+
const masterKey = getStore("masterKey");
267267
if (masterKey !== undefined && resource.salt !== null) {
268268
const encryptedVault = await this.cryptoService.decrypt(masterKey, {
269269
iv: resource.iv,

0 commit comments

Comments
 (0)