mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-28 06:39:27 +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.9 KiB
TypeScript
104 lines
3.9 KiB
TypeScript
import type { InjectableServiceHub } from "../../../lib/src/services/implements/injectable/InjectableServiceHub";
|
|
import { ServiceRebuilder } from "../../../lib/src/serviceModules/Rebuilder";
|
|
import { ServiceFileHandler } from "../../../serviceModules/FileHandler";
|
|
import { StorageAccessManager } from "../../../lib/src/managers/StorageProcessingManager";
|
|
import type { ServiceModules } from "../../../types";
|
|
import type { LiveSyncBaseCore } from "../../../LiveSyncBaseCore";
|
|
import type { ServiceContext } from "../../../lib/src/services/base/ServiceBase";
|
|
import { FileAccessFSAPI } from "./FileAccessFSAPI";
|
|
import { ServiceFileAccessFSAPI } from "./ServiceFileAccessImpl";
|
|
import { ServiceDatabaseFileAccessFSAPI } from "./DatabaseFileAccess";
|
|
import { StorageEventManagerFSAPI } from "../managers/StorageEventManagerFSAPI";
|
|
|
|
/**
|
|
* Initialize service modules for FileSystem API webapp version
|
|
* This is the webapp equivalent of ObsidianLiveSyncPlugin.initialiseServiceModules
|
|
*
|
|
* @param rootHandle - The root FileSystemDirectoryHandle for the vault
|
|
* @param core - The LiveSyncBaseCore instance
|
|
* @param services - The service hub
|
|
* @returns ServiceModules containing all initialized service modules
|
|
*/
|
|
export function initialiseServiceModulesFSAPI(
|
|
rootHandle: FileSystemDirectoryHandle,
|
|
core: LiveSyncBaseCore<ServiceContext, any>,
|
|
services: InjectableServiceHub<ServiceContext>
|
|
): ServiceModules {
|
|
const storageAccessManager = new StorageAccessManager();
|
|
|
|
// FileSystem API-specific file access
|
|
const vaultAccess = new FileAccessFSAPI(rootHandle, {
|
|
storageAccessManager: storageAccessManager,
|
|
vaultService: services.vault,
|
|
settingService: services.setting,
|
|
APIService: services.API,
|
|
pathService: services.path,
|
|
});
|
|
|
|
// FileSystem API-specific storage event manager
|
|
const storageEventManager = new StorageEventManagerFSAPI(rootHandle, core, {
|
|
fileProcessing: services.fileProcessing,
|
|
setting: services.setting,
|
|
vaultService: services.vault,
|
|
storageAccessManager: storageAccessManager,
|
|
APIService: services.API,
|
|
});
|
|
|
|
// Storage access using FileSystem API adapter
|
|
const storageAccess = new ServiceFileAccessFSAPI({
|
|
API: services.API,
|
|
setting: services.setting,
|
|
fileProcessing: services.fileProcessing,
|
|
vault: services.vault,
|
|
appLifecycle: services.appLifecycle,
|
|
storageEventManager: storageEventManager,
|
|
storageAccessManager: storageAccessManager,
|
|
vaultAccess: vaultAccess,
|
|
});
|
|
|
|
// Database file access (platform-independent)
|
|
const databaseFileAccess = new ServiceDatabaseFileAccessFSAPI({
|
|
API: services.API,
|
|
database: services.database,
|
|
path: services.path,
|
|
storageAccess: storageAccess,
|
|
vault: services.vault,
|
|
});
|
|
|
|
// File handler (platform-independent)
|
|
const fileHandler = new (ServiceFileHandler as any)({
|
|
API: services.API,
|
|
databaseFileAccess: databaseFileAccess,
|
|
conflict: services.conflict,
|
|
setting: services.setting,
|
|
fileProcessing: services.fileProcessing,
|
|
vault: services.vault,
|
|
path: services.path,
|
|
replication: services.replication,
|
|
storageAccess: storageAccess,
|
|
});
|
|
|
|
// Rebuilder (platform-independent)
|
|
const rebuilder = new ServiceRebuilder({
|
|
API: services.API,
|
|
database: services.database,
|
|
appLifecycle: services.appLifecycle,
|
|
setting: services.setting,
|
|
remote: services.remote,
|
|
databaseEvents: services.databaseEvents,
|
|
replication: services.replication,
|
|
replicator: services.replicator,
|
|
UI: services.UI,
|
|
vault: services.vault,
|
|
fileHandler: fileHandler,
|
|
storageAccess: storageAccess,
|
|
control: services.control,
|
|
});
|
|
|
|
return {
|
|
rebuilder,
|
|
fileHandler,
|
|
databaseFileAccess,
|
|
storageAccess,
|
|
};
|
|
}
|