Skip to content

Commit

Permalink
fix: uuid missing on launch page, added logging to auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Mar 21, 2024
1 parent a553595 commit 0d2d90b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
Expand Down
23 changes: 16 additions & 7 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/prelaunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 23 additions & 0 deletions src/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MCProtocol | undefined> {
// return new Promise((resolve, reject) => {
// if (serverInfo.includes(':')) {
Expand Down
7 changes: 5 additions & 2 deletions src/views/LaunchingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 0d2d90b

Please sign in to comment.