1
0

Add visual indicator for relocated folders and update commit logic to handle missing folders

This commit is contained in:
2025-05-25 03:01:36 +02:00
parent d78576056c
commit c8b8ac8dda
4 changed files with 98 additions and 24 deletions

View File

@@ -84,6 +84,23 @@
border-style: solid !important;
border-color: gold !important;
}
.needs-relocation {
opacity: 0.5;
pointer-events: auto; /* Wichtig: trotzdem klickbar lassen! */
position: relative;
}
.needs-relocation::after {
content: "!";
color: #e11d48;
font-weight: bold;
font-size: 1.2em;
position: absolute;
left: 8px;
top: 8px;
background: #fff1f2;
border-radius: 50%;
padding: 0 5px;
}
#currentTitle {
/* erlauben, dass der Text umbricht */
@@ -211,11 +228,11 @@
<!-- Interaction Bar -->
<div class="w-full h-16 flex items-center p-4 interaction-bar"
style="background: var(--bg-sidebar); border-top: 1px solid var(--border)">
<button id="commitBtn"
<!--<button id="commitBtn"
class="ml-auto px-4 py-2 border rounded font-semibold"
style="background: var(--accent); color: #fff; border-color: var(--border)">
Commit
</button>
</button>-->
</div>
<script src="renderer.js"></script>

85
main.js
View File

@@ -18,13 +18,45 @@ const store = new Store({
skipGitPrompt: true,
intelligentCommitThreshold: 20,
autostart: false,
closeToTray: true
closeToTray: true,
needsRelocation: true
}
});
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);
// Für jeden betroffenen Folder Event schicken:
updatedFolders.forEach(folderObj => {
win.webContents.send('folders-location-updated', folderObj);
});
}
}
updateMissingFolders();
setInterval(updateMissingFolders, 3000);
function createTray(win) {
const iconPath = path.join(__dirname, 'assets/icon/trayicon.png');
const icon = nativeImage.createFromPath(iconPath);
@@ -731,10 +763,17 @@ app.whenReady().then(() => {
});
// Zähle Commits
ipcMain.handle('get-commit-count', async (_e, folderObj) => {
const git = simpleGit(folderObj.path);
const log = await git.log();
return log.total; // Anzahl der Commits
ipcMain.handle('get-commit-count', async (_e, folderObj) => {
try {
if (folderObj.needsRelocation || !fs.existsSync(folderObj.path)) {
return 0;
}
const git = simpleGit(folderObj.path);
const log = await git.log();
return log.total;
} catch (err) {
return 0;
}
});
// Prüfe, ob es ungestagte Änderungen gibt
@@ -756,22 +795,28 @@ app.whenReady().then(() => {
// Commits holen
ipcMain.handle('get-commits', async (_e, folderObj) => {
const git = simpleGit(folderObj.path);
// alle Commits holen
const log = await git.log(['--all']);
// aktuellen HEADHash ermitteln
const fullHead = (await git.revparse(['--verify', 'HEAD'])).trim();
const head = fullHead.substring(0, 7);
return {
head,
commits: log.all.map(c => ({
hash: c.hash.substring(0, 7),
date: c.date,
message: c.message
}))
};
try {
if (folderObj.needsRelocation || !fs.existsSync(folderObj.path)) {
// Folder nicht vorhanden, geben wir leere Liste zurück
return { head: null, commits: [] };
}
const git = simpleGit(folderObj.path);
const log = await git.log(['--all']);
const fullHead = (await git.revparse(['--verify', 'HEAD'])).trim();
const head = fullHead.substring(0, 7);
return {
head,
commits: log.all.map(c => ({
hash: c.hash.substring(0, 7),
date: c.date,
message: c.message
}))
};
} catch (err) {
// Im Fehlerfall (z.B. Verzeichnis gelöscht)
return { head: null, commits: [] };
}
});
// Diff
ipcMain.handle('diff-commit', async (_e, folderObj, hash) => {
const git = simpleGit(folderObj.path);

View File

@@ -43,6 +43,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
onTrayToggleMonitoring: (callback) => ipcRenderer.on('tray-toggle-monitoring', callback),
onTrayRemoveFolder: (callback) => ipcRenderer.on('tray-remove-folder', callback),
onTrayAddFolder: (callback) => ipcRenderer.on('tray-add-folder', callback),
onFoldersLocationUpdated: (callback) => ipcRenderer.on('folders-location-updated', (e, folderObj) => callback(folderObj)),
});
ipcRenderer.on('repo-updated', (_e, folder) => {

View File

@@ -260,6 +260,9 @@ folders.forEach(folderObj => {
const folder = folderObj.path;
titleEl.textContent = folder;
const { head, commits } = await window.electronAPI.getCommits(folderObj);
if (!commits || !commits.length) {
return;
}
contentList.innerHTML = commits.map(c => `
<li class="w-full p-3 mb-2 bg-white border border-gray-200 rounded shadow-sm
@@ -452,7 +455,7 @@ folders.forEach(folderObj => {
window.electronAPI.showFolderContextMenu(titleEl.textContent);
}
});
/*
const commitBtn = document.getElementById('commitBtn');
commitBtn.addEventListener('click', async () => {
const folderObj = await window.electronAPI.getSelected();
@@ -475,7 +478,7 @@ folders.forEach(folderObj => {
commitBtn.disabled = false;
commitBtn.textContent = 'Commit';
});
*/
window.electronAPI.onTrayToggleMonitoring(async (_e, folderPath) => {
const folders = await window.electronAPI.getFolders();
@@ -514,4 +517,12 @@ folders.forEach(folderObj => {
if (sel) await renderContent(sel);
});
window.electronAPI.onFoldersLocationUpdated(folderObj => {
const selector = `[data-folder-path="${folderObj.path.replace(/"/g, '\\"')}"]`;
const li = document.querySelector(selector);
if (li) {
li.classList.toggle('needs-relocation', folderObj.needsRelocation);
// evtl. noch ein !-Icon sichtbar machen
}
});
});