Files
NFD2NFC/index.html

168 lines
4.3 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>
<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) {
for (const path of result.paths) {
addDirectoryToList(path, new Date().toISOString());
}
}
});
// 디렉토리를 목록에 추가하는 함수
function addDirectoryToList(dirPath, lastUpdateTime) {
// 이미 목록에 있는 경우 중복 추가 방지
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 timeCell = document.createElement('td');
timeCell.textContent = new Date(lastUpdateTime).toLocaleString();
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(timeCell);
directoryRow.appendChild(removeCell);
directoriesList.appendChild(directoryRow);
}
// 로그 메시지를 로그 섹션에 추가하는 함수
function appendLog(message) {
logDiv.textContent += `${ message }\n`;
logDiv.scrollTop = logDiv.scrollHeight; // 자동 스크롤
}
// 디렉토리 목록 업데이트 이벤트 수신
window.electronAPI.onUpdateDirectories((directories) => {
// 기존 목록 초기화
directoriesList.innerHTML = '';
for (const [dirPath, lastUpdateTime] of Object.entries(directories)) {
addDirectoryToList(dirPath, lastUpdateTime);
}
});
// 로그 메시지 수신 시
window.electronAPI.onLog((message) => {
appendLog(message);
});
</script>
</body>
</html>