need test - electron updater

This commit is contained in:
AMIAY
2026-01-25 00:19:11 +01:00
parent f974d9c767
commit c8d7707b70
8 changed files with 529 additions and 48 deletions

View File

@@ -602,38 +602,38 @@
</div>
</div>
<div id="progressOverlay" class="progress-overlay" style="display: none;">
<div class="progress-content">
<div class="progress-info">
<span id="progressText" data-i18n="progress.initializing">Initializing...</span>
<span id="progressPercent">0%</span>
</div>
<div class="progress-bar-container">
<div id="progressBarFill" class="progress-bar-fill"></div>
</div>
<div class="progress-details">
<span id="progressSpeed"></span>
<span id="progressSize"></span>
</div>
<div id="progressErrorContainer" class="progress-error-container" style="display: none;">
<div id="progressErrorMessage" class="progress-error-message"></div>
<div class="progress-retry-section">
<span id="progressRetryInfo" class="progress-retry-info"></span>
<div class="progress-retry-buttons">
<button id="progressJRRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Java Download
</button>
<button id="progressPWRRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Game Download
</button>
<button id="progressRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Download
</button>
</div>
</div>
</div>
</div>
</div>
<div id="progressOverlay" class="progress-overlay" style="display: none;">
<div class="progress-content">
<div class="progress-info">
<span id="progressText" data-i18n="progress.initializing">Initializing...</span>
<span id="progressPercent">0%</span>
</div>
<div class="progress-bar-container">
<div id="progressBarFill" class="progress-bar-fill"></div>
</div>
<div class="progress-details">
<span id="progressSpeed"></span>
<span id="progressSize"></span>
</div>
<div id="progressErrorContainer" class="progress-error-container" style="display: none;">
<div id="progressErrorMessage" class="progress-error-message"></div>
<div class="progress-retry-section">
<span id="progressRetryInfo" class="progress-retry-info"></span>
<div class="progress-retry-buttons">
<button id="progressJRRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Java Download
</button>
<button id="progressPWRRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Game Download
</button>
<button id="progressRetryBtn" class="progress-retry-btn" style="display: none;">
Retry Download
</button>
</div>
</div>
</div>
</div>
</div>
<div id="chatUsernameModal" class="chat-username-modal" style="display: none;">
<div class="chat-username-modal-content">
@@ -854,6 +854,7 @@
<script src="js/i18n.js"></script>
<script type="module" src="js/settings.js"></script>
<script type="module" src="js/update.js"></script>
<script src="js/updater.js"></script>
</body>

157
GUI/js/updater.js Normal file
View File

@@ -0,0 +1,157 @@
// Launcher Update Manager UI
let updateModal = null;
let downloadProgressBar = null;
function initUpdater() {
// Listen for update events from main process
if (window.electronAPI && window.electronAPI.onUpdateAvailable) {
window.electronAPI.onUpdateAvailable((updateInfo) => {
showUpdateModal(updateInfo);
});
}
if (window.electronAPI && window.electronAPI.onUpdateDownloadProgress) {
window.electronAPI.onUpdateDownloadProgress((progress) => {
updateDownloadProgress(progress);
});
}
if (window.electronAPI && window.electronAPI.onUpdateDownloaded) {
window.electronAPI.onUpdateDownloaded((info) => {
showInstallUpdatePrompt(info);
});
}
}
function showUpdateModal(updateInfo) {
if (updateModal) {
updateModal.remove();
}
updateModal = document.createElement('div');
updateModal.className = 'update-modal-overlay';
updateModal.innerHTML = `
<div class="update-modal">
<div class="update-header">
<i class="fas fa-download"></i>
<h2>Launcher Update Available</h2>
</div>
<div class="update-content">
<p class="update-version">Version ${updateInfo.newVersion} is available!</p>
<p class="current-version">Current version: ${updateInfo.currentVersion}</p>
${updateInfo.releaseNotes ? `<div class="release-notes">${updateInfo.releaseNotes}</div>` : ''}
</div>
<div class="update-progress" style="display: none;">
<div class="progress-bar-container">
<div class="progress-bar" id="updateProgressBar"></div>
</div>
<p class="progress-text" id="updateProgressText">Downloading...</p>
</div>
<div class="update-actions">
<button class="btn-secondary" onclick="dismissUpdateModal()">
<i class="fas fa-times"></i> Later
</button>
<button class="btn-primary" onclick="downloadUpdate()">
<i class="fas fa-download"></i> Download Update
</button>
</div>
</div>
`;
document.body.appendChild(updateModal);
}
async function downloadUpdate() {
const downloadBtn = updateModal.querySelector('.btn-primary');
const laterBtn = updateModal.querySelector('.btn-secondary');
const progressDiv = updateModal.querySelector('.update-progress');
// Disable buttons and show progress
downloadBtn.disabled = true;
laterBtn.disabled = true;
progressDiv.style.display = 'block';
try {
await window.electronAPI.downloadUpdate();
} catch (error) {
console.error('Failed to download update:', error);
alert('Failed to download update. Please try again later.');
dismissUpdateModal();
}
}
function updateDownloadProgress(progress) {
if (!updateModal) return;
const progressBar = document.getElementById('updateProgressBar');
const progressText = document.getElementById('updateProgressText');
if (progressBar) {
progressBar.style.width = `${progress.percent}%`;
}
if (progressText) {
const mbTransferred = (progress.transferred / 1024 / 1024).toFixed(2);
const mbTotal = (progress.total / 1024 / 1024).toFixed(2);
const speed = (progress.bytesPerSecond / 1024 / 1024).toFixed(2);
progressText.textContent = `Downloading... ${mbTransferred}MB / ${mbTotal}MB (${speed} MB/s)`;
}
}
function showInstallUpdatePrompt(info) {
if (updateModal) {
updateModal.remove();
}
updateModal = document.createElement('div');
updateModal.className = 'update-modal-overlay';
updateModal.innerHTML = `
<div class="update-modal">
<div class="update-header">
<i class="fas fa-check-circle"></i>
<h2>Update Downloaded</h2>
</div>
<div class="update-content">
<p>Version ${info.version} has been downloaded and is ready to install.</p>
<p class="update-note">The launcher will restart to complete the installation.</p>
</div>
<div class="update-actions">
<button class="btn-secondary" onclick="dismissUpdateModal()">
<i class="fas fa-times"></i> Install Later
</button>
<button class="btn-primary" onclick="installUpdate()">
<i class="fas fa-sync-alt"></i> Restart & Install
</button>
</div>
</div>
`;
document.body.appendChild(updateModal);
}
async function installUpdate() {
try {
await window.electronAPI.installUpdate();
} catch (error) {
console.error('Failed to install update:', error);
}
}
function dismissUpdateModal() {
if (updateModal) {
updateModal.remove();
updateModal = null;
}
}
// Initialize when DOM is ready
document.addEventListener('DOMContentLoaded', initUpdater);
// Export functions
window.UpdaterUI = {
showUpdateModal,
dismissUpdateModal,
downloadUpdate,
installUpdate
};

