make configuration slideble
This commit is contained in:
parent
f082223f2a
commit
8b519a85bc
72
main.js
72
main.js
|
|
@ -2,7 +2,6 @@ const { app, BrowserWindow, ipcMain, dialog } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let configWindow;
|
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
|
|
@ -11,59 +10,15 @@ function createWindow() {
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
|
webviewTag: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.loadURL('https://photos.onedrive.com');
|
mainWindow.loadFile(path.join(__dirname, 'renderer/index.html'));
|
||||||
mainWindow.setTitle('OneDrive Photos');
|
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() {
|
app.whenReady().then(createWindow);
|
||||||
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', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
|
|
@ -71,25 +26,20 @@ app.on('window-all-closed', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle configuration settings
|
app.on('activate', () => {
|
||||||
ipcMain.on('open-config-window', () => {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
if (!configWindow) {
|
createWindow();
|
||||||
createConfigWindow();
|
|
||||||
} else {
|
|
||||||
configWindow.focus();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Modified IPC handlers
|
||||||
|
ipcMain.on('toggle-config', () => {
|
||||||
|
mainWindow.webContents.send('toggle-config');
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('set-config', (event, config) => {
|
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('Destination Folder:', config.destFolder);
|
||||||
console.log('OneDrive Source Path:', config.onedriveSource);
|
console.log('OneDrive Source Path:', config.onedriveSource);
|
||||||
|
|
||||||
// Close the configuration window
|
|
||||||
if (configWindow) {
|
|
||||||
configWindow.close();
|
|
||||||
configWindow = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('select-folder', (event) => {
|
ipcMain.on('select-folder', (event) => {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
#config-panel {
|
||||||
|
position: fixed;
|
||||||
|
width: 300px;
|
||||||
|
height: 100vh;
|
||||||
|
right: -300px;
|
||||||
|
top: 0;
|
||||||
|
background: white;
|
||||||
|
border-left: 1px solid #ccc;
|
||||||
|
padding: 20px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
transition: right 0.3s ease-in-out;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
#config-panel.open {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
#main-content {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
#config-button {
|
||||||
|
position: fixed;
|
||||||
|
top: 10px;
|
||||||
|
right: 180px;
|
||||||
|
z-index: 1000;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: transparent;
|
||||||
|
color: #0078d4;
|
||||||
|
border: 1px solid #0078d4;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
height: 32px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
#config-button:hover {
|
||||||
|
background: #f0f8ff;
|
||||||
|
}
|
||||||
|
#config-button i {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
.close-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 24px;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 5px 10px;
|
||||||
|
color: #666;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
.close-button:hover {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.panel-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding-right: 40px;
|
||||||
|
}
|
||||||
|
.close-button i {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button id="config-button">
|
||||||
|
<i class="fas fa-cog"></i>
|
||||||
|
Configuration
|
||||||
|
</button>
|
||||||
|
<webview id="main-content" src="https://photos.onedrive.com"></webview>
|
||||||
|
<div id="config-panel">
|
||||||
|
<button class="close-button" id="close-config">
|
||||||
|
<i class="fas fa-arrow-right"></i>
|
||||||
|
</button>
|
||||||
|
<div class="panel-header">
|
||||||
|
<h1>Configuration</h1>
|
||||||
|
</div>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const { ipcRenderer } = require('electron');
|
||||||
|
|
||||||
|
// Configuration button handler
|
||||||
|
document.getElementById('config-button').addEventListener('click', () => {
|
||||||
|
ipcRenderer.send('toggle-config');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Configuration panel toggle
|
||||||
|
ipcRenderer.on('toggle-config', () => {
|
||||||
|
const panel = document.getElementById('config-panel');
|
||||||
|
panel.classList.toggle('open');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Folder selection
|
||||||
|
document.getElementById('select-folder').addEventListener('click', () => {
|
||||||
|
ipcRenderer.send('select-folder');
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on('folder-selected', (event, path) => {
|
||||||
|
document.getElementById('dest-folder').value = path;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Form submission
|
||||||
|
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 });
|
||||||
|
// Close the panel after saving
|
||||||
|
document.getElementById('config-panel').classList.remove('open');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add close button handler
|
||||||
|
document.getElementById('close-config').addEventListener('click', () => {
|
||||||
|
document.getElementById('config-panel').classList.remove('open');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue