Files
NFD2NFC/index.html

141 lines
3.6 KiB
HTML

<!-- index.html -->
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Directory Watcher App</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
#selected-directories {
margin-top: 20px;
text-align: left;
max-width: 500px;
margin-left: auto;
margin-right: auto;
}
.directory-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px;
border-bottom: 1px solid #ccc;
}
.directory-path {
word-break: break-all;
}
.remove-button {
background-color: #ff4d4d;
border: none;
color: white;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
}
#log {
margin-top: 20px;
text-align: left;
white-space: pre-wrap;
background-color: #f0f0f0;
padding: 10px;
border-radius: 5px;
height: 200px;
overflow-y: scroll;
max-width: 500px;
margin-left: auto;
margin-right: auto;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Directory Watcher Application</h1>
<button id="select-directory">Select Directories</button>
<div id="selected-directories">
<h2>Watched Directories</h2>
<div id="directories-list">
<!-- Selected directories will appear here -->
</div>
</div>
<div id="log">
Logs will appear here.
</div>
<script>
const selectDirButton = document.getElementById('select-directory');
const directoriesList = document.getElementById('directories-list');
const logDiv = document.getElementById('log');
// Function to add a directory to the list in the UI
function addDirectoryToList(dirPath) {
// Avoid adding duplicates
if (document.querySelector(`[data-path="${ dirPath }"]`)) {
return;
}
const directoryItem = document.createElement('div');
directoryItem.className = 'directory-item';
directoryItem.setAttribute('data-path', dirPath);
const pathSpan = document.createElement('span');
pathSpan.className = 'directory-path';
pathSpan.textContent = dirPath;
const removeBtn = document.createElement('button');
removeBtn.className = 'remove-button';
removeBtn.textContent = 'Remove';
removeBtn.addEventListener('click', async () => {
const response = await window.electronAPI.removeDirectory(dirPath);
if (response.success) {
directoriesList.removeChild(directoryItem);
appendLog(`Stopped watching directory: "${ dirPath }"`);
} else {
appendLog(`Failed to remove directory: "${ response.message }"`);
}
});
directoryItem.appendChild(pathSpan);
directoryItem.appendChild(removeBtn);
directoriesList.appendChild(directoryItem);
}
// Function to append log messages to the log div
function appendLog(message) {
logDiv.textContent += `${ message }\n`;
logDiv.scrollTop = logDiv.scrollHeight; // Auto-scroll to the bottom
}
// Event listener for the "Select Directories" button
selectDirButton.addEventListener('click', async () => {
const result = await window.electronAPI.selectDirectories();
if (!result.canceled) {
for (const path of result.paths) {
addDirectoryToList(path);
}
}
});
// Listen for log messages from the main process
window.electronAPI.onLog((message) => {
appendLog(message);
});
</script>
</body>
</html>