View File

@@ -5990,4 +5990,167 @@ select.settings-input option {
to {
opacity: 1;
}
}
}
/* Launcher Update Modal Styles */
.update-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.85);
backdrop-filter: blur(10px);
display: flex;
align-items: center;
justify-content: center;
z-index: 100000;
animation: fadeIn 0.3s ease;
}
.update-modal {
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
border: 2px solid rgba(147, 51, 234, 0.3);
border-radius: 16px;
padding: 2rem;
max-width: 500px;
width: 90%;
box-shadow: 0 20px 60px rgba(147, 51, 234, 0.3);
animation: slideUp 0.3s ease;
}
@keyframes slideUp {
from {
transform: translateY(30px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.update-header {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 1.5rem;
color: #9333ea;
}
.update-header i {
font-size: 2rem;
}
.update-header h2 {
margin: 0;
font-size: 1.5rem;
color: #fff;
}
.update-content {
color: #e0e0e0;
margin-bottom: 1.5rem;
}
.update-version {
font-size: 1.2rem;
font-weight: 600;
color: #9333ea;
margin-bottom: 0.5rem;
}
.current-version {
color: #888;
font-size: 0.9rem;
margin-bottom: 1rem;
}
.release-notes {
background: rgba(0, 0, 0, 0.3);
border-left: 3px solid #9333ea;
padding: 1rem;
border-radius: 8px;
max-height: 200px;
overflow-y: auto;
font-size: 0.9rem;
line-height: 1.6;
}
.update-progress {
margin-bottom: 1.5rem;
}
.progress-bar-container {
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
height: 20px;
overflow: hidden;
margin-bottom: 0.5rem;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, #9333ea 0%, #7c3aed 100%);
width: 0%;
transition: width 0.3s ease;
border-radius: 10px;
}
.progress-text {
color: #aaa;
font-size: 0.9rem;
text-align: center;
margin: 0;
}
.update-note {
background: rgba(147, 51, 234, 0.1);
border: 1px solid rgba(147, 51, 234, 0.3);
padding: 0.75rem;
border-radius: 8px;
font-size: 0.9rem;
margin-top: 1rem;
}
.update-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
}
.update-actions button {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 0.5rem;
}
.update-actions .btn-primary {
background: linear-gradient(135deg, #9333ea 0%, #7c3aed 100%);
color: white;
}
.update-actions .btn-primary:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(147, 51, 234, 0.4);
}
.update-actions .btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: #e0e0e0;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.update-actions .btn-secondary:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.15);
}
.update-actions button:disabled {
opacity: 0.5;
cursor: not-allowed;
}