()
| 158 | } |
| 159 | |
| 160 | export function migrateFromLegacyStore(): boolean { |
| 161 | if (migrationAttempted) return false; |
| 162 | migrationAttempted = true; |
| 163 | |
| 164 | if (!needsMigration()) return false; |
| 165 | |
| 166 | try { |
| 167 | const legacyData = localStorage.getItem(STORAGE_KEYS.legacy); |
| 168 | if (!legacyData) return false; |
| 169 | |
| 170 | const legacyState = parseLegacyPersistedState(legacyData); |
| 171 | if (!legacyState) return false; |
| 172 | |
| 173 | // Apply legacy boolean migrations first |
| 174 | const migratedState = applyLegacyMigrations(legacyState); |
| 175 | |
| 176 | // Extract and save each domain |
| 177 | saveDomainStore( |
| 178 | STORAGE_KEYS.pointCloud, |
| 179 | extractDomainState(migratedState, POINT_CLOUD_PROPERTIES) |
| 180 | ); |
| 181 | saveDomainStore( |
| 182 | STORAGE_KEYS.camera, |
| 183 | extractDomainState(migratedState, CAMERA_PROPERTIES) |
| 184 | ); |
| 185 | saveDomainStore( |
| 186 | STORAGE_KEYS.ui, |
| 187 | extractDomainState(migratedState, UI_PROPERTIES) |
| 188 | ); |
| 189 | saveDomainStore( |
| 190 | STORAGE_KEYS.export, |
| 191 | extractDomainState(migratedState, EXPORT_PROPERTIES) |
| 192 | ); |
| 193 | |
| 194 | // Remove legacy store after successful migration |
| 195 | localStorage.removeItem(STORAGE_KEYS.legacy); |
| 196 | |
| 197 | appLogger.info('[Store Migration] Successfully migrated from legacy store to domain stores'); |
| 198 | return true; |
| 199 | } catch (error) { |
| 200 | appLogger.error('[Store Migration] Failed to migrate legacy store:', error); |
| 201 | return false; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Check if the app version changed since last visit and show a notification if so. |
no test coverage detected