v2.9
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
await insertUsername();
|
||||
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 5000 ms (5 seconds)
|
||||
|
||||
const backupButton = document.getElementById('backup');
|
||||
const shareButton = document.getElementById('share_dir');
|
||||
@@ -11,6 +12,53 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
const decryptButton = document.getElementById('decrypt');
|
||||
const logoutButton = document.getElementById('logout');
|
||||
|
||||
async function loadReceivedFiles() {
|
||||
const checkFileReceived = await window.electronAPI.checkFileExists('filesReceived.json');
|
||||
if (!checkFileReceived) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const fileData = await window.electronAPI.readFile('filesReceived.json');
|
||||
const filesJson = JSON.parse(fileData.content);
|
||||
const receivedFiles = filesJson.receivedFiles;
|
||||
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const existingButtons = Array.from(notificationsDiv.children).map(button => button.getAttribute('data-filepath'));
|
||||
|
||||
receivedFiles.forEach(filePath => {
|
||||
// Check if the button for this file path already exists
|
||||
if (!existingButtons.includes(filePath)) {
|
||||
const button = document.createElement('button');
|
||||
button.setAttribute('data-filepath', filePath); // Set a custom attribute to track the file path
|
||||
button.name = 'notification';
|
||||
button.textContent = 'You received a file';
|
||||
button.addEventListener('click', () => handleFileReceivedButtonPressed(filePath, button));
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error loading received files:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFileReceivedButtonPressed(filePath, button) {
|
||||
console.log('Notification button clicked!');
|
||||
|
||||
// Open file in file explorer
|
||||
await window.electronAPI.showFileInExplorer(filePath)
|
||||
.then(() => console.log('File explorer opened'))
|
||||
.catch(error => console.error('Error opening file explorer:', error));
|
||||
|
||||
// Remove the button
|
||||
button.remove();
|
||||
|
||||
// Call to remove the path from the JSON file
|
||||
await window.electronAPI.removePathFromReceivedFiles(filePath)
|
||||
.then(() => console.log('Path removed from received files'))
|
||||
.catch(error => console.error('Error removing path:', error));
|
||||
}
|
||||
|
||||
|
||||
checkDirBackupFileExists()
|
||||
.then(() => console.log('verificare backupDir facuta'));
|
||||
@@ -134,7 +182,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
|
||||
const button = document.getElementById('backup_alert');
|
||||
const button = document.getElementById('share_alert');
|
||||
button.remove();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user