@@ -109,7 +109,23 @@ class SceneManagerImpl extends ISceneManager {
109109 logger? .e ('Failed to find current scene!' );
110110 throw KeyNotFoundException (message: 'There was no current scene!' );
111111 }
112- return SceneEntity .fromMap (currentRecord.key, currentRecord.value);
112+ return _restoreSceneImagePath (tx, SceneEntity .fromMap (currentRecord.key, currentRecord.value));
113+ }
114+
115+ Future <SceneEntity > _restoreSceneImagePath (Transaction tx, SceneEntity scene) async {
116+ final imageID = scene.imageID? .trim ();
117+ if (imageID == null || imageID.isEmpty) {
118+ return scene;
119+ }
120+
121+ final resolvedImagePath = _blobManager.getPath (imageID);
122+ if (scene.imagePath == resolvedImagePath) {
123+ return scene;
124+ }
125+
126+ final store = stringMapStoreFactory.store (StoreNames .scenes);
127+ await store.record (scene.id).update (tx, {SceneEntity .kImagePathFieldName: resolvedImagePath});
128+ return scene.copyWith (imagePath: resolvedImagePath);
113129 }
114130
115131 Future <String > _createBlobFromFile (String imagePath) async {
@@ -161,7 +177,7 @@ class SceneManagerImpl extends ISceneManager {
161177 } else {
162178 final store = stringMapStoreFactory.store (StoreNames .scenes);
163179 final map = (await store.record (key).get (tx))! ;
164- return SceneEntity .fromMap (key, map);
180+ return _restoreSceneImagePath (tx, SceneEntity .fromMap (key, map) );
165181 }
166182 }
167183
@@ -173,7 +189,10 @@ class SceneManagerImpl extends ISceneManager {
173189 } else {
174190 final store = stringMapStoreFactory.store (StoreNames .scenes);
175191 final records = await store.find (tx);
176- final scenes = records.map ((record) => SceneEntity .fromMap (record.key, record.value)).toList ();
192+ final scenes = < SceneEntity > [];
193+ for (final record in records) {
194+ scenes.add (await _restoreSceneImagePath (tx, SceneEntity .fromMap (record.key, record.value)));
195+ }
177196 return scenes;
178197 }
179198 }
@@ -229,7 +248,7 @@ class SceneManagerImpl extends ISceneManager {
229248 throw KeyNotFoundException (message: 'Failed to found current scene ID `$newSceneID `' );
230249 }
231250 final fromScene = _current;
232- final toScene = SceneEntity .fromMap (newSceneID, newCurrentRecord);
251+ final toScene = await _restoreSceneImagePath (tx, SceneEntity .fromMap (newSceneID, newCurrentRecord) );
233252 _current = toScene;
234253 _globalEventBus.fire (CurrentSceneChangedEvent (fromScene, toScene));
235254 return toScene;
@@ -350,7 +369,7 @@ class SceneManagerImpl extends ISceneManager {
350369 if (cancelToken? .isCancelled == true ) {
351370 throw Exception ('Operation cancelled' );
352371 }
353- final scene = SceneEntity .fromMap (record.key, record.value);
372+ final scene = await _restoreSceneImagePath (tx, SceneEntity .fromMap (record.key, record.value) );
354373 final accessEpoch = scene.lastAccessTime.millisecondsSinceEpoch;
355374 if (accessEpoch > lastAccessEpoch) {
356375 lastAccessEpoch = accessEpoch;
0 commit comments