1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-04-25 15:28:41 +02: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,15 +78,12 @@ async function createMainWindow () {
return window; return window;
} }
if (!gotTheLock && !safeStorage.isEncryptionAvailable()) // Disable multiple instances if is not possible to share session keys require('@electron/remote/main').initialize();
app.quit();
else {
require('@electron/remote/main').initialize();
// Initialize ipcHandlers // Initialize ipcHandlers
ipcHandlers(); ipcHandlers();
ipcMain.on('refresh-theme-settings', () => { ipcMain.on('refresh-theme-settings', () => {
const appTheme = settingsStore.get('application_theme'); const appTheme = settingsStore.get('application_theme');
if (isWindows && mainWindow) { if (isWindows && mainWindow) {
mainWindow.setTitleBarOverlay({ mainWindow.setTitleBarOverlay({
@ -94,26 +91,29 @@ else {
symbolColor: appTheme === 'dark' ? '#fff' : '#000' symbolColor: appTheme === 'dark' ? '#fff' : '#000'
}); });
} }
}); });
ipcMain.on('change-window-title', (_, title: string) => { ipcMain.on('change-window-title', (_, title: string) => {
if (mainWindow) mainWindow.setTitle(title); if (mainWindow) mainWindow.setTitle(title);
}); });
// quit application when all windows are closed // quit application when all windows are closed
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits // on macOS it is common for applications to stay open until the user explicitly quits
if (!isMacOS) app.quit(); if (!isMacOS) app.quit();
}); });
app.on('activate', async () => { app.on('activate', async () => {
// on macOS it is common to re-create a window even after all windows have been closed // on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) if (mainWindow === null)
mainWindow = await createMainWindow(); mainWindow = await createMainWindow();
}); });
// 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();
// create main BrowserWindow when electron is ready
app.on('ready', async () => {
mainWindowState = windowStateKeeper({ mainWindowState = windowStateKeeper({
defaultWidth: 1024, defaultWidth: 1024,
defaultHeight: 800 defaultHeight: 800
@ -128,12 +128,6 @@ else {
// if (isDevelopment) // if (isDevelopment)
// mainWindow.webContents.openDevTools(); // 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 => { process.on('uncaughtException', error => {
mainWindow.webContents.send('unhandled-exception', error); mainWindow.webContents.send('unhandled-exception', error);
}); });
@ -141,9 +135,9 @@ else {
process.on('unhandledRejection', error => { process.on('unhandledRejection', error => {
mainWindow.webContents.send('unhandled-exception', error); mainWindow.webContents.send('unhandled-exception', error);
}); });
}); });
app.on('browser-window-created', (event, window) => { app.on('browser-window-created', (event, window) => {
if (isDevelopment) { if (isDevelopment) {
const { antares } = require('../../package.json'); const { antares } = require('../../package.json');
const extensionPath = path.resolve(__dirname, `../../misc/${antares.devtoolsId}`); const extensionPath = path.resolve(__dirname, `../../misc/${antares.devtoolsId}`);
@ -157,8 +151,7 @@ else {
window.webContents.on('did-create-window', (w) => { // Close new windows window.webContents.on('did-create-window', (w) => { // Close new windows
w.close(); w.close();
}); });
}); });
}
function createAppMenu () { function createAppMenu () {
const menuTemplate: OsMenu = { const menuTemplate: OsMenu = {

View File

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