From adc8738e5b0319c8478006f0b3f36871c0affa29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 20 May 2022 11:22:59 +0200 Subject: [PATCH] Web: log SocketIO connection status in notifications history --- web/app/src/stores/socket-status.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/web/app/src/stores/socket-status.js b/web/app/src/stores/socket-status.js index 2672468b..fdc6fbf2 100644 --- a/web/app/src/stores/socket-status.js +++ b/web/app/src/stores/socket-status.js @@ -1,5 +1,12 @@ -import { stringifyStyle } from '@vue/shared' import { defineStore } from 'pinia' +import { useNotifs } from '@/stores/notifications' + +// Not sure if this is the best way to deal with those notifications. It feels a +// bit spaghetto to have one Pinia store influence another. Maybe move this to +// the app level once the Workers and Settings views are fleshed out. Maybe +// that'll cause the Notifications popover to be handled at the app-global +// level, instead of per view, creating a better place to put this logic. +const notifs = useNotifs(); /** * Status of the SocketIO/Websocket connection to Flamenco Manager. @@ -9,6 +16,8 @@ export const useSocketStatus = defineStore('socket-status', { /** @type { bool } */ isConnected: false, + wasEverDisconnected: false, + /** @type {string} */ message: "", }), @@ -17,16 +26,27 @@ export const useSocketStatus = defineStore('socket-status', { * Indicate the connection was lost. * @param {string} reason */ - disconnected(reason) { + disconnected(reason) { + // Only patch the state if it actually will change. + if (!this.isConnected) + return; + notifs.add(`Connection to Flamenco Manager lost`); this.$patch({ isConnected: false, + wasEverDisconnected: true, message: `${reason}`, }); }, /** * Indicate the connection is good. */ - connected() { + connected() { + // Only patch the state if it actually will change. + if (this.isConnected) + return; + + if (this.wasEverDisconnected) + notifs.add("Connection to Flamenco Manager established"); this.$patch({ isConnected: true, message: "",