mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-13 01:35:57 +00:00
- Rename methods for automatic binging checking.
- Add automatic binging checks.
This commit is contained in:
@@ -411,7 +411,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
get useSyncPluginEtc() {
|
||||
return this.plugin.settings.usePluginEtc;
|
||||
}
|
||||
_isThisModuleEnabled() {
|
||||
isThisModuleEnabled() {
|
||||
return this.plugin.settings.usePluginSync;
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
|
||||
pluginList: IPluginDataExDisplay[] = [];
|
||||
showPluginSyncModal() {
|
||||
if (!this._isThisModuleEnabled()) {
|
||||
if (!this.isThisModuleEnabled()) {
|
||||
return;
|
||||
}
|
||||
if (this.pluginDialog) {
|
||||
@@ -492,7 +492,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
return this.getFileCategory(filePath) != "";
|
||||
}
|
||||
private async _everyOnDatabaseInitialized(showNotice: boolean) {
|
||||
if (!this._isThisModuleEnabled()) return true;
|
||||
if (!this.isThisModuleEnabled()) return true;
|
||||
try {
|
||||
this._log("Scanning customizations...");
|
||||
await this.scanAllConfigFiles(showNotice);
|
||||
@@ -504,7 +504,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
return true;
|
||||
}
|
||||
async _everyBeforeReplicate(showNotice: boolean) {
|
||||
if (!this._isThisModuleEnabled()) return true;
|
||||
if (!this.isThisModuleEnabled()) return true;
|
||||
if (this.settings.autoSweepPlugins) {
|
||||
await this.scanAllConfigFiles(showNotice);
|
||||
return true;
|
||||
@@ -512,7 +512,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
return true;
|
||||
}
|
||||
async _everyOnResumeProcess(): Promise<boolean> {
|
||||
if (!this._isThisModuleEnabled()) return true;
|
||||
if (!this.isThisModuleEnabled()) return true;
|
||||
if (this._isMainSuspended()) {
|
||||
return true;
|
||||
}
|
||||
@@ -528,7 +528,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
}
|
||||
_everyAfterResumeProcess(): Promise<boolean> {
|
||||
const q = activeDocument.querySelector(`.livesync-ribbon-showcustom`);
|
||||
q?.toggleClass("sls-hidden", !this._isThisModuleEnabled());
|
||||
q?.toggleClass("sls-hidden", !this.isThisModuleEnabled());
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
async reloadPluginList(showMessage: boolean) {
|
||||
@@ -870,7 +870,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
}
|
||||
|
||||
async updatePluginList(showMessage: boolean, updatedDocumentPath?: FilePathWithPrefix): Promise<void> {
|
||||
if (!this._isThisModuleEnabled()) {
|
||||
if (!this.isThisModuleEnabled()) {
|
||||
this.pluginScanProcessor.clearQueue();
|
||||
this.pluginList = [];
|
||||
pluginList.set(this.pluginList);
|
||||
@@ -1168,13 +1168,13 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
}
|
||||
async _anyModuleParsedReplicationResultItem(docs: PouchDB.Core.ExistingDocument<EntryDoc>) {
|
||||
if (!docs._id.startsWith(ICXHeader)) return false;
|
||||
if (this._isThisModuleEnabled()) {
|
||||
if (this.isThisModuleEnabled()) {
|
||||
await this.updatePluginList(
|
||||
false,
|
||||
(docs as AnyEntry).path ? (docs as AnyEntry).path : this.getPath(docs as AnyEntry)
|
||||
);
|
||||
}
|
||||
if (this._isThisModuleEnabled() && this.plugin.settings.notifyPluginOrSettingUpdated) {
|
||||
if (this.isThisModuleEnabled() && this.plugin.settings.notifyPluginOrSettingUpdated) {
|
||||
if (!this.pluginDialog || (this.pluginDialog && !this.pluginDialog.isOpened())) {
|
||||
const fragment = createFragment((doc) => {
|
||||
doc.createEl("span", undefined, (a) => {
|
||||
@@ -1218,7 +1218,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
this.periodicPluginSweepProcessor?.disable();
|
||||
if (!this._isMainReady) return true;
|
||||
if (!this._isMainSuspended()) return true;
|
||||
if (!this._isThisModuleEnabled()) return true;
|
||||
if (!this.isThisModuleEnabled()) return true;
|
||||
if (this.settings.autoSweepPlugins) {
|
||||
await this.scanAllConfigFiles(false);
|
||||
}
|
||||
@@ -1504,7 +1504,7 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
async watchVaultRawEventsAsync(path: FilePath) {
|
||||
if (!this._isMainReady) return false;
|
||||
if (this._isMainSuspended()) return false;
|
||||
if (!this._isThisModuleEnabled()) return false;
|
||||
if (!this.isThisModuleEnabled()) return false;
|
||||
// if (!this.isTargetPath(path)) return false;
|
||||
const stat = await this.plugin.storageAccess.statHidden(path);
|
||||
// Make sure that target is a file.
|
||||
@@ -1686,10 +1686,10 @@ export class ConfigSync extends LiveSyncCommands {
|
||||
enableFetch?: boolean;
|
||||
enableOverwrite?: boolean;
|
||||
}): Promise<boolean> {
|
||||
await this._askHiddenFileConfiguration(opt);
|
||||
await this.__askHiddenFileConfiguration(opt);
|
||||
return true;
|
||||
}
|
||||
async _askHiddenFileConfiguration(opt: { enableFetch?: boolean; enableOverwrite?: boolean }) {
|
||||
private async __askHiddenFileConfiguration(opt: { enableFetch?: boolean; enableOverwrite?: boolean }) {
|
||||
const message = `Would you like to enable **Customization sync**?
|
||||
|
||||
> [!DETAILS]-
|
||||
|
||||
@@ -81,13 +81,13 @@ function getComparingMTime(
|
||||
}
|
||||
|
||||
export class HiddenFileSync extends LiveSyncCommands {
|
||||
_isThisModuleEnabled() {
|
||||
isThisModuleEnabled() {
|
||||
return this.plugin.settings.syncInternalFiles;
|
||||
}
|
||||
|
||||
periodicInternalFileScanProcessor: PeriodicProcessor = new PeriodicProcessor(
|
||||
this.plugin,
|
||||
async () => this._isThisModuleEnabled() && this._isDatabaseReady() && (await this.scanAllStorageChanges(false))
|
||||
async () => this.isThisModuleEnabled() && this._isDatabaseReady() && (await this.scanAllStorageChanges(false))
|
||||
);
|
||||
|
||||
get kvDB() {
|
||||
@@ -151,7 +151,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
this._fileInfoLastProcessed = await autosaveCache(this.kvDB, "hidden-file-lastProcessed");
|
||||
this._databaseInfoLastProcessed = await autosaveCache(this.kvDB, "hidden-file-lastProcessed-database");
|
||||
this._fileInfoLastKnown = await autosaveCache(this.kvDB, "hidden-file-lastKnown");
|
||||
if (this._isThisModuleEnabled()) {
|
||||
if (this.isThisModuleEnabled()) {
|
||||
if (this._fileInfoLastProcessed.size == 0 && this._fileInfoLastProcessed.size == 0) {
|
||||
this._log(`No cache found. Performing startup scan.`, LOG_LEVEL_VERBOSE);
|
||||
await this.performStartupScan(true);
|
||||
@@ -163,7 +163,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
}
|
||||
async _everyBeforeReplicate(showNotice: boolean) {
|
||||
if (
|
||||
this._isThisModuleEnabled() &&
|
||||
this.isThisModuleEnabled() &&
|
||||
this._isDatabaseReady() &&
|
||||
this.settings.syncInternalFilesBeforeReplication &&
|
||||
!this.settings.watchInternalFileChanges
|
||||
@@ -200,7 +200,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
isReady() {
|
||||
if (!this._isMainReady) return false;
|
||||
if (this._isMainSuspended()) return false;
|
||||
if (!this._isThisModuleEnabled()) return false;
|
||||
if (!this.isThisModuleEnabled()) return false;
|
||||
return true;
|
||||
}
|
||||
shouldSkipFile = [] as FilePathWithPrefixLC[];
|
||||
@@ -212,11 +212,11 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
async _everyOnResumeProcess(): Promise<boolean> {
|
||||
this.periodicInternalFileScanProcessor?.disable();
|
||||
if (this._isMainSuspended()) return true;
|
||||
if (this._isThisModuleEnabled()) {
|
||||
if (this.isThisModuleEnabled()) {
|
||||
await this.performStartupScan(false);
|
||||
}
|
||||
this.periodicInternalFileScanProcessor.enable(
|
||||
this._isThisModuleEnabled() && this.settings.syncInternalFilesInterval
|
||||
this.isThisModuleEnabled() && this.settings.syncInternalFilesInterval
|
||||
? this.settings.syncInternalFilesInterval * 1000
|
||||
: 0
|
||||
);
|
||||
@@ -228,7 +228,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
if (this._isMainSuspended()) return Promise.resolve(true);
|
||||
if (!this.services.appLifecycle.isReady()) return Promise.resolve(true);
|
||||
this.periodicInternalFileScanProcessor.enable(
|
||||
this._isThisModuleEnabled() && this.settings.syncInternalFilesInterval
|
||||
this.isThisModuleEnabled() && this.settings.syncInternalFilesInterval
|
||||
? this.settings.syncInternalFilesInterval * 1000
|
||||
: 0
|
||||
);
|
||||
@@ -256,7 +256,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
||||
|
||||
async _anyProcessOptionalSyncFiles(doc: LoadedEntry): Promise<boolean> {
|
||||
if (isInternalMetadata(doc._id)) {
|
||||
if (this._isThisModuleEnabled()) {
|
||||
if (this.isThisModuleEnabled()) {
|
||||
//system file
|
||||
const filename = getPath(doc);
|
||||
if (await this.services.vault.isTargetFile(filename)) {
|
||||
@@ -1492,7 +1492,7 @@ Offline Changed files: ${files.length}`;
|
||||
}
|
||||
const deleted = metaOnDB.deleted || metaOnDB._deleted || false;
|
||||
if (deleted) {
|
||||
const result = await this._deleteFile(storageFilePath);
|
||||
const result = await this.__deleteFile(storageFilePath);
|
||||
if (result == "OK") {
|
||||
this.updateLastProcessedDeletion(storageFilePath, metaOnDB);
|
||||
return true;
|
||||
@@ -1506,7 +1506,7 @@ Offline Changed files: ${files.length}`;
|
||||
if (fileOnDB === false) {
|
||||
throw new Error(`Failed to read file from database:${storageFilePath}`);
|
||||
}
|
||||
const resultStat = await this._writeFile(storageFilePath, fileOnDB, force);
|
||||
const resultStat = await this.__writeFile(storageFilePath, fileOnDB, force);
|
||||
if (resultStat) {
|
||||
this.updateLastProcessed(storageFilePath, metaOnDB, resultStat);
|
||||
this.queueNotification(storageFilePath);
|
||||
@@ -1539,7 +1539,7 @@ Offline Changed files: ${files.length}`;
|
||||
}
|
||||
}
|
||||
|
||||
async _writeFile(storageFilePath: FilePath, fileOnDB: LoadedEntry, force: boolean): Promise<false | UXStat> {
|
||||
async __writeFile(storageFilePath: FilePath, fileOnDB: LoadedEntry, force: boolean): Promise<false | UXStat> {
|
||||
try {
|
||||
const statBefore = await this.plugin.storageAccess.statHidden(storageFilePath);
|
||||
const isExist = statBefore != null;
|
||||
@@ -1578,7 +1578,7 @@ Offline Changed files: ${files.length}`;
|
||||
}
|
||||
}
|
||||
|
||||
async _deleteFile(storageFilePath: FilePath): Promise<false | "OK" | "ALREADY"> {
|
||||
async __deleteFile(storageFilePath: FilePath): Promise<false | "OK" | "ALREADY"> {
|
||||
const result = await this.__removeFile(storageFilePath);
|
||||
if (result === false) {
|
||||
this._log(`STORAGE <x- DB: ${storageFilePath}: deleting (hidden) Failed`);
|
||||
@@ -1596,10 +1596,10 @@ Offline Changed files: ${files.length}`;
|
||||
// <-- Database To Storage Functions
|
||||
|
||||
private async _allAskUsingOptionalSyncFeature(opt: { enableFetch?: boolean; enableOverwrite?: boolean }) {
|
||||
await this._askHiddenFileConfiguration(opt);
|
||||
await this.__askHiddenFileConfiguration(opt);
|
||||
return true;
|
||||
}
|
||||
async _askHiddenFileConfiguration(opt: { enableFetch?: boolean; enableOverwrite?: boolean }) {
|
||||
private async __askHiddenFileConfiguration(opt: { enableFetch?: boolean; enableOverwrite?: boolean }) {
|
||||
const messageFetch = `${opt.enableFetch ? `> - Fetch: Use the files stored from other devices. Choose this option if you have already configured hidden file synchronization on those devices and wish to accept their files.\n` : ""}`;
|
||||
const messageOverwrite = `${opt.enableOverwrite ? `> - Overwrite: Use the files from this device. Select this option if you want to overwrite the files stored on other devices.\n` : ""}`;
|
||||
const messageMerge = `> - Merge: Merge the files from this device with those on other devices. Choose this option if you wish to combine files from multiple sources.
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import type ObsidianLiveSyncPlugin from "../main.ts";
|
||||
import { MARK_DONE } from "../modules/features/ModuleLog.ts";
|
||||
import type { LiveSyncCore } from "../main.ts";
|
||||
import { __$checkInstanceBinding } from "../lib/src/dev/checks.ts";
|
||||
|
||||
let noticeIndex = 0;
|
||||
export abstract class LiveSyncCommands {
|
||||
@@ -42,6 +43,7 @@ export abstract class LiveSyncCommands {
|
||||
constructor(plugin: ObsidianLiveSyncPlugin) {
|
||||
this.plugin = plugin;
|
||||
this.onBindFunction(plugin, plugin.services);
|
||||
__$checkInstanceBinding(this);
|
||||
}
|
||||
abstract onunload(): void;
|
||||
abstract onload(): void | Promise<void>;
|
||||
|
||||
@@ -33,176 +33,6 @@ import { getPlatformName } from "../../lib/src/PlatformAPIs/obsidian/Environment
|
||||
import type { LiveSyncCore } from "../../main.ts";
|
||||
import { TrysteroReplicator } from "../../lib/src/replication/trystero/TrysteroReplicator.ts";
|
||||
|
||||
// class P2PReplicatorCommandBase extends LiveSyncCommands implements P2PReplicatorBase {
|
||||
// storeP2PStatusLine = reactiveSource("");
|
||||
|
||||
// getSettings(): P2PSyncSetting {
|
||||
// return this.plugin.settings;
|
||||
// }
|
||||
// get settings() {
|
||||
// return this.plugin.settings;
|
||||
// }
|
||||
// getDB() {
|
||||
// return this.plugin.localDatabase.localDatabase;
|
||||
// }
|
||||
|
||||
// get confirm(): Confirm {
|
||||
// return this.plugin.confirm;
|
||||
// }
|
||||
// _simpleStore!: SimpleStore<any>;
|
||||
|
||||
// simpleStore(): SimpleStore<any> {
|
||||
// return this._simpleStore;
|
||||
// }
|
||||
|
||||
// constructor(plugin: ObsidianLiveSyncPlugin) {
|
||||
// super(plugin);
|
||||
// this.onBindFunction(plugin, plugin.services);
|
||||
// }
|
||||
|
||||
// async handleReplicatedDocuments(docs: EntryDoc[]): Promise<void> {
|
||||
// // console.log("Processing Replicated Docs", docs);
|
||||
// return await this.services.replication.parseSynchroniseResult(
|
||||
// docs as PouchDB.Core.ExistingDocument<EntryDoc>[]
|
||||
// );
|
||||
// }
|
||||
// onunload(): void {
|
||||
// throw new Error("Method not implemented.");
|
||||
// }
|
||||
// onload(): void | Promise<void> {
|
||||
// throw new Error("Method not implemented.");
|
||||
// }
|
||||
|
||||
// init() {
|
||||
// this._simpleStore = this.services.database.openSimpleStore("p2p-sync");
|
||||
// return Promise.resolve(this);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// export class P2PReplicator extends P2PReplicatorMixIn(P2PReplicatorCommandBase) implements CommandShim {
|
||||
// storeP2PStatusLine = reactiveSource("");
|
||||
// _anyNewReplicator(settingOverride: Partial<RemoteDBSettings> = {}): Promise<LiveSyncAbstractReplicator> {
|
||||
// const settings = { ...this.settings, ...settingOverride };
|
||||
// if (settings.remoteType == REMOTE_P2P) {
|
||||
// return Promise.resolve(new LiveSyncTrysteroReplicator(this.plugin));
|
||||
// }
|
||||
// return undefined!;
|
||||
// }
|
||||
// override getPlatform(): string {
|
||||
// return getPlatformName();
|
||||
// }
|
||||
|
||||
// override onunload(): void {
|
||||
// removeP2PReplicatorInstance();
|
||||
// void this.close();
|
||||
// }
|
||||
|
||||
// override onload(): void | Promise<void> {
|
||||
// eventHub.onEvent(EVENT_REQUEST_OPEN_P2P, () => {
|
||||
// void this.openPane();
|
||||
// });
|
||||
// this.p2pLogCollector.p2pReplicationLine.onChanged((line) => {
|
||||
// this.storeP2PStatusLine.value = line.value;
|
||||
// });
|
||||
// }
|
||||
// async _everyOnInitializeDatabase(): Promise<boolean> {
|
||||
// await this.initialiseP2PReplicator();
|
||||
// return Promise.resolve(true);
|
||||
// }
|
||||
|
||||
// private async _allSuspendExtraSync() {
|
||||
// this.plugin.settings.P2P_Enabled = false;
|
||||
// this.plugin.settings.P2P_AutoAccepting = AutoAccepting.NONE;
|
||||
// this.plugin.settings.P2P_AutoBroadcast = false;
|
||||
// this.plugin.settings.P2P_AutoStart = false;
|
||||
// this.plugin.settings.P2P_AutoSyncPeers = "";
|
||||
// this.plugin.settings.P2P_AutoWatchPeers = "";
|
||||
// return await Promise.resolve(true);
|
||||
// }
|
||||
|
||||
// // async $everyOnLoadStart() {
|
||||
// // return await Promise.resolve();
|
||||
// // }
|
||||
|
||||
// async openPane() {
|
||||
// await this.services.API.showWindow(VIEW_TYPE_P2P);
|
||||
// }
|
||||
|
||||
// async _everyOnloadStart(): Promise<boolean> {
|
||||
// // this.plugin.registerView(VIEW_TYPE_P2P, (leaf) => new P2PReplicatorPaneView(leaf, this.plugin));
|
||||
// this.plugin.addCommand({
|
||||
// id: "open-p2p-replicator",
|
||||
// name: "P2P Sync : Open P2P Replicator",
|
||||
// callback: async () => {
|
||||
// await this.openPane();
|
||||
// },
|
||||
// });
|
||||
// this.plugin.addCommand({
|
||||
// id: "p2p-establish-connection",
|
||||
// name: "P2P Sync : Connect to the Signalling Server",
|
||||
// checkCallback: (isChecking) => {
|
||||
// if (isChecking) {
|
||||
// return !(this._replicatorInstance?.server?.isServing ?? false);
|
||||
// }
|
||||
// void this.open();
|
||||
// },
|
||||
// });
|
||||
// this.plugin.addCommand({
|
||||
// id: "p2p-close-connection",
|
||||
// name: "P2P Sync : Disconnect from the Signalling Server",
|
||||
// checkCallback: (isChecking) => {
|
||||
// if (isChecking) {
|
||||
// return this._replicatorInstance?.server?.isServing ?? false;
|
||||
// }
|
||||
// Logger(`Closing P2P Connection`, LOG_LEVEL_NOTICE);
|
||||
// void this.close();
|
||||
// },
|
||||
// });
|
||||
// this.plugin.addCommand({
|
||||
// id: "replicate-now-by-p2p",
|
||||
// name: "Replicate now by P2P",
|
||||
// checkCallback: (isChecking) => {
|
||||
// if (isChecking) {
|
||||
// if (this.settings.remoteType == REMOTE_P2P) return false;
|
||||
// if (!this._replicatorInstance?.server?.isServing) return false;
|
||||
// return true;
|
||||
// }
|
||||
// void this._replicatorInstance?.replicateFromCommand(false);
|
||||
// },
|
||||
// });
|
||||
// this.plugin
|
||||
// .addRibbonIcon("waypoints", "P2P Replicator", async () => {
|
||||
// await this.openPane();
|
||||
// })
|
||||
// .addClass("livesync-ribbon-replicate-p2p");
|
||||
|
||||
// return await Promise.resolve(true);
|
||||
// }
|
||||
// _everyAfterResumeProcess(): Promise<boolean> {
|
||||
// if (this.settings.P2P_Enabled && this.settings.P2P_AutoStart) {
|
||||
// setTimeout(() => void this.open(), 100);
|
||||
// }
|
||||
// const rep = this._replicatorInstance;
|
||||
// rep?.allowReconnection();
|
||||
// return Promise.resolve(true);
|
||||
// }
|
||||
// _everyBeforeSuspendProcess(): Promise<boolean> {
|
||||
// const rep = this._replicatorInstance;
|
||||
// rep?.disconnectFromServer();
|
||||
// return Promise.resolve(true);
|
||||
// }
|
||||
|
||||
// override onBindFunction(core: LiveSyncCore, services: typeof core.services): void {
|
||||
// services.replicator.handleGetNewReplicator(this._anyNewReplicator.bind(this));
|
||||
// services.databaseEvents.handleOnDatabaseInitialisation(this._everyOnInitializeDatabase.bind(this));
|
||||
// services.appLifecycle.handleOnInitialise(this._everyOnloadStart.bind(this));
|
||||
// services.appLifecycle.handleOnSuspending(this._everyBeforeSuspendProcess.bind(this));
|
||||
// services.appLifecycle.handleOnResumed(this._everyAfterResumeProcess.bind(this));
|
||||
// services.setting.handleSuspendExtraSync(this._allSuspendExtraSync.bind(this));
|
||||
// }
|
||||
// }
|
||||
|
||||
export class P2PReplicator extends LiveSyncCommands implements P2PReplicatorBase, CommandShim {
|
||||
storeP2PStatusLine = reactiveSource("");
|
||||
|
||||
@@ -230,7 +60,8 @@ export class P2PReplicator extends LiveSyncCommands implements P2PReplicatorBase
|
||||
setReplicatorFunc(() => this._replicatorInstance);
|
||||
addP2PEventHandlers(this);
|
||||
this.afterConstructor();
|
||||
this.onBindFunction(plugin, plugin.services);
|
||||
// onBindFunction is called in super class
|
||||
// this.onBindFunction(plugin, plugin.services);
|
||||
}
|
||||
|
||||
async handleReplicatedDocuments(docs: EntryDoc[]): Promise<void> {
|
||||
|
||||
2
src/lib
2
src/lib
Submodule src/lib updated: 6f58b4f076...6972cf45b3
@@ -1,6 +1,7 @@
|
||||
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, Logger } from "octagonal-wheels/common/logger";
|
||||
import type { LOG_LEVEL } from "../lib/src/common/types";
|
||||
import type { LiveSyncCore } from "../main";
|
||||
import { __$checkInstanceBinding } from "../lib/src/dev/checks";
|
||||
// import { unique } from "octagonal-wheels/collection";
|
||||
// import type { IObsidianModule } from "./AbstractObsidianModule.ts";
|
||||
// import type {
|
||||
@@ -159,6 +160,7 @@ export abstract class AbstractModule {
|
||||
constructor(public core: LiveSyncCore) {
|
||||
this.onBindFunction(core, core.services);
|
||||
Logger(`[${this.constructor.name}] Loaded`, LOG_LEVEL_VERBOSE);
|
||||
__$checkInstanceBinding(this);
|
||||
}
|
||||
saveSettings = this.core.saveSettings.bind(this.core);
|
||||
|
||||
|
||||
@@ -37,18 +37,18 @@ export abstract class AbstractObsidianModule extends AbstractModule {
|
||||
|
||||
saveSettings = this.plugin.saveSettings.bind(this.plugin);
|
||||
|
||||
_isMainReady() {
|
||||
isMainReady() {
|
||||
return this.services.appLifecycle.isReady();
|
||||
}
|
||||
_isMainSuspended() {
|
||||
isMainSuspended() {
|
||||
return this.services.appLifecycle.isSuspended();
|
||||
}
|
||||
_isDatabaseReady() {
|
||||
isDatabaseReady() {
|
||||
return this.services.database.isDatabaseReady();
|
||||
}
|
||||
|
||||
//should be overridden
|
||||
_isThisModuleEnabled() {
|
||||
isThisModuleEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +102,11 @@ export class ModuleDatabaseFileAccess extends AbstractModule implements Database
|
||||
}
|
||||
|
||||
async createChunks(file: UXFileInfo, force: boolean = false, skipCheck?: boolean): Promise<boolean> {
|
||||
return await this._store(file, force, skipCheck, true);
|
||||
return await this.__store(file, force, skipCheck, true);
|
||||
}
|
||||
|
||||
async store(file: UXFileInfo, force: boolean = false, skipCheck?: boolean): Promise<boolean> {
|
||||
return await this._store(file, force, skipCheck, false);
|
||||
return await this.__store(file, force, skipCheck, false);
|
||||
}
|
||||
async storeContent(path: FilePathWithPrefix, content: string): Promise<boolean> {
|
||||
const blob = createTextBlob(content);
|
||||
@@ -124,10 +124,10 @@ export class ModuleDatabaseFileAccess extends AbstractModule implements Database
|
||||
body: blob,
|
||||
isInternal,
|
||||
};
|
||||
return await this._store(dummyUXFileInfo, true, false, false);
|
||||
return await this.__store(dummyUXFileInfo, true, false, false);
|
||||
}
|
||||
|
||||
async _store(
|
||||
private async __store(
|
||||
file: UXFileInfo,
|
||||
force: boolean = false,
|
||||
skipCheck?: boolean,
|
||||
|
||||
@@ -5,30 +5,30 @@ import { AbstractModule } from "../AbstractModule";
|
||||
export class ModulePeriodicProcess extends AbstractModule {
|
||||
periodicSyncProcessor = new PeriodicProcessor(this.core, async () => await this.services.replication.replicate());
|
||||
|
||||
_disablePeriodic() {
|
||||
disablePeriodic() {
|
||||
this.periodicSyncProcessor?.disable();
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
_resumePeriodic() {
|
||||
resumePeriodic() {
|
||||
this.periodicSyncProcessor.enable(
|
||||
this.settings.periodicReplication ? this.settings.periodicReplicationInterval * 1000 : 0
|
||||
);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
private _allOnUnload() {
|
||||
return this._disablePeriodic();
|
||||
return this.disablePeriodic();
|
||||
}
|
||||
_everyBeforeRealizeSetting(): Promise<boolean> {
|
||||
return this._disablePeriodic();
|
||||
private _everyBeforeRealizeSetting(): Promise<boolean> {
|
||||
return this.disablePeriodic();
|
||||
}
|
||||
_everyBeforeSuspendProcess(): Promise<boolean> {
|
||||
return this._disablePeriodic();
|
||||
private _everyBeforeSuspendProcess(): Promise<boolean> {
|
||||
return this.disablePeriodic();
|
||||
}
|
||||
_everyAfterResumeProcess(): Promise<boolean> {
|
||||
return this._resumePeriodic();
|
||||
private _everyAfterResumeProcess(): Promise<boolean> {
|
||||
return this.resumePeriodic();
|
||||
}
|
||||
_everyAfterRealizeSetting(): Promise<boolean> {
|
||||
return this._resumePeriodic();
|
||||
private _everyAfterRealizeSetting(): Promise<boolean> {
|
||||
return this.resumePeriodic();
|
||||
}
|
||||
|
||||
onBindFunction(core: LiveSyncCore, services: typeof core.services): void {
|
||||
|
||||
@@ -343,7 +343,7 @@ export class ModuleFileAccessObsidian extends AbstractObsidianModule implements
|
||||
// }
|
||||
// }
|
||||
|
||||
async _deleteVaultItem(file: TFile | TFolder) {
|
||||
async __deleteVaultItem(file: TFile | TFolder) {
|
||||
if (file instanceof TFile) {
|
||||
if (!(await this.services.vault.isTargetFile(file.path))) return;
|
||||
}
|
||||
@@ -361,7 +361,7 @@ export class ModuleFileAccessObsidian extends AbstractObsidianModule implements
|
||||
this._log(
|
||||
`All files under the parent directory (${dir.path}) have been deleted, so delete this one.`
|
||||
);
|
||||
await this._deleteVaultItem(dir);
|
||||
await this.__deleteVaultItem(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ export class ModuleFileAccessObsidian extends AbstractObsidianModule implements
|
||||
const file = this.vaultAccess.getAbstractFileByPath(path);
|
||||
if (file === null) return;
|
||||
if (file instanceof TFile || file instanceof TFolder) {
|
||||
return await this._deleteVaultItem(file);
|
||||
return await this.__deleteVaultItem(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export class ModuleObsidianAPI extends AbstractObsidianModule {
|
||||
return !this.last_successful_post;
|
||||
}
|
||||
|
||||
async _fetchByAPI(url: string, authHeader: string, opts?: RequestInit): Promise<Response> {
|
||||
async __fetchByAPI(url: string, authHeader: string, opts?: RequestInit): Promise<Response> {
|
||||
const body = opts?.body as string;
|
||||
|
||||
const transformedHeaders = { ...(opts?.headers as Record<string, string>) };
|
||||
@@ -69,7 +69,7 @@ export class ModuleObsidianAPI extends AbstractObsidianModule {
|
||||
const body = opts?.body as string;
|
||||
const size = body ? ` (${body.length})` : "";
|
||||
try {
|
||||
const r = await this._fetchByAPI(url, authHeader, opts);
|
||||
const r = await this.__fetchByAPI(url, authHeader, opts);
|
||||
this.plugin.requestCount.value = this.plugin.requestCount.value + 1;
|
||||
if (method == "POST" || method == "PUT") {
|
||||
this.last_successful_post = r.status - (r.status % 100) == 200;
|
||||
@@ -149,7 +149,7 @@ export class ModuleObsidianAPI extends AbstractObsidianModule {
|
||||
try {
|
||||
this.plugin.requestCount.value = this.plugin.requestCount.value + 1;
|
||||
const response: Response = await (useRequestAPI
|
||||
? this._fetchByAPI(url.toString(), authHeader, { ...opts, headers })
|
||||
? this.__fetchByAPI(url.toString(), authHeader, { ...opts, headers })
|
||||
: fetch(url, { ...opts, headers }));
|
||||
if (method == "POST" || method == "PUT") {
|
||||
this.last_successful_post = response.ok;
|
||||
|
||||
@@ -32,10 +32,10 @@ export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||
}
|
||||
|
||||
private _performRestart(): void {
|
||||
this._performAppReload();
|
||||
this.__performAppReload();
|
||||
}
|
||||
|
||||
_performAppReload() {
|
||||
__performAppReload() {
|
||||
//@ts-ignore
|
||||
this.app.commands.executeCommandById("app:reload");
|
||||
}
|
||||
@@ -182,7 +182,7 @@ export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||
{ defaultAction: RETRY_LATER }
|
||||
);
|
||||
if (ret == RESTART_NOW) {
|
||||
this._performAppReload();
|
||||
this.__performAppReload();
|
||||
} else if (ret == RESTART_AFTER_STABLE) {
|
||||
this.services.appLifecycle.scheduleRestart();
|
||||
}
|
||||
@@ -225,7 +225,7 @@ export class ModuleObsidianEvents extends AbstractObsidianModule {
|
||||
this.core._totalProcessingCount.onChanged((e) => {
|
||||
if (e.value == 0) {
|
||||
if (stableCheck-- <= 0) {
|
||||
this._performAppReload();
|
||||
this.__performAppReload();
|
||||
}
|
||||
this._log(
|
||||
`Obsidian will be restarted soon! (Within ${stableCheck} seconds)`,
|
||||
|
||||
@@ -105,11 +105,11 @@ export class ModuleObsidianMenu extends AbstractObsidianModule {
|
||||
});
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
_onWorkspaceReady() {
|
||||
private __onWorkspaceReady() {
|
||||
void this.services.appLifecycle.onReady();
|
||||
}
|
||||
private _everyOnload(): Promise<boolean> {
|
||||
this.app.workspace.onLayoutReady(this._onWorkspaceReady.bind(this));
|
||||
this.app.workspace.onLayoutReady(this.__onWorkspaceReady.bind(this));
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export class ModuleIntegratedTest extends AbstractObsidianModule {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async _orDie(key: string, proc: () => Promise<boolean>): Promise<true> | never {
|
||||
async __orDie(key: string, proc: () => Promise<boolean>): Promise<true> | never {
|
||||
if (!(await this._test(key, proc))) {
|
||||
throw new Error(`${key}`);
|
||||
}
|
||||
@@ -64,13 +64,13 @@ export class ModuleIntegratedTest extends AbstractObsidianModule {
|
||||
}
|
||||
return await this.core.storageAccess.readHiddenFileText(file);
|
||||
}
|
||||
async _proceed(no: number, title: string): Promise<boolean> {
|
||||
async __proceed(no: number, title: string): Promise<boolean> {
|
||||
const stepFile = "_STEP.md" as FilePathWithPrefix;
|
||||
const stepAckFile = "_STEP_ACK.md" as FilePathWithPrefix;
|
||||
const stepContent = `Step ${no}`;
|
||||
await this.services.conflict.resolveByNewest(stepFile);
|
||||
await this.core.storageAccess.writeFileAuto(stepFile, stepContent);
|
||||
await this._orDie(`Wait for acknowledge ${no}`, async () => {
|
||||
await this.__orDie(`Wait for acknowledge ${no}`, async () => {
|
||||
if (
|
||||
!(await this.waitWithReplicating(async () => {
|
||||
return await this.storageContentIsEqual(stepAckFile, stepContent);
|
||||
@@ -81,13 +81,13 @@ export class ModuleIntegratedTest extends AbstractObsidianModule {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
async _join(no: number, title: string): Promise<boolean> {
|
||||
async __join(no: number, title: string): Promise<boolean> {
|
||||
const stepFile = "_STEP.md" as FilePathWithPrefix;
|
||||
const stepAckFile = "_STEP_ACK.md" as FilePathWithPrefix;
|
||||
// const otherStepFile = `_STEP_${isLeader ? "R" : "L"}.md` as FilePathWithPrefix;
|
||||
const stepContent = `Step ${no}`;
|
||||
|
||||
await this._orDie(`Wait for step ${no} (${title})`, async () => {
|
||||
await this.__orDie(`Wait for step ${no} (${title})`, async () => {
|
||||
if (
|
||||
!(await this.waitWithReplicating(async () => {
|
||||
return await this.storageContentIsEqual(stepFile, stepContent);
|
||||
@@ -116,16 +116,16 @@ export class ModuleIntegratedTest extends AbstractObsidianModule {
|
||||
check: () => Promise<boolean>;
|
||||
}): Promise<boolean> {
|
||||
if (isGameChanger) {
|
||||
await this._proceed(step, title);
|
||||
await this.__proceed(step, title);
|
||||
try {
|
||||
await proc();
|
||||
} catch (e) {
|
||||
this._log(`Error: ${e}`);
|
||||
return false;
|
||||
}
|
||||
return await this._orDie(`Step ${step} - ${title}`, async () => await this.waitWithReplicating(check));
|
||||
return await this.__orDie(`Step ${step} - ${title}`, async () => await this.waitWithReplicating(check));
|
||||
} else {
|
||||
return await this._join(step, title);
|
||||
return await this.__join(step, title);
|
||||
}
|
||||
}
|
||||
// // see scenario.md
|
||||
@@ -151,7 +151,7 @@ export class ModuleIntegratedTest extends AbstractObsidianModule {
|
||||
`Test as ${isLeader ? "Leader" : "Receiver"} command file ${testCommandFile}`
|
||||
);
|
||||
if (isLeader) {
|
||||
await this._proceed(0, "start");
|
||||
await this.__proceed(0, "start");
|
||||
}
|
||||
await this.tryReplicate();
|
||||
|
||||
|
||||
@@ -56,10 +56,10 @@ export class ModuleReplicateTest extends AbstractObsidianModule {
|
||||
async dumpList() {
|
||||
if (this.settings.syncInternalFiles) {
|
||||
this._log("Write file list (Include Hidden)");
|
||||
await this._dumpFileListIncludeHidden("files.md");
|
||||
await this.__dumpFileListIncludeHidden("files.md");
|
||||
} else {
|
||||
this._log("Write file list");
|
||||
await this._dumpFileList("files.md");
|
||||
await this.__dumpFileList("files.md");
|
||||
}
|
||||
}
|
||||
async _everyBeforeReplicate(showMessage: boolean): Promise<boolean> {
|
||||
@@ -73,7 +73,7 @@ export class ModuleReplicateTest extends AbstractObsidianModule {
|
||||
id: "dump-file-structure-normal",
|
||||
name: `Dump Structure (Normal)`,
|
||||
callback: () => {
|
||||
void this._dumpFileList("files.md").finally(() => {
|
||||
void this.__dumpFileList("files.md").finally(() => {
|
||||
void this.refreshSyncStatus();
|
||||
});
|
||||
},
|
||||
@@ -83,7 +83,7 @@ export class ModuleReplicateTest extends AbstractObsidianModule {
|
||||
name: "Dump Structure (Include Hidden)",
|
||||
callback: () => {
|
||||
const d = "files.md";
|
||||
void this._dumpFileListIncludeHidden(d);
|
||||
void this.__dumpFileListIncludeHidden(d);
|
||||
},
|
||||
});
|
||||
this.addCommand({
|
||||
@@ -164,7 +164,7 @@ export class ModuleReplicateTest extends AbstractObsidianModule {
|
||||
}
|
||||
}
|
||||
|
||||
async _dumpFileList(outFile?: string) {
|
||||
async __dumpFileList(outFile?: string) {
|
||||
if (!this.core || !this.core.storageAccess) {
|
||||
this._log("No storage access", LOG_LEVEL_INFO);
|
||||
return;
|
||||
@@ -204,7 +204,7 @@ export class ModuleReplicateTest extends AbstractObsidianModule {
|
||||
this._log(`Dumped ${out.length} files`, LOG_LEVEL_INFO);
|
||||
}
|
||||
|
||||
async _dumpFileListIncludeHidden(outFile?: string) {
|
||||
async __dumpFileListIncludeHidden(outFile?: string) {
|
||||
const ignorePatterns = getFileRegExp(this.plugin.settings, "syncInternalFilesIgnorePatterns");
|
||||
const targetPatterns = getFileRegExp(this.plugin.settings, "syncInternalFilesTargetPatterns");
|
||||
const out = [] as any[];
|
||||
|
||||
@@ -320,7 +320,7 @@ export class ModuleLog extends AbstractObsidianModule {
|
||||
private _everyOnloadAfterLoadSettings(): Promise<boolean> {
|
||||
logStore
|
||||
.pipeTo(
|
||||
new QueueProcessor((logs) => logs.forEach((e) => this._addLog(e.message, e.level, e.key)), {
|
||||
new QueueProcessor((logs) => logs.forEach((e) => this.__addLog(e.message, e.level, e.key)), {
|
||||
suspended: false,
|
||||
batchSize: 20,
|
||||
concurrentLimit: 1,
|
||||
@@ -367,7 +367,7 @@ export class ModuleLog extends AbstractObsidianModule {
|
||||
})
|
||||
);
|
||||
}
|
||||
_addLog(message: any, level: LOG_LEVEL = LOG_LEVEL_INFO, key = ""): void {
|
||||
__addLog(message: any, level: LOG_LEVEL = LOG_LEVEL_INFO, key = ""): void {
|
||||
if (level == LOG_LEVEL_DEBUG && !showDebugLog) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user