diff --git a/src/composables/settingsSyncer.ts b/src/composables/settingsSyncer.ts index 7df072d14..477b60112 100644 --- a/src/composables/settingsSyncer.ts +++ b/src/composables/settingsSyncer.ts @@ -81,6 +81,11 @@ export function useBlueOsStorage(key: string, defaultValue: MaybeRef): Rem return vehicleStore.lastConnectedVehicleId } + const getLastConnectedUser = async (): Promise => { + const missoinStore = useMissionStore() + return missoinStore.lastConnectedUser + } + const askIfUserWantsToUseBlueOsValue = async (): Promise => { let useBlueOsValue = true @@ -146,6 +151,7 @@ export function useBlueOsStorage(key: string, defaultValue: MaybeRef): Rem const username = await getUsername() const currentVehicleId = await getCurrentVehicleId() const lastConnectedVehicleId = await getLastConnectedVehicleId() + const lastConnectedUser = await getLastConnectedUser() // Clear initial sync routine if there's one left, as we are going to start a new one clearTimeout(initialSyncTimeout) @@ -164,11 +170,12 @@ export function useBlueOsStorage(key: string, defaultValue: MaybeRef): Rem // By default, if there's a conflict, we use the value from BlueOS. let useBlueOsValue = true - // If the connected vehicle is the same as the last connected vehicle, and there are conflicts, it means the user - // has made changes while offline, so we ask the user if they want to keep the local value or the one from BlueOS. + // If the connected vehicle is the same as the last connected vehicle, and the user is also the same, and there + // are conflicts, it means the user has made changes while offline, so we ask the user if they want to keep the + // local value or the one from BlueOS. // If the connected vehicle is different from the last connected vehicle, we just use the value from BlueOS, as we // don't want to overwrite the value on the new vehicle with the one from the previous vehicle. - if (lastConnectedVehicleId === currentVehicleId) { + if (lastConnectedUser === username && lastConnectedVehicleId === currentVehicleId) { console.debug(`Conflict with BlueOS for key '${key}'. Asking user what to do.`) useBlueOsValue = await askIfUserWantsToUseBlueOsValue() } diff --git a/src/stores/mission.ts b/src/stores/mission.ts index 2eaeb5808..01512544f 100644 --- a/src/stores/mission.ts +++ b/src/stores/mission.ts @@ -11,6 +11,7 @@ import type { Waypoint, WaypointCoordinates } from '@/types/mission' export const useMissionStore = defineStore('mission', () => { const username = useStorage('cockpit-username', '') + const lastConnectedUser = localStorage.getItem('cockpit-last-connected-user') || undefined const missionName = ref('') const slideEventsEnabled = useBlueOsStorage('cockpit-slide-events-enabled', true) const slideEventsCategoriesRequired = useBlueOsStorage( @@ -62,6 +63,9 @@ export const useMissionStore = defineStore('mission', () => { } onMounted(async () => { + // If theres a username saved, assign it as the last connected user + localStorage.setItem('cockpit-last-connected-user', username.value) + console.log(`Last connected user set to ${username.value}.`) if (username.value) return // If no username is set, ask the user to enter one @@ -70,6 +74,7 @@ export const useMissionStore = defineStore('mission', () => { return { username, + lastConnectedUser, changeUsername, missionName, lastMissionName,