From da904e6ddd19bacb9b0dbfbfcb935d17ce658574 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 25 Sep 2025 12:11:00 +0200 Subject: [PATCH] refactor: migrate PluginLifecycle to use PathUtils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced multiple basePath hacks (lines 25, 70, 86) with PathUtils.getVaultPath() - Replaced path.join with PathUtils.joinPath() and getPluginDir() - Removed path import after migration to PathUtils - Added PathUtils integration for consistent path operations - All three basePath hack locations now use proper Obsidian API methods - TempDirectoryManager calls already updated in previous commit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/plugin/PluginLifecycle.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugin/PluginLifecycle.ts b/src/plugin/PluginLifecycle.ts index 10a3ab3..8202c4b 100644 --- a/src/plugin/PluginLifecycle.ts +++ b/src/plugin/PluginLifecycle.ts @@ -9,10 +9,14 @@ import { PandocTypstConverter } from '../converters/PandocTypstConverter'; import { TemplateManager } from '../templates/TemplateManager'; import { EmbeddedTemplateManager } from '../templates/embeddedTemplates'; import { TempDirectoryManager } from '../core/TempDirectoryManager'; -import * as path from 'path'; +import { PathUtils } from '../core/PathUtils'; export class PluginLifecycle { - constructor(private plugin: obsidianTypstPDFExport) {} + private readonly pathUtils: PathUtils; + + constructor(private plugin: obsidianTypstPDFExport) { + this.pathUtils = new PathUtils(plugin.app); + } /** * Initialize the plugin during onload @@ -22,8 +26,8 @@ export class PluginLifecycle { await this.plugin.loadSettings(); // Initialize embedded template manager - const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath; - const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!); + const vaultPath = this.pathUtils.getVaultPath(); + const pluginDir = this.pathUtils.joinPath(vaultPath, this.pathUtils.getPluginDir(this.plugin.manifest)); this.plugin.embeddedTemplateManager = new EmbeddedTemplateManager(pluginDir); // Extract any missing templates from embedded data @@ -67,7 +71,7 @@ export class PluginLifecycle { // Clean up temp directories on plugin unload (fire-and-forget async) (async () => { try { - const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath; + const vaultPath = this.pathUtils.getVaultPath(); const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app); await cleanupManager.cleanupAllTempDirs(); } catch (error) { @@ -83,7 +87,7 @@ export class PluginLifecycle { // Clean up temp directories (fire-and-forget async) (async () => { try { - const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath; + const vaultPath = this.pathUtils.getVaultPath(); const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app); const _result = await cleanupManager.cleanupAllTempDirs();