1
0
mirror of https://github.com/vrtmrz/obsidian-livesync.git synced 2025-03-03 15:32:25 +02:00

fixed some base on awsome advices.

- do not show too frequent message.
- fixing code mistake
This commit is contained in:
vrtmrz 2021-10-17 11:06:25 +09:00
parent f3f0639d95
commit 57187a0926
5 changed files with 22 additions and 3688 deletions

4
.gitignore vendored
View File

@ -7,8 +7,8 @@ node_modules
package-lock.json package-lock.json
# build # build
# main.js main.js
*.js.map *.js.map
# obsidian # obsidian
data.json data.json

3670
main.js

File diff suppressed because one or more lines are too long

32
main.ts
View File

@ -342,7 +342,7 @@ class LocalPouchDB {
// console.log(nleafid); // console.log(nleafid);
let pieceData = await this.localDatabase.get<EntryLeaf>(nleafid); let pieceData = await this.localDatabase.get<EntryLeaf>(nleafid);
if (pieceData.type == "leaf" && pieceData.data == piece) { if (pieceData.type == "leaf" && pieceData.data == piece) {
this.addLog("hashe:data exists."); this.addLog("hash:data exists.");
leafid = nleafid; leafid = nleafid;
needMake = false; needMake = false;
tryNextHash = false; tryNextHash = false;
@ -425,7 +425,7 @@ class LocalPouchDB {
password: setting.couchDB_PASSWORD, password: setting.couchDB_PASSWORD,
}; };
if (this.syncHandler != null) { if (this.syncHandler != null) {
this.addLog("Another replication running.", true); this.addLog("Another replication running.");
return false; return false;
} }
let dbret = await connectRemoteCouchDB(uri, auth); let dbret = await connectRemoteCouchDB(uri, auth);
@ -601,6 +601,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
this.addLog("loading plugin"); this.addLog("loading plugin");
await this.openDatabase(); await this.openDatabase();
await this.loadSettings(); await this.loadSettings();
addIcon( addIcon(
"replicate", "replicate",
`<g transform="matrix(1.15 0 0 1.15 -8.31 -9.52)" fill="currentColor" fill-rule="evenodd"> `<g transform="matrix(1.15 0 0 1.15 -8.31 -9.52)" fill="currentColor" fill-rule="evenodd">
@ -640,13 +641,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
this.addSettingTab(new ObsidianLiveSyncSettingTab(this.app, this)); this.addSettingTab(new ObsidianLiveSyncSettingTab(this.app, this));
setTimeout(async () => { this.app.workspace.onLayoutReady(async () => {
await this.initializeDatabase(); await this.initializeDatabase();
this.realizeSettingSyncMode(); this.realizeSettingSyncMode();
if (this.settings.syncOnStart) { if (this.settings.syncOnStart) {
await this.replicate(false); await this.replicate(false);
} }
}, 100); });
// when in mobile, too long suspended , connection won't back if setting retry:true // when in mobile, too long suspended , connection won't back if setting retry:true
this.registerInterval( this.registerInterval(
@ -662,7 +663,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
this.watchWindowVisiblity = this.watchWindowVisiblity.bind(this); this.watchWindowVisiblity = this.watchWindowVisiblity.bind(this);
window.addEventListener("visibilitychange", this.watchWindowVisiblity); window.addEventListener("visibilitychange", this.watchWindowVisiblity);
} }
onunload() { onunload() {
if (this.gcTimerHandler != null) { if (this.gcTimerHandler != null) {
clearTimeout(this.gcTimerHandler); clearTimeout(this.gcTimerHandler);
@ -971,7 +971,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
let entry = v as TFile & TFolder; let entry = v as TFile & TFolder;
if (entry.children) { if (entry.children) {
await this.deleteFolderOnDB(entry); await this.deleteFolderOnDB(entry);
this.app.vault.delete(entry); await this.app.vault.delete(entry);
} else { } else {
await this.deleteFromDB(entry); await this.deleteFromDB(entry);
} }
@ -1418,6 +1418,18 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
//await this.test(); //await this.test();
}) })
); );
new Setting(containerEl)
.setName("Re-init")
.addButton((button) =>
button
.setButtonText("Init Database again")
.setDisabled(false)
.onClick(async () => {
await this.plugin.resetLocalDatabase();
await this.plugin.initializeDatabase();
})
);
new Setting(containerEl) new Setting(containerEl)
.setName("Garbage Collect") .setName("Garbage Collect")
.addButton((button) => .addButton((button) =>
@ -1429,14 +1441,6 @@ class ObsidianLiveSyncSettingTab extends PluginSettingTab {
//await this.test(); //await this.test();
}) })
) )
.addButton((button) =>
button
.setButtonText("Reset local files")
.setDisabled(false)
.onClick(async () => {
//await this.test();
})
);
new Setting(containerEl).setName("Remote Database Operations").addButton((button) => new Setting(containerEl).setName("Remote Database Operations").addButton((button) =>
button button
.setButtonText("Reset remote database") .setButtonText("Reset remote database")

View File

@ -1,7 +1,7 @@
{ {
"id": "obsidian-livesync", "id": "obsidian-livesync",
"name": "Obsidian Live sync", "name": "Obsidian Live sync",
"version": "0.0.8", "version": "0.0.9",
"minAppVersion": "0.9.12", "minAppVersion": "0.9.12",
"description": "obsidian Live synchronization plugin.", "description": "obsidian Live synchronization plugin.",
"author": "vorotamoroz", "author": "vorotamoroz",

View File

@ -1,6 +1,6 @@
{ {
"name": "obsidian-livesync", "name": "obsidian-livesync",
"version": "0.0.8", "version": "0.0.9",
"description": "obsidian Live synchronization plugin.", "description": "obsidian Live synchronization plugin.",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {