82 lines
No EOL
2.5 KiB
JavaScript
82 lines
No EOL
2.5 KiB
JavaScript
const { app, BrowserWindow, ipcMain } = require('electron'); // ipcMain hinzufügen
|
|
const path = require('path');
|
|
const fs = require('fs'); // Behalte fs bei, falls du es für die Pfadprüfung brauchst
|
|
|
|
// Füge electron-reloader hinzu
|
|
try {
|
|
require('electron-reloader')(module);
|
|
} catch (_) {}
|
|
|
|
function createWindow() {
|
|
const win = new BrowserWindow({
|
|
width: 1200,
|
|
height: 800,
|
|
frame: false,
|
|
webPreferences: {
|
|
contextIsolation: true,
|
|
preload: path.join(__dirname, 'preload.js') // Preload-Skript hinzufügen
|
|
},
|
|
});
|
|
|
|
// Pfad für neuere Angular-Versionen (v17+)
|
|
const indexPath = path.join(__dirname, '../dist/projektmanagement-tool/browser/index.html');
|
|
console.log('Versuche zu laden:', indexPath);
|
|
|
|
// Prüfen, ob die Datei existiert, bevor sie geladen wird
|
|
if (fs.existsSync(indexPath)) {
|
|
win.loadFile(indexPath);
|
|
} else {
|
|
console.error(`Index-Datei nicht gefunden unter: ${indexPath}`);
|
|
// Optional: Lade eine Fehlerseite oder schließe die App
|
|
win.loadURL(`data:text/html,<html><body><h1>Fehler: index.html nicht gefunden</h1><p>Pfad: ${indexPath}</p></body></html>`);
|
|
}
|
|
|
|
// Öffne DevTools für Debugging (auskommentiert, um automatisches Öffnen zu verhindern)
|
|
win.webContents.openDevTools();
|
|
}
|
|
|
|
// IPC-Handler für Fensteraktionen hinzufügen
|
|
ipcMain.on('minimize-window', (event) => {
|
|
const window = BrowserWindow.fromWebContents(event.sender);
|
|
window?.minimize();
|
|
});
|
|
|
|
ipcMain.on('maximize-window', (event) => {
|
|
const window = BrowserWindow.fromWebContents(event.sender);
|
|
if (window?.isMaximized()) {
|
|
window.unmaximize();
|
|
} else {
|
|
window?.maximize();
|
|
}
|
|
});
|
|
|
|
ipcMain.on('close-window', (event) => {
|
|
const window = BrowserWindow.fromWebContents(event.sender);
|
|
window?.close();
|
|
});
|
|
|
|
app.whenReady().then(createWindow);
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|
|
|
|
// Fehlerbehandlung beim Starten
|
|
app.on('ready', () => {
|
|
try {
|
|
const distPath = path.join(__dirname, '../dist/projektmanagement-tool');
|
|
if (fs.existsSync(distPath)) {
|
|
console.log('Dist-Verzeichnis gefunden:', distPath);
|
|
const browserPath = path.join(distPath, 'browser');
|
|
if (fs.existsSync(browserPath)) {
|
|
console.log('Browser-Verzeichnis gefunden:', browserPath);
|
|
} else {
|
|
console.error('Browser-Verzeichnis nicht gefunden!');
|
|
}
|
|
} else {
|
|
console.error('Dist-Verzeichnis nicht gefunden!');
|
|
}
|
|
} catch (error) {
|
|
console.error('Fehler beim Überprüfen des Verzeichnisses:', error);
|
|
}
|
|
}); |