mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-05 16:45:20 +00:00
Now, Self-hosted LiveSync has finally begun to be split into the Self-hosted LiveSync plugin for Obsidian, and a properly abstracted version of it. This may not offer much benefit to Obsidian plugin users, or might even cause a slight inconvenience, but I believe it will certainly help improve testability and make the ecosystem better. However, I do not see the point in putting something with little benefit into beta, so I am handling this on the alpha branch. I would actually preferred to create an R&D branch, but I was not keen on the ampersand, and I feel it will eventually become a proper beta anyway. ### Refactored - Separated `ObsidianLiveSyncPlugin` into `ObsidianLiveSyncPlugin` and `LiveSyncBaseCore`. - Now `LiveSyncCore` indicates the type specified version of `LiveSyncBaseCore`. - Referencing `plugin.xxx` has been rewritten to referencing the corresponding service or `core.xxx`. ### Internal API changes - Storage Access APIs are now yielding Promises. This is to allow more limited storage platforms to be supported. ### R&D - Browser-version of Self-hosted LiveSync is now in development. This is not intended for public use now, but I will eventually make it available for testing. - We can see the code in `src/apps/webapp` for the browser version.
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import { LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
import {
|
|
LOG_LEVEL_INFO,
|
|
LOG_LEVEL_NOTICE,
|
|
type AnyEntry,
|
|
type DocumentID,
|
|
type FilePath,
|
|
type FilePathWithPrefix,
|
|
type LOG_LEVEL,
|
|
} from "../lib/src/common/types.ts";
|
|
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";
|
|
import { createInstanceLogFunction } from "@/lib/src/services/lib/logUtils.ts";
|
|
|
|
let noticeIndex = 0;
|
|
export abstract class LiveSyncCommands {
|
|
/**
|
|
* @deprecated This class is deprecated. Please use core
|
|
*/
|
|
plugin: ObsidianLiveSyncPlugin;
|
|
core: LiveSyncCore;
|
|
get app() {
|
|
return this.plugin.app;
|
|
}
|
|
get settings() {
|
|
return this.core.settings;
|
|
}
|
|
get localDatabase() {
|
|
return this.core.localDatabase;
|
|
}
|
|
get services() {
|
|
return this.core.services;
|
|
}
|
|
|
|
// id2path(id: DocumentID, entry?: EntryHasPath, stripPrefix?: boolean): FilePathWithPrefix {
|
|
// return this.plugin.$$id2path(id, entry, stripPrefix);
|
|
// }
|
|
async path2id(filename: FilePathWithPrefix | FilePath, prefix?: string): Promise<DocumentID> {
|
|
return await this.services.path.path2id(filename, prefix);
|
|
}
|
|
|
|
getPath(entry: AnyEntry): FilePathWithPrefix {
|
|
return this.services.path.getPath(entry);
|
|
}
|
|
|
|
constructor(plugin: ObsidianLiveSyncPlugin, core: LiveSyncCore) {
|
|
this.plugin = plugin;
|
|
this.core = core;
|
|
this.onBindFunction(this.core, this.core.services);
|
|
this._log = createInstanceLogFunction(this.constructor.name, this.services.API);
|
|
__$checkInstanceBinding(this);
|
|
}
|
|
abstract onunload(): void;
|
|
abstract onload(): void | Promise<void>;
|
|
|
|
_isMainReady() {
|
|
return this.services.appLifecycle.isReady();
|
|
}
|
|
_isMainSuspended() {
|
|
return this.services.appLifecycle.isSuspended();
|
|
}
|
|
_isDatabaseReady() {
|
|
return this.services.database.isDatabaseReady();
|
|
}
|
|
|
|
_log: ReturnType<typeof createInstanceLogFunction>;
|
|
|
|
_verbose = (msg: any, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_VERBOSE, key);
|
|
};
|
|
|
|
_info = (msg: any, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_INFO, key);
|
|
};
|
|
|
|
_notice = (msg: any, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_NOTICE, key);
|
|
};
|
|
_progress = (prefix: string = "", level: LOG_LEVEL = LOG_LEVEL_NOTICE) => {
|
|
const key = `keepalive-progress-${noticeIndex++}`;
|
|
return {
|
|
log: (msg: any) => {
|
|
this._log(prefix + msg, level, key);
|
|
},
|
|
once: (msg: any) => {
|
|
this._log(prefix + msg, level);
|
|
},
|
|
done: (msg: string = "Done") => {
|
|
this._log(prefix + msg + MARK_DONE, level, key);
|
|
},
|
|
};
|
|
};
|
|
|
|
_debug = (msg: any, key?: string) => {
|
|
this._log(msg, LOG_LEVEL_VERBOSE, key);
|
|
};
|
|
|
|
onBindFunction(core: LiveSyncCore, services: typeof core.services) {
|
|
// Override if needed.
|
|
}
|
|
}
|