diff --git a/main.js b/main.js index d14982c..b7e1e52 100644 --- a/main.js +++ b/main.js @@ -1,30 +1,105 @@ -const { app, BrowserWindow } = require('electron') +const { app, BrowserWindow, ipcMain, dialog } = require('electron'); +const path = require('path'); + +let mainWindow; +let configWindow; function createWindow() { - const win = new BrowserWindow({ + mainWindow = new BrowserWindow({ width: 1200, height: 800, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false, } - }) + }); - win.loadURL('https://photos.onedrive.com') - win.setTitle('OneDrive Photos') + 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() + createWindow(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { - createWindow() + createWindow(); } - }) -}) + }); +}); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { - app.quit() + 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); + }); +}); diff --git a/renderer/config.html b/renderer/config.html new file mode 100644 index 0000000..59907ca --- /dev/null +++ b/renderer/config.html @@ -0,0 +1,42 @@ + + +
+ + +