From 0d2d90bdec245ca5a9ada63f1128e9fb5b5636fa Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Thu, 21 Mar 2024 14:32:44 +0000 Subject: [PATCH] fix: uuid missing on launch page, added logging to auto updater --- package.json | 2 +- src/background.ts | 23 ++++++++++++++++------- src/prelaunch.ts | 3 ++- src/utils/utilities.ts | 23 +++++++++++++++++++++++ src/views/LaunchingPage.vue | 7 +++++-- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 7023f81e..d7bfe8c2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "productName": "FTB Electron App", "name": "ftb-app", - "version": "1.25.3", + "version": "1.25.4", "private": true, "main": "background.js", "email": "admin@feed-the-beast.com", diff --git a/src/background.ts b/src/background.ts index 27cc9c7b..ea680273 100644 --- a/src/background.ts +++ b/src/background.ts @@ -17,12 +17,17 @@ const logger = createLogger('background.ts'); autoUpdater.logger = electronLogger; -autoUpdater.on('checking-for-update', () => ipcMain.emit('updater:checking-for-update')); -autoUpdater.on('update-available', () => ipcMain.emit('updater:update-available')); -autoUpdater.on('update-not-available', () => ipcMain.emit('updater:update-not-available')); -autoUpdater.on('error', (error) => ipcMain.emit('updater:error', JSON.stringify(error))); -autoUpdater.on('download-progress', (progress) => ipcMain.emit('updater:download-progress')); -autoUpdater.on('update-downloaded', (info) => ipcMain.emit('updater:update-downloaded')); +const logAndEmit = (event: string, ...args: any[]) => { + logger.debug("Emitting downloader event", event, args) + ipcMain.emit(event, ...args); +} + +autoUpdater.on('checking-for-update', () => logAndEmit('updater:checking-for-update')); +autoUpdater.on('update-available', () => logAndEmit('updater:update-available')); +autoUpdater.on('update-not-available', () => logAndEmit('updater:update-not-available')); +autoUpdater.on('error', (error) => logAndEmit('updater:error', JSON.stringify(error))); +autoUpdater.on('download-progress', (progress) => logAndEmit('updater:download-progress', progress)); +autoUpdater.on('update-downloaded', (info) => logAndEmit('updater:update-downloaded', info)); function getAppHome() { if (os.platform() === "darwin") { @@ -629,9 +634,11 @@ ipcMain.handle('updater:check-for-update', async () => { if (result?.downloadPromise) { logger.debug("Waiting for download promise") - await result.downloadPromise; + const version = await result.downloadPromise; + logger.debug("Download promise resolved", version) // Quit the app and install the update + logger.debug("Requesting app quit and install") autoUpdater.quitAndInstall() return true; } @@ -655,8 +662,10 @@ ipcMain.handle('app:launch', async () => { }) ipcMain.handle('app:quit-and-install', async () => { + logger.debug("Quitting and installing app") // Restart the entire app autoUpdater.quitAndInstall(); + }); async function createWindow(reset = false) { diff --git a/src/prelaunch.ts b/src/prelaunch.ts index a1704071..5801d7ef 100644 --- a/src/prelaunch.ts +++ b/src/prelaunch.ts @@ -27,7 +27,8 @@ ipcRenderer.invoke('updater:check-for-update') logger.info("Received updater", updater); if (updater) { logger.info("For some reason, we got the update here so let's also try and update", updater); - ipcRenderer.invoke('app:quit-and-install') + await ipcRenderer.invoke('app:quit-and-install') + logger.info("Update should have been installed") return; } diff --git a/src/utils/utilities.ts b/src/utils/utilities.ts index fb986629..0bab3d95 100644 --- a/src/utils/utilities.ts +++ b/src/utils/utilities.ts @@ -53,6 +53,29 @@ export async function waitForWebsockets(user: string, websockets: Socket) { } } +export async function waitForWebsocketsAndData(user: string, websockets: Socket, fieldDataPredicate: () => boolean) { + logger.debug("Waiting for websockets and data for user", user); + await waitForWebsockets(user, websockets); + + logger.debug("Websockets connected, waiting for data for user", user); + // Now wait for some data, let's give it 30 seconds to get the data before we give up + await new Promise((resolve, reject) => { + const timeoutRef = setTimeout(() => { + clearTimeout(timeoutRef); + reject("Timed out waiting for data"); + }, 30_000); + + const interval = setInterval(() => { + if (fieldDataPredicate()) { + logger.debug("Data found for user", user); + clearInterval(interval); + clearTimeout(timeoutRef); + resolve(null); + } + }, 100); + }); +} + // export function queryServer(serverInfo: string): Promise { // return new Promise((resolve, reject) => { // if (serverInfo.includes(':')) { diff --git a/src/views/LaunchingPage.vue b/src/views/LaunchingPage.vue index 745e8501..8f383fb4 100644 --- a/src/views/LaunchingPage.vue +++ b/src/views/LaunchingPage.vue @@ -204,7 +204,7 @@ import {alertController} from '@/core/controllers/alertController'; import {gobbleError} from '@/utils/helpers/asyncHelpers'; import {sendMessage} from '@/core/websockets/websocketsApi'; import {FixedSizeArray} from '@/utils/std/fixedSizeArray'; -import {safeNavigate, waitForWebsockets} from '@/utils'; +import {safeNavigate, waitForWebsocketsAndData} from '@/utils'; import {createLogger} from '@/core/logger'; import {SocketState} from '@/modules/websocket/types'; @@ -372,7 +372,10 @@ export default class LaunchingPage extends Vue { public async mounted() { this.logger.debug("Mounted Launch page, waiting for websockets..."); - await waitForWebsockets("Launch page", this.websockets.socket) + await waitForWebsocketsAndData("Launch page", this.websockets.socket, () => { + // This should get resolved quickly but it's possible it wont + return this.instance != null; + }) this.logger.debug("Websockets ready, loading instance")