Files
openclawEle/renderer.js
2026-03-01 00:07:25 +08:00

119 lines
3.5 KiB
JavaScript

// Check if window.electronAPI exists
if (window.electronAPI) {
document.getElementById('close-btn').addEventListener('click', () => {
window.electronAPI.windowControl('close');
});
document.getElementById('minimize-btn').addEventListener('click', () => {
window.electronAPI.windowControl('minimize');
});
}
// Logic for View Switching
const views = {
main: document.getElementById('view-main'),
custom: document.getElementById('view-custom'),
progress: document.getElementById('view-progress'),
config: document.getElementById('view-config')
};
function switchView(viewName) {
Object.values(views).forEach(v => v.classList.remove('active'));
views[viewName].classList.add('active');
}
// Main View Handlers
document.getElementById('btn-custom-install').addEventListener('click', () => {
switchView('custom');
});
document.getElementById('btn-install-now').addEventListener('click', () => {
startInstallation();
});
// Custom View Handlers
document.getElementById('btn-back-main').addEventListener('click', () => {
switchView('main');
});
document.getElementById('btn-install-start').addEventListener('click', () => {
startInstallation();
});
document.getElementById('btn-change-path').addEventListener('click', async () => {
if (window.electronAPI) {
const path = await window.electronAPI.selectDirectory();
if (path) {
document.getElementById('install-path').value = path;
}
}
});
// Installation Process Simulation
function startInstallation() {
switchView('progress');
const fill = document.getElementById('progress-fill');
const text = document.getElementById('progress-text');
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 15;
if (progress >= 100) {
progress = 100;
clearInterval(interval);
setTimeout(() => {
switchView('config');
}, 500);
}
fill.style.width = progress + '%';
text.innerText = `正在安装文件... ${Math.floor(progress)}%`;
}, 300);
}
// Config View Handlers
document.getElementById('btn-change-workdir').addEventListener('click', async () => {
if (window.electronAPI) {
const path = await window.electronAPI.selectDirectory();
if (path) {
document.getElementById('work-dir').value = path;
}
}
});
// Service selection logic
const cards = document.querySelectorAll('.service-card');
cards.forEach(card => {
card.addEventListener('click', () => {
cards.forEach(c => c.classList.remove('active'));
card.classList.add('active');
});
});
document.getElementById('btn-test-api').addEventListener('click', () => {
const btn = document.getElementById('btn-test-api');
const originalText = btn.innerText;
btn.innerText = '验证中...';
btn.disabled = true;
// Simulate API testing
setTimeout(() => {
btn.innerText = '验证通过';
btn.style.backgroundColor = '#40c057';
btn.style.color = 'white';
document.getElementById('btn-finish').disabled = false;
setTimeout(() => {
btn.innerText = originalText;
btn.style.backgroundColor = '';
btn.style.color = '';
btn.disabled = false;
}, 2000);
}, 1000);
});
document.getElementById('btn-finish').addEventListener('click', () => {
if (window.electronAPI) {
window.electronAPI.windowControl('close'); // or launch main app
}
});