Skip to content

Commit 7d3cae1

Browse files
committed
implement file auto-save
1 parent 991716c commit 7d3cae1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

jupyter_rtc_core/rooms/yroom.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,12 @@ def write_sync_update(self, message_payload: bytes, client_id: str | None = None
312312
313313
This method can also be called manually.
314314
"""
315-
# Broadcast the message:
315+
# Broadcast the message
316316
message = pycrdt.create_update_message(message_payload)
317317
self._broadcast_message(message, message_type="SyncUpdate")
318318

319-
# Save the file to disk.
320-
# TODO: requires YRoomLoader implementation
321-
return
319+
# Save the file to disk
320+
self.file_api.schedule_save()
322321

323322

324323
def handle_awareness_update(self, client_id: str, message: bytes) -> None:

jupyter_rtc_core/rooms/yroom_file_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ async def _process_scheduled_saves(self) -> None:
178178
file_format = self.file_format
179179
file_type = self.file_type if self.file_type in SAVEABLE_FILE_TYPES else "file"
180180

181+
# Save the YDoc via the ContentsManager
181182
await ensure_async(self._contents_manager.save(
182183
{
183184
"format": file_format,
@@ -186,6 +187,10 @@ async def _process_scheduled_saves(self) -> None:
186187
},
187188
path
188189
))
190+
191+
# Mark 'dirty' as `False`. This hides the "unsaved changes" icon
192+
# in the JupyterLab tab rendering this YDoc in the frontend.
193+
self.jupyter_ydoc.dirty = False
189194
except Exception as e:
190195
self.log.error("An exception occurred when saving JupyterYDoc.")
191196
self.log.exception(e)

0 commit comments

Comments
 (0)