mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-13 02:51:51 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc158e9f2b | ||
|
|
6513c53c7e | ||
|
|
5d1074065c | ||
|
|
b444082b0c | ||
|
|
d5e6419504 | ||
|
|
1bf1e1540d | ||
|
|
be1e6b11ac |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "obsidian-livesync",
|
"id": "obsidian-livesync",
|
||||||
"name": "Self-hosted LiveSync",
|
"name": "Self-hosted LiveSync",
|
||||||
"version": "0.17.9",
|
"version": "0.17.13",
|
||||||
"minAppVersion": "0.9.12",
|
"minAppVersion": "0.9.12",
|
||||||
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Community implementation of self-hosted livesync. Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"author": "vorotamoroz",
|
"author": "vorotamoroz",
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.17.9",
|
"version": "0.17.13",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.17.9",
|
"version": "0.17.13",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"diff-match-patch": "^1.0.5",
|
"diff-match-patch": "^1.0.5",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.17.9",
|
"version": "0.17.13",
|
||||||
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
"description": "Reflect your vault changes to some other devices immediately. Please make sure to disable other synchronize solutions to avoid content corruption or duplication.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { App, Modal } from "obsidian";
|
import { App, Modal } from "obsidian";
|
||||||
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from "diff-match-patch";
|
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from "diff-match-patch";
|
||||||
import { diff_result } from "./lib/src/types";
|
import { diff_result } from "./lib/src/types";
|
||||||
import { escapeStringToHTML } from "./lib/src/utils";
|
import { escapeStringToHTML } from "./lib/src/strbin";
|
||||||
|
|
||||||
export class ConflictResolveModal extends Modal {
|
export class ConflictResolveModal extends Modal {
|
||||||
// result: Array<[number, string]>;
|
// result: Array<[number, string]>;
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { TFile, Modal, App } from "obsidian";
|
import { TFile, Modal, App } from "obsidian";
|
||||||
import { path2id } from "./utils";
|
import { path2id } from "./utils";
|
||||||
import { base64ToArrayBuffer, base64ToString, escapeStringToHTML, isValidPath } from "./lib/src/utils";
|
import { base64ToArrayBuffer, base64ToString, escapeStringToHTML } from "./lib/src/strbin";
|
||||||
|
import { isValidPath } from "./lib/src/path";
|
||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "diff-match-patch";
|
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "diff-match-patch";
|
||||||
import { LoadedEntry, LOG_LEVEL } from "./lib/src/types";
|
import { LoadedEntry, LOG_LEVEL } from "./lib/src/types";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
|
import { getDocData } from "./lib/src/utils";
|
||||||
|
|
||||||
export class DocumentHistoryModal extends Modal {
|
export class DocumentHistoryModal extends Modal {
|
||||||
plugin: ObsidianLiveSyncPlugin;
|
plugin: ObsidianLiveSyncPlugin;
|
||||||
@@ -64,7 +66,7 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
this.currentDoc = w;
|
this.currentDoc = w;
|
||||||
this.info.innerHTML = `Modified:${new Date(w.mtime).toLocaleString()}`;
|
this.info.innerHTML = `Modified:${new Date(w.mtime).toLocaleString()}`;
|
||||||
let result = "";
|
let result = "";
|
||||||
const w1data = w.datatype == "plain" ? w.data : base64ToString(w.data);
|
const w1data = w.datatype == "plain" ? getDocData(w.data) : base64ToString(w.data);
|
||||||
this.currentDeleted = w.deleted;
|
this.currentDeleted = w.deleted;
|
||||||
this.currentText = w1data;
|
this.currentText = w1data;
|
||||||
if (this.showDiff) {
|
if (this.showDiff) {
|
||||||
@@ -74,7 +76,7 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
const w2 = await db.getDBEntry(path2id(this.file), { rev: oldRev }, false, false, true);
|
const w2 = await db.getDBEntry(path2id(this.file), { rev: oldRev }, false, false, true);
|
||||||
if (w2 != false) {
|
if (w2 != false) {
|
||||||
const dmp = new diff_match_patch();
|
const dmp = new diff_match_patch();
|
||||||
const w2data = w2.datatype == "plain" ? w2.data : base64ToString(w2.data);
|
const w2data = w2.datatype == "plain" ? getDocData(w2.data) : base64ToString(w2.data);
|
||||||
const diff = dmp.diff_main(w2data, w1data);
|
const diff = dmp.diff_main(w2data, w1data);
|
||||||
dmp.diff_cleanupSemantic(diff);
|
dmp.diff_cleanupSemantic(diff);
|
||||||
for (const v of diff) {
|
for (const v of diff) {
|
||||||
@@ -176,7 +178,7 @@ export class DocumentHistoryModal extends Modal {
|
|||||||
Logger("Path is not valid to write content.", LOG_LEVEL.INFO);
|
Logger("Path is not valid to write content.", LOG_LEVEL.INFO);
|
||||||
}
|
}
|
||||||
if (this.currentDoc?.datatype == "plain") {
|
if (this.currentDoc?.datatype == "plain") {
|
||||||
await this.app.vault.adapter.write(pathToWrite, this.currentDoc.data);
|
await this.app.vault.adapter.write(pathToWrite, getDocData(this.currentDoc.data));
|
||||||
await focusFile(pathToWrite);
|
await focusFile(pathToWrite);
|
||||||
this.close();
|
this.close();
|
||||||
} else if (this.currentDoc?.datatype == "newnote") {
|
} else if (this.currentDoc?.datatype == "newnote") {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { LocalPouchDBBase } from "./lib/src/LocalPouchDBBase.js";
|
|||||||
import { Logger } from "./lib/src/logger.js";
|
import { Logger } from "./lib/src/logger.js";
|
||||||
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
import { PouchDB } from "./lib/src/pouchdb-browser.js";
|
||||||
import { EntryDoc, LOG_LEVEL } from "./lib/src/types.js";
|
import { EntryDoc, LOG_LEVEL } from "./lib/src/types.js";
|
||||||
import { enableEncryption } from "./lib/src/utils.js";
|
import { enableEncryption } from "./lib/src/utils_couchdb.js";
|
||||||
import { isCloudantURI, isValidRemoteCouchDBURI } from "./lib/src/utils_couchdb.js";
|
import { isCloudantURI, isValidRemoteCouchDBURI } from "./lib/src/utils_couchdb.js";
|
||||||
import { id2path, path2id } from "./utils.js";
|
import { id2path, path2id } from "./utils.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
import { App, Modal } from "obsidian";
|
import { App, Modal } from "obsidian";
|
||||||
import { escapeStringToHTML } from "./lib/src/utils";
|
import { logMessageStore } from "./lib/src/stores";
|
||||||
|
import { escapeStringToHTML } from "./lib/src/strbin";
|
||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
|
|
||||||
export class LogDisplayModal extends Modal {
|
export class LogDisplayModal extends Modal {
|
||||||
plugin: ObsidianLiveSyncPlugin;
|
plugin: ObsidianLiveSyncPlugin;
|
||||||
logEl: HTMLDivElement;
|
logEl: HTMLDivElement;
|
||||||
|
unsubscribe: () => void;
|
||||||
constructor(app: App, plugin: ObsidianLiveSyncPlugin) {
|
constructor(app: App, plugin: ObsidianLiveSyncPlugin) {
|
||||||
super(app);
|
super(app);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
updateLog() {
|
|
||||||
let msg = "";
|
|
||||||
for (const v of this.plugin.logMessage) {
|
|
||||||
msg += escapeStringToHTML(v) + "<br>";
|
|
||||||
}
|
|
||||||
this.logEl.innerHTML = msg;
|
|
||||||
}
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
|
|
||||||
@@ -25,13 +21,18 @@ export class LogDisplayModal extends Modal {
|
|||||||
div.addClass("op-scrollable");
|
div.addClass("op-scrollable");
|
||||||
div.addClass("op-pre");
|
div.addClass("op-pre");
|
||||||
this.logEl = div;
|
this.logEl = div;
|
||||||
this.updateLog = this.updateLog.bind(this);
|
this.unsubscribe = logMessageStore.observe((e) => {
|
||||||
this.plugin.addLogHook = this.updateLog;
|
let msg = "";
|
||||||
this.updateLog();
|
for (const v of e) {
|
||||||
|
msg += escapeStringToHTML(v) + "<br>";
|
||||||
|
}
|
||||||
|
this.logEl.innerHTML = msg;
|
||||||
|
})
|
||||||
|
logMessageStore.invalidate();
|
||||||
}
|
}
|
||||||
onClose() {
|
onClose() {
|
||||||
const { contentEl } = this;
|
const { contentEl } = this;
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
this.plugin.addLogHook = null;
|
if (this.unsubscribe) this.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "obsidian";
|
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl, TextAreaComponent, MarkdownRenderer, stringifyYaml } from "obsidian";
|
||||||
import { DEFAULT_SETTINGS, LOG_LEVEL, ObsidianLiveSyncSettings, RemoteDBSettings } from "./lib/src/types";
|
import { DEFAULT_SETTINGS, LOG_LEVEL, ObsidianLiveSyncSettings, RemoteDBSettings } from "./lib/src/types";
|
||||||
import { path2id, id2path } from "./utils";
|
import { path2id, id2path } from "./utils";
|
||||||
import { delay, Semaphore, versionNumberString2Number } from "./lib/src/utils";
|
import { delay } from "./lib/src/utils";
|
||||||
|
import { Semaphore } from "./lib/src/semaphore";
|
||||||
|
import { versionNumberString2Number } from "./lib/src/strbin";
|
||||||
import { Logger } from "./lib/src/logger";
|
import { Logger } from "./lib/src/logger";
|
||||||
import { checkSyncInfo, isCloudantURI } from "./lib/src/utils_couchdb.js";
|
import { checkSyncInfo, isCloudantURI } from "./lib/src/utils_couchdb.js";
|
||||||
import { testCrypt } from "./lib/src/e2ee_v2";
|
import { testCrypt } from "./lib/src/e2ee_v2";
|
||||||
@@ -1184,8 +1186,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
.setValue(this.plugin.settings.customChunkSize + "")
|
.setValue(this.plugin.settings.customChunkSize + "")
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
let v = Number(value);
|
let v = Number(value);
|
||||||
if (isNaN(v) || v < 100) {
|
if (isNaN(v) || v < 1) {
|
||||||
v = 100;
|
v = 1;
|
||||||
}
|
}
|
||||||
this.plugin.settings.customChunkSize = v;
|
this.plugin.settings.customChunkSize = v;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
@@ -1423,7 +1425,7 @@ ${stringifyYaml(pluginConfig)}`;
|
|||||||
const releaser = await semaphore.acquire(1, "verifyAndRepair");
|
const releaser = await semaphore.acquire(1, "verifyAndRepair");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Logger(`Update into ${file.path}`);
|
Logger(`UPDATE DATABASE ${file.path}`);
|
||||||
await this.plugin.updateIntoDB(file, false, null, true);
|
await this.plugin.updateIntoDB(file, false, null, true);
|
||||||
i++;
|
i++;
|
||||||
Logger(`${i}/${files.length}\n${file.path}`, LOG_LEVEL.NOTICE, "verify");
|
Logger(`${i}/${files.length}\n${file.path}`, LOG_LEVEL.NOTICE, "verify");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import ObsidianLiveSyncPlugin from "./main";
|
import ObsidianLiveSyncPlugin from "./main";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { DevicePluginList, PluginDataEntry } from "./types";
|
import { DevicePluginList, PluginDataEntry } from "./types";
|
||||||
import { versionNumberString2Number } from "./lib/src/utils";
|
import { versionNumberString2Number } from "./lib/src/strbin";
|
||||||
|
|
||||||
type JudgeResult = "" | "NEWER" | "EVEN" | "EVEN_BUT_DIFFERENT" | "OLDER" | "REMOTE_ONLY";
|
type JudgeResult = "" | "NEWER" | "EVEN" | "EVEN_BUT_DIFFERENT" | "OLDER" | "REMOTE_ONLY";
|
||||||
|
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 4ef5986b4d...133bae3607
274
src/main.ts
274
src/main.ts
@@ -1,34 +1,14 @@
|
|||||||
import { debounce, Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, PluginManifest, App, } from "obsidian";
|
import { debounce, Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, PluginManifest, App } from "obsidian";
|
||||||
import { Diff, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "diff-match-patch";
|
import { Diff, DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, diff_match_patch } from "diff-match-patch";
|
||||||
|
|
||||||
import { EntryDoc, LoadedEntry, ObsidianLiveSyncSettings, diff_check_result, diff_result_leaf, EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, InternalFileEntry } from "./lib/src/types";
|
import { EntryDoc, LoadedEntry, ObsidianLiveSyncSettings, diff_check_result, diff_result_leaf, EntryBody, LOG_LEVEL, VER, DEFAULT_SETTINGS, diff_result, FLAGMD_REDFLAG, SYNCINFO_ID, InternalFileEntry } from "./lib/src/types";
|
||||||
import { PluginDataEntry, PERIODIC_PLUGIN_SWEEP, PluginList, DevicePluginList, InternalFileInfo } from "./types";
|
import { PluginDataEntry, PERIODIC_PLUGIN_SWEEP, PluginList, DevicePluginList, InternalFileInfo, queueItem } from "./types";
|
||||||
import {
|
import { getDocData, isDocContentSame } from "./lib/src/utils";
|
||||||
base64ToString,
|
import { Logger } from "./lib/src/logger";
|
||||||
arrayBufferToBase64,
|
|
||||||
base64ToArrayBuffer,
|
|
||||||
isValidPath,
|
|
||||||
versionNumberString2Number,
|
|
||||||
runWithLock,
|
|
||||||
shouldBeIgnored,
|
|
||||||
getProcessingCounts,
|
|
||||||
setLockNotifier,
|
|
||||||
isPlainText,
|
|
||||||
setNoticeClass,
|
|
||||||
NewNotice,
|
|
||||||
getLocks,
|
|
||||||
WrappedNotice,
|
|
||||||
Semaphore,
|
|
||||||
} from "./lib/src/utils";
|
|
||||||
import { Logger, setLogger } from "./lib/src/logger";
|
|
||||||
import { LocalPouchDB } from "./LocalPouchDB";
|
import { LocalPouchDB } from "./LocalPouchDB";
|
||||||
import { LogDisplayModal } from "./LogDisplayModal";
|
import { LogDisplayModal } from "./LogDisplayModal";
|
||||||
import { ConflictResolveModal } from "./ConflictResolveModal";
|
import { ConflictResolveModal } from "./ConflictResolveModal";
|
||||||
import { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab";
|
import { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab";
|
||||||
import { DocumentHistoryModal } from "./DocumentHistoryModal";
|
import { DocumentHistoryModal } from "./DocumentHistoryModal";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { applyPatch, clearAllPeriodic, clearAllTriggers, clearTrigger, disposeMemoObject, generatePatchObj, id2path, isObjectMargeApplicable, isSensibleMargeApplicable, memoIfNotExist, memoObject, path2id, retrieveMemoObject, setTrigger, tryParseJSON } from "./utils";
|
import { applyPatch, clearAllPeriodic, clearAllTriggers, clearTrigger, disposeMemoObject, generatePatchObj, id2path, isObjectMargeApplicable, isSensibleMargeApplicable, memoIfNotExist, memoObject, path2id, retrieveMemoObject, setTrigger, tryParseJSON } from "./utils";
|
||||||
import { decrypt, encrypt } from "./lib/src/e2ee_v2";
|
import { decrypt, encrypt } from "./lib/src/e2ee_v2";
|
||||||
|
|
||||||
@@ -36,6 +16,13 @@ const isDebug = false;
|
|||||||
|
|
||||||
import { InputStringDialog, PluginDialogModal, PopoverSelectString } from "./dialogs";
|
import { InputStringDialog, PluginDialogModal, PopoverSelectString } from "./dialogs";
|
||||||
import { isCloudantURI } from "./lib/src/utils_couchdb";
|
import { isCloudantURI } from "./lib/src/utils_couchdb";
|
||||||
|
import { getGlobalStore, observeStores } from "./lib/src/store";
|
||||||
|
import { lockStore, logMessageStore, logStore } from "./lib/src/stores";
|
||||||
|
import { NewNotice, setNoticeClass, WrappedNotice } from "./lib/src/wrapper";
|
||||||
|
import { base64ToString, versionNumberString2Number, base64ToArrayBuffer, arrayBufferToBase64 } from "./lib/src/strbin";
|
||||||
|
import { isPlainText, isValidPath, shouldBeIgnored } from "./lib/src/path";
|
||||||
|
import { runWithLock } from "./lib/src/lock";
|
||||||
|
import { Semaphore } from "./lib/src/semaphore";
|
||||||
|
|
||||||
setNoticeClass(Notice);
|
setNoticeClass(Notice);
|
||||||
|
|
||||||
@@ -46,6 +33,7 @@ const FileWatchEventQueueMax = 10;
|
|||||||
|
|
||||||
function getAbstractFileByPath(path: string): TAbstractFile | null {
|
function getAbstractFileByPath(path: string): TAbstractFile | null {
|
||||||
// Hidden API but so useful.
|
// Hidden API but so useful.
|
||||||
|
// @ts-ignore
|
||||||
if ("getAbstractFileByPathInsensitive" in app.vault && (app.vault.adapter?.insensitive ?? false)) {
|
if ("getAbstractFileByPathInsensitive" in app.vault && (app.vault.adapter?.insensitive ?? false)) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return app.vault.getAbstractFileByPathInsensitive(path);
|
return app.vault.getAbstractFileByPathInsensitive(path);
|
||||||
@@ -133,10 +121,10 @@ type FileEventItem = {
|
|||||||
type: FileEventType,
|
type: FileEventType,
|
||||||
args: FileEventArgs
|
args: FileEventArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ObsidianLiveSyncPlugin extends Plugin {
|
export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||||
settings: ObsidianLiveSyncSettings;
|
settings: ObsidianLiveSyncSettings;
|
||||||
localDatabase: LocalPouchDB;
|
localDatabase: LocalPouchDB;
|
||||||
logMessage: string[] = [];
|
|
||||||
statusBar: HTMLElement;
|
statusBar: HTMLElement;
|
||||||
statusBar2: HTMLElement;
|
statusBar2: HTMLElement;
|
||||||
suspended: boolean;
|
suspended: boolean;
|
||||||
@@ -283,7 +271,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
setLogger(this.addLog.bind(this)); // Logger moved to global.
|
logStore.subscribe(e => this.addLog(e.message, e.level, e.key));
|
||||||
Logger("loading plugin");
|
Logger("loading plugin");
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const manifestVersion: string = MANIFEST_VERSION || "0.0.0";
|
const manifestVersion: string = MANIFEST_VERSION || "0.0.0";
|
||||||
@@ -343,7 +331,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
|
|
||||||
this.statusBar = this.addStatusBarItem();
|
this.statusBar = this.addStatusBarItem();
|
||||||
this.statusBar.addClass("syncstatusbar");
|
this.statusBar.addClass("syncstatusbar");
|
||||||
this.refreshStatusText = this.refreshStatusText.bind(this);
|
|
||||||
|
|
||||||
this.statusBar2 = this.addStatusBarItem();
|
this.statusBar2 = this.addStatusBarItem();
|
||||||
this.watchVaultChange = this.watchVaultChange.bind(this);
|
this.watchVaultChange = this.watchVaultChange.bind(this);
|
||||||
@@ -358,6 +345,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
this.parseReplicationResult = this.parseReplicationResult.bind(this);
|
this.parseReplicationResult = this.parseReplicationResult.bind(this);
|
||||||
|
|
||||||
this.setPeriodicSync = this.setPeriodicSync.bind(this);
|
this.setPeriodicSync = this.setPeriodicSync.bind(this);
|
||||||
|
this.clearPeriodicSync = this.clearPeriodicSync.bind(this);
|
||||||
this.periodicSync = this.periodicSync.bind(this);
|
this.periodicSync = this.periodicSync.bind(this);
|
||||||
this.loadQueuedFiles = this.loadQueuedFiles.bind(this);
|
this.loadQueuedFiles = this.loadQueuedFiles.bind(this);
|
||||||
|
|
||||||
@@ -632,9 +620,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
|
|
||||||
this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000);
|
this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000);
|
||||||
this.triggerCheckPluginUpdate = debounce(this.triggerCheckPluginUpdate.bind(this), 3000);
|
this.triggerCheckPluginUpdate = debounce(this.triggerCheckPluginUpdate.bind(this), 3000);
|
||||||
setLockNotifier(() => {
|
|
||||||
this.refreshStatusText();
|
|
||||||
});
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: "livesync-plugin-dialog",
|
id: "livesync-plugin-dialog",
|
||||||
name: "Show Plugins and their settings",
|
name: "Show Plugins and their settings",
|
||||||
@@ -724,9 +710,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const isMobile = this.app.isMobile;
|
const isMobile = this.app.isMobile;
|
||||||
this.localDatabase = new LocalPouchDB(this.settings, vaultName, isMobile);
|
this.localDatabase = new LocalPouchDB(this.settings, vaultName, isMobile);
|
||||||
this.localDatabase.updateInfo = () => {
|
this.observeForLogs();
|
||||||
this.refreshStatusText();
|
|
||||||
};
|
|
||||||
return await this.localDatabase.initializeDatabase();
|
return await this.localDatabase.initializeDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,6 +852,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
if (this.watchedFileEventQueue[i].type != type) break;
|
if (this.watchedFileEventQueue[i].type != type) break;
|
||||||
this.watchedFileEventQueue.remove(this.watchedFileEventQueue[i]);
|
this.watchedFileEventQueue.remove(this.watchedFileEventQueue[i]);
|
||||||
|
this.queuedFilesStore.set({ queuedItems: this.queuedFiles, fileEventItems: this.watchedFileEventQueue });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -880,7 +865,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
ctx
|
ctx
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.refreshStatusText();
|
this.queuedFilesStore.set({ queuedItems: this.queuedFiles, fileEventItems: this.watchedFileEventQueue });
|
||||||
if (this.isReady) {
|
if (this.isReady) {
|
||||||
await this.procFileEvent();
|
await this.procFileEvent();
|
||||||
}
|
}
|
||||||
@@ -919,8 +904,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
if (queue.type == "DELETE") {
|
if (queue.type == "DELETE") {
|
||||||
if (file instanceof TFile) {
|
if (file instanceof TFile) {
|
||||||
await this.deleteFromDB(file);
|
await this.deleteFromDB(file);
|
||||||
} else if (file instanceof TFolder) {
|
|
||||||
await this.deleteFolderOnDB(file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (queue.type == "RENAME") {
|
if (queue.type == "RENAME") {
|
||||||
@@ -935,11 +918,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
await this.localDatabase.kvDB.set(key, file.stat.mtime);
|
await this.localDatabase.kvDB.set(key, file.stat.mtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.refreshStatusText();
|
|
||||||
} while (this.watchedFileEventQueue.length != 0);
|
} while (this.watchedFileEventQueue.length != 0);
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
this.refreshStatusText();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1054,30 +1035,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
return this.getFilePath(file.parent) + "/" + file.name;
|
return this.getFilePath(file.parent) + "/" + file.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
async watchVaultRenameAsync(file: TAbstractFile, oldFile: any, cache?: CacheData) {
|
async watchVaultRenameAsync(file: TFile, oldFile: any, cache?: CacheData) {
|
||||||
Logger(`${oldFile} renamed to ${file.path}`, LOG_LEVEL.VERBOSE);
|
Logger(`${oldFile} renamed to ${file.path}`, LOG_LEVEL.VERBOSE);
|
||||||
if (file instanceof TFolder) {
|
if (file instanceof TFile) {
|
||||||
const newFiles = this.GetAllFilesRecursively(file);
|
|
||||||
// for guard edge cases. this won't happen and each file's event will be raise.
|
|
||||||
for (const i of newFiles) {
|
|
||||||
try {
|
|
||||||
const newFilePath = normalizePath(this.getFilePath(i));
|
|
||||||
const newFile = getAbstractFileByPath(newFilePath);
|
|
||||||
if (newFile instanceof TFile) {
|
|
||||||
Logger(`save ${newFile.path} into db`);
|
|
||||||
await this.updateIntoDB(newFile);
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
Logger(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Logger(`delete below ${oldFile} from db`);
|
|
||||||
await this.deleteFromDBbyPath(oldFile);
|
|
||||||
} else if (file instanceof TFile) {
|
|
||||||
try {
|
try {
|
||||||
Logger(`file save ${file.path} into db`);
|
// Logger(`RENAMING.. ${file.path} into db`);
|
||||||
await this.updateIntoDB(file, false, cache);
|
await this.updateIntoDB(file, false, cache);
|
||||||
Logger(`deleted ${oldFile} from db`);
|
// Logger(`deleted ${oldFile} from db`);
|
||||||
await this.deleteFromDBbyPath(oldFile);
|
await this.deleteFromDBbyPath(oldFile);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
Logger(ex);
|
Logger(ex);
|
||||||
@@ -1085,7 +1049,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addLogHook: () => void = null;
|
|
||||||
//--> Basic document Functions
|
//--> Basic document Functions
|
||||||
notifies: { [key: string]: { notice: Notice; timer: NodeJS.Timeout; count: number } } = {};
|
notifies: { [key: string]: { notice: Notice; timer: NodeJS.Timeout; count: number } } = {};
|
||||||
|
|
||||||
@@ -1106,12 +1069,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const messageContent = typeof message == "string" ? message : message instanceof Error ? `${message.name}:${message.message}` : JSON.stringify(message, null, 2);
|
const messageContent = typeof message == "string" ? message : message instanceof Error ? `${message.name}:${message.message}` : JSON.stringify(message, null, 2);
|
||||||
const newMessage = timestamp + "->" + messageContent;
|
const newMessage = timestamp + "->" + messageContent;
|
||||||
|
|
||||||
this.logMessage = [].concat(this.logMessage).concat([newMessage]).slice(-100);
|
|
||||||
console.log(vaultName + ":" + newMessage);
|
console.log(vaultName + ":" + newMessage);
|
||||||
|
logMessageStore.apply(e => [...e, newMessage].slice(-100));
|
||||||
this.setStatusBarText(null, messageContent.substring(0, 30));
|
this.setStatusBarText(null, messageContent.substring(0, 30));
|
||||||
// if (message instanceof Error) {
|
|
||||||
// console.trace(message);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (level >= LOG_LEVEL.NOTICE) {
|
if (level >= LOG_LEVEL.NOTICE) {
|
||||||
if (!key) key = messageContent;
|
if (!key) key = messageContent;
|
||||||
@@ -1150,7 +1110,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.addLogHook != null) this.addLogHook();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureDirectory(fullPath: string) {
|
async ensureDirectory(fullPath: string) {
|
||||||
@@ -1198,7 +1157,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
ctime: doc.ctime,
|
ctime: doc.ctime,
|
||||||
mtime: doc.mtime,
|
mtime: doc.mtime,
|
||||||
});
|
});
|
||||||
// this.batchFileChange = this.batchFileChange.filter((e) => e != newFile.path);
|
|
||||||
Logger(msg + path);
|
Logger(msg + path);
|
||||||
touch(newFile);
|
touch(newFile);
|
||||||
this.app.vault.trigger("create", newFile);
|
this.app.vault.trigger("create", newFile);
|
||||||
@@ -1214,11 +1172,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
await this.ensureDirectory(path);
|
await this.ensureDirectory(path);
|
||||||
try {
|
try {
|
||||||
const newFile = await this.app.vault.create(normalizePath(path), doc.data, {
|
const newFile = await this.app.vault.create(normalizePath(path), getDocData(doc.data), {
|
||||||
ctime: doc.ctime,
|
ctime: doc.ctime,
|
||||||
mtime: doc.mtime,
|
mtime: doc.mtime,
|
||||||
});
|
});
|
||||||
// this.batchFileChange = this.batchFileChange.filter((e) => e != newFile.path);
|
|
||||||
Logger(msg + path);
|
Logger(msg + path);
|
||||||
touch(newFile);
|
touch(newFile);
|
||||||
this.app.vault.trigger("create", newFile);
|
this.app.vault.trigger("create", newFile);
|
||||||
@@ -1241,11 +1198,11 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
} else {
|
} else {
|
||||||
await this.app.vault.delete(file);
|
await this.app.vault.delete(file);
|
||||||
}
|
}
|
||||||
Logger(`deleted:${file.path}`);
|
Logger(`xxx <- STORAGE (deleted) ${file.path}`);
|
||||||
Logger(`other items:${dir.children.length}`);
|
Logger(`files: ${dir.children.length}`);
|
||||||
if (dir.children.length == 0) {
|
if (dir.children.length == 0) {
|
||||||
if (!this.settings.doNotDeleteFolder) {
|
if (!this.settings.doNotDeleteFolder) {
|
||||||
Logger(`all files deleted by replication, so delete dir`);
|
Logger(`All files under the parent directory (${dir}) have been deleted, so delete this one.`);
|
||||||
await this.deleteVaultItem(dir);
|
await this.deleteVaultItem(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1261,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
await this.ensureDirectory(path);
|
await this.ensureDirectory(path);
|
||||||
try {
|
try {
|
||||||
await this.app.vault.modify(file, doc.data, { ctime: doc.ctime, mtime: doc.mtime });
|
await this.app.vault.modify(file, getDocData(doc.data), { ctime: doc.ctime, mtime: doc.mtime });
|
||||||
Logger(msg + path);
|
Logger(msg + path);
|
||||||
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
// this.batchFileChange = this.batchFileChange.filter((e) => e != file.path);
|
||||||
const xf = getAbstractFileByPath(file.path) as TFile;
|
const xf = getAbstractFileByPath(file.path) as TFile;
|
||||||
@@ -1353,7 +1310,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.refreshStatusText();
|
|
||||||
}
|
}
|
||||||
async handleDBChangedAsync(change: EntryBody) {
|
async handleDBChangedAsync(change: EntryBody) {
|
||||||
|
|
||||||
@@ -1398,13 +1354,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queuedFiles: {
|
queuedFiles = [] as queueItem[];
|
||||||
entry: EntryBody;
|
queuedFilesStore = getGlobalStore("queuedFiles", { queuedItems: [] as queueItem[], fileEventItems: [] as FileEventItem[] });
|
||||||
missingChildren: string[];
|
|
||||||
timeout?: number;
|
|
||||||
done?: boolean;
|
|
||||||
warned?: boolean;
|
|
||||||
}[] = [];
|
|
||||||
chunkWaitTimeout = 60000;
|
chunkWaitTimeout = 60000;
|
||||||
|
|
||||||
saveQueuedFiles() {
|
saveQueuedFiles() {
|
||||||
@@ -1431,7 +1382,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
await this.syncInternalFilesAndDatabase("pull", false, false, w);
|
await this.syncInternalFilesAndDatabase("pull", false, false, w);
|
||||||
Logger(`Applying hidden ${w.length} files changed`);
|
Logger(`Applying hidden ${w.length} files changed`);
|
||||||
});
|
});
|
||||||
this.refreshStatusText();
|
|
||||||
}
|
}
|
||||||
procInternalFile(filename: string) {
|
procInternalFile(filename: string) {
|
||||||
this.procInternalFiles.push(filename);
|
this.procInternalFiles.push(filename);
|
||||||
@@ -1463,6 +1413,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.queuedFiles = this.queuedFiles.filter((e) => !e.done);
|
this.queuedFiles = this.queuedFiles.filter((e) => !e.done);
|
||||||
|
this.queuedFilesStore.set({ queuedItems: this.queuedFiles, fileEventItems: this.watchedFileEventQueue });
|
||||||
this.saveQueuedFiles();
|
this.saveQueuedFiles();
|
||||||
}
|
}
|
||||||
parseIncomingChunk(chunk: PouchDB.Core.ExistingDocument<EntryDoc>) {
|
parseIncomingChunk(chunk: PouchDB.Core.ExistingDocument<EntryDoc>) {
|
||||||
@@ -1526,7 +1477,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
|
|
||||||
//---> Sync
|
//---> Sync
|
||||||
async parseReplicationResult(docs: Array<PouchDB.Core.ExistingDocument<EntryDoc>>): Promise<void> {
|
async parseReplicationResult(docs: Array<PouchDB.Core.ExistingDocument<EntryDoc>>): Promise<void> {
|
||||||
this.refreshStatusText();
|
|
||||||
for (const change of docs) {
|
for (const change of docs) {
|
||||||
if (isPluginChunk(change._id)) {
|
if (isPluginChunk(change._id)) {
|
||||||
if (this.settings.notifyPluginOrSettingUpdated) {
|
if (this.settings.notifyPluginOrSettingUpdated) {
|
||||||
@@ -1598,8 +1548,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPeriodicSync() {
|
setPeriodicSync() {
|
||||||
|
this.clearPeriodicSync();
|
||||||
if (this.settings.periodicReplication && this.settings.periodicReplicationInterval > 0) {
|
if (this.settings.periodicReplication && this.settings.periodicReplicationInterval > 0) {
|
||||||
this.clearPeriodicSync();
|
|
||||||
this.periodicSyncHandler = this.setInterval(async () => await this.periodicSync(), Math.max(this.settings.periodicReplicationInterval, 30) * 1000);
|
this.periodicSyncHandler = this.setInterval(async () => await this.periodicSync(), Math.max(this.settings.periodicReplicationInterval, 30) * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1641,7 +1591,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
if (this.settings.liveSync) {
|
if (this.settings.liveSync) {
|
||||||
this.localDatabase.openReplication(this.settings, true, false, this.parseReplicationResult);
|
this.localDatabase.openReplication(this.settings, true, false, this.parseReplicationResult);
|
||||||
this.refreshStatusText();
|
|
||||||
}
|
}
|
||||||
if (this.settings.syncInternalFiles) {
|
if (this.settings.syncInternalFiles) {
|
||||||
await this.syncInternalFilesAndDatabase("safe", false);
|
await this.syncInternalFilesAndDatabase("safe", false);
|
||||||
@@ -1653,63 +1602,80 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
|
|
||||||
lastMessage = "";
|
lastMessage = "";
|
||||||
|
|
||||||
|
observeForLogs() {
|
||||||
|
const observer__ = observeStores(this.queuedFilesStore, lockStore);
|
||||||
|
const observer = observeStores(observer__, this.localDatabase.stat);
|
||||||
|
|
||||||
|
observer.observe(e => {
|
||||||
|
const sent = e.sent;
|
||||||
|
const arrived = e.arrived;
|
||||||
|
const maxPullSeq = e.maxPullSeq;
|
||||||
|
const maxPushSeq = e.maxPushSeq;
|
||||||
|
const lastSyncPullSeq = e.lastSyncPullSeq;
|
||||||
|
const lastSyncPushSeq = e.lastSyncPushSeq;
|
||||||
|
let pushLast = "";
|
||||||
|
let pullLast = "";
|
||||||
|
let w = "";
|
||||||
|
switch (e.syncStatus) {
|
||||||
|
case "CLOSED":
|
||||||
|
case "COMPLETED":
|
||||||
|
case "NOT_CONNECTED":
|
||||||
|
w = "⏹";
|
||||||
|
break;
|
||||||
|
case "STARTED":
|
||||||
|
w = "🌀";
|
||||||
|
break;
|
||||||
|
case "PAUSED":
|
||||||
|
w = "💤";
|
||||||
|
break;
|
||||||
|
case "CONNECTED":
|
||||||
|
w = "⚡";
|
||||||
|
pushLast = ((lastSyncPushSeq == 0) ? "" : (lastSyncPushSeq >= maxPushSeq ? " (LIVE)" : ` (${maxPushSeq - lastSyncPushSeq})`));
|
||||||
|
pullLast = ((lastSyncPullSeq == 0) ? "" : (lastSyncPullSeq >= maxPullSeq ? " (LIVE)" : ` (${maxPullSeq - lastSyncPullSeq})`));
|
||||||
|
break;
|
||||||
|
case "ERRORED":
|
||||||
|
w = "⚠";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
w = "?";
|
||||||
|
}
|
||||||
|
this.statusBar.title = e.syncStatus;
|
||||||
|
let waiting = "";
|
||||||
|
if (this.settings.batchSave) {
|
||||||
|
waiting = " " + this.watchedFileEventQueue.map((e) => "🛫").join("");
|
||||||
|
waiting = waiting.replace(/(🛫){10}/g, "🚀");
|
||||||
|
}
|
||||||
|
let queued = "";
|
||||||
|
const queue = Object.entries(e.queuedItems).filter((e) => !e[1].warned);
|
||||||
|
const queuedCount = queue.length;
|
||||||
|
|
||||||
|
if (queuedCount) {
|
||||||
|
const pieces = queue.map((e) => e[1].missingChildren).reduce((prev, cur) => prev + cur.length, 0);
|
||||||
|
queued = ` 🧩 ${queuedCount} (${pieces})`;
|
||||||
|
}
|
||||||
|
const processes = e.count;
|
||||||
|
const processesDisp = processes == 0 ? "" : ` ⏳${processes}`;
|
||||||
|
const message = `Sync: ${w} ↑${sent}${pushLast} ↓${arrived}${pullLast}${waiting}${processesDisp}${queued}`;
|
||||||
|
// const locks = getLocks();
|
||||||
|
const pendingTask = e.pending.length
|
||||||
|
? "\nPending: " +
|
||||||
|
Object.entries(e.pending.reduce((p, c) => ({ ...p, [c]: (p[c] ?? 0) + 1 }), {} as { [key: string]: number }))
|
||||||
|
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
||||||
|
.join(", ")
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const runningTask = e.running.length
|
||||||
|
? "\nRunning: " +
|
||||||
|
Object.entries(e.running.reduce((p, c) => ({ ...p, [c]: (p[c] ?? 0) + 1 }), {} as { [key: string]: number }))
|
||||||
|
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
||||||
|
.join(", ")
|
||||||
|
: "";
|
||||||
|
this.setStatusBarText(message + pendingTask + runningTask);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
refreshStatusText() {
|
refreshStatusText() {
|
||||||
const sent = this.localDatabase.docSent;
|
return;
|
||||||
const arrived = this.localDatabase.docArrived;
|
|
||||||
let w = "";
|
|
||||||
switch (this.localDatabase.syncStatus) {
|
|
||||||
case "CLOSED":
|
|
||||||
case "COMPLETED":
|
|
||||||
case "NOT_CONNECTED":
|
|
||||||
w = "⏹";
|
|
||||||
break;
|
|
||||||
case "STARTED":
|
|
||||||
w = "🌀";
|
|
||||||
break;
|
|
||||||
case "PAUSED":
|
|
||||||
w = "💤";
|
|
||||||
break;
|
|
||||||
case "CONNECTED":
|
|
||||||
w = "⚡";
|
|
||||||
break;
|
|
||||||
case "ERRORED":
|
|
||||||
w = "⚠";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
w = "?";
|
|
||||||
}
|
|
||||||
this.statusBar.title = this.localDatabase.syncStatus;
|
|
||||||
let waiting = "";
|
|
||||||
if (this.settings.batchSave) {
|
|
||||||
waiting = " " + this.watchedFileEventQueue.map((e) => "🛫").join("");
|
|
||||||
waiting = waiting.replace(/(🛫){10}/g, "🚀");
|
|
||||||
}
|
|
||||||
let queued = "";
|
|
||||||
const queue = Object.entries(this.queuedFiles).filter((e) => !e[1].warned);
|
|
||||||
const queuedCount = queue.length;
|
|
||||||
|
|
||||||
if (queuedCount) {
|
|
||||||
const pieces = queue.map((e) => e[1].missingChildren).reduce((prev, cur) => prev + cur.length, 0);
|
|
||||||
queued = ` 🧩 ${queuedCount} (${pieces})`;
|
|
||||||
}
|
|
||||||
const processes = getProcessingCounts();
|
|
||||||
const processesDisp = processes == 0 ? "" : ` ⏳${processes}`;
|
|
||||||
const message = `Sync: ${w} ↑${sent} ↓${arrived}${waiting}${processesDisp}${queued}`;
|
|
||||||
const locks = getLocks();
|
|
||||||
const pendingTask = locks.pending.length
|
|
||||||
? "\nPending: " +
|
|
||||||
Object.entries(locks.pending.reduce((p, c) => ({ ...p, [c]: (p[c] ?? 0) + 1 }), {} as { [key: string]: number }))
|
|
||||||
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
|
||||||
.join(", ")
|
|
||||||
: "";
|
|
||||||
|
|
||||||
const runningTask = locks.running.length
|
|
||||||
? "\nRunning: " +
|
|
||||||
Object.entries(locks.running.reduce((p, c) => ({ ...p, [c]: (p[c] ?? 0) + 1 }), {} as { [key: string]: number }))
|
|
||||||
.map((e) => `${e[0]}${e[1] == 1 ? "" : `(${e[1]})`}`)
|
|
||||||
.join(", ")
|
|
||||||
: "";
|
|
||||||
this.setStatusBarText(message + pendingTask + runningTask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logHideTimer: NodeJS.Timeout = null;
|
logHideTimer: NodeJS.Timeout = null;
|
||||||
@@ -1724,10 +1690,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
const root = activeDocument.documentElement;
|
const root = activeDocument.documentElement;
|
||||||
const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`);
|
const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`);
|
||||||
q.forEach(e => e.setAttr("data-log", '' + (newMsg + "\n" + newLog) + ''))
|
q.forEach(e => e.setAttr("data-log", '' + (newMsg + "\n" + newLog) + ''))
|
||||||
// root.style.setProperty("--slsmessage", '"' + (newMsg + "\n" + newLog).split("\n").join("\\a ") + '"');
|
|
||||||
} else {
|
} else {
|
||||||
const root = activeDocument.documentElement;
|
const root = activeDocument.documentElement;
|
||||||
// root.style.setProperty("--slsmessage", '""');
|
|
||||||
const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`);
|
const q = root.querySelectorAll(`.CodeMirror-wrap,.cm-s-obsidian>.cm-editor,.canvas-wrapper`);
|
||||||
q.forEach(e => e.setAttr("data-log", ''))
|
q.forEach(e => e.setAttr("data-log", ''))
|
||||||
}
|
}
|
||||||
@@ -1866,7 +1830,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await runAll("UPDATE DATABASE", onlyInStorage, async (e) => {
|
await runAll("UPDATE DATABASE", onlyInStorage, async (e) => {
|
||||||
Logger(`Update into ${e.path}`);
|
Logger(`UPDATE DATABASE ${e.path}`);
|
||||||
await this.updateIntoDB(e, initialScan);
|
await this.updateIntoDB(e, initialScan);
|
||||||
});
|
});
|
||||||
if (!initialScan) {
|
if (!initialScan) {
|
||||||
@@ -1957,18 +1921,18 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
try {
|
try {
|
||||||
const doc = await this.localDatabase.getDBEntry(path, { rev: rev }, false, false, true);
|
const doc = await this.localDatabase.getDBEntry(path, { rev: rev }, false, false, true);
|
||||||
if (doc === false) return false;
|
if (doc === false) return false;
|
||||||
let data = doc.data;
|
let data = getDocData(doc.data)
|
||||||
if (doc.datatype == "newnote") {
|
if (doc.datatype == "newnote") {
|
||||||
data = base64ToString(doc.data);
|
data = base64ToString(data);
|
||||||
} else if (doc.datatype == "plain") {
|
} else if (doc.datatype == "plain") {
|
||||||
data = doc.data;
|
// NO OP.
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
deleted: doc.deleted || doc._deleted,
|
deleted: doc.deleted || doc._deleted,
|
||||||
ctime: doc.ctime,
|
ctime: doc.ctime,
|
||||||
mtime: doc.mtime,
|
mtime: doc.mtime,
|
||||||
rev: rev,
|
rev: rev,
|
||||||
data: data,
|
data: data
|
||||||
};
|
};
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex.status && ex.status == 404) {
|
if (ex.status && ex.status == 404) {
|
||||||
@@ -2462,11 +2426,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
if (shouldBeIgnored(file.path)) {
|
if (shouldBeIgnored(file.path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let content = "";
|
let content: string | string[];
|
||||||
let datatype: "plain" | "newnote" = "newnote";
|
let datatype: "plain" | "newnote" = "newnote";
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
if (!isPlainText(file.name)) {
|
if (!isPlainText(file.name)) {
|
||||||
|
Logger(`Reading : ${file.path}`, LOG_LEVEL.VERBOSE);
|
||||||
const contentBin = await this.app.vault.readBinary(file);
|
const contentBin = await this.app.vault.readBinary(file);
|
||||||
|
Logger(`Processing: ${file.path}`, LOG_LEVEL.VERBOSE);
|
||||||
content = await arrayBufferToBase64(contentBin);
|
content = await arrayBufferToBase64(contentBin);
|
||||||
datatype = "newnote";
|
datatype = "newnote";
|
||||||
} else {
|
} else {
|
||||||
@@ -2502,12 +2468,12 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
try {
|
try {
|
||||||
const old = await this.localDatabase.getDBEntry(fullPath, null, false, false);
|
const old = await this.localDatabase.getDBEntry(fullPath, null, false, false);
|
||||||
if (old !== false) {
|
if (old !== false) {
|
||||||
const oldData = { data: old.data, deleted: old._deleted || old.deleted, };
|
const oldData = { data: old.data, deleted: old._deleted || old.deleted };
|
||||||
const newData = { data: d.data, deleted: d._deleted || d.deleted };
|
const newData = { data: d.data, deleted: d._deleted || d.deleted };
|
||||||
if (JSON.stringify(oldData) == JSON.stringify(newData)) {
|
if (oldData.deleted != newData.deleted) return false;
|
||||||
Logger(msg + "Skipped (not changed) " + fullPath + ((d._deleted || d.deleted) ? " (deleted)" : ""), LOG_LEVEL.VERBOSE);
|
if (!isDocContentSame(old.data, newData.data)) return false;
|
||||||
return true;
|
Logger(msg + "Skipped (not changed) " + fullPath + ((d._deleted || d.deleted) ? " (deleted)" : ""), LOG_LEVEL.VERBOSE);
|
||||||
}
|
return true;
|
||||||
// d._rev = old._rev;
|
// d._rev = old._rev;
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -2569,7 +2535,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
async getPluginList(): Promise<{ plugins: PluginList; allPlugins: DevicePluginList; thisDevicePlugins: DevicePluginList }> {
|
async getPluginList(): Promise<{ plugins: PluginList; allPlugins: DevicePluginList; thisDevicePlugins: DevicePluginList }> {
|
||||||
const db = this.localDatabase.localDatabase;
|
const db = this.localDatabase.localDatabase;
|
||||||
const docList = await db.allDocs<PluginDataEntry>({ startkey: PSCHeader, endkey: PSCHeaderEnd, include_docs: false });
|
const docList = await db.allDocs<PluginDataEntry>({ startkey: PSCHeader, endkey: PSCHeaderEnd, include_docs: false });
|
||||||
const oldDocs: PluginDataEntry[] = ((await Promise.all(docList.rows.map(async (e) => await this.localDatabase.getDBEntry(e.id)))).filter((e) => e !== false) as LoadedEntry[]).map((e) => JSON.parse(e.data));
|
const oldDocs: PluginDataEntry[] = ((await Promise.all(docList.rows.map(async (e) => await this.localDatabase.getDBEntry(e.id)))).filter((e) => e !== false) as LoadedEntry[]).map((e) => JSON.parse(getDocData(e.data)));
|
||||||
const plugins: { [key: string]: PluginDataEntry[] } = {};
|
const plugins: { [key: string]: PluginDataEntry[] } = {};
|
||||||
const allPlugins: { [key: string]: PluginDataEntry } = {};
|
const allPlugins: { [key: string]: PluginDataEntry } = {};
|
||||||
const thisDevicePlugins: { [key: string]: PluginDataEntry } = {};
|
const thisDevicePlugins: { [key: string]: PluginDataEntry } = {};
|
||||||
|
|||||||
10
src/types.ts
10
src/types.ts
@@ -1,5 +1,5 @@
|
|||||||
import { PluginManifest } from "obsidian";
|
import { PluginManifest } from "obsidian";
|
||||||
import { DatabaseEntry } from "./lib/src/types";
|
import { DatabaseEntry, EntryBody } from "./lib/src/types";
|
||||||
|
|
||||||
export interface PluginDataEntry extends DatabaseEntry {
|
export interface PluginDataEntry extends DatabaseEntry {
|
||||||
deviceVaultName: string;
|
deviceVaultName: string;
|
||||||
@@ -30,3 +30,11 @@ export interface InternalFileInfo {
|
|||||||
size: number;
|
size: number;
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type queueItem = {
|
||||||
|
entry: EntryBody;
|
||||||
|
missingChildren: string[];
|
||||||
|
timeout?: number;
|
||||||
|
done?: boolean;
|
||||||
|
warned?: boolean;
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { normalizePath } from "obsidian";
|
import { normalizePath } from "obsidian";
|
||||||
|
|
||||||
import { path2id_base, id2path_base } from "./lib/src/utils";
|
import { path2id_base, id2path_base } from "./lib/src/path";
|
||||||
|
|
||||||
// For backward compatibility, using the path for determining id.
|
// For backward compatibility, using the path for determining id.
|
||||||
// Only CouchDB unacceptable ID (that starts with an underscore) has been prefixed with "/".
|
// Only CouchDB unacceptable ID (that starts with an underscore) has been prefixed with "/".
|
||||||
|
|||||||
19
updates.md
19
updates.md
@@ -35,15 +35,26 @@
|
|||||||
- Fixed button styling.
|
- Fixed button styling.
|
||||||
- Changed:
|
- Changed:
|
||||||
- Conflict checking on synchronising has been enabled for every note in default.
|
- Conflict checking on synchronising has been enabled for every note in default.
|
||||||
|
|
||||||
- 0.17.8
|
- 0.17.8
|
||||||
- Improved: Performance improved. Prebuilt PouchDB is no longer used.
|
- Improved: Performance improved. Prebuilt PouchDB is no longer used.
|
||||||
- Fixed: Merging hidden files is also fixed.
|
- Fixed: Merging hidden files is also fixed.
|
||||||
- New Feature: Now we can synchronise automatically after merging conflicts.
|
- New Feature: Now we can synchronise automatically after merging conflicts.
|
||||||
|
|
||||||
- 0.17.9
|
- 0.17.9
|
||||||
- Fixed: Conflict merge of internal files is no longer broken.
|
- Fixed: Conflict merge of internal files is no longer broken.
|
||||||
- Improved: Smoother status display inside the editor.
|
- Improved: Smoother status display inside the editor.
|
||||||
|
- 0.17.10
|
||||||
|
- Fixed: Large file synchronising has been now addressed!
|
||||||
|
Note: When synchronising large files, we have to set `Chunk size` to lower than 50, disable `Read chunks online`, `Batch size` should be set 50-100, and `Batch limit` could be around 20.
|
||||||
|
- 0.17.11
|
||||||
|
- Fixed:
|
||||||
|
- Performance improvement
|
||||||
|
- Now `Chunk size` can be set to under one hundred.
|
||||||
|
- New feature:
|
||||||
|
- The number of transfers required before replication stabilises is now displayed.
|
||||||
|
- 0.17.12: Skipped.
|
||||||
|
- 0.17.13
|
||||||
|
- Fixed: Document history is now displayed again.
|
||||||
|
- Reorganised: Many files have been refactored.
|
||||||
|
|
||||||
### 0.16.0
|
### 0.16.0
|
||||||
- Now hidden files need not be scanned. Changes will be detected automatically.
|
- Now hidden files need not be scanned. Changes will be detected automatically.
|
||||||
|
|||||||
Reference in New Issue
Block a user