Files
Git-Manager-Gui/CREATE_COMPLETE_FILES.sh

206 lines
6.8 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
##############################################################################
# CREATE_COMPLETE_FILES.sh
#
# Dieses Script erstellt die vollständigen renderer.js und main.js Dateien
# mit allen notwendigen Änderungen für Auto-Login und persistente Settings.
#
# VERWENDUNG:
# 1. Speichere dieses Script in deinem Projekt-Ordner
# 2. Mache es ausführbar: chmod +x CREATE_COMPLETE_FILES.sh
# 3. Führe es aus: ./CREATE_COMPLETE_FILES.sh
# 4. Die neuen Dateien werden erstellt: renderer_NEW.js und main_NEW.js
# 5. Ersetze deine alten Dateien mit den neuen
#
##############################################################################
echo "========================================="
echo "Erstelle vollständige Dateien..."
echo "========================================="
echo ""
# Prüfe ob Original-Dateien existieren
if [ ! -f "renderer.js" ]; then
echo "❌ FEHLER: renderer.js nicht gefunden!"
echo "Bitte führe dieses Script im Projekt-Ordner aus."
exit 1
fi
if [ ! -f "main.js" ]; then
echo "❌ FEHLER: main.js nicht gefunden!"
echo "Bitte führe dieses Script im Projekt-Ordner aus."
exit 1
fi
echo "✅ Original-Dateien gefunden"
echo ""
# Backup erstellen
echo "📦 Erstelle Backups..."
cp renderer.js renderer.js.backup
cp main.js main.js.backup
echo "✅ Backups erstellt: renderer.js.backup, main.js.backup"
echo ""
# RENDERER.JS - Patch anwenden
echo "🔧 Patche renderer.js..."
# Erstelle temporäre Datei mit der neuen DOMContentLoaded Funktion
cat > /tmp/new_domcontentloaded.js << 'NEWFUNC'
window.addEventListener('DOMContentLoaded', async () => {
// Prevent default drag/drop on document (except in repo view)
document.addEventListener('dragover', e => {
if (currentState.view !== 'gitea-repo') {
e.preventDefault();
}
});
document.addEventListener('drop', e => {
if (currentState.view !== 'gitea-repo') {
e.preventDefault();
}
});
// Load credentials and auto-login if available
try {
const creds = await window.electronAPI.loadCredentials();
if (creds) {
// Fülle Settings-Felder
if ($('githubToken')) $('githubToken').value = creds.githubToken || '';
if ($('giteaToken')) $('giteaToken').value = creds.giteaToken || '';
if ($('giteaURL')) $('giteaURL').value = creds.giteaURL || '';
// AUTO-LOGIN: Wenn Gitea-Credentials vorhanden sind, lade sofort die Repos
if (creds.giteaToken && creds.giteaURL) {
console.log('✅ Credentials gefunden - Auto-Login wird gestartet...');
setStatus('Lade deine Projekte...');
// Kurze Verzögerung damit UI fertig geladen ist
setTimeout(() => {
loadGiteaRepos();
}, 500);
} else {
console.log(' Keine vollständigen Gitea-Credentials - bitte in Settings eintragen');
setStatus('Bereit - bitte Settings konfigurieren');
}
} else {
console.log(' Keine Credentials gespeichert');
setStatus('Bereit - bitte Settings konfigurieren');
}
} catch (error) {
console.error('Error loading credentials:', error);
setStatus('Fehler beim Laden der Einstellungen');
}
NEWFUNC
# Nutze sed um die alte Funktion zu ersetzen
# (Dies ist komplex - nutze Python für robusteres Replacement)
python3 << 'PYSCRIPT'
import re
# Lese Original-Datei
with open('renderer.js', 'r', encoding='utf-8') as f:
content = f.read()
# Lese neue Funktion
with open('/tmp/new_domcontentloaded.js', 'r') as f:
new_func_start = f.read()
# Finde die alte DOMContentLoaded Funktion und ersetze nur den Anfang
# Der Rest (Event Handlers) bleibt gleich
pattern = r"(window\.addEventListener\('DOMContentLoaded', async \(\) => \{.*?// Load credentials.*?try \{.*?\} catch \(error\) \{.*?console\.error\('Error loading credentials:', error\);.*?\})"
# Suche nach dem Pattern
match = re.search(pattern, content, re.DOTALL)
if match:
# Ersetze nur den Credentials-Loading Teil
old_section = match.group(1)
content = content.replace(old_section, new_func_start)
# Schreibe neue Datei
with open('renderer_NEW.js', 'w', encoding='utf-8') as f:
f.write(content)
print("✅ renderer_NEW.js erstellt")
else:
print("⚠️ Konnte Funktion nicht automatisch patchen")
print(" Bitte nutze die manuellen Patches")
PYSCRIPT
echo ""
# MAIN.JS - Patch anwenden
echo "🔧 Patche main.js..."
python3 << 'PYSCRIPT2'
import re
# Lese Original
with open('main.js', 'r', encoding='utf-8') as f:
content = f.read()
# ÄNDERUNG 1: Entferne getDataDir, ändere getCredentialsFilePath
old_funcs = r"function getDataDir\(\) \{[^}]+\}\s*function getCredentialsFilePath\(\) \{[^}]+\}"
new_func = """function getCredentialsFilePath() {
return ppath.join(app.getPath('userData'), 'credentials.json');
}"""
content = re.sub(old_funcs, new_func, content)
# ÄNDERUNG 2: Patche save-credentials Handler
old_handler = r"(ipcMain\.handle\('save-credentials', async \(event, data\) => \{[\s\S]*?const DATA_DIR = getDataDir\(\);[\s\S]*?ensureDir\(DATA_DIR\);[^}]+)\}"
new_handler = """ipcMain.handle('save-credentials', async (event, data) => {
try {
const CREDENTIALS_FILE = getCredentialsFilePath();
const userDataDir = app.getPath('userData');
if (!fs.existsSync(userDataDir)) {
fs.mkdirSync(userDataDir, { recursive: true });
}
const json = JSON.stringify(data);
const cipher = crypto.createCipheriv(ALGORITHM, SECRET_KEY, IV);
const encrypted = Buffer.concat([cipher.update(json, 'utf8'), cipher.final()]);
fs.writeFileSync(CREDENTIALS_FILE, encrypted);
console.log('✅ Credentials saved to:', CREDENTIALS_FILE);
return { ok: true };
} catch (e) {
console.error('save-credentials error', e);
return { ok: false, error: String(e) };
}
});"""
content = re.sub(old_handler, new_handler, content, flags=re.DOTALL)
# Schreibe neue Datei
with open('main_NEW.js', 'w', encoding='utf-8') as f:
f.write(content)
print("✅ main_NEW.js erstellt")
PYSCRIPT2
echo ""
echo "========================================="
echo "✅ FERTIG!"
echo "========================================="
echo ""
echo "Neue Dateien erstellt:"
echo " 📄 renderer_NEW.js"
echo " 📄 main_NEW.js"
echo ""
echo "Backups erstellt:"
echo " 💾 renderer.js.backup"
echo " 💾 main.js.backup"
echo ""
echo "Nächste Schritte:"
echo " 1. Prüfe die neuen Dateien"
echo " 2. Ersetze die alten:"
echo " mv renderer_NEW.js renderer.js"
echo " mv main_NEW.js main.js"
echo " 3. Starte die App neu"
echo ""
echo "Bei Problemen: Backups wiederherstellen"
echo " mv renderer.js.backup renderer.js"
echo " mv main.js.backup main.js"
echo ""