mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-16 19:50:37 +01:00
feat: ability to open multiple app sessions
This commit is contained in:
parent
664b2181be
commit
075f542dc8
@ -1,14 +1,46 @@
|
||||
import { app, dialog, ipcMain } from 'electron';
|
||||
import { app, dialog, ipcMain, safeStorage } from 'electron';
|
||||
import * as Store from 'electron-store';
|
||||
|
||||
import { validateSender } from '../libs/misc/validateSender';
|
||||
import { ShortcutRegister } from '../libs/ShortcutRegister';
|
||||
|
||||
export default () => {
|
||||
ipcMain.on('close-app', (event) => {
|
||||
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
||||
if (!validateSender(event.senderFrame)) {
|
||||
return {
|
||||
status: 'error',
|
||||
response: 'Unauthorized process'
|
||||
};
|
||||
}
|
||||
app.exit();
|
||||
});
|
||||
|
||||
ipcMain.on('set-key', (event, key) => {
|
||||
if (safeStorage.isEncryptionAvailable()) {
|
||||
const sessionStore = new Store({
|
||||
name: 'session',
|
||||
fileExtension: ''
|
||||
});
|
||||
const encrypted = safeStorage.encryptString(key);
|
||||
sessionStore.set('key', encrypted);
|
||||
event.returnValue = true;
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('get-key', (event) => {
|
||||
if (!safeStorage.isEncryptionAvailable()) {
|
||||
event.returnValue = false;
|
||||
return;
|
||||
}
|
||||
const sessionStore = new Store({
|
||||
name: 'session',
|
||||
fileExtension: ''
|
||||
});
|
||||
const encrypted = sessionStore.get('key') as string;
|
||||
const key = safeStorage.decryptString(Buffer.from(encrypted, 'utf-8'));
|
||||
event.returnValue = key;
|
||||
});
|
||||
|
||||
ipcMain.handle('show-open-dialog', (event, options) => {
|
||||
if (!validateSender(event.senderFrame)) return { status: 'error', response: 'Unauthorized process' };
|
||||
return dialog.showOpenDialog(options);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as remoteMain from '@electron/remote/main';
|
||||
import { app, BrowserWindow, ipcMain, nativeImage } from 'electron';
|
||||
import { app, BrowserWindow, ipcMain, nativeImage, safeStorage } from 'electron';
|
||||
import * as Store from 'electron-store';
|
||||
import * as windowStateKeeper from 'electron-window-state';
|
||||
import * as path from 'path';
|
||||
@ -78,7 +78,8 @@ async function createMainWindow () {
|
||||
return window;
|
||||
}
|
||||
|
||||
if (!gotTheLock) app.quit();
|
||||
if (!gotTheLock && !safeStorage.isEncryptionAvailable()) // Disable multiple instances if is not possible to share session keys
|
||||
app.quit();
|
||||
else {
|
||||
require('@electron/remote/main').initialize();
|
||||
|
||||
@ -127,6 +128,12 @@ else {
|
||||
// if (isDevelopment)
|
||||
// mainWindow.webContents.openDevTools();
|
||||
|
||||
// const key = safeStorage.encryptString('godisnothere');
|
||||
// console.log('KEY:', key.toString('hex'));
|
||||
|
||||
// const decrypted = safeStorage.decryptString(key);
|
||||
// console.log(decrypted.toString());
|
||||
|
||||
process.on('uncaughtException', error => {
|
||||
mainWindow.webContents.send('unhandled-exception', error);
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ConnectionParams } from 'common/interfaces/antares';
|
||||
import { uidGen } from 'common/libs/uidGen';
|
||||
import * as crypto from 'crypto';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import * as Store from 'electron-store';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
@ -17,10 +18,18 @@ export interface SidebarElement {
|
||||
icon?: null | string;
|
||||
}
|
||||
|
||||
if (!key)
|
||||
localStorage.setItem('key', crypto.randomBytes(16).toString('hex'));
|
||||
else
|
||||
localStorage.setItem('key', key);
|
||||
if (!key) {
|
||||
const storedKey = ipcRenderer.sendSync('get-key');
|
||||
|
||||
if (!storedKey) {
|
||||
const newKey = crypto.randomBytes(16).toString('hex');
|
||||
localStorage.setItem('key', newKey);
|
||||
}
|
||||
else
|
||||
localStorage.setItem('key', storedKey);
|
||||
}
|
||||
|
||||
ipcRenderer.send('set-key', key);
|
||||
|
||||
const persistentStore = new Store({
|
||||
name: 'connections',
|
||||
|
Loading…
x
Reference in New Issue
Block a user