mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-13 17:55:56 +00:00
Mini fix:
fixed the problem that plugin sync timing and notification.
This commit is contained in:
54
main.ts
54
main.ts
@@ -1914,7 +1914,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
// suspend all temporary.
|
// suspend all temporary.
|
||||||
if (this.suspended) return;
|
if (this.suspended) return;
|
||||||
if (this.settings.autoSweepPlugins) {
|
if (this.settings.autoSweepPlugins) {
|
||||||
await this.sweepPlugin();
|
await this.sweepPlugin(false);
|
||||||
}
|
}
|
||||||
if (this.settings.liveSync) {
|
if (this.settings.liveSync) {
|
||||||
await this.localDatabase.openReplication(this.settings, true, false, this.parseReplicationResult);
|
await this.localDatabase.openReplication(this.settings, true, false, this.parseReplicationResult);
|
||||||
@@ -2294,7 +2294,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
(async () => await this.checkPluginUpdate())();
|
(async () => await this.checkPluginUpdate())();
|
||||||
}
|
}
|
||||||
async checkPluginUpdate() {
|
async checkPluginUpdate() {
|
||||||
await this.sweepPlugin();
|
await this.sweepPlugin(false);
|
||||||
const { allPlugins, thisDevicePlugins } = await this.getPluginList();
|
const { allPlugins, thisDevicePlugins } = await this.getPluginList();
|
||||||
const arrPlugins = Object.values(allPlugins);
|
const arrPlugins = Object.values(allPlugins);
|
||||||
for (const plugin of arrPlugins) {
|
for (const plugin of arrPlugins) {
|
||||||
@@ -2350,8 +2350,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async periodicPluginSweep() {
|
async periodicPluginSweep() {
|
||||||
console.log("periodic p s ");
|
await this.sweepPlugin(false);
|
||||||
await this.sweepPlugin();
|
|
||||||
}
|
}
|
||||||
async realizeSettingSyncMode() {
|
async realizeSettingSyncMode() {
|
||||||
this.localDatabase.closeReplication();
|
this.localDatabase.closeReplication();
|
||||||
@@ -2361,14 +2360,14 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
// disable all sync temporary.
|
// disable all sync temporary.
|
||||||
if (this.suspended) return;
|
if (this.suspended) return;
|
||||||
if (this.settings.autoSweepPlugins) {
|
if (this.settings.autoSweepPlugins) {
|
||||||
await this.sweepPlugin();
|
await this.sweepPlugin(false);
|
||||||
}
|
}
|
||||||
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();
|
this.refreshStatusText();
|
||||||
}
|
}
|
||||||
this.setPeriodicSync();
|
this.setPeriodicSync();
|
||||||
this.periodicPluginSweep();
|
this.setPluginSweep();
|
||||||
}
|
}
|
||||||
lastMessage = "";
|
lastMessage = "";
|
||||||
refreshStatusText() {
|
refreshStatusText() {
|
||||||
@@ -2423,7 +2422,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
await this.applyBatchChange();
|
await this.applyBatchChange();
|
||||||
if (this.settings.autoSweepPlugins) {
|
if (this.settings.autoSweepPlugins) {
|
||||||
await this.sweepPlugin();
|
await this.sweepPlugin(false);
|
||||||
}
|
}
|
||||||
this.localDatabase.openReplication(this.settings, false, showMessage, this.parseReplicationResult);
|
this.localDatabase.openReplication(this.settings, false, showMessage, this.parseReplicationResult);
|
||||||
}
|
}
|
||||||
@@ -2434,7 +2433,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
async replicateAllToServer(showingNotice?: boolean) {
|
async replicateAllToServer(showingNotice?: boolean) {
|
||||||
if (this.settings.autoSweepPlugins) {
|
if (this.settings.autoSweepPlugins) {
|
||||||
await this.sweepPlugin();
|
await this.sweepPlugin(showingNotice);
|
||||||
}
|
}
|
||||||
return await this.localDatabase.replicateAllToServer(this.settings, showingNotice);
|
return await this.localDatabase.replicateAllToServer(this.settings, showingNotice);
|
||||||
}
|
}
|
||||||
@@ -2847,12 +2846,17 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
return { plugins, allPlugins, thisDevicePlugins };
|
return { plugins, allPlugins, thisDevicePlugins };
|
||||||
}
|
}
|
||||||
async sweepPlugin() {
|
async sweepPlugin(showMessage = false) {
|
||||||
if (this.settings.deviceAndVaultName.trim() == "") {
|
const logLevel = showMessage ? LOG_LEVEL.NOTICE : LOG_LEVEL.INFO;
|
||||||
Logger("Set your device and vault name in the setting dialog.", LOG_LEVEL.NOTICE);
|
if (!this.settings.encrypt) {
|
||||||
|
Logger("You have to encrypt the database to use plugin setting sync.", LOG_LEVEL.NOTICE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger("Sweeping plugins", LOG_LEVEL.VERBOSE);
|
if (!this.settings.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 db = this.localDatabase.localDatabase;
|
||||||
let oldDocs = await db.allDocs({ startkey: `ps:${this.settings.deviceAndVaultName}-`, endkey: `ps:${this.settings.deviceAndVaultName}.`, include_docs: true });
|
let oldDocs = await db.allDocs({ startkey: `ps:${this.settings.deviceAndVaultName}-`, endkey: `ps:${this.settings.deviceAndVaultName}.`, include_docs: true });
|
||||||
Logger("OLD DOCS.", LOG_LEVEL.VERBOSE);
|
Logger("OLD DOCS.", LOG_LEVEL.VERBOSE);
|
||||||
@@ -2909,7 +2913,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
await this.localDatabase.putDBEntry(d);
|
await this.localDatabase.putDBEntry(d);
|
||||||
oldDocs.rows = oldDocs.rows.filter((e) => e.id != d._id);
|
oldDocs.rows = oldDocs.rows.filter((e) => e.id != d._id);
|
||||||
Logger(`Plugin saved:${m.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Plugin saved:${m.name}`, logLevel);
|
||||||
//remove saved plugin data.
|
//remove saved plugin data.
|
||||||
}
|
}
|
||||||
Logger(`Deleting old plugins`, LOG_LEVEL.VERBOSE);
|
Logger(`Deleting old plugins`, LOG_LEVEL.VERBOSE);
|
||||||
@@ -2918,7 +2922,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
return e.doc;
|
return e.doc;
|
||||||
});
|
});
|
||||||
await db.bulkDocs(delDocs);
|
await db.bulkDocs(delDocs);
|
||||||
Logger(`Sweep plugin done.`, LOG_LEVEL.VERBOSE);
|
Logger(`Sweep plugin done.`, logLevel);
|
||||||
}
|
}
|
||||||
async applyPluginData(plugin: PluginDataEntry) {
|
async applyPluginData(plugin: PluginDataEntry) {
|
||||||
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
const pluginTargetFolderPath = normalizePath(plugin.manifest.dir) + "/";
|
||||||
@@ -3797,8 +3801,8 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
|
|
||||||
updateDisabledOfDeviceAndVaultName();
|
updateDisabledOfDeviceAndVaultName();
|
||||||
const sweepPlugin = async () => {
|
const sweepPlugin = async (showMessage: boolean) => {
|
||||||
await this.plugin.sweepPlugin();
|
await this.plugin.sweepPlugin(showMessage);
|
||||||
updatePluginPane();
|
updatePluginPane();
|
||||||
};
|
};
|
||||||
const updatePluginPane = async () => {
|
const updatePluginPane = async () => {
|
||||||
@@ -3887,7 +3891,7 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
Logger(`Updating plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Updating plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
await this.plugin.applyPluginData(plugin);
|
await this.plugin.applyPluginData(plugin);
|
||||||
Logger(`Setting done:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Setting done:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
await sweepPlugin();
|
await sweepPlugin(true);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
pluginConfig.querySelectorAll(".apply-plugin-version").forEach((e) =>
|
pluginConfig.querySelectorAll(".apply-plugin-version").forEach((e) =>
|
||||||
@@ -3896,7 +3900,7 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
Logger(`Setting plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Setting plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
await this.plugin.applyPlugin(plugin);
|
await this.plugin.applyPlugin(plugin);
|
||||||
Logger(`Updated plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Updated plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
await sweepPlugin();
|
await sweepPlugin(true);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
pluginConfig.querySelectorAll(".sls-plugin-apply-all-newer-plugin").forEach((e) =>
|
pluginConfig.querySelectorAll(".sls-plugin-apply-all-newer-plugin").forEach((e) =>
|
||||||
@@ -3930,7 +3934,7 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
Logger(`Updated plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Updated plugin:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await sweepPlugin();
|
await sweepPlugin(true);
|
||||||
Logger("Done", LOG_LEVEL.NOTICE);
|
Logger("Done", LOG_LEVEL.NOTICE);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -3957,7 +3961,7 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
Logger(`Setting done:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
Logger(`Setting done:${plugin.manifest.name}`, LOG_LEVEL.NOTICE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await sweepPlugin();
|
await sweepPlugin(true);
|
||||||
Logger("Done", LOG_LEVEL.NOTICE);
|
Logger("Done", LOG_LEVEL.NOTICE);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -4001,16 +4005,8 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
.setButtonText("Save plugins")
|
.setButtonText("Save plugins")
|
||||||
.setDisabled(false)
|
.setDisabled(false)
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
if (!this.plugin.settings.encrypt) {
|
|
||||||
Logger("You have to encrypt the database to use plugin setting sync.", LOG_LEVEL.NOTICE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.plugin.settings.deviceAndVaultName) {
|
|
||||||
Logger("You have to set your device and vault name.", LOG_LEVEL.NOTICE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Logger("Save plugins.", LOG_LEVEL.NOTICE);
|
Logger("Save plugins.", LOG_LEVEL.NOTICE);
|
||||||
await sweepPlugin();
|
await sweepPlugin(true);
|
||||||
Logger("All plugins have been saved.", LOG_LEVEL.NOTICE);
|
Logger("All plugins have been saved.", LOG_LEVEL.NOTICE);
|
||||||
await this.plugin.replicate(true);
|
await this.plugin.replicate(true);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "obsidian-livesync",
|
"id": "obsidian-livesync",
|
||||||
"name": "Self-hosted LiveSync",
|
"name": "Self-hosted LiveSync",
|
||||||
"version": "0.1.25",
|
"version": "0.1.26",
|
||||||
"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",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "obsidian-livesync",
|
"name": "obsidian-livesync",
|
||||||
"version": "0.1.25",
|
"version": "0.1.26",
|
||||||
"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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user