@@ -16,6 +16,7 @@ export const excerptAfter = 300
|
|||||||
export const highlightClass = `suggestion-highlight omnisearch-highlight ${
|
export const highlightClass = `suggestion-highlight omnisearch-highlight ${
|
||||||
settings.highlight ? 'omnisearch-default-highlight' : ''
|
settings.highlight ? 'omnisearch-default-highlight' : ''
|
||||||
}`
|
}`
|
||||||
|
export const K_DISABLE_OMNISEARCH = 'omnisearch-disabled'
|
||||||
|
|
||||||
export const eventBus = new EventBus()
|
export const eventBus = new EventBus()
|
||||||
|
|
||||||
|
|||||||
10
src/main.ts
10
src/main.ts
@@ -4,6 +4,7 @@ import {
|
|||||||
OmnisearchVaultModal,
|
OmnisearchVaultModal,
|
||||||
} from './components/modals'
|
} from './components/modals'
|
||||||
import {
|
import {
|
||||||
|
isPluginDisabled,
|
||||||
loadSettings,
|
loadSettings,
|
||||||
saveSettings,
|
saveSettings,
|
||||||
settings,
|
settings,
|
||||||
@@ -29,6 +30,13 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
|
|
||||||
async onload(): Promise<void> {
|
async onload(): Promise<void> {
|
||||||
await loadSettings(this)
|
await loadSettings(this)
|
||||||
|
this.addSettingTab(new SettingsTab(this))
|
||||||
|
|
||||||
|
if (isPluginDisabled()) {
|
||||||
|
console.log('Omnisearch - Plugin disabled')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await cleanOldCacheFiles()
|
await cleanOldCacheFiles()
|
||||||
await OmnisearchCache.clearOldDatabases()
|
await OmnisearchCache.clearOldDatabases()
|
||||||
|
|
||||||
@@ -38,7 +46,6 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
this.addRibbonButton()
|
this.addRibbonButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addSettingTab(new SettingsTab(this))
|
|
||||||
eventBus.disable('vault')
|
eventBus.disable('vault')
|
||||||
eventBus.disable('infile')
|
eventBus.disable('infile')
|
||||||
eventBus.on('global', EventNames.ToggleExcerpts, () => {
|
eventBus.on('global', EventNames.ToggleExcerpts, () => {
|
||||||
@@ -252,3 +259,4 @@ function registerAPI(plugin: OmnisearchPlugin): void {
|
|||||||
// Deprecated
|
// Deprecated
|
||||||
;(app as any).plugins.plugins.omnisearch.api = api
|
;(app as any).plugins.plugins.omnisearch.api = api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
} from 'obsidian'
|
} from 'obsidian'
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
import { database } from './database'
|
import { database } from './database'
|
||||||
import { getTextExtractor, isCacheEnabled } from './globals'
|
import { K_DISABLE_OMNISEARCH, getTextExtractor, isCacheEnabled } from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
|
|
||||||
interface WeightingSettings {
|
interface WeightingSettings {
|
||||||
@@ -55,6 +55,8 @@ export interface OmnisearchSettings extends WeightingSettings {
|
|||||||
*/
|
*/
|
||||||
export const showExcerpt = writable(false)
|
export const showExcerpt = writable(false)
|
||||||
|
|
||||||
|
const needsARestart = `<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
||||||
|
|
||||||
export class SettingsTab extends PluginSettingTab {
|
export class SettingsTab extends PluginSettingTab {
|
||||||
plugin: OmnisearchPlugin
|
plugin: OmnisearchPlugin
|
||||||
|
|
||||||
@@ -72,6 +74,11 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
const { containerEl } = this
|
const { containerEl } = this
|
||||||
containerEl.empty()
|
containerEl.empty()
|
||||||
|
|
||||||
|
if (app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1') {
|
||||||
|
const span = containerEl.createEl('span')
|
||||||
|
span.innerHTML = `<strong style="color: var(--text-accent)">⚠️ OMNISEARCH IS DISABLED ⚠️</strong>`
|
||||||
|
}
|
||||||
|
|
||||||
// Settings main title
|
// Settings main title
|
||||||
containerEl.createEl('h2', { text: 'Omnisearch' })
|
containerEl.createEl('h2', { text: 'Omnisearch' })
|
||||||
|
|
||||||
@@ -138,7 +145,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
Add extensions separated by a space, without the dot. Example: "<code>txt org</code>".<br />
|
Add extensions separated by a space, without the dot. Example: "<code>txt org</code>".<br />
|
||||||
⚠️ <span style="color: var(--text-accent)">Using extensions of non-plaintext files (like .docx or .pptx) WILL cause crashes,
|
⚠️ <span style="color: var(--text-accent)">Using extensions of non-plaintext files (like .docx or .pptx) WILL cause crashes,
|
||||||
because Omnisearch will try to index their content.</span><br />
|
because Omnisearch will try to index their content.</span><br />
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
${needsARestart}`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Additional files to index')
|
.setName('Additional files to index')
|
||||||
@@ -192,7 +199,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
||||||
⚠️ <span style="color: var(--text-accent)">You probably should <strong>NOT</strong> disable this.</span><br>
|
⚠️ <span style="color: var(--text-accent)">You probably should <strong>NOT</strong> disable this.</span><br>
|
||||||
⚠️ <span style="color: var(--text-accent)">Changing this setting will clear the cache.</span><br>
|
⚠️ <span style="color: var(--text-accent)">Changing this setting will clear the cache.</span><br>
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>
|
${needsARestart}
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
@@ -211,7 +218,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
camelCaseDesc.createSpan({}, span => {
|
camelCaseDesc.createSpan({}, span => {
|
||||||
span.innerHTML = `Enable this if you want to be able to search for CamelCaseWords as separate words.<br/>
|
span.innerHTML = `Enable this if you want to be able to search for CamelCaseWords as separate words.<br/>
|
||||||
⚠️ <span style="color: var(--text-accent)">Changing this setting will clear the cache.</span><br>
|
⚠️ <span style="color: var(--text-accent)">Changing this setting will clear the cache.</span><br>
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>
|
${needsARestart}
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
@@ -364,7 +371,9 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Enable verbose logging')
|
.setName('Enable verbose logging')
|
||||||
.setDesc('Adds a LOT of logs for debugging purposes. Don\'t forget to disable it.')
|
.setDesc(
|
||||||
|
"Adds a LOT of logs for debugging purposes. Don't forget to disable it."
|
||||||
|
)
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.verboseLogging).onChange(async v => {
|
toggle.setValue(settings.verboseLogging).onChange(async v => {
|
||||||
settings.verboseLogging = v
|
settings.verboseLogging = v
|
||||||
@@ -375,14 +384,33 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
//#endregion Debugginh
|
//#endregion Debugginh
|
||||||
|
|
||||||
//#region Danger Zone
|
//#region Danger Zone
|
||||||
if (isCacheEnabled()) {
|
new Setting(containerEl).setName('Danger Zone').setHeading()
|
||||||
new Setting(containerEl).setName('Danger Zone').setHeading()
|
|
||||||
|
|
||||||
|
const disableDesc = new DocumentFragment()
|
||||||
|
disableDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `Disable Omnisearch on this device only.<br>
|
||||||
|
${needsARestart}`
|
||||||
|
})
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Disable on this device')
|
||||||
|
.setDesc(disableDesc)
|
||||||
|
.addToggle(toggle =>
|
||||||
|
toggle.setValue(isPluginDisabled()).onChange(async v => {
|
||||||
|
if (v) {
|
||||||
|
app.saveLocalStorage(K_DISABLE_OMNISEARCH, '1')
|
||||||
|
} else {
|
||||||
|
app.saveLocalStorage(K_DISABLE_OMNISEARCH) // No value = unset
|
||||||
|
}
|
||||||
|
new Notice('Omnisearch - Disabled. Please restart Obsidian.')
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isCacheEnabled()) {
|
||||||
const resetCacheDesc = new DocumentFragment()
|
const resetCacheDesc = new DocumentFragment()
|
||||||
resetCacheDesc.createSpan({}, span => {
|
resetCacheDesc.createSpan({}, span => {
|
||||||
span.innerHTML = `Erase all Omnisearch cache data.
|
span.innerHTML = `Erase all Omnisearch cache data.
|
||||||
Use this if Omnisearch results are inconsistent, missing, or appear outdated.<br>
|
Use this if Omnisearch results are inconsistent, missing, or appear outdated.<br>
|
||||||
<strong style="color: var(--text-accent)">Needs a restart to fully take effect.</strong>`
|
${needsARestart}`
|
||||||
})
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Clear cache data')
|
.setName('Clear cache data')
|
||||||
@@ -446,3 +474,7 @@ export async function loadSettings(plugin: Plugin): Promise<void> {
|
|||||||
export async function saveSettings(plugin: Plugin): Promise<void> {
|
export async function saveSettings(plugin: Plugin): Promise<void> {
|
||||||
await plugin.saveData(settings)
|
await plugin.saveData(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPluginDisabled(): boolean {
|
||||||
|
return app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1'
|
||||||
|
}
|
||||||
4
src/typings/types-obsidian.d.ts
vendored
4
src/typings/types-obsidian.d.ts
vendored
@@ -17,7 +17,7 @@ declare module 'obsidian' {
|
|||||||
|
|
||||||
interface App {
|
interface App {
|
||||||
appId: string
|
appId: string
|
||||||
|
loadLocalStorage(key: string): string | null
|
||||||
|
saveLocalStorage(key: string, value?: string): void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user