Web: log SocketIO connection status in notifications history

This commit is contained in:
Sybren A. Stüvel 2022-05-20 11:22:59 +02:00
parent 79c632bc9f
commit adc8738e5b

View File

@ -1,5 +1,12 @@
import { stringifyStyle } from '@vue/shared'
import { defineStore } from 'pinia' 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. * Status of the SocketIO/Websocket connection to Flamenco Manager.
@ -9,6 +16,8 @@ export const useSocketStatus = defineStore('socket-status', {
/** @type { bool } */ /** @type { bool } */
isConnected: false, isConnected: false,
wasEverDisconnected: false,
/** @type {string} */ /** @type {string} */
message: "", message: "",
}), }),
@ -18,8 +27,13 @@ export const useSocketStatus = defineStore('socket-status', {
* @param {string} reason * @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({ this.$patch({
isConnected: false, isConnected: false,
wasEverDisconnected: true,
message: `${reason}`, message: `${reason}`,
}); });
}, },
@ -27,6 +41,12 @@ export const useSocketStatus = defineStore('socket-status', {
* Indicate the connection is good. * 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({ this.$patch({
isConnected: true, isConnected: true,
message: "", message: "",