From 7c613daad1ac89fe33869c4ea2b6dd5c84173892 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 26 Jun 2024 15:40:25 -0300 Subject: [PATCH] widgets: Replace `timesMounted` with `everMounted` on the manager vars We were using it to check if the widget was ever mounted, so it already satisfies the requirements. Updating it on every mount was causing the profile to change all the time, which makes syncing dificult. --- src/assets/defaults.ts | 4 ++-- src/components/WidgetHugger.vue | 4 ++-- src/stores/widgetManager.ts | 24 ++++++++++++++++++++++-- src/types/miniWidgets.ts | 2 +- src/types/widgets.ts | 4 ++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/assets/defaults.ts b/src/assets/defaults.ts index aa2f8bff8..54583aa29 100644 --- a/src/assets/defaults.ts +++ b/src/assets/defaults.ts @@ -13,7 +13,7 @@ export const defaultProfileVehicleCorrespondency = { } export const defaultWidgetManagerVars = { - timesMounted: 0, + everMounted: false, configMenuOpen: false, allowMoving: false, lastNonMaximizedX: 0.4, @@ -24,7 +24,7 @@ export const defaultWidgetManagerVars = { } export const defaultMiniWidgetManagerVars = { - timesMounted: 0, + everMounted: false, configMenuOpen: false, highlighted: false, } diff --git a/src/components/WidgetHugger.vue b/src/components/WidgetHugger.vue index b75c1ae00..4ed4f7cff 100644 --- a/src/components/WidgetHugger.vue +++ b/src/components/WidgetHugger.vue @@ -211,10 +211,10 @@ const resizeWidgetToMinimalSize = (): void => { } onMounted(async () => { - if (managerVars.value.timesMounted === 0) { + if (managerVars.value.everMounted === false) { resizeWidgetToMinimalSize() } - managerVars.value.timesMounted += 1 + managerVars.value.everMounted = true if (widgetResizeHandles.value) { for (let i = 0; i < widgetResizeHandles.value.length; i++) { diff --git a/src/stores/widgetManager.ts b/src/stores/widgetManager.ts index e7f2d5691..0acafea53 100644 --- a/src/stores/widgetManager.ts +++ b/src/stores/widgetManager.ts @@ -593,9 +593,29 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => { v.visible = v.visible ?? true // If there's any configuration menu open, close it - v.widgets.forEach((w) => (w.managerVars.configMenuOpen = false)) - v.miniWidgetContainers.forEach((c) => c.widgets.forEach((w) => (w.managerVars.configMenuOpen = false))) + v.widgets.forEach((w) => { + w.managerVars.configMenuOpen = false + w.managerVars.everMounted = true + // @ts-ignore: This is an old value that we are removing on those that still hold it + w.managerVars.timesMounted = undefined + }) + v.miniWidgetContainers.forEach((c) => + c.widgets.forEach((w) => { + w.managerVars.configMenuOpen = false + w.managerVars.everMounted = true + // @ts-ignore: This is an old value that we are removing on those that still hold it + w.managerVars.timesMounted = undefined + }) + ) }) + + currentMiniWidgetsProfile.value.containers.forEach((c) => + c.widgets.forEach((w) => { + w.managerVars.everMounted = true + // @ts-ignore: This is an old value that we are removing on those that still hold it + w.managerVars.timesMounted = undefined + }) + ) }) }) diff --git a/src/types/miniWidgets.ts b/src/types/miniWidgets.ts index cad5039c7..3f7ac8a84 100644 --- a/src/types/miniWidgets.ts +++ b/src/types/miniWidgets.ts @@ -42,7 +42,7 @@ export type MiniWidget = { /** * Number of times the mini-widget was mounted */ - timesMounted: number + everMounted: boolean /** * If the configuration menu is open or not */ diff --git a/src/types/widgets.ts b/src/types/widgets.ts index 3331b8b7e..372e3986d 100644 --- a/src/types/widgets.ts +++ b/src/types/widgets.ts @@ -51,7 +51,7 @@ export type Widget = { /** * Number of times the widget was mounted */ - timesMounted: number + everMounted: boolean /** * If the configuration menu is open or not */ @@ -128,7 +128,7 @@ export type Profile = { export const isWidget = (maybeWidget: Widget): maybeWidget is Widget => { const widgetProps = ['hash', 'component', 'position', 'size', 'name', 'options', 'managerVars'] - const managetVarsProps = ['timesMounted'] + const managetVarsProps = ['everMounted'] let realWidget = true widgetProps.forEach((p) => { // @ts-ignore