Files
NFD2NFC/index.html

166 lines
4.0 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;
max-width: 700px;
margin-left: auto;
margin-right: auto;
text-align: left;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
padding: 12px;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
.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: 150px;
overflow-y: scroll;
max-width: 700px;
margin-left: auto;
margin-right: auto;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>디렉토리 감시 애플리케이션</h1>
<button id="select-directory">디렉토리 선택</button>
<div id="selected-directories">
<h2>감시 중인 디렉토리</h2>
<table>
<thead>
<tr>
<th>디렉토리 경로</th>
<th>제거</th>
</tr>
</thead>
<tbody id="directories-list">
<!-- 선택된 디렉토리 목록이 여기에 표시됩니다 -->
</tbody>
</table>
</div>
<div id="log">
로그가 여기에 표시됩니다.
</div>
<script>
const selectDirButton = document.getElementById('select-directory');
const directoriesList = document.getElementById('directories-list');
const logDiv = document.getElementById('log');
selectDirButton.addEventListener('click', async () => {
const result = await window.electronAPI.selectDirectories();
if (!result.canceled) {
refreshDirectories(); // 즉시 갱신
}
});
function addDirectoryToList(dirPath) {
if (document.querySelector(`[data-path="${ dirPath }"]`)) {
return;
}
const directoryRow = document.createElement('tr');
directoryRow.setAttribute('data-path', dirPath);
const pathCell = document.createElement('td');
pathCell.textContent = dirPath;
const removeCell = document.createElement('td');
const removeBtn = document.createElement('button');
removeBtn.className = 'remove-button';
removeBtn.textContent = '제거';
removeBtn.addEventListener('click', async () => {
const response = await window.electronAPI.removeDirectory(dirPath);
if (response.success) {
directoriesList.removeChild(directoryRow);
appendLog(`디렉토리 감시 중지: "${ dirPath }"`);
} else {
appendLog(`디렉토리 제거 실패: "${ response.message }"`);
}
});
removeCell.appendChild(removeBtn);
directoryRow.appendChild(pathCell);
directoryRow.appendChild(removeCell);
directoriesList.appendChild(directoryRow);
}
function refreshDirectories() {
window.electronAPI.getDirectories().then((directories) => {
directoriesList.innerHTML = '';
for (const dirPath of Object.keys(directories)) {
addDirectoryToList(dirPath);
}
});
}
window.addEventListener('DOMContentLoaded', () => {
// Initially load directories
refreshDirectories();
// Then refresh every 10 seconds
setInterval(refreshDirectories, 10000);
});
// Listen for refresh-directories event
window.electronAPI.on('refresh-directories', refreshDirectories);
function appendLog(message) {
logDiv.textContent += `${ message }\n`;
logDiv.scrollTop = logDiv.scrollHeight;
}
window.electronAPI.onLog((message) => {
appendLog(message);
});
</script>
</body>
</html>