Cleaning deps

This commit is contained in:
Scott Tomaszewski 2025-04-24 16:25:00 -04:00
parent 52e579c3f7
commit 93c26d5a25
2 changed files with 34 additions and 41 deletions

View file

@ -13,23 +13,23 @@ import { BibleMarkupProcessor } from './BibleMarkupProcessor';
*/
export default class DisciplesJournalPlugin extends Plugin {
settings: DisciplesJournalSettings;
// Services
private esvApiService: ESVApiService;
private bibleContentService: BibleContentService;
private bibleBookFiles: BibleBookFiles;
// Components
private bibleStyles: BibleStyles;
private bibleReferenceRenderer: BibleReferenceRenderer;
private bibleMarkupProcessor: BibleMarkupProcessor;
async onload() {
console.log('Loading Disciples Journal plugin');
// Initialize settings
await this.loadSettings();
// Initialize services
this.esvApiService = new ESVApiService(this);
this.bibleContentService = new BibleContentService(this, this.esvApiService);
@ -38,14 +38,10 @@ export default class DisciplesJournalPlugin extends Plugin {
if (!this.settings.esvApiToken) {
new Notice('Disciples Journal: ESV API token not set. Bible content may not load correctly. Visit the plugin settings to add your API token.', 10000);
}
// Initialize components
this.bibleStyles = new BibleStyles();
this.bibleBookFiles = new BibleBookFiles(
this.app,
this.bibleContentService,
this.settings
);
this.bibleBookFiles = new BibleBookFiles(this, this.bibleContentService);
this.bibleReferenceRenderer = new BibleReferenceRenderer(
this.bibleContentService,
@ -55,34 +51,34 @@ export default class DisciplesJournalPlugin extends Plugin {
// Initialize markup processor
this.bibleMarkupProcessor = new BibleMarkupProcessor(this.bibleReferenceRenderer, this.settings);
// Register bible reference processor
this.registerMarkdownCodeBlockProcessor('bible', this.bibleMarkupProcessor.processBibleCodeBlock.bind(this.bibleMarkupProcessor));
// Register markdown post processor for inline references
this.registerMarkdownPostProcessor(this.bibleMarkupProcessor.processInlineBibleReferences.bind(this.bibleMarkupProcessor));
// Register settings tab
this.addSettingTab(new DisciplesJournalSettingsTab(this.app, this));
// Register active leaf change to update styles
this.registerEvent(this.app.workspace.on('active-leaf-change', this.handleActiveLeafChange.bind(this)));
// Load Bible data
await this.loadBibleData();
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
/**
* Load the Bible data from source
*/
@ -95,7 +91,7 @@ export default class DisciplesJournalPlugin extends Plugin {
console.error('Error loading Bible data:', error);
}
}
/**
* Handle leaf change event to check for verse references in the URL
*/
@ -103,14 +99,14 @@ export default class DisciplesJournalPlugin extends Plugin {
// Refresh theme/styling when active leaf changes
this.updateBibleStyles();
}
/**
* Update Bible styles with current settings
*/
public updateBibleStyles(): void {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!activeLeaf) return;
// Each popup window has a unique document, so we need to apply styles to each one
// See https://discord.com/channels/686053708261228577/840286264964022302/1362059117190975519
// Note: this doesnt completely work. When a new popout is created the style cars arent ported over
@ -121,8 +117,8 @@ export default class DisciplesJournalPlugin extends Plugin {
const theme = isDarkMode ? 'dark' : 'light';
this.bibleStyles.applyStyles(
doc,
theme,
this.settings.stylePreset,
theme,
this.settings.stylePreset,
this.settings.bibleTextFontSize,
{
wordsOfChristColor: this.settings.wordsOfChristColor,

View file

@ -1,25 +1,22 @@
import { App, TFile } from 'obsidian';
import { TFile } from 'obsidian';
import { BibleContentService } from './BibleContentService';
import { BibleReference } from '../core/BibleReference';
import { BibleFormatter } from '../utils/BibleFormatter';
import { DisciplesJournalSettings } from '../settings/DisciplesJournalSettings';
import DisciplesJournalPlugin from "../core/DisciplesJournalPlugin";
/**
* Service for creating and opening Bible chapter notes
*/
export class BibleBookFiles {
private app: App;
private plugin: DisciplesJournalPlugin;
private bibleContentService: BibleContentService;
private settings: DisciplesJournalSettings;
constructor(
app: App,
plugin: DisciplesJournalPlugin,
bibleContentService: BibleContentService,
settings: DisciplesJournalSettings
) {
this.app = app;
this.plugin = plugin;
this.bibleContentService = bibleContentService;
this.settings = settings;
}
/**
@ -39,18 +36,18 @@ export class BibleBookFiles {
const chapterPath = `${fullPath}/${parsedRef.book}/${parsedRef.book} ${parsedRef.chapter}.md`;
// Check if note exists
const fileExists = await this.app.vault.adapter.exists(chapterPath);
const fileExists = await this.plugin.app.vault.adapter.exists(chapterPath);
if (!fileExists && this.settings.downloadOnDemand) {
if (!fileExists && this.plugin.settings.downloadOnDemand) {
// Create the note with content from the API
await this.createChapterNote(parsedRef);
}
// Try opening the note
const file = this.app.vault.getAbstractFileByPath(chapterPath);
const file = this.plugin.app.vault.getAbstractFileByPath(chapterPath);
if (file && file instanceof TFile) {
const leaf = this.app.workspace.getLeaf(false);
const leaf = this.plugin.app.workspace.getLeaf(false);
await leaf.openFile(file);
// If there's a specific verse, scroll to it
@ -97,10 +94,10 @@ export class BibleBookFiles {
const chapterPath = `${fullPath}/${reference.book}/${reference.book} ${reference.chapter}.md`;
// Ensure the directory exists
await this.app.vault.adapter.mkdir(bookPath);
await this.plugin.app.vault.adapter.mkdir(bookPath);
// Create the note
await this.app.vault.create(chapterPath, content);
await this.plugin.app.vault.create(chapterPath, content);
return chapterPath;
} catch (error) {
@ -113,6 +110,6 @@ export class BibleBookFiles {
* Get the full path with version
*/
private getFullContentPath(): string {
return `${this.settings.bibleContentVaultPath}/${this.settings.preferredBibleVersion}`;
return `${this.plugin.settings.bibleContentVaultPath}/${this.plugin.settings.preferredBibleVersion}`;
}
}