const { app, BrowserWindow, ipcMain, dialog } = require('electron'); const path = require('path'); let mainWindow; let configWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 1200, height: 800, webPreferences: { nodeIntegration: true, contextIsolation: false, } }); mainWindow.loadURL('https://photos.onedrive.com'); mainWindow.setTitle('OneDrive Photos'); // Open the DevTools. // mainWindow.webContents.openDevTools(); // Add this to the createWindow function mainWindow.webContents.on('did-finish-load', () => { mainWindow.webContents.executeJavaScript(` const button = document.createElement('button'); button.textContent = 'Open Configuration'; button.style.position = 'fixed'; button.style.top = '10px'; button.style.right = '10px'; button.style.zIndex = '1000'; button.addEventListener('click', () => { require('electron').ipcRenderer.send('open-config-window'); }); document.body.appendChild(button); `); }); } function createConfigWindow() { configWindow = new BrowserWindow({ width: 600, height: 400, webPreferences: { nodeIntegration: true, contextIsolation: false, } }); // Load config.html from the renderer directory configWindow.loadFile(path.join(__dirname, 'renderer/config.html')); configWindow.setTitle('Configuration'); // Open the DevTools. // configWindow.webContents.openDevTools(); } app.whenReady().then(() => { createWindow(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); }); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); // Handle configuration settings ipcMain.on('open-config-window', () => { if (!configWindow) { createConfigWindow(); } else { configWindow.focus(); } }); ipcMain.on('set-config', (event, config) => { // Save the configuration settings (you can use a file or a database) console.log('Destination Folder:', config.destFolder); console.log('OneDrive Source Path:', config.onedriveSource); // Close the configuration window if (configWindow) { configWindow.close(); configWindow = null; } }); ipcMain.on('select-folder', (event) => { dialog.showOpenDialog({ properties: ['openDirectory'] }).then(result => { if (!result.canceled) { event.reply('folder-selected', result.filePaths[0]); } }).catch(err => { console.log(err); }); });