mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-24 23:21:41 +00:00
New feature.
- Local database name can now be customized. - Buttons to back skip-patterns of Hidden file sync to default.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl } from "obsidian";
|
import { App, PluginSettingTab, Setting, sanitizeHTMLToDom, RequestUrlParam, requestUrl, TextAreaComponent } from "obsidian";
|
||||||
import { EntryDoc, LOG_LEVEL, RemoteDBSettings } from "./lib/src/types";
|
import { EntryDoc, LOG_LEVEL, RemoteDBSettings } from "./lib/src/types";
|
||||||
import { path2id, id2path } from "./utils";
|
import { path2id, id2path } from "./utils";
|
||||||
import { delay, runWithLock } from "./lib/src/utils";
|
import { delay, runWithLock } from "./lib/src/utils";
|
||||||
@@ -591,6 +591,31 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
text.inputEl.setAttribute("type", "number");
|
text.inputEl.setAttribute("type", "number");
|
||||||
});
|
});
|
||||||
|
let newDatabaseName = this.plugin.settings.additionalSuffixOfDatabaseName + "";
|
||||||
|
new Setting(containerLocalDatabaseEl)
|
||||||
|
.setName("Database suffix")
|
||||||
|
.setDesc("Set unique name for using same vault name on different directory.")
|
||||||
|
.addText((text) => {
|
||||||
|
text.setPlaceholder("")
|
||||||
|
.setValue(newDatabaseName)
|
||||||
|
.onChange((value) => {
|
||||||
|
newDatabaseName = value;
|
||||||
|
|
||||||
|
});
|
||||||
|
}).addButton((button) => {
|
||||||
|
button.setButtonText("Change")
|
||||||
|
.onClick(async () => {
|
||||||
|
if (this.plugin.settings.additionalSuffixOfDatabaseName == newDatabaseName) {
|
||||||
|
Logger("Suffix was not changed.", LOG_LEVEL.NOTICE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.plugin.settings.additionalSuffixOfDatabaseName = newDatabaseName;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
Logger("Suffix has been changed. Reopening database...", LOG_LEVEL.NOTICE);
|
||||||
|
await this.plugin.initializeDatabase();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
addScreenElement("10", containerLocalDatabaseEl);
|
addScreenElement("10", containerLocalDatabaseEl);
|
||||||
const containerGeneralSettingsEl = containerEl.createDiv();
|
const containerGeneralSettingsEl = containerEl.createDiv();
|
||||||
@@ -787,6 +812,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
);
|
);
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Scan hidden files periodicaly.")
|
.setName("Scan hidden files periodicaly.")
|
||||||
|
.setDesc("Seconds, zero to disable.")
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
text.setPlaceholder("")
|
text.setPlaceholder("")
|
||||||
.setValue(this.plugin.settings.syncInternalFilesInterval + "")
|
.setValue(this.plugin.settings.syncInternalFilesInterval + "")
|
||||||
@@ -800,12 +826,15 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
text.inputEl.setAttribute("type", "number");
|
text.inputEl.setAttribute("type", "number");
|
||||||
});
|
});
|
||||||
|
let skipPatternTextArea: TextAreaComponent = null;
|
||||||
|
const defaultSkipPattern = "\\/node_modules\\/, \\/\\.git\\/, \\/obsidian-livesync\\/";
|
||||||
|
const defaultSkipPatternXPlat = defaultSkipPattern + ",\\/workspace$";
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Skip patterns")
|
.setName("Skip patterns")
|
||||||
.setDesc(
|
.setDesc(
|
||||||
"Regular expression"
|
"Regular expression, If you use hidden file sync between desktop and mobile, adding `workspace$` is recommended."
|
||||||
)
|
)
|
||||||
.addTextArea((text) =>
|
.addTextArea((text) => {
|
||||||
text
|
text
|
||||||
.setValue(this.plugin.settings.syncInternalFilesIgnorePatterns)
|
.setValue(this.plugin.settings.syncInternalFilesIgnorePatterns)
|
||||||
.setPlaceholder("\\/node_modules\\/, \\/\\.git\\/")
|
.setPlaceholder("\\/node_modules\\/, \\/\\.git\\/")
|
||||||
@@ -813,7 +842,27 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.syncInternalFilesIgnorePatterns = value;
|
this.plugin.settings.syncInternalFilesIgnorePatterns = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
})
|
})
|
||||||
|
skipPatternTextArea = text;
|
||||||
|
return text;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
new Setting(containerSyncSettingEl)
|
||||||
|
.setName("Skip patterns defaults")
|
||||||
|
.addButton((button) => {
|
||||||
|
button.setButtonText("Default")
|
||||||
|
.onClick(async () => {
|
||||||
|
skipPatternTextArea.setValue(defaultSkipPattern);
|
||||||
|
this.plugin.settings.syncInternalFilesIgnorePatterns = defaultSkipPattern;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
}).addButton((button) => {
|
||||||
|
button.setButtonText("Cross-platform")
|
||||||
|
.onClick(async () => {
|
||||||
|
skipPatternTextArea.setValue(defaultSkipPatternXPlat);
|
||||||
|
this.plugin.settings.syncInternalFilesIgnorePatterns = defaultSkipPatternXPlat;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
new Setting(containerSyncSettingEl)
|
new Setting(containerSyncSettingEl)
|
||||||
.setName("Touch hidden files")
|
.setName("Touch hidden files")
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 1f67fb604c...1133f82732
23
src/main.ts
23
src/main.ts
@@ -189,6 +189,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
deviceAndVaultName: string;
|
deviceAndVaultName: string;
|
||||||
isMobile = false;
|
isMobile = false;
|
||||||
|
|
||||||
|
getVaultName(): string {
|
||||||
|
return this.app.vault.getName() + (this.settings?.additionalSuffixOfDatabaseName ? ("-" + this.settings.additionalSuffixOfDatabaseName) : "");
|
||||||
|
}
|
||||||
|
|
||||||
setInterval(handler: () => any, timeout?: number): number {
|
setInterval(handler: () => any, timeout?: number): number {
|
||||||
const timer = window.setInterval(handler, timeout);
|
const timer = window.setInterval(handler, timeout);
|
||||||
this.registerInterval(timer);
|
this.registerInterval(timer);
|
||||||
@@ -214,7 +218,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
async onload() {
|
async onload() {
|
||||||
setLogger(this.addLog.bind(this)); // Logger moved to global.
|
setLogger(this.addLog.bind(this)); // Logger moved to global.
|
||||||
Logger("loading plugin");
|
Logger("loading plugin");
|
||||||
const lsname = "obsidian-live-sync-ver" + this.app.vault.getName();
|
const lsname = "obsidian-live-sync-ver" + this.getVaultName();
|
||||||
const last_version = localStorage.getItem(lsname);
|
const last_version = localStorage.getItem(lsname);
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -296,6 +300,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
this.settings.autoSweepPlugins = false;
|
this.settings.autoSweepPlugins = false;
|
||||||
this.settings.usePluginSync = false;
|
this.settings.usePluginSync = false;
|
||||||
this.settings.suspendFileWatching = true;
|
this.settings.suspendFileWatching = true;
|
||||||
|
this.settings.syncInternalFiles = false;
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
await this.openDatabase();
|
await this.openDatabase();
|
||||||
const warningMessage = "The red flag is raised! The whole initialize steps are skipped, and any file changes are not captured.";
|
const warningMessage = "The red flag is raised! The whole initialize steps are skipped, and any file changes are not captured.";
|
||||||
@@ -555,7 +560,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
if (this.localDatabase != null) {
|
if (this.localDatabase != null) {
|
||||||
this.localDatabase.close();
|
this.localDatabase.close();
|
||||||
}
|
}
|
||||||
const vaultName = this.app.vault.getName();
|
const vaultName = this.getVaultName();
|
||||||
Logger("Open Database...");
|
Logger("Open Database...");
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const isMobile = this.app.isMobile;
|
const isMobile = this.app.isMobile;
|
||||||
@@ -582,7 +587,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
// So, use history is always enabled.
|
// So, use history is always enabled.
|
||||||
this.settings.useHistory = true;
|
this.settings.useHistory = true;
|
||||||
|
|
||||||
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName();
|
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.getVaultName();
|
||||||
if (this.settings.deviceAndVaultName != "") {
|
if (this.settings.deviceAndVaultName != "") {
|
||||||
if (!localStorage.getItem(lsname)) {
|
if (!localStorage.getItem(lsname)) {
|
||||||
this.deviceAndVaultName = this.settings.deviceAndVaultName;
|
this.deviceAndVaultName = this.settings.deviceAndVaultName;
|
||||||
@@ -598,7 +603,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.app.vault.getName();
|
const lsname = "obsidian-live-sync-vaultanddevicename-" + this.getVaultName();
|
||||||
|
|
||||||
localStorage.setItem(lsname, this.deviceAndVaultName || "");
|
localStorage.setItem(lsname, this.deviceAndVaultName || "");
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
@@ -861,7 +866,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
if (this.settings && !this.settings.showVerboseLog && level == LOG_LEVEL.VERBOSE) {
|
if (this.settings && !this.settings.showVerboseLog && level == LOG_LEVEL.VERBOSE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const valutName = this.app.vault.getName();
|
const valutName = this.getVaultName();
|
||||||
const timestamp = new Date().toLocaleString();
|
const timestamp = new Date().toLocaleString();
|
||||||
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;
|
||||||
@@ -1115,11 +1120,11 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
|
|
||||||
saveQueuedFiles() {
|
saveQueuedFiles() {
|
||||||
const saveData = JSON.stringify(this.queuedFiles.filter((e) => !e.done).map((e) => e.entry._id));
|
const saveData = JSON.stringify(this.queuedFiles.filter((e) => !e.done).map((e) => e.entry._id));
|
||||||
const lsname = "obsidian-livesync-queuefiles-" + this.app.vault.getName();
|
const lsname = "obsidian-livesync-queuefiles-" + this.getVaultName();
|
||||||
localStorage.setItem(lsname, saveData);
|
localStorage.setItem(lsname, saveData);
|
||||||
}
|
}
|
||||||
async loadQueuedFiles() {
|
async loadQueuedFiles() {
|
||||||
const lsname = "obsidian-livesync-queuefiles-" + this.app.vault.getName();
|
const lsname = "obsidian-livesync-queuefiles-" + this.getVaultName();
|
||||||
const ids = JSON.parse(localStorage.getItem(lsname) || "[]") as string[];
|
const ids = JSON.parse(localStorage.getItem(lsname) || "[]") as string[];
|
||||||
const ret = await this.localDatabase.localDatabase.allDocs({ keys: ids, include_docs: true });
|
const ret = await this.localDatabase.localDatabase.allDocs({ keys: ids, include_docs: true });
|
||||||
for (const doc of ret.rows) {
|
for (const doc of ret.rows) {
|
||||||
@@ -2226,7 +2231,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.localDatabase.putDBEntry(saveData, true);
|
await this.localDatabase.putDBEntry(saveData, true);
|
||||||
Logger(`internal files STORAGE --> DB:${file.path}: Done`);
|
Logger(`STORAGE --> DB:${file.path}: (hidden) Done`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2330,7 +2335,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async filterTargetFiles(files: InternalFileInfo[], targetFiles: string[] | false = false) {
|
filterTargetFiles(files: InternalFileInfo[], targetFiles: string[] | false = false) {
|
||||||
const ignorePatterns = this.settings.syncInternalFilesIgnorePatterns.toLocaleLowerCase()
|
const ignorePatterns = this.settings.syncInternalFilesIgnorePatterns.toLocaleLowerCase()
|
||||||
.replace(/\n| /g, "")
|
.replace(/\n| /g, "")
|
||||||
.split(",").filter(e => e).map(e => new RegExp(e));
|
.split(",").filter(e => e).map(e => new RegExp(e));
|
||||||
|
|||||||
Reference in New Issue
Block a user