import { InjectableAPIService } from "@lib/services/implements/injectable/InjectableAPIService"; import { InjectableAppLifecycleService } from "@lib/services/implements/injectable/InjectableAppLifecycleService"; import { InjectableConflictService } from "@lib/services/implements/injectable/InjectableConflictService"; import { InjectableDatabaseEventService } from "@lib/services/implements/injectable/InjectableDatabaseEventService"; import { InjectableDatabaseService } from "@lib/services/implements/injectable/InjectableDatabaseService"; import { InjectableFileProcessingService } from "@lib/services/implements/injectable/InjectableFileProcessingService"; import { InjectablePathService } from "@lib/services/implements/injectable/InjectablePathService"; import { InjectableRemoteService } from "@lib/services/implements/injectable/InjectableRemoteService"; import { InjectableReplicationService } from "@lib/services/implements/injectable/InjectableReplicationService"; import { InjectableReplicatorService } from "@lib/services/implements/injectable/InjectableReplicatorService"; import { InjectableSettingService } from "@lib/services/implements/injectable/InjectableSettingService"; import { InjectableTestService } from "@lib/services/implements/injectable/InjectableTestService"; import { InjectableTweakValueService } from "@lib/services/implements/injectable/InjectableTweakValueService"; import { InjectableVaultService } from "@lib/services/implements/injectable/InjectableVaultService"; import { ConfigServiceBrowserCompat } from "@lib/services/implements/browser/ConfigServiceBrowserCompat"; import type { ObsidianServiceContext } from "@lib/services/implements/obsidian/ObsidianServiceContext.ts"; import { Platform } from "@/deps"; import type { SimpleStore } from "@/lib/src/common/utils"; import type { IDatabaseService } from "@/lib/src/services/base/IService"; import { handlers } from "@/lib/src/services/lib/HandlerUtils"; import { ObsHttpHandler } from "../essentialObsidian/APILib/ObsHttpHandler"; // All Services will be migrated to be based on Plain Services, not Injectable Services. // This is a migration step. export class ObsidianAPIService extends InjectableAPIService { _customHandler: ObsHttpHandler | undefined; getCustomFetchHandler(): ObsHttpHandler { if (!this._customHandler) this._customHandler = new ObsHttpHandler(undefined, undefined); return this._customHandler; } async showWindow(viewType: string): Promise { const leaves = this.app.workspace.getLeavesOfType(viewType); if (leaves.length == 0) { await this.app.workspace.getLeaf(true).setViewState({ type: viewType, active: true, }); } else { await leaves[0].setViewState({ type: viewType, active: true, }); } if (leaves.length > 0) { await this.app.workspace.revealLeaf(leaves[0]); } } private get app() { return this.context.app; } getPlatform(): string { if (Platform.isAndroidApp) { return "android-app"; } else if (Platform.isIosApp) { return "ios"; } else if (Platform.isMacOS) { return "macos"; } else if (Platform.isMobileApp) { return "mobile-app"; } else if (Platform.isMobile) { return "mobile"; } else if (Platform.isSafari) { return "safari"; } else if (Platform.isDesktop) { return "desktop"; } else if (Platform.isDesktopApp) { return "desktop-app"; } else { return "unknown-obsidian"; } } override isMobile(): boolean { //@ts-ignore : internal API return this.app.isMobile; } override getAppID(): string { return `${"appId" in this.app ? this.app.appId : ""}`; } override getAppVersion(): string { const navigatorString = globalThis.navigator?.userAgent ?? ""; const match = navigatorString.match(/obsidian\/([0-9]+\.[0-9]+\.[0-9]+)/); if (match && match.length >= 2) { return match[1]; } return "0.0.0"; } override getPluginVersion(): string { return this.context.plugin.manifest.version; } } export class ObsidianPathService extends InjectablePathService {} export class ObsidianDatabaseService extends InjectableDatabaseService { openSimpleStore = handlers().binder("openSimpleStore") as (( kind: string ) => SimpleStore) & { setHandler: (handler: IDatabaseService["openSimpleStore"], override?: boolean) => void }; } export class ObsidianDatabaseEventService extends InjectableDatabaseEventService {} // InjectableReplicatorService export class ObsidianReplicatorService extends InjectableReplicatorService {} // InjectableFileProcessingService export class ObsidianFileProcessingService extends InjectableFileProcessingService {} // InjectableReplicationService export class ObsidianReplicationService extends InjectableReplicationService {} // InjectableRemoteService export class ObsidianRemoteService extends InjectableRemoteService {} // InjectableConflictService export class ObsidianConflictService extends InjectableConflictService {} // InjectableAppLifecycleService export class ObsidianAppLifecycleService extends InjectableAppLifecycleService {} // InjectableSettingService export class ObsidianSettingService extends InjectableSettingService {} // InjectableTweakValueService export class ObsidianTweakValueService extends InjectableTweakValueService {} // InjectableVaultService export class ObsidianVaultService extends InjectableVaultService {} // InjectableTestService export class ObsidianTestService extends InjectableTestService {} export class ObsidianConfigService extends ConfigServiceBrowserCompat {}