add config.html page
This commit is contained in:
parent
af7b0d88cf
commit
f082223f2a
99
main.js
99
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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Configuration</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Configuration</h1>
|
||||
<form id="config-form">
|
||||
<div>
|
||||
<label for="dest-folder">Destination Folder for Photo Sync:</label>
|
||||
<input type="text" id="dest-folder" name="dest-folder" readonly>
|
||||
<button type="button" id="select-folder">Select Folder</button>
|
||||
</div>
|
||||
<div>
|
||||
<label for="onedrive-source">OneDrive Source Path:</label>
|
||||
<input type="text" id="onedrive-source" name="onedrive-source">
|
||||
</div>
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
document.getElementById('select-folder').addEventListener('click', () => {
|
||||
ipcRenderer.send('select-folder');
|
||||
});
|
||||
|
||||
ipcRenderer.on('folder-selected', (event, path) => {
|
||||
document.getElementById('dest-folder').value = path;
|
||||
});
|
||||
|
||||
document.getElementById('config-form').addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
const destFolder = document.getElementById('dest-folder').value;
|
||||
const onedriveSource = document.getElementById('onedrive-source').value;
|
||||
ipcRenderer.send('set-config', { destFolder, onedriveSource });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue