mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
initial implementation for password saving (#132)
* initial implementation for password saving * support restoring password in interceptor * Fix modal overflow and position styles * warn about 429, better error handling --------- Co-authored-by: jeffvli <jeffvictorli@gmail.com> Co-authored-by: Jeff <42182408+jeffvli@users.noreply.github.com>
This commit is contained in:
parent
a3a84766e4
commit
2fac9efc1b
13 changed files with 310 additions and 62 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { ipcMain } from 'electron';
|
||||
import { ipcMain, safeStorage } from 'electron';
|
||||
import Store from 'electron-store';
|
||||
|
||||
export const store = new Store();
|
||||
|
|
@ -10,3 +10,41 @@ ipcMain.handle('settings-get', (_event, data: { property: string }) => {
|
|||
ipcMain.on('settings-set', (__event, data: { property: string; value: any }) => {
|
||||
store.set(`${data.property}`, data.value);
|
||||
});
|
||||
|
||||
ipcMain.handle('password-get', (_event, server: string): string | null => {
|
||||
if (safeStorage.isEncryptionAvailable()) {
|
||||
const servers = store.get('server') as Record<string, string> | undefined;
|
||||
|
||||
if (!servers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const encrypted = servers[server];
|
||||
if (!encrypted) return null;
|
||||
|
||||
const decrypted = safeStorage.decryptString(Buffer.from(encrypted, 'hex'));
|
||||
return decrypted;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
ipcMain.on('password-remove', (_event, server: string) => {
|
||||
const passwords = store.get('server', {}) as Record<string, string>;
|
||||
if (server in passwords) {
|
||||
delete passwords[server];
|
||||
}
|
||||
store.set({ server: passwords });
|
||||
});
|
||||
|
||||
ipcMain.handle('password-set', (_event, password: string, server: string) => {
|
||||
if (safeStorage.isEncryptionAvailable()) {
|
||||
const encrypted = safeStorage.encryptString(password);
|
||||
const passwords = store.get('server', {}) as Record<string, string>;
|
||||
passwords[server] = encrypted.toString('hex');
|
||||
store.set({ server: passwords });
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ const disableMediaKeys = () => {
|
|||
ipcRenderer.send('global-media-keys-disable');
|
||||
};
|
||||
|
||||
const passwordGet = async (server: string): Promise<string | null> => {
|
||||
return ipcRenderer.invoke('password-get', server);
|
||||
};
|
||||
|
||||
const passwordRemove = (server: string) => {
|
||||
ipcRenderer.send('password-remove', server);
|
||||
};
|
||||
|
||||
const passwordSet = async (password: string, server: string): Promise<boolean> => {
|
||||
return ipcRenderer.invoke('password-set', password, server);
|
||||
};
|
||||
|
||||
const setZoomFactor = (zoomFactor: number) => {
|
||||
webFrame.setZoomFactor(zoomFactor / 100);
|
||||
};
|
||||
|
|
@ -31,6 +43,9 @@ export const localSettings = {
|
|||
disableMediaKeys,
|
||||
enableMediaKeys,
|
||||
get,
|
||||
passwordGet,
|
||||
passwordRemove,
|
||||
passwordSet,
|
||||
restart,
|
||||
set,
|
||||
setZoomFactor,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue