DEV Community

TaqsBlaze
TaqsBlaze

Posted on

Help with Electron ICP and Vue3

Hi everyone
I'm working on a electron application and I'm implementing software update check which is making use of ICP now this worked perfect before and all of a sudden stopped working, no error, no exception no thing just silently failing

here are snippets of the code

preload.js:

checkForUpdates: () => ipcRenderer.invoke('check-for-updates'), onUpdateStatus: (callback) => ipcRenderer.on('update-status:available', callback), onNoUpdate: (callback) => ipcRenderer.on('update-status:no-update', callback), onUpdateError: (callback) => ipcRenderer.on('update-status:error', callback), 
Enter fullscreen mode Exit fullscreen mode

main.js

ipcMain.handle('check-for-updates', async (event) => { try { const updateInfoUrl = 'url to update info'; const updateInfoResponse = await fetch(updateInfoUrl); if (!updateInfoResponse.ok) { throw new Error(`Failed to fetch update info: ${updateInfoResponse.statusText}`); } const updateInfo = await updateInfoResponse.json(); const currentAppVersion = app.getVersion(); const latestVersion = updateInfo.version; const appName = `AppName${latestVersion}.exe`; const downloadUrl = `${updateInfo.downloadUrl}${appName}`; if (latestVersion > currentAppVersion) { try { let data = { version: latestVersion, downloadUrl: downloadUrl }; console.log('Main Process: Sending update-status:available with data:', data); if (event.sender && !event.sender.isDestroyed()) { // Check if sender is still valid event.sender.send('update-status:available', data); console.log(`Main Process: Message 'update-status:available' sent successfully to sender ID ${event.sender.id}.`); } else { console.warn('Main Process: Could not send message. Renderer sender is destroyed or invalid.'); } console.log(`Update version ${latestVersion} available. User will be prompted for manual download.`); } catch (error) { console.log(`Error sending update-status:available:: ${error.message}`); } } else { event.sender.send('update-status:no-update'); console.log('No update available.'); } return { success: true }; } catch (error) { event.sender.send('update-status:error', error.message); return { success: false, error: error.message }; } }); 
Enter fullscreen mode Exit fullscreen mode

app.js: (in mountent)

window.electronAPI.onUpdateStatus((data) => { console.log('Update available:', data); this.updateAvailableVersion = data.version; this.updateDownloadLink = data.downloadUrl; this.showUpdateModal = true; // Show the new update notification modal this.updateStatusMessage = `New version ${data.version} is available!`; this.updateErrorMessage = ''; // Clear any previous error messages }); 
Enter fullscreen mode Exit fullscreen mode

(method triggering checking update)

async checkForSoftwareUpdates() { console.log('checking for updates....') this.updateStatusMessage = 'Checking for updates...'; this.updateErrorMessage = ''; this.showUpdateModal = false; this.updateAvailableVersion = null; this.updateDownloadLink = null; this.lastUpdateCheck = new Date().toLocaleString(); if (window.electronAPI && window.electronAPI.checkForUpdates) { console.log("Cheking now...") await window.electronAPI.checkForUpdates(); } else { console.warn('Electron API or checkForUpdates method not available. Cannot check for updates.'); this.updateErrorMessage = 'Update check not available in this environment.'; } }, 
Enter fullscreen mode Exit fullscreen mode

If anyone can assist/point out what I'm doing wrong please
if the listener in mounted is triggered I should see a modal with new software update details and a download button which I currently do get but this was working fine previously

Top comments (0)