mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-02-25 05:28:47 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
255e7bf828 | ||
|
|
6f9e7bbcf4 | ||
|
|
ce1c94a814 | ||
|
|
caf7934f28 | ||
|
|
31ab0e90f6 |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: vrtmrz
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-livesync",
|
||||
"name": "Self-hosted LiveSync",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.2",
|
||||
"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.",
|
||||
"author": "vorotamoroz",
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "obsidian-livesync",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-livesync",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"diff-match-patch": "^1.0.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-livesync",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.2",
|
||||
"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",
|
||||
"type": "module",
|
||||
|
||||
@@ -357,7 +357,7 @@ export class LocalPouchDB {
|
||||
Logger(childrens);
|
||||
}
|
||||
} catch (ex) {
|
||||
Logger(`Something went wrong on reading elements of ${obj._id} from database.`, LOG_LEVEL.NOTICE);
|
||||
Logger(`Something went wrong on reading elements of ${obj._id} from database:`, LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.VERBOSE);
|
||||
this.corruptedEntries[obj._id] = obj;
|
||||
return false;
|
||||
@@ -388,7 +388,7 @@ export class LocalPouchDB {
|
||||
Logger(`Missing document content!, could not read ${obj._id} from database.`, LOG_LEVEL.NOTICE);
|
||||
return false;
|
||||
}
|
||||
Logger(`Something went wrong on reading ${obj._id} from database.`, LOG_LEVEL.NOTICE);
|
||||
Logger(`Something went wrong on reading ${obj._id} from database:`, LOG_LEVEL.NOTICE);
|
||||
Logger(ex);
|
||||
}
|
||||
}
|
||||
@@ -594,7 +594,7 @@ export class LocalPouchDB {
|
||||
try {
|
||||
pieceData.data = await decrypt(pieceData.data, this.settings.passphrase);
|
||||
} catch (e) {
|
||||
Logger("Decode failed !");
|
||||
Logger("Decode failed!");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -667,8 +667,8 @@ export class LocalPouchDB {
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
Logger("ERROR ON SAVING LEAVES ");
|
||||
Logger(ex);
|
||||
Logger("ERROR ON SAVING LEAVES:", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.NOTICE);
|
||||
saved = false;
|
||||
}
|
||||
}
|
||||
@@ -822,7 +822,7 @@ export class LocalPouchDB {
|
||||
}
|
||||
const dbret = await connectRemoteCouchDB(uri, auth);
|
||||
if (typeof dbret === "string") {
|
||||
Logger(`could not connect to ${uri}:${dbret}`, LOG_LEVEL.NOTICE);
|
||||
Logger(`could not connect to ${uri}: ${dbret}`, LOG_LEVEL.NOTICE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -932,8 +932,8 @@ export class LocalPouchDB {
|
||||
}
|
||||
this.updateInfo();
|
||||
} catch (ex) {
|
||||
Logger("Replication callback error");
|
||||
Logger(ex);
|
||||
Logger("Replication callback error", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.NOTICE);
|
||||
}
|
||||
// re-connect to retry with original setting
|
||||
if (retrying) {
|
||||
@@ -1032,8 +1032,8 @@ export class LocalPouchDB {
|
||||
notice.setMessage(`Replication pulled:${e.docs_read}`);
|
||||
}
|
||||
} catch (ex) {
|
||||
Logger("Replication callback error");
|
||||
Logger(ex);
|
||||
Logger("Replication callback error", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.NOTICE);
|
||||
}
|
||||
});
|
||||
this.syncStatus = "COMPLETED";
|
||||
@@ -1046,7 +1046,8 @@ export class LocalPouchDB {
|
||||
} catch (ex) {
|
||||
this.syncStatus = "ERRORED";
|
||||
this.updateInfo();
|
||||
Logger("Pulling Replication error", LOG_LEVEL.NOTICE);
|
||||
Logger("Pulling Replication error:", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.NOTICE);
|
||||
this.cancelHandler(replicate);
|
||||
this.syncHandler = this.cancelHandler(this.syncHandler);
|
||||
if (notice != null) notice.hide();
|
||||
@@ -1087,7 +1088,8 @@ export class LocalPouchDB {
|
||||
Logger("Remote Database Destroyed", LOG_LEVEL.NOTICE);
|
||||
await this.tryCreateRemoteDatabase(setting);
|
||||
} catch (ex) {
|
||||
Logger("something happend on Remote Database Destory", LOG_LEVEL.NOTICE);
|
||||
Logger("Something happened on Remote Database Destory:", LOG_LEVEL.NOTICE);
|
||||
Logger(ex, LOG_LEVEL.NOTICE);
|
||||
}
|
||||
}
|
||||
async tryCreateRemoteDatabase(setting: ObsidianLiveSyncSettings) {
|
||||
|
||||
@@ -875,9 +875,9 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
.setDesc("")
|
||||
.addText((text) => {
|
||||
text.setPlaceholder("desktop-main")
|
||||
.setValue(this.plugin.settings.deviceAndVaultName)
|
||||
.setValue(this.plugin.deviceAndVaultName)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.deviceAndVaultName = value;
|
||||
this.plugin.deviceAndVaultName = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
// text.inputEl.setAttribute("type", "password");
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
$: {
|
||||
deviceAndPlugins = {};
|
||||
for (const p of plugins) {
|
||||
if (p.deviceVaultName == plugin.settings.deviceAndVaultName && !showOwnPlugins) {
|
||||
if (p.deviceVaultName == plugin.deviceAndVaultName && !showOwnPlugins) {
|
||||
continue;
|
||||
}
|
||||
if (!(p.deviceVaultName in deviceAndPlugins)) {
|
||||
|
||||
25
src/main.ts
25
src/main.ts
@@ -63,6 +63,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
statusBar: HTMLElement;
|
||||
statusBar2: HTMLElement;
|
||||
suspended: boolean;
|
||||
deviceAndVaultName: string;
|
||||
|
||||
setInterval(handler: () => any, timeout?: number): number {
|
||||
const timer = window.setInterval(handler, timeout);
|
||||
@@ -320,6 +321,15 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
this.settings.workingEncrypt = this.settings.encrypt;
|
||||
this.settings.workingPassphrase = this.settings.passphrase;
|
||||
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName();
|
||||
if (this.settings.deviceAndVaultName != "") {
|
||||
if (!localStorage.getItem(lsname)) {
|
||||
this.deviceAndVaultName = this.settings.deviceAndVaultName;
|
||||
localStorage.setItem(lsname, this.deviceAndVaultName);
|
||||
this.settings.deviceAndVaultName = "";
|
||||
}
|
||||
}
|
||||
this.deviceAndVaultName = localStorage.getItem(lsname) || "";
|
||||
}
|
||||
|
||||
triggerRealizeSettingSyncMode() {
|
||||
@@ -327,6 +337,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName();
|
||||
|
||||
localStorage.setItem(lsname, this.deviceAndVaultName || "");
|
||||
await this.saveData(this.settings);
|
||||
this.localDatabase.settings = this.settings;
|
||||
this.triggerRealizeSettingSyncMode();
|
||||
@@ -1428,7 +1441,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
}
|
||||
plugins[v.deviceVaultName].push(v);
|
||||
allPlugins[v._id] = v;
|
||||
if (v.deviceVaultName == this.settings.deviceAndVaultName) {
|
||||
if (v.deviceVaultName == this.deviceAndVaultName) {
|
||||
thisDevicePlugins[v.manifest.id] = v;
|
||||
}
|
||||
}
|
||||
@@ -1443,15 +1456,15 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
Logger("You have to encrypt the database to use plugin setting sync.", LOG_LEVEL.NOTICE);
|
||||
return;
|
||||
}
|
||||
if (!this.settings.deviceAndVaultName) {
|
||||
if (!this.deviceAndVaultName) {
|
||||
Logger("You have to set your device and vault name.", LOG_LEVEL.NOTICE);
|
||||
return;
|
||||
}
|
||||
Logger("Sweeping plugins", logLevel);
|
||||
const db = this.localDatabase.localDatabase;
|
||||
const oldDocs = await db.allDocs({
|
||||
startkey: `ps:${this.settings.deviceAndVaultName}-`,
|
||||
endkey: `ps:${this.settings.deviceAndVaultName}.`,
|
||||
startkey: `ps:${this.deviceAndVaultName}-`,
|
||||
endkey: `ps:${this.deviceAndVaultName}.`,
|
||||
include_docs: true,
|
||||
});
|
||||
Logger("OLD DOCS.", LOG_LEVEL.VERBOSE);
|
||||
@@ -1476,9 +1489,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
mtime = (await adapter.stat(path + "/data.json")).mtime;
|
||||
}
|
||||
const p: PluginDataEntry = {
|
||||
_id: `ps:${this.settings.deviceAndVaultName}-${m.id}`,
|
||||
_id: `ps:${this.deviceAndVaultName}-${m.id}`,
|
||||
dataJson: pluginData["data.json"],
|
||||
deviceVaultName: this.settings.deviceAndVaultName,
|
||||
deviceVaultName: this.deviceAndVaultName,
|
||||
mainJs: pluginData["main.js"],
|
||||
styleCss: pluginData["styles.css"],
|
||||
manifest: m,
|
||||
|
||||
Reference in New Issue
Block a user