diff --git a/src/lib b/src/lib index 7c275d5..a02102b 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 7c275d50ae3988903f6d518603450d24e979c1ff +Subproject commit a02102b13197826f1591448a6bf5ecdee8673d00 diff --git a/src/modules/essentialObsidian/ModuleObsidianAPI.ts b/src/modules/essentialObsidian/ModuleObsidianAPI.ts index 1ddc4fd..cdd085b 100644 --- a/src/modules/essentialObsidian/ModuleObsidianAPI.ts +++ b/src/modules/essentialObsidian/ModuleObsidianAPI.ts @@ -15,7 +15,6 @@ import { replicationFilter } from "@/lib/src/pouchdb/compress.ts"; import { disableEncryption } from "@/lib/src/pouchdb/encryption.ts"; import { enableEncryption } from "@/lib/src/pouchdb/encryption.ts"; import { setNoticeClass } from "../../lib/src/mock_and_interop/wrapper.ts"; -import { ObsHttpHandler } from "./APILib/ObsHttpHandler.ts"; import { PouchDB } from "../../lib/src/pouchdb/pouchdb-browser.ts"; import { AuthorizationHeaderGenerator } from "../../lib/src/replication/httplib.ts"; import type { LiveSyncCore } from "../../main.ts"; @@ -27,10 +26,7 @@ async function fetchByAPI(request: RequestUrlParam, errorAsResult = false): Prom const ret = await requestUrl({ ...request, throw: !errorAsResult }); return ret; } - export class ModuleObsidianAPI extends AbstractObsidianModule { - _customHandler!: ObsHttpHandler; - _authHeader = new AuthorizationHeaderGenerator(); _previousErrors = new Set(); @@ -47,10 +43,7 @@ export class ModuleObsidianAPI extends AbstractObsidianModule { eventHub.emitEvent(EVENT_ON_UNRESOLVED_ERROR); } last_successful_post = false; - _customFetchHandler(): ObsHttpHandler { - if (!this._customHandler) this._customHandler = new ObsHttpHandler(undefined, undefined); - return this._customHandler; - } + _getLastPostFailedBySize(): boolean { return !this.last_successful_post; } @@ -286,11 +279,6 @@ export class ModuleObsidianAPI extends AbstractObsidianModule { } } - _isMobile(): boolean { - //@ts-ignore : internal API - return this.app.isMobile; - } - _vaultName(): string { return this.app.vault.getName(); } @@ -308,38 +296,16 @@ export class ModuleObsidianAPI extends AbstractObsidianModule { return undefined; } - _anyGetAppId(): string { - return `${"appId" in this.app ? this.app.appId : ""}`; - } - private _reportUnresolvedMessages(): Promise<(string | Error)[]> { return Promise.resolve([...this._previousErrors]); } - private _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"; - } - - private _getPluginVersion(): string { - return this.plugin.manifest.version; - } - onBindFunction(core: LiveSyncCore, services: typeof core.services) { - services.API.getCustomFetchHandler.setHandler(this._customFetchHandler.bind(this)); services.API.isLastPostFailedDueToPayloadSize.setHandler(this._getLastPostFailedBySize.bind(this)); services.remote.connect.setHandler(this._connectRemoteCouchDB.bind(this)); - services.API.isMobile.setHandler(this._isMobile.bind(this)); services.vault.getVaultName.setHandler(this._getVaultName.bind(this)); services.vault.vaultName.setHandler(this._vaultName.bind(this)); services.vault.getActiveFilePath.setHandler(this._getActiveFilePath.bind(this)); - services.API.getAppID.setHandler(this._anyGetAppId.bind(this)); - services.API.getAppVersion.setHandler(this._getAppVersion.bind(this)); - services.API.getPluginVersion.setHandler(this._getPluginVersion.bind(this)); services.appLifecycle.getUnresolvedMessages.addHandler(this._reportUnresolvedMessages.bind(this)); } } diff --git a/src/modules/essentialObsidian/ModuleObsidianMenu.ts b/src/modules/essentialObsidian/ModuleObsidianMenu.ts index 0186504..736ae10 100644 --- a/src/modules/essentialObsidian/ModuleObsidianMenu.ts +++ b/src/modules/essentialObsidian/ModuleObsidianMenu.ts @@ -113,26 +113,8 @@ export class ModuleObsidianMenu extends AbstractObsidianModule { return Promise.resolve(true); } - private async _showView(viewType: string) { - 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]); - } - } onBindFunction(core: LiveSyncCore, services: typeof core.services): void { services.appLifecycle.onInitialise.addHandler(this._everyOnloadStart.bind(this)); services.appLifecycle.onLoaded.addHandler(this._everyOnload.bind(this)); - services.API.showWindow.setHandler(this._showView.bind(this)); } } diff --git a/src/modules/services/ObsidianServices.ts b/src/modules/services/ObsidianServices.ts index 2f79c67..e4b05b7 100644 --- a/src/modules/services/ObsidianServices.ts +++ b/src/modules/services/ObsidianServices.ts @@ -18,11 +18,40 @@ 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"; @@ -44,6 +73,25 @@ export class ObsidianAPIService extends InjectableAPIService= 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 {