refactor: migrate PluginLifecycle to use PathUtils
- 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 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+10
-6
@@ -9,10 +9,14 @@ import { PandocTypstConverter } from '../converters/PandocTypstConverter';
|
|||||||
import { TemplateManager } from '../templates/TemplateManager';
|
import { TemplateManager } from '../templates/TemplateManager';
|
||||||
import { EmbeddedTemplateManager } from '../templates/embeddedTemplates';
|
import { EmbeddedTemplateManager } from '../templates/embeddedTemplates';
|
||||||
import { TempDirectoryManager } from '../core/TempDirectoryManager';
|
import { TempDirectoryManager } from '../core/TempDirectoryManager';
|
||||||
import * as path from 'path';
|
import { PathUtils } from '../core/PathUtils';
|
||||||
|
|
||||||
export class PluginLifecycle {
|
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
|
* Initialize the plugin during onload
|
||||||
@@ -22,8 +26,8 @@ export class PluginLifecycle {
|
|||||||
await this.plugin.loadSettings();
|
await this.plugin.loadSettings();
|
||||||
|
|
||||||
// Initialize embedded template manager
|
// Initialize embedded template manager
|
||||||
const vaultPath = (this.plugin.app.vault.adapter as unknown as { basePath: string }).basePath;
|
const vaultPath = this.pathUtils.getVaultPath();
|
||||||
const pluginDir = path.join(vaultPath, this.plugin.manifest.dir!);
|
const pluginDir = this.pathUtils.joinPath(vaultPath, this.pathUtils.getPluginDir(this.plugin.manifest));
|
||||||
this.plugin.embeddedTemplateManager = new EmbeddedTemplateManager(pluginDir);
|
this.plugin.embeddedTemplateManager = new EmbeddedTemplateManager(pluginDir);
|
||||||
|
|
||||||
// Extract any missing templates from embedded data
|
// 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)
|
// Clean up temp directories on plugin unload (fire-and-forget async)
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
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 cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app);
|
||||||
await cleanupManager.cleanupAllTempDirs();
|
await cleanupManager.cleanupAllTempDirs();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -83,7 +87,7 @@ export class PluginLifecycle {
|
|||||||
// Clean up temp directories (fire-and-forget async)
|
// Clean up temp directories (fire-and-forget async)
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
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 cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir, undefined, this.plugin.app);
|
||||||
const _result = await cleanupManager.cleanupAllTempDirs();
|
const _result = await cleanupManager.cleanupAllTempDirs();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user