mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-08 16:51:51 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ab0e90f6 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "obsidian-livesync",
|
"id": "obsidian-livesync",
|
||||||
"name": "Self-hosted LiveSync",
|
"name": "Self-hosted LiveSync",
|
||||||
"version": "0.7.0",
|
"version": "0.7.1",
|
||||||
"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.7.0",
|
"version": "0.7.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.7.0",
|
"version": "0.7.1",
|
||||||
"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.7.0",
|
"version": "0.7.1",
|
||||||
"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",
|
||||||
|
|||||||
@@ -875,9 +875,9 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
.setDesc("")
|
.setDesc("")
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
text.setPlaceholder("desktop-main")
|
text.setPlaceholder("desktop-main")
|
||||||
.setValue(this.plugin.settings.deviceAndVaultName)
|
.setValue(this.plugin.deviceAndVaultName)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.deviceAndVaultName = value;
|
this.plugin.deviceAndVaultName = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
// text.inputEl.setAttribute("type", "password");
|
// text.inputEl.setAttribute("type", "password");
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
$: {
|
$: {
|
||||||
deviceAndPlugins = {};
|
deviceAndPlugins = {};
|
||||||
for (const p of plugins) {
|
for (const p of plugins) {
|
||||||
if (p.deviceVaultName == plugin.settings.deviceAndVaultName && !showOwnPlugins) {
|
if (p.deviceVaultName == plugin.deviceAndVaultName && !showOwnPlugins) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(p.deviceVaultName in deviceAndPlugins)) {
|
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;
|
statusBar: HTMLElement;
|
||||||
statusBar2: HTMLElement;
|
statusBar2: HTMLElement;
|
||||||
suspended: boolean;
|
suspended: boolean;
|
||||||
|
deviceAndVaultName: string;
|
||||||
|
|
||||||
setInterval(handler: () => any, timeout?: number): number {
|
setInterval(handler: () => any, timeout?: number): number {
|
||||||
const timer = window.setInterval(handler, timeout);
|
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 = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||||
this.settings.workingEncrypt = this.settings.encrypt;
|
this.settings.workingEncrypt = this.settings.encrypt;
|
||||||
this.settings.workingPassphrase = this.settings.passphrase;
|
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() {
|
triggerRealizeSettingSyncMode() {
|
||||||
@@ -327,6 +337,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
|
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName();
|
||||||
|
|
||||||
|
localStorage.setItem(lsname, this.deviceAndVaultName || "");
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
this.localDatabase.settings = this.settings;
|
this.localDatabase.settings = this.settings;
|
||||||
this.triggerRealizeSettingSyncMode();
|
this.triggerRealizeSettingSyncMode();
|
||||||
@@ -1428,7 +1441,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
plugins[v.deviceVaultName].push(v);
|
plugins[v.deviceVaultName].push(v);
|
||||||
allPlugins[v._id] = v;
|
allPlugins[v._id] = v;
|
||||||
if (v.deviceVaultName == this.settings.deviceAndVaultName) {
|
if (v.deviceVaultName == this.deviceAndVaultName) {
|
||||||
thisDevicePlugins[v.manifest.id] = v;
|
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);
|
Logger("You have to encrypt the database to use plugin setting sync.", LOG_LEVEL.NOTICE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.settings.deviceAndVaultName) {
|
if (!this.deviceAndVaultName) {
|
||||||
Logger("You have to set your device and vault name.", LOG_LEVEL.NOTICE);
|
Logger("You have to set your device and vault name.", LOG_LEVEL.NOTICE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger("Sweeping plugins", logLevel);
|
Logger("Sweeping plugins", logLevel);
|
||||||
const db = this.localDatabase.localDatabase;
|
const db = this.localDatabase.localDatabase;
|
||||||
const oldDocs = await db.allDocs({
|
const oldDocs = await db.allDocs({
|
||||||
startkey: `ps:${this.settings.deviceAndVaultName}-`,
|
startkey: `ps:${this.deviceAndVaultName}-`,
|
||||||
endkey: `ps:${this.settings.deviceAndVaultName}.`,
|
endkey: `ps:${this.deviceAndVaultName}.`,
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
});
|
});
|
||||||
Logger("OLD DOCS.", LOG_LEVEL.VERBOSE);
|
Logger("OLD DOCS.", LOG_LEVEL.VERBOSE);
|
||||||
@@ -1476,9 +1489,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
mtime = (await adapter.stat(path + "/data.json")).mtime;
|
mtime = (await adapter.stat(path + "/data.json")).mtime;
|
||||||
}
|
}
|
||||||
const p: PluginDataEntry = {
|
const p: PluginDataEntry = {
|
||||||
_id: `ps:${this.settings.deviceAndVaultName}-${m.id}`,
|
_id: `ps:${this.deviceAndVaultName}-${m.id}`,
|
||||||
dataJson: pluginData["data.json"],
|
dataJson: pluginData["data.json"],
|
||||||
deviceVaultName: this.settings.deviceAndVaultName,
|
deviceVaultName: this.deviceAndVaultName,
|
||||||
mainJs: pluginData["main.js"],
|
mainJs: pluginData["main.js"],
|
||||||
styleCss: pluginData["styles.css"],
|
styleCss: pluginData["styles.css"],
|
||||||
manifest: m,
|
manifest: m,
|
||||||
|
|||||||
Reference in New Issue
Block a user