CI / config (push) Canceled after 0s
CI / test-frontend (push) Canceled after 0s
CI / test-rust (push) Canceled after 0s
CI / test-e2e (push) Canceled after 0s
CI / test-e2e-release (push) Canceled after 0s
CI / build (push) Canceled after 0s
CI / release (push) Canceled after 0s
CI / docker (push) Canceled after 0s
CI / docker-website (push) Canceled after 0s
Replace visible SilverBullet branding, localize the primary login and editor surfaces, and seed new spaces with a Chinese home page while preserving Markdown file names and command IDs. Co-Authored-By: Codex <noreply@anthropic.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import {
|
|
editor,
|
|
index,
|
|
space,
|
|
sync,
|
|
} from "@silverbulletmd/silverbullet/syscalls";
|
|
|
|
let lastProgress = -1;
|
|
let lastProgressAt = 0;
|
|
|
|
export async function syncSpaceCommand() {
|
|
await editor.flashNotification("正在同步全部文件…");
|
|
await sync.performSpaceSync();
|
|
await editor.flashNotification("同步完成");
|
|
}
|
|
|
|
export async function syncFileCommand() {
|
|
await editor.flashNotification("正在同步当前文件…");
|
|
await sync.performFileSync(await editor.getCurrentPath());
|
|
await editor.flashNotification("同步完成");
|
|
}
|
|
|
|
export async function spaceSyncComplete(message: { operations: number }) {
|
|
if (message.operations > 0) {
|
|
// Update the page list
|
|
await space.listFiles();
|
|
}
|
|
|
|
void index.ensureFullIndex();
|
|
}
|
|
|
|
export async function fileSyncComplete(message: {
|
|
path: string;
|
|
operations: number;
|
|
}) {
|
|
if (message.operations > 0) {
|
|
// Re-read the specific file's metadata to trigger file:changed event
|
|
await space.getFileMeta(message.path);
|
|
}
|
|
}
|
|
|
|
export async function updateSyncStatus(event: {
|
|
status: {
|
|
filesProcessed: number;
|
|
totalFiles: number;
|
|
};
|
|
}) {
|
|
// Update the status in the UI
|
|
const percentage = Math.round(
|
|
(event.status.filesProcessed / event.status.totalFiles) * 100,
|
|
);
|
|
if (percentage >= 99) {
|
|
// Just hide it
|
|
await editor.hideProgress("sync");
|
|
lastProgressAt = 0;
|
|
} else {
|
|
const now = Date.now();
|
|
if (lastProgress !== percentage || now - lastProgressAt >= 1000) {
|
|
lastProgress = percentage;
|
|
lastProgressAt = now;
|
|
await editor.showProgress("sync", percentage);
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function reportSyncConflict({ path }: { path: string }) {
|
|
await editor.flashNotification(`同步冲突:${path},已创建冲突副本`, "error");
|
|
}
|