mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 14:01:48 -03:00
Add cache clearing documentation for electron-updater
- Introduced CLEAR-UPDATE-CACHE.md to guide users on clearing the electron-updater cache across macOS, Windows, and Linux. - Added programmatic method for cache clearing in JavaScript. - Enhanced update handling in main.js and preload.js to support new update events. - Updated GUI styles for download buttons and progress indicators in update.js and style.css.
This commit is contained in:
78
CLEAR-UPDATE-CACHE.md
Normal file
78
CLEAR-UPDATE-CACHE.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# Clearing Electron-Updater Cache
|
||||||
|
|
||||||
|
To force electron-updater to re-download an update file, you need to clear the cached download.
|
||||||
|
|
||||||
|
## Quick Method (Terminal)
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
# Remove the entire cache directory
|
||||||
|
rm -rf ~/Library/Caches/hytale-f2p-launcher
|
||||||
|
|
||||||
|
# Or just remove pending downloads
|
||||||
|
rm -rf ~/Library/Caches/hytale-f2p-launcher/pending
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
```bash
|
||||||
|
# Remove the entire cache directory
|
||||||
|
rmdir /s "%LOCALAPPDATA%\hytale-f2p-launcher-updater"
|
||||||
|
|
||||||
|
# Or just remove pending downloads
|
||||||
|
rmdir /s "%LOCALAPPDATA%\hytale-f2p-launcher-updater\pending"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
```bash
|
||||||
|
# Remove the entire cache directory
|
||||||
|
rm -rf ~/.cache/hytale-f2p-launcher-updater
|
||||||
|
|
||||||
|
# Or just remove pending downloads
|
||||||
|
rm -rf ~/.cache/hytale-f2p-launcher-updater/pending
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cache Locations
|
||||||
|
|
||||||
|
electron-updater stores downloaded updates in:
|
||||||
|
|
||||||
|
- **macOS**: `~/Library/Caches/hytale-f2p-launcher/`
|
||||||
|
- **Windows**: `%LOCALAPPDATA%\hytale-f2p-launcher-updater\`
|
||||||
|
- **Linux**: `~/.cache/hytale-f2p-launcher-updater/`
|
||||||
|
|
||||||
|
The cache typically contains:
|
||||||
|
- `pending/` - Downloaded update files waiting to be installed
|
||||||
|
- Metadata files about available updates
|
||||||
|
|
||||||
|
## After Clearing
|
||||||
|
|
||||||
|
After clearing the cache:
|
||||||
|
1. Restart the launcher
|
||||||
|
2. It will check for updates again
|
||||||
|
3. The update will be re-downloaded from scratch
|
||||||
|
|
||||||
|
## Programmatic Method
|
||||||
|
|
||||||
|
You can also clear the cache programmatically by adding this to your code:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { autoUpdater } = require('electron-updater');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
|
function clearUpdateCache() {
|
||||||
|
const cacheDir = path.join(
|
||||||
|
os.homedir(),
|
||||||
|
process.platform === 'win32'
|
||||||
|
? 'AppData/Local/hytale-f2p-launcher-updater'
|
||||||
|
: process.platform === 'darwin'
|
||||||
|
? 'Library/Caches/hytale-f2p-launcher'
|
||||||
|
: '.cache/hytale-f2p-launcher-updater'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (fs.existsSync(cacheDir)) {
|
||||||
|
fs.rmSync(cacheDir, { recursive: true, force: true });
|
||||||
|
console.log('Update cache cleared');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
125
GUI/js/update.js
125
GUI/js/update.js
@@ -10,6 +10,19 @@ class ClientUpdateManager {
|
|||||||
this.showUpdatePopup(updateInfo);
|
this.showUpdatePopup(updateInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen for electron-updater events
|
||||||
|
window.electronAPI.onUpdateAvailable((updateInfo) => {
|
||||||
|
this.showUpdatePopup(updateInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.electronAPI.onUpdateDownloadProgress((progress) => {
|
||||||
|
this.updateDownloadProgress(progress);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.electronAPI.onUpdateDownloaded((updateInfo) => {
|
||||||
|
this.showUpdateDownloaded(updateInfo);
|
||||||
|
});
|
||||||
|
|
||||||
this.checkForUpdatesOnDemand();
|
this.checkForUpdatesOnDemand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,23 +46,42 @@ class ClientUpdateManager {
|
|||||||
<div class="update-popup-versions">
|
<div class="update-popup-versions">
|
||||||
<div class="version-row">
|
<div class="version-row">
|
||||||
<span class="version-label">Current Version:</span>
|
<span class="version-label">Current Version:</span>
|
||||||
<span class="version-current">${updateInfo.currentVersion}</span>
|
<span class="version-current">${updateInfo.currentVersion || updateInfo.version || 'Unknown'}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="version-row">
|
<div class="version-row">
|
||||||
<span class="version-label">New Version:</span>
|
<span class="version-label">New Version:</span>
|
||||||
<span class="version-new">${updateInfo.newVersion}</span>
|
<span class="version-new">${updateInfo.newVersion || updateInfo.version || 'Unknown'}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="update-popup-message">
|
<div class="update-popup-message">
|
||||||
A new version of Hytale F2P Launcher is available.<br>
|
A new version of Hytale F2P Launcher is available.<br>
|
||||||
Please download the latest version to continue using the launcher.
|
<span id="update-status-text">Downloading update automatically...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="update-download-btn" class="update-download-btn">
|
<div id="update-progress-container" style="display: none; margin-bottom: 1rem;">
|
||||||
<i class="fas fa-external-link-alt" style="margin-right: 0.5rem;"></i>
|
<div style="display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 0.75rem; color: #9ca3af;">
|
||||||
Download Update
|
<span id="update-progress-percent">0%</span>
|
||||||
</button>
|
<span id="update-progress-speed">0 KB/s</span>
|
||||||
|
</div>
|
||||||
|
<div style="width: 100%; height: 8px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; overflow: hidden;">
|
||||||
|
<div id="update-progress-bar" style="width: 0%; height: 100%; background: linear-gradient(90deg, #3b82f6, #9333ea); transition: width 0.3s ease;"></div>
|
||||||
|
</div>
|
||||||
|
<div style="margin-top: 0.5rem; font-size: 0.75rem; color: #9ca3af; text-align: center;">
|
||||||
|
<span id="update-progress-size">0 MB / 0 MB</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="update-buttons-container" style="display: none;">
|
||||||
|
<button id="update-install-btn" class="update-download-btn">
|
||||||
|
<i class="fas fa-check" style="margin-right: 0.5rem;"></i>
|
||||||
|
Install & Restart
|
||||||
|
</button>
|
||||||
|
<button id="update-download-btn" class="update-download-btn update-download-btn-secondary" style="margin-top: 0.75rem;">
|
||||||
|
<i class="fas fa-external-link-alt" style="margin-right: 0.5rem;"></i>
|
||||||
|
Manually Download
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="update-popup-footer">
|
<div class="update-popup-footer">
|
||||||
This popup cannot be closed until you update the launcher
|
This popup cannot be closed until you update the launcher
|
||||||
@@ -62,6 +94,31 @@ class ClientUpdateManager {
|
|||||||
|
|
||||||
this.blockInterface();
|
this.blockInterface();
|
||||||
|
|
||||||
|
// Show progress container immediately (auto-download is enabled)
|
||||||
|
const progressContainer = document.getElementById('update-progress-container');
|
||||||
|
if (progressContainer) {
|
||||||
|
progressContainer.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
const installBtn = document.getElementById('update-install-btn');
|
||||||
|
if (installBtn) {
|
||||||
|
installBtn.addEventListener('click', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
installBtn.disabled = true;
|
||||||
|
installBtn.innerHTML = '<i class="fas fa-spinner fa-spin" style="margin-right: 0.5rem;"></i>Installing...';
|
||||||
|
|
||||||
|
try {
|
||||||
|
await window.electronAPI.quitAndInstallUpdate();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error installing update:', error);
|
||||||
|
installBtn.disabled = false;
|
||||||
|
installBtn.innerHTML = '<i class="fas fa-check" style="margin-right: 0.5rem;"></i>Install & Restart';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const downloadBtn = document.getElementById('update-download-btn');
|
const downloadBtn = document.getElementById('update-download-btn');
|
||||||
if (downloadBtn) {
|
if (downloadBtn) {
|
||||||
downloadBtn.addEventListener('click', async (e) => {
|
downloadBtn.addEventListener('click', async (e) => {
|
||||||
@@ -80,7 +137,7 @@ class ClientUpdateManager {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Error opening download page:', error);
|
console.error('❌ Error opening download page:', error);
|
||||||
downloadBtn.disabled = false;
|
downloadBtn.disabled = false;
|
||||||
downloadBtn.innerHTML = '<i class="fas fa-external-link-alt" style="margin-right: 0.5rem;"></i>Download Update';
|
downloadBtn.innerHTML = '<i class="fas fa-external-link-alt" style="margin-right: 0.5rem;"></i>Manually Download';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -99,6 +156,58 @@ class ClientUpdateManager {
|
|||||||
console.log('🔔 Update popup displayed with new style');
|
console.log('🔔 Update popup displayed with new style');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDownloadProgress(progress) {
|
||||||
|
const progressBar = document.getElementById('update-progress-bar');
|
||||||
|
const progressPercent = document.getElementById('update-progress-percent');
|
||||||
|
const progressSpeed = document.getElementById('update-progress-speed');
|
||||||
|
const progressSize = document.getElementById('update-progress-size');
|
||||||
|
const statusText = document.getElementById('update-status-text');
|
||||||
|
|
||||||
|
if (progressBar && progress) {
|
||||||
|
const percent = Math.round(progress.percent || 0);
|
||||||
|
progressBar.style.width = `${percent}%`;
|
||||||
|
|
||||||
|
if (progressPercent) {
|
||||||
|
progressPercent.textContent = `${percent}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progressSpeed && progress.bytesPerSecond) {
|
||||||
|
const speedMBps = (progress.bytesPerSecond / 1024 / 1024).toFixed(2);
|
||||||
|
progressSpeed.textContent = `${speedMBps} MB/s`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progressSize && progress.transferred && progress.total) {
|
||||||
|
const transferredMB = (progress.transferred / 1024 / 1024).toFixed(2);
|
||||||
|
const totalMB = (progress.total / 1024 / 1024).toFixed(2);
|
||||||
|
progressSize.textContent = `${transferredMB} MB / ${totalMB} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusText) {
|
||||||
|
statusText.textContent = `Downloading update... ${percent}%`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showUpdateDownloaded(updateInfo) {
|
||||||
|
const statusText = document.getElementById('update-status-text');
|
||||||
|
const progressContainer = document.getElementById('update-progress-container');
|
||||||
|
const buttonsContainer = document.getElementById('update-buttons-container');
|
||||||
|
|
||||||
|
if (statusText) {
|
||||||
|
statusText.textContent = 'Update downloaded! Ready to install.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progressContainer) {
|
||||||
|
progressContainer.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttonsContainer) {
|
||||||
|
buttonsContainer.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Update downloaded, ready to install');
|
||||||
|
}
|
||||||
|
|
||||||
blockInterface() {
|
blockInterface() {
|
||||||
const mainContent = document.querySelector('.flex.w-full.h-screen');
|
const mainContent = document.querySelector('.flex.w-full.h-screen');
|
||||||
if (mainContent) {
|
if (mainContent) {
|
||||||
|
|||||||
@@ -4404,6 +4404,27 @@ select.settings-input option {
|
|||||||
0 0 0 1px rgba(255, 255, 255, 0.05) !important;
|
0 0 0 1px rgba(255, 255, 255, 0.05) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.update-download-btn-secondary {
|
||||||
|
background: rgba(255, 255, 255, 0.1) !important;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2) !important;
|
||||||
|
box-shadow:
|
||||||
|
0 2px 8px rgba(0, 0, 0, 0.2),
|
||||||
|
0 0 0 1px rgba(255, 255, 255, 0.05) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-download-btn-secondary:hover:not(:disabled) {
|
||||||
|
background: rgba(255, 255, 255, 0.15) !important;
|
||||||
|
border-color: rgba(255, 255, 255, 0.3) !important;
|
||||||
|
transform: translateY(-1px) !important;
|
||||||
|
box-shadow:
|
||||||
|
0 4px 12px rgba(0, 0, 0, 0.3),
|
||||||
|
0 0 0 1px rgba(255, 255, 255, 0.1) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-download-btn-secondary:active:not(:disabled) {
|
||||||
|
transform: translateY(0) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.update-popup-footer {
|
.update-popup-footer {
|
||||||
text-align: center !important;
|
text-align: center !important;
|
||||||
|
|||||||
@@ -43,9 +43,17 @@ class AppUpdater {
|
|||||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||||
this.mainWindow.webContents.send('update-available', {
|
this.mainWindow.webContents.send('update-available', {
|
||||||
version: info.version,
|
version: info.version,
|
||||||
|
newVersion: info.version,
|
||||||
|
currentVersion: app.getVersion(),
|
||||||
releaseName: info.releaseName,
|
releaseName: info.releaseName,
|
||||||
releaseNotes: info.releaseNotes
|
releaseNotes: info.releaseNotes
|
||||||
});
|
});
|
||||||
|
// Also send to the old popup handler for compatibility
|
||||||
|
this.mainWindow.webContents.send('show-update-popup', {
|
||||||
|
currentVersion: app.getVersion(),
|
||||||
|
newVersion: info.version,
|
||||||
|
version: info.version
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
1
main.js
1
main.js
@@ -731,6 +731,7 @@ ipcMain.handle('check-for-updates', async () => {
|
|||||||
return {
|
return {
|
||||||
updateAvailable: result?.updateInfo ? true : false,
|
updateAvailable: result?.updateInfo ? true : false,
|
||||||
version: result?.updateInfo?.version,
|
version: result?.updateInfo?.version,
|
||||||
|
newVersion: result?.updateInfo?.version,
|
||||||
currentVersion: app.getVersion()
|
currentVersion: app.getVersion()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
10
preload.js
10
preload.js
@@ -51,6 +51,16 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||||||
onUpdatePopup: (callback) => {
|
onUpdatePopup: (callback) => {
|
||||||
ipcRenderer.on('show-update-popup', (event, data) => callback(data));
|
ipcRenderer.on('show-update-popup', (event, data) => callback(data));
|
||||||
},
|
},
|
||||||
|
onUpdateAvailable: (callback) => {
|
||||||
|
ipcRenderer.on('update-available', (event, data) => callback(data));
|
||||||
|
},
|
||||||
|
onUpdateDownloadProgress: (callback) => {
|
||||||
|
ipcRenderer.on('update-download-progress', (event, data) => callback(data));
|
||||||
|
},
|
||||||
|
onUpdateDownloaded: (callback) => {
|
||||||
|
ipcRenderer.on('update-downloaded', (event, data) => callback(data));
|
||||||
|
},
|
||||||
|
quitAndInstallUpdate: () => ipcRenderer.invoke('quit-and-install-update'),
|
||||||
|
|
||||||
getGpuInfo: () => ipcRenderer.invoke('get-gpu-info'),
|
getGpuInfo: () => ipcRenderer.invoke('get-gpu-info'),
|
||||||
saveGpuPreference: (gpuPreference) => ipcRenderer.invoke('save-gpu-preference', gpuPreference),
|
saveGpuPreference: (gpuPreference) => ipcRenderer.invoke('save-gpu-preference', gpuPreference),
|
||||||
|
|||||||
Reference in New Issue
Block a user