mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-16 14:22:32 +00:00
(chore): Improve type assertion, remove unused imports
This commit is contained in:
+1
-1
Submodule src/lib updated: 61741c1748...4d5adcdee0
@@ -1,29 +1,16 @@
|
|||||||
import { stringifyYaml } from "../../../deps.ts";
|
|
||||||
import {
|
import {
|
||||||
type ObsidianLiveSyncSettings,
|
|
||||||
type FilePathWithPrefix,
|
type FilePathWithPrefix,
|
||||||
type DocumentID,
|
type DocumentID,
|
||||||
LOG_LEVEL_NOTICE,
|
LOG_LEVEL_NOTICE,
|
||||||
LOG_LEVEL_VERBOSE,
|
LOG_LEVEL_VERBOSE,
|
||||||
type LoadedEntry,
|
type LoadedEntry,
|
||||||
REMOTE_COUCHDB,
|
|
||||||
REMOTE_MINIO,
|
|
||||||
type MetaEntry,
|
type MetaEntry,
|
||||||
type FilePath,
|
type FilePath,
|
||||||
DEFAULT_SETTINGS,
|
} from "@lib/common/types.ts";
|
||||||
} from "../../../lib/src/common/types.ts";
|
import { createBlob, getFileRegExp, isDocContentSame, readAsBlob } from "@lib/common/utils.ts";
|
||||||
import {
|
import { Logger } from "@lib/common/logger.ts";
|
||||||
createBlob,
|
import { addPrefix, shouldBeIgnored, stripAllPrefixes } from "@lib/string_and_binary/path.ts";
|
||||||
getFileRegExp,
|
import { $msg } from "@lib/common/i18n.ts";
|
||||||
isDocContentSame,
|
|
||||||
parseHeaderValues,
|
|
||||||
readAsBlob,
|
|
||||||
} from "../../../lib/src/common/utils.ts";
|
|
||||||
import { Logger } from "../../../lib/src/common/logger.ts";
|
|
||||||
import { isCloudantURI } from "../../../lib/src/pouchdb/utils_couchdb.ts";
|
|
||||||
import { requestToCouchDBWithCredentials } from "../../../common/utils.ts";
|
|
||||||
import { addPrefix, shouldBeIgnored, stripAllPrefixes } from "../../../lib/src/string_and_binary/path.ts";
|
|
||||||
import { $msg } from "../../../lib/src/common/i18n.ts";
|
|
||||||
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
||||||
import { LiveSyncSetting as Setting } from "./LiveSyncSetting.ts";
|
import { LiveSyncSetting as Setting } from "./LiveSyncSetting.ts";
|
||||||
import {
|
import {
|
||||||
@@ -32,14 +19,13 @@ import {
|
|||||||
EVENT_REQUEST_RUN_DOCTOR,
|
EVENT_REQUEST_RUN_DOCTOR,
|
||||||
EVENT_REQUEST_RUN_FIX_INCOMPLETE,
|
EVENT_REQUEST_RUN_FIX_INCOMPLETE,
|
||||||
eventHub,
|
eventHub,
|
||||||
} from "../../../common/events.ts";
|
} from "@/common/events.ts";
|
||||||
import { ICHeader, ICXHeader, PSCHeader } from "../../../common/types.ts";
|
import { ICHeader, ICXHeader, PSCHeader } from "@/common/types.ts";
|
||||||
import { HiddenFileSync } from "../../../features/HiddenFileSync/CmdHiddenFileSync.ts";
|
import { HiddenFileSync } from "@/features/HiddenFileSync/CmdHiddenFileSync.ts";
|
||||||
import { EVENT_REQUEST_SHOW_HISTORY } from "../../../common/obsidianEvents.ts";
|
import { EVENT_REQUEST_SHOW_HISTORY } from "@/common/obsidianEvents.ts";
|
||||||
import { generateCredentialObject } from "../../../lib/src/replication/httplib.ts";
|
|
||||||
import type { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab.ts";
|
import type { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab.ts";
|
||||||
import type { PageFunctions } from "./SettingPane.ts";
|
import type { PageFunctions } from "./SettingPane.ts";
|
||||||
import { generateReport } from "@/common/reportTool.ts";
|
import { isNotFoundError } from "@lib/common/utils.doc.ts";
|
||||||
export function paneHatch(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElement, { addPanel }: PageFunctions): void {
|
export function paneHatch(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElement, { addPanel }: PageFunctions): void {
|
||||||
// const hatchWarn = this.createEl(paneEl, "div", { text: `To stop the boot up sequence for fixing problems on databases, you can put redflag.md on top of your vault (Rebooting obsidian is required).` });
|
// const hatchWarn = this.createEl(paneEl, "div", { text: `To stop the boot up sequence for fixing problems on databases, you can put redflag.md on top of your vault (Rebooting obsidian is required).` });
|
||||||
// hatchWarn.addClass("op-warn-info");
|
// hatchWarn.addClass("op-warn-info");
|
||||||
@@ -160,14 +146,14 @@ export function paneHatch(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElement,
|
|||||||
}
|
}
|
||||||
if (!(await addOn.storeInternalFileToDatabase(file, true))) {
|
if (!(await addOn.storeInternalFileToDatabase(file, true))) {
|
||||||
Logger(
|
Logger(
|
||||||
`Failed to store the file to the database (Hidden file): ${file}`,
|
`Failed to store the file to the database (Hidden file): ${file.path}`,
|
||||||
LOG_LEVEL_NOTICE
|
LOG_LEVEL_NOTICE
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(await this.core.fileHandler.storeFileToDB(file as FilePath, true))) {
|
if (!(await this.core.fileHandler.storeFileToDB(file, true))) {
|
||||||
Logger(
|
Logger(
|
||||||
`Failed to store the file to the database: ${file}`,
|
`Failed to store the file to the database: ${file}`,
|
||||||
LOG_LEVEL_NOTICE
|
LOG_LEVEL_NOTICE
|
||||||
@@ -406,8 +392,8 @@ export function paneHatch(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElement,
|
|||||||
Logger(`Converting ${docName} Failed!`, LOG_LEVEL_NOTICE);
|
Logger(`Converting ${docName} Failed!`, LOG_LEVEL_NOTICE);
|
||||||
Logger(ret, LOG_LEVEL_VERBOSE);
|
Logger(ret, LOG_LEVEL_VERBOSE);
|
||||||
}
|
}
|
||||||
} catch (ex: any) {
|
} catch (ex: unknown) {
|
||||||
if (ex?.status == 404) {
|
if (isNotFoundError(ex)) {
|
||||||
// We can perform this safely
|
// We can perform this safely
|
||||||
if ((await this.core.localDatabase.putRaw(newDoc)).ok) {
|
if ((await this.core.localDatabase.putRaw(newDoc)).ok) {
|
||||||
Logger(`${docName} has been converted`, LOG_LEVEL_NOTICE);
|
Logger(`${docName} has been converted`, LOG_LEVEL_NOTICE);
|
||||||
|
|||||||
@@ -5,9 +5,17 @@ import { ObsHttpHandler } from "../essentialObsidian/APILib/ObsHttpHandler";
|
|||||||
import { ObsidianConfirm } from "./ObsidianConfirm";
|
import { ObsidianConfirm } from "./ObsidianConfirm";
|
||||||
import type { Confirm } from "@lib/interfaces/Confirm";
|
import type { Confirm } from "@lib/interfaces/Confirm";
|
||||||
import { requestUrl, type RequestUrlParam } from "@/deps";
|
import { requestUrl, type RequestUrlParam } from "@/deps";
|
||||||
|
import { compatGlobal } from "@/lib/src/common/coreEnvFunctions";
|
||||||
// All Services will be migrated to be based on Plain Services, not Injectable Services.
|
// All Services will be migrated to be based on Plain Services, not Injectable Services.
|
||||||
// This is a migration step.
|
// This is a migration step.
|
||||||
|
|
||||||
|
declare module "obsidian" {
|
||||||
|
interface App {
|
||||||
|
appId?: string;
|
||||||
|
isMobile?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class ObsidianAPIService extends InjectableAPIService<ObsidianServiceContext> {
|
export class ObsidianAPIService extends InjectableAPIService<ObsidianServiceContext> {
|
||||||
_customHandler: ObsHttpHandler | undefined;
|
_customHandler: ObsHttpHandler | undefined;
|
||||||
_confirmInstance: Confirm;
|
_confirmInstance: Confirm;
|
||||||
@@ -83,8 +91,7 @@ export class ObsidianAPIService extends InjectableAPIService<ObsidianServiceCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
override isMobile(): boolean {
|
override isMobile(): boolean {
|
||||||
//@ts-ignore : internal API
|
return "isMobile" in this.app ? !!this.app.isMobile : false;
|
||||||
return this.app.isMobile;
|
|
||||||
}
|
}
|
||||||
override getAppID(): string {
|
override getAppID(): string {
|
||||||
return `${"appId" in this.app ? this.app.appId : ""}`;
|
return `${"appId" in this.app ? this.app.appId : ""}`;
|
||||||
@@ -95,7 +102,7 @@ export class ObsidianAPIService extends InjectableAPIService<ObsidianServiceCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
override getAppVersion(): string {
|
override getAppVersion(): string {
|
||||||
const navigatorString = globalThis.navigator?.userAgent ?? "";
|
const navigatorString = compatGlobal.navigator?.userAgent ?? "";
|
||||||
const match = navigatorString.match(/obsidian\/([0-9]+\.[0-9]+\.[0-9]+)/);
|
const match = navigatorString.match(/obsidian\/([0-9]+\.[0-9]+\.[0-9]+)/);
|
||||||
if (match && match.length >= 2) {
|
if (match && match.length >= 2) {
|
||||||
return match[1];
|
return match[1];
|
||||||
@@ -196,7 +203,7 @@ export class ObsidianAPIService extends InjectableAPIService<ObsidianServiceCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
override setInterval(handler: () => void, timeout: number): number {
|
override setInterval(handler: () => void, timeout: number): number {
|
||||||
const timerId = globalThis.setInterval(handler, timeout) as unknown as number;
|
const timerId = compatGlobal.setInterval(handler, timeout);
|
||||||
this.context.plugin.registerInterval(timerId);
|
this.context.plugin.registerInterval(timerId);
|
||||||
return timerId;
|
return timerId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user