refactor: integrate PathUtils into FontManager.ts
- Replace path.join operations with PathUtils methods - Remove path module import, use PathUtils for all path operations - Already used vault.adapter correctly for file operations - Maintain consistency with other migrated files
This commit is contained in:
1 file changed
+14
-5
@@ -6,7 +6,7 @@
|
|||||||
import type { obsidianTypstPDFExport } from '../../main';
|
import type { obsidianTypstPDFExport } from '../../main';
|
||||||
import { ExportErrorHandler } from '../core/ExportErrorHandler';
|
import { ExportErrorHandler } from '../core/ExportErrorHandler';
|
||||||
import { FALLBACK_FONTS } from '../core/constants';
|
import { FALLBACK_FONTS } from '../core/constants';
|
||||||
import * as path from 'path';
|
import { PathUtils } from '../core/PathUtils';
|
||||||
|
|
||||||
export class FontManager {
|
export class FontManager {
|
||||||
constructor(private plugin: obsidianTypstPDFExport) {}
|
constructor(private plugin: obsidianTypstPDFExport) {}
|
||||||
@@ -67,8 +67,11 @@ export class FontManager {
|
|||||||
typstPath: typstPath
|
typstPath: typstPath
|
||||||
};
|
};
|
||||||
|
|
||||||
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
|
const pathUtils = new PathUtils(this.plugin.app);
|
||||||
await this.plugin.app.vault.adapter.write(fontsCachePath,
|
const vaultPath = pathUtils.getVaultPath();
|
||||||
|
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
|
||||||
|
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
|
||||||
|
await this.plugin.app.vault.adapter.write(fontsCachePath,
|
||||||
JSON.stringify(cacheData, null, 2));
|
JSON.stringify(cacheData, null, 2));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to cache fonts from typst:', error);
|
console.error('Failed to cache fonts from typst:', error);
|
||||||
@@ -86,7 +89,10 @@ export class FontManager {
|
|||||||
error: error.message
|
error: error.message
|
||||||
};
|
};
|
||||||
|
|
||||||
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
|
const pathUtils = new PathUtils(this.plugin.app);
|
||||||
|
const vaultPath = pathUtils.getVaultPath();
|
||||||
|
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
|
||||||
|
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
|
||||||
await this.plugin.app.vault.adapter.write(fontsCachePath,
|
await this.plugin.app.vault.adapter.write(fontsCachePath,
|
||||||
JSON.stringify(cacheData, null, 2));
|
JSON.stringify(cacheData, null, 2));
|
||||||
}
|
}
|
||||||
@@ -97,7 +103,10 @@ export class FontManager {
|
|||||||
*/
|
*/
|
||||||
async getCachedFonts(): Promise<string[]> {
|
async getCachedFonts(): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
|
const pathUtils = new PathUtils(this.plugin.app);
|
||||||
|
const vaultPath = pathUtils.getVaultPath();
|
||||||
|
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
|
||||||
|
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
|
||||||
const cacheContent = await this.plugin.app.vault.adapter.read(fontsCachePath);
|
const cacheContent = await this.plugin.app.vault.adapter.read(fontsCachePath);
|
||||||
const cacheData = JSON.parse(cacheContent);
|
const cacheData = JSON.parse(cacheContent);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user