import { Setting } from 'obsidian'
import type { LocatorSettings } from './utils'
import { saveSettings } from './utils'
import { htmlDescription } from './utils'
import type LocatorPlugin from 'src/main'
import { debounce } from 'lodash-es'
export function injectSettingsIndexing(
plugin: LocatorPlugin,
settings: LocatorSettings,
containerEl: HTMLElement
) {
const textExtractor = plugin.getTextExtractor()
const aiImageAnalyzer = plugin.getAIImageAnalyzer()
const database = plugin.database
const clearCacheDebounced = debounce(async () => {
await database.clearCache()
}, 1000)
new Setting(containerEl)
.setName('Indexing')
.setHeading()
.setDesc(
htmlDescription(`⚠️ Changing indexing settings will clear the cache, and requires a restart of Obsidian.
${
textExtractor
? `👍 You have installed Text Extractor, Locator can use it to index PDFs and images contents.
Text extraction only works on desktop, but the cache can be synchronized with your mobile device.`
: `⚠️ Locator requires Text Extractor to index PDFs and images.`
}
${
aiImageAnalyzer
? `
👍 You have installed AI Image Analyzer, Locator can use it to index images contents with ai.`
: `
⚠️ Locator requires AI Image Analyzer to index images with ai.`
}`)
)
// PDF Indexing
new Setting(containerEl)
.setName(`PDFs content indexing ${textExtractor ? '' : '⚠️ Disabled'}`)
.setDesc(
htmlDescription(
`Locator will use Text Extractor to index the content of your PDFs.`
)
)
.addToggle(toggle =>
toggle.setValue(settings.PDFIndexing).onChange(async v => {
await database.clearCache()
settings.PDFIndexing = v
await saveSettings(plugin)
})
)
.setDisabled(!textExtractor)
// Images Indexing
new Setting(containerEl)
.setName(`Images OCR indexing ${textExtractor ? '' : '⚠️ Disabled'}`)
.setDesc(
htmlDescription(
`Locator will use Text Extractor to OCR your images and index their content.`
)
)
.addToggle(toggle =>
toggle.setValue(settings.imagesIndexing).onChange(async v => {
await database.clearCache()
settings.imagesIndexing = v
await saveSettings(plugin)
})
)
.setDisabled(!textExtractor)
// Office Documents Indexing
const indexOfficesDesc = new DocumentFragment()
indexOfficesDesc.createSpan({}, span => {
span.innerHTML = `Locator will use Text Extractor to index the content of your office documents (currently
.docxand
.xlsx).` }) new Setting(containerEl) .setName(`Documents content indexing ${textExtractor ? '' : '⚠️ Disabled'}`) .setDesc(indexOfficesDesc) .addToggle(toggle => toggle.setValue(settings.officeIndexing).onChange(async v => { await database.clearCache() settings.officeIndexing = v await saveSettings(plugin) }) ) .setDisabled(!textExtractor) // AI Images Indexing const aiIndexImagesDesc = new DocumentFragment() aiIndexImagesDesc.createSpan({}, span => { span.innerHTML = `Locator will use AI Image Analyzer to index the content of your images with ai.` }) new Setting(containerEl) .setName(`Images AI indexing ${aiImageAnalyzer ? '' : '⚠️ Disabled'}`) .setDesc(aiIndexImagesDesc) .addToggle(toggle => toggle.setValue(settings.aiImageIndexing).onChange(async v => { await database.clearCache() settings.aiImageIndexing = v await saveSettings(plugin) }) ) .setDisabled(!aiImageAnalyzer) // Index filenames of unsupported files new Setting(containerEl) .setName('Index paths of unsupported files') .setDesc( htmlDescription(` Locator can index filenames of "unsupported" files, such as e.g.
.mp4or non-extracted PDFs & images.
md
files, Locator can also index other PLAINTEXT files.txt org csv
".