61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
const { app, BrowserWindow } = require('electron');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
let mainWindow;
|
|
|
|
// 🔄 AUTO-RELOAD FOR DEVELOPMENT
|
|
function setupAutoReload(win) {
|
|
const watcher = fs.watch(path.join(__dirname), { recursive: true }, (eventType, filename) => {
|
|
if (filename && (filename.endsWith('.js') || filename.endsWith('.html') || filename.endsWith('.css') || filename.endsWith('.json'))) {
|
|
console.log(`🔄 File changed: ${filename} - Reloading...`);
|
|
win.reload();
|
|
}
|
|
});
|
|
|
|
win.on('closed', () => {
|
|
watcher.close();
|
|
});
|
|
}
|
|
|
|
function createWindow() {
|
|
mainWindow = new BrowserWindow({
|
|
width: 1280,
|
|
height: 720,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
},
|
|
backgroundColor: '#000000',
|
|
title: 'Mrtva Dolina - Death Valley'
|
|
});
|
|
|
|
mainWindow.loadFile('index.html');
|
|
|
|
// 🔄 Enable Auto Reload
|
|
setupAutoReload(mainWindow);
|
|
|
|
// Odpri DevTools (za development)
|
|
mainWindow.webContents.openDevTools();
|
|
|
|
mainWindow.on('closed', () => {
|
|
mainWindow = null;
|
|
});
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow();
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow();
|
|
}
|
|
});
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|