1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-03-15 10:50:04 +01:00

fix: error with multiple sessions in non-dev environment

This commit is contained in:
Fabio Di Stasio 2023-11-13 18:08:29 +01:00
parent 075f542dc8
commit 169f610b2e
2 changed files with 72 additions and 76 deletions

View File

@ -78,87 +78,80 @@ async function createMainWindow () {
return window;
}
if (!gotTheLock && !safeStorage.isEncryptionAvailable()) // Disable multiple instances if is not possible to share session keys
app.quit();
else {
require('@electron/remote/main').initialize();
require('@electron/remote/main').initialize();
// Initialize ipcHandlers
ipcHandlers();
// Initialize ipcHandlers
ipcHandlers();
ipcMain.on('refresh-theme-settings', () => {
const appTheme = settingsStore.get('application_theme');
if (isWindows && mainWindow) {
mainWindow.setTitleBarOverlay({
color: appTheme === 'dark' ? '#3f3f3f' : '#fff',
symbolColor: appTheme === 'dark' ? '#fff' : '#000'
});
}
});
ipcMain.on('change-window-title', (_, title: string) => {
if (mainWindow) mainWindow.setTitle(title);
});
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (!isMacOS) app.quit();
});
app.on('activate', async () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null)
mainWindow = await createMainWindow();
});
// create main BrowserWindow when electron is ready
app.on('ready', async () => {
mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 800
ipcMain.on('refresh-theme-settings', () => {
const appTheme = settingsStore.get('application_theme');
if (isWindows && mainWindow) {
mainWindow.setTitleBarOverlay({
color: appTheme === 'dark' ? '#3f3f3f' : '#fff',
symbolColor: appTheme === 'dark' ? '#fff' : '#000'
});
}
});
ipcMain.on('change-window-title', (_, title: string) => {
if (mainWindow) mainWindow.setTitle(title);
});
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (!isMacOS) app.quit();
});
app.on('activate', async () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null)
mainWindow = await createMainWindow();
createAppMenu();
});
if (isWindows)
mainWindow.show();
// create main BrowserWindow when electron is ready
app.on('ready', async () => {
if (!gotTheLock && !safeStorage.isEncryptionAvailable()) // Disable multiple instances if is not possible to share session keys
app.quit();
// 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);
});
process.on('unhandledRejection', error => {
mainWindow.webContents.send('unhandled-exception', error);
});
mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 800
});
app.on('browser-window-created', (event, window) => {
if (isDevelopment) {
const { antares } = require('../../package.json');
const extensionPath = path.resolve(__dirname, `../../misc/${antares.devtoolsId}`);
window.webContents.session.loadExtension(extensionPath, { allowFileAccess: true }).catch(console.error);
}
mainWindow = await createMainWindow();
createAppMenu();
window.webContents.on('will-navigate', (e) => { // Prevent browser navigation
e.preventDefault();
});
if (isWindows)
mainWindow.show();
window.webContents.on('did-create-window', (w) => { // Close new windows
w.close();
});
// if (isDevelopment)
// mainWindow.webContents.openDevTools();
process.on('uncaughtException', error => {
mainWindow.webContents.send('unhandled-exception', error);
});
}
process.on('unhandledRejection', error => {
mainWindow.webContents.send('unhandled-exception', error);
});
});
app.on('browser-window-created', (event, window) => {
if (isDevelopment) {
const { antares } = require('../../package.json');
const extensionPath = path.resolve(__dirname, `../../misc/${antares.devtoolsId}`);
window.webContents.session.loadExtension(extensionPath, { allowFileAccess: true }).catch(console.error);
}
window.webContents.on('will-navigate', (e) => { // Prevent browser navigation
e.preventDefault();
});
window.webContents.on('did-create-window', (w) => { // Close new windows
w.close();
});
});
function createAppMenu () {
const menuTemplate: OsMenu = {

View File

@ -6,7 +6,7 @@ import * as Store from 'electron-store';
import { defineStore } from 'pinia';
import { useWorkspacesStore } from '@/stores/workspaces';
const key = localStorage.getItem('key');
let key = localStorage.getItem('key');
export interface SidebarElement {
isFolder: boolean;
@ -18,18 +18,21 @@ export interface SidebarElement {
icon?: null | string;
}
if (!key) {
const storedKey = ipcRenderer.sendSync('get-key');
if (!key) { // If no key in local storace
const storedKey = ipcRenderer.sendSync('get-key');// Ask for key stored on disk
if (!storedKey) {
if (!storedKey) { // Of nop stored key on disk
const newKey = crypto.randomBytes(16).toString('hex');
localStorage.setItem('key', newKey);
key = newKey;
}
else
else {
localStorage.setItem('key', storedKey);
key = storedKey;
}
}
ipcRenderer.send('set-key', key);
else
ipcRenderer.send('set-key', key);
const persistentStore = new Store({
name: 'connections',