mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-12 01:11:03 +02:00
fix: error with multiple sessions in non-dev environment
This commit is contained in:
parent
075f542dc8
commit
169f610b2e
131
src/main/main.ts
131
src/main/main.ts
@ -78,87 +78,80 @@ 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({
|
||||||
color: appTheme === 'dark' ? '#3f3f3f' : '#fff',
|
color: appTheme === 'dark' ? '#3f3f3f' : '#fff',
|
||||||
symbolColor: appTheme === 'dark' ? '#fff' : '#000'
|
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('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();
|
mainWindow = await createMainWindow();
|
||||||
createAppMenu();
|
});
|
||||||
|
|
||||||
if (isWindows)
|
// create main BrowserWindow when electron is ready
|
||||||
mainWindow.show();
|
app.on('ready', async () => {
|
||||||
|
if (!gotTheLock && !safeStorage.isEncryptionAvailable()) // Disable multiple instances if is not possible to share session keys
|
||||||
|
app.quit();
|
||||||
|
|
||||||
// if (isDevelopment)
|
mainWindowState = windowStateKeeper({
|
||||||
// mainWindow.webContents.openDevTools();
|
defaultWidth: 1024,
|
||||||
|
defaultHeight: 800
|
||||||
// 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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('browser-window-created', (event, window) => {
|
mainWindow = await createMainWindow();
|
||||||
if (isDevelopment) {
|
createAppMenu();
|
||||||
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
|
if (isWindows)
|
||||||
e.preventDefault();
|
mainWindow.show();
|
||||||
});
|
|
||||||
|
|
||||||
window.webContents.on('did-create-window', (w) => { // Close new windows
|
// if (isDevelopment)
|
||||||
w.close();
|
// 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 () {
|
function createAppMenu () {
|
||||||
const menuTemplate: OsMenu = {
|
const menuTemplate: OsMenu = {
|
||||||
|
@ -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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user