silverbullet/website/API/sync.md

44 lines
906 B
Markdown
Raw Normal View History

2025-01-17 03:41:52 +08:00
# Sync API
The Sync API provides functions for interacting with the sync engine when the client runs in Sync mode.
## Sync Operations
### sync.isSyncing()
2025-01-17 03:41:52 +08:00
Checks if a sync is currently in progress.
Example:
```lua
if sync.isSyncing() then
2025-01-17 03:41:52 +08:00
print("Sync in progress...")
end
```
### sync.hasInitialSyncCompleted()
2025-01-17 03:41:52 +08:00
Checks if an initial sync has completed.
Example:
```lua
if sync.hasInitialSyncCompleted() then
2025-01-17 03:41:52 +08:00
print("Initial sync completed")
else
print("Waiting for initial sync...")
end
```
### sync.scheduleFileSync(path)
2025-01-17 03:41:52 +08:00
Actively schedules a file to be synced. Sync will happen by default too, but this prioritizes the file.
Example:
```lua
sync.scheduleFileSync("notes/important.md")
2025-01-17 03:41:52 +08:00
```
### sync.scheduleSpaceSync()
2025-01-17 03:41:52 +08:00
Schedules a sync without waiting for the usual sync interval.
Example:
```lua
local changes = sync.scheduleSpaceSync()
2025-01-17 03:41:52 +08:00
print("Number of changes synced: " .. changes)