mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-02-19 18:48:46 +00:00
New feature:
- Bootup sequence prevention implemented. Touched the docs up:
This commit is contained in:
@@ -635,6 +635,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
c.addClass("op-warn");
|
||||
}
|
||||
}
|
||||
const hatchWarn = containerHatchEl.createEl("div", { text: `To stop the bootup sequence for fixing problems on databases, you can put redflag.md on top of your vault (Rebooting obsidian is required).` });
|
||||
hatchWarn.addClass("op-warn");
|
||||
const dropHistory = async (sendToServer: boolean) => {
|
||||
this.plugin.settings.liveSync = false;
|
||||
this.plugin.settings.periodicReplication = false;
|
||||
@@ -763,6 +765,10 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
})
|
||||
);
|
||||
|
||||
containerHatchEl.createEl("div", {
|
||||
text: sanitizeHTMLToDom(`Advanced buttons<br>
|
||||
These buttons could break your database easily.`),
|
||||
});
|
||||
new Setting(containerHatchEl)
|
||||
.setName("Reset remote database")
|
||||
.setDesc("Reset remote database, this affects only database. If you replicate again, remote database will restored by local database.")
|
||||
|
||||
58
src/main.ts
58
src/main.ts
@@ -1,8 +1,24 @@
|
||||
import { debounce, Notice, Plugin, TFile, addIcon, TFolder, normalizePath, TAbstractFile, Editor, MarkdownView, PluginManifest } from "obsidian";
|
||||
import { diff_match_patch } from "diff-match-patch";
|
||||
|
||||
import { EntryDoc, LoadedEntry, ObsidianLiveSyncSettings, diff_check_result, diff_result_leaf, EntryBody, PluginDataEntry, LOG_LEVEL, VER, PERIODIC_PLUGIN_SWEEP, DEFAULT_SETTINGS, PluginList, DevicePluginList, diff_result } from "./types";
|
||||
import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock } from "./utils";
|
||||
import {
|
||||
EntryDoc,
|
||||
LoadedEntry,
|
||||
ObsidianLiveSyncSettings,
|
||||
diff_check_result,
|
||||
diff_result_leaf,
|
||||
EntryBody,
|
||||
PluginDataEntry,
|
||||
LOG_LEVEL,
|
||||
VER,
|
||||
PERIODIC_PLUGIN_SWEEP,
|
||||
DEFAULT_SETTINGS,
|
||||
PluginList,
|
||||
DevicePluginList,
|
||||
diff_result,
|
||||
FLAGMD_REDFLAG,
|
||||
} from "./types";
|
||||
import { base64ToString, arrayBufferToBase64, base64ToArrayBuffer, isValidPath, versionNumberString2Number, id2path, path2id, runWithLock, shouldBeIgnored } from "./utils";
|
||||
import { Logger, setLogger } from "./logger";
|
||||
import { LocalPouchDB } from "./LocalPouchDB";
|
||||
import { LogDisplayModal } from "./LogDisplayModal";
|
||||
@@ -22,6 +38,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
this.registerInterval(timer);
|
||||
return timer;
|
||||
}
|
||||
isRedFlagRaised(): boolean {
|
||||
const redflag = this.app.vault.getAbstractFileByPath(normalizePath(FLAGMD_REDFLAG));
|
||||
if (redflag != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async onload() {
|
||||
setLogger(this.addLog.bind(this)); // Logger moved to global.
|
||||
Logger("loading plugin");
|
||||
@@ -90,7 +113,27 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
try {
|
||||
await this.initializeDatabase();
|
||||
if (this.isRedFlagRaised()) {
|
||||
this.settings.batchSave = false;
|
||||
this.settings.liveSync = false;
|
||||
this.settings.periodicReplication = false;
|
||||
this.settings.syncOnSave = false;
|
||||
this.settings.syncOnStart = false;
|
||||
this.settings.syncOnFileOpen = false;
|
||||
this.settings.autoSweepPlugins = false;
|
||||
this.settings.usePluginSync = false;
|
||||
this.settings.suspendFileWatching = true;
|
||||
await this.saveSettings();
|
||||
await this.openDatabase();
|
||||
const warningMessage = "The red flag is raised! The whole initialize steps are skipped, and any file changes are not captured.";
|
||||
Logger(warningMessage, LOG_LEVEL.NOTICE);
|
||||
this.setStatusBarText(warningMessage);
|
||||
} else {
|
||||
if (this.settings.suspendFileWatching) {
|
||||
Logger("'Suspend file watching' turned on. Are you sure this is what you intended? Every modification on the vault will be ignored.", LOG_LEVEL.NOTICE);
|
||||
}
|
||||
await this.initializeDatabase();
|
||||
}
|
||||
await this.realizeSettingSyncMode();
|
||||
this.registerWatchEvents();
|
||||
if (this.settings.syncOnStart) {
|
||||
@@ -470,6 +513,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
|
||||
async doc2storage_create(docEntry: EntryBody, force?: boolean) {
|
||||
const pathSrc = id2path(docEntry._id);
|
||||
if (shouldBeIgnored(pathSrc)) {
|
||||
return;
|
||||
}
|
||||
const doc = await this.localDatabase.getDBEntry(pathSrc, { rev: docEntry._rev });
|
||||
if (doc === false) return;
|
||||
const path = id2path(doc._id);
|
||||
@@ -527,6 +573,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
}
|
||||
async doc2storate_modify(docEntry: EntryBody, file: TFile, force?: boolean) {
|
||||
const pathSrc = id2path(docEntry._id);
|
||||
if (shouldBeIgnored(pathSrc)) {
|
||||
return;
|
||||
}
|
||||
if (docEntry._deleted) {
|
||||
//basically pass.
|
||||
//but if there're no docs left, delete file.
|
||||
@@ -1141,6 +1190,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
async updateIntoDB(file: TFile) {
|
||||
if (shouldBeIgnored(file.path)) {
|
||||
return;
|
||||
}
|
||||
await this.localDatabase.waitForGCComplete();
|
||||
let content = "";
|
||||
let datatype: "plain" | "newnote" = "newnote";
|
||||
|
||||
@@ -226,3 +226,5 @@ export interface PluginList {
|
||||
export interface DevicePluginList {
|
||||
[key: string]: PluginDataEntry;
|
||||
}
|
||||
|
||||
export const FLAGMD_REDFLAG = "redflag.md";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { normalizePath } from "obsidian";
|
||||
import { Logger } from "./logger";
|
||||
import { LOG_LEVEL } from "./types";
|
||||
import { FLAGMD_REDFLAG, LOG_LEVEL } from "./types";
|
||||
|
||||
export function arrayBufferToBase64(buffer: ArrayBuffer): Promise<string> {
|
||||
return new Promise((res) => {
|
||||
@@ -79,6 +79,13 @@ export function isValidPath(filename: string): boolean {
|
||||
return sx == filename;
|
||||
}
|
||||
|
||||
export function shouldBeIgnored(filename: string): boolean {
|
||||
if (filename == FLAGMD_REDFLAG) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function versionNumberString2Number(version: string): number {
|
||||
return version // "1.23.45"
|
||||
.split(".") // 1 23 45
|
||||
|
||||
Reference in New Issue
Block a user