mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-23 13:02:58 +00:00
Reduce Community lint type-safety warnings
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { App } from "@/deps.ts";
|
||||
|
||||
function getSettingsManager(app: App): Record<string, unknown> {
|
||||
const manager: unknown = Reflect.get(app, "setting");
|
||||
if (typeof manager !== "object" || manager === null) {
|
||||
throw new TypeError("Obsidian does not expose the settings manager");
|
||||
}
|
||||
return manager as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function invokeSettingsMethod(app: App, methodName: string, args: unknown[] = []): void {
|
||||
const manager = getSettingsManager(app);
|
||||
const method = manager[methodName];
|
||||
if (typeof method !== "function") {
|
||||
throw new TypeError(`Obsidian does not expose settings.${methodName}`);
|
||||
}
|
||||
Reflect.apply(method, manager, args);
|
||||
}
|
||||
|
||||
export function openObsidianSettings(app: App, tabId: string): void {
|
||||
invokeSettingsMethod(app, "open");
|
||||
invokeSettingsMethod(app, "openTabById", [tabId]);
|
||||
}
|
||||
|
||||
export function closeObsidianSettings(app: App): void {
|
||||
invokeSettingsMethod(app, "close");
|
||||
}
|
||||
Reference in New Issue
Block a user