Add sync functionality and remove configuration HTML

- Implemented 'start-sync' IPC event in main.js to initiate synchronization with provided configuration.
- Added a 'Sync Now' button in index.html to trigger the sync process.
- Updated renderer.js to handle sync button click, ensuring both destination folder and OneDrive source path are set before proceeding.
- Removed obsolete config.html file as its functionality is now integrated into the main application flow.
- Enhanced styles for the new sync button in styles.css.
This commit is contained in:
Tiger Ren 2025-01-08 01:00:49 +08:00
parent 1c7fc924f3
commit d5a4eac1ae
5 changed files with 46 additions and 43 deletions

View File

@ -199,3 +199,9 @@ ipcMain.on('select-folder', (event) => {
console.log(err);
});
});
ipcMain.on('start-sync', (event, config) => {
console.log('Starting sync with config:', config);
// Here you can implement the sync logic using the config.destFolder
// and config.onedriveSource parameters
});

View File

@ -1,42 +0,0 @@
<!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>

View File

@ -37,6 +37,9 @@
<button type="submit" class="submit-button">Save Changes</button>
</form>
<button id="sync-button">Sync Now</button>
</div>
</div>

View File

@ -65,6 +65,18 @@ document.getElementById('config-form').addEventListener('submit', (event) => {
console.log('Configuration panel closed');
});
document.getElementById('sync-button').addEventListener('click', () => {
const destFolder = document.getElementById('dest-folder').value;
const onedriveSource = document.getElementById('onedrive-source').value;
if (!destFolder || !onedriveSource) {
alert('Please set both destination folder and OneDrive source path first');
return;
}
ipcRenderer.send('start-sync', { destFolder, onedriveSource });
});
// Config loaded handler
ipcRenderer.on('config-loaded', (event, config) => {
console.log('Received saved configuration:', config);
@ -107,4 +119,5 @@ function createStatusDisplay() {
document.getElementById('close-config').addEventListener('click', () => {
console.log('Close button clicked');
document.getElementById('config-panel').classList.remove('open');
});
});

View File

@ -218,3 +218,26 @@ body {
70% { opacity: 1; }
100% { opacity: 0; }
}
/* Sync Button */
#sync-button {
width: 100%;
background: #0078d4;
color: white;
border: none;
padding: 10px 24px;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
margin-top: 16px;
}
#sync-button:hover {
background: #106ebe;
}
#sync-button:active {
background: #005a9e;
}