Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Feb 13, 2025
1 parent 43f0af4 commit 7999c6f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/composables/settingsSyncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function useBlueOsStorage<T>(key: string, defaultValue: MaybeRef<T>): Rem
const vehicleAddress = await getVehicleAddress()
const username = await getUsername()

logger.debug(`Updating '${key}' on BlueOS.`)
logger.debug(`Updating '${key}' on BlueOS. New value:`, newValue, 'New epoch:', updateEpoch)

const tryToUpdateBlueOsValue = async (): Promise<void> => {
// Clear update routine if there's one left, as we are going to start a new one
Expand Down Expand Up @@ -222,6 +222,21 @@ export function useBlueOsStorage<T>(key: string, defaultValue: MaybeRef<T>): Rem
// By default, if there's a conflict, we use the value with the newest epoch
let useBlueOsValue = (remoteEpoch ?? 0) > (localEpoch ?? 0)

// Do nothing if both values are undefined
if (currentValue.value === undefined && valueOnBlueOS === undefined) {
logger.debug(`Both local and remote values for '${key}' are undefined. No need to update.`)
finishedInitialFetch.value = true
return
} else if (currentValue.value === undefined) {
// If only the local value is undefined, use the value from BlueOS
logger.debug(`Local value for '${key}' is undefined. Using value from BlueOS.`)
useBlueOsValue = true
} else if (valueOnBlueOS === undefined) {
// If only the remote value is undefined, use the value from local storage
logger.debug(`Remote value for '${key}' is undefined. Using value from local storage.`)
useBlueOsValue = false
}

const msg = `Key: ${key} // Epochs: Remote: ${remoteEpoch}, Local: ${localEpoch} // Use BlueOS value: ${useBlueOsValue}`
logger.debug(msg)

Expand All @@ -245,6 +260,8 @@ export function useBlueOsStorage<T>(key: string, defaultValue: MaybeRef<T>): Rem
const message = `Fetched remote value of key ${key} from the vehicle.`
openSnackbar({ message, duration: 3000, variant: 'success' })

finishedInitialFetch.value = true

if (key === savedProfilesKey) {
await showDialog({
title: 'Widget profiles imported',
Expand Down

0 comments on commit 7999c6f

Please sign in to comment.