Skip to content

Commit

Permalink
widgets: Replace timesMounted with everMounted on the manager vars
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rafaellehmkuhl authored and patrickelectric committed Jun 27, 2024
1 parent cff8900 commit 78365a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/assets/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const defaultProfileVehicleCorrespondency = {
}

export const defaultWidgetManagerVars = {
timesMounted: 0,
everMounted: false,
configMenuOpen: false,
allowMoving: false,
lastNonMaximizedX: 0.4,
Expand All @@ -24,7 +24,7 @@ export const defaultWidgetManagerVars = {
}

export const defaultMiniWidgetManagerVars = {
timesMounted: 0,
everMounted: false,
configMenuOpen: false,
highlighted: false,
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/WidgetHugger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
24 changes: 22 additions & 2 deletions src/stores/widgetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/types/miniWidgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/types/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 78365a5

Please sign in to comment.