From 76c35efd31c76d02d9d126c54aa151089047cd87 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 25 May 2025 03:57:13 +0200 Subject: [PATCH] Refactor folder location check and event handling in main.js --- main.js | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/main.js b/main.js index 3b808bb..f9b465e 100644 --- a/main.js +++ b/main.js @@ -27,34 +27,7 @@ let tray = null; let isQuiting = false; -function updateMissingFolders(win) { - let folders = store.get('folders') || []; - let updatedFolders = []; - let anyChanged = false; - folders = folders.map(f => { - const missing = !fs.existsSync(f.path); - const needsRelocation = f.needsRelocation || false; - if (needsRelocation !== missing) { - anyChanged = true; - updatedFolders.push({ ...f, needsRelocation: missing }); - return { ...f, needsRelocation: missing }; - } - return f; - }); - - if (anyChanged) { - store.set('folders', folders); - console.log("change detected"); - // Für jeden betroffenen Folder Event schicken: - updatedFolders.forEach(folderObj => { - win.webContents.send('folders-location-updated', folderObj); - }); - } -} - -updateMissingFolders(win); -setInterval(updateMissingFolders(win), 3000); @@ -606,6 +579,36 @@ async function autoCommit(folderPath, message) { app.whenReady().then(() => { const win = createWindow(); + function updateMissingFolders(win) { + let folders = store.get('folders') || []; + let updatedFolders = []; + let anyChanged = false; + + folders = folders.map(f => { + const missing = !fs.existsSync(f.path); + const needsRelocation = f.needsRelocation || false; + if (needsRelocation !== missing) { + anyChanged = true; + updatedFolders.push({ ...f, needsRelocation: missing }); + return { ...f, needsRelocation: missing }; + } + return f; + }); + + if (anyChanged) { + store.set('folders', folders); + console.log("change detected"); + // Für jeden betroffenen Folder Event schicken: + updatedFolders.forEach(folderObj => { + win.webContents.send('folders-location-updated', folderObj); + }); + } + } + + updateMissingFolders(win); + setInterval(() => updateMissingFolders(win), 3000); + + // Menubar const menu = Menu.buildFromTemplate([ {