diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index e92c8ac..7293596 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -9,7 +9,7 @@ import InputSearch from "./InputSearch.svelte" import ModalContainer from "./ModalContainer.svelte" import { eventBus, type ResultNote } from "src/globals" import { createNote, openNote } from "src/notes" -import { getSuggestions } from "src/search" +import { getSuggestions, reindexNotes } from "src/search" import { loopIndex } from "src/utils" import { OmnisearchInFileModal, type OmnisearchVaultModal } from "src/modals" import ResultItemVault from "./ResultItemVault.svelte" @@ -29,6 +29,7 @@ $: if (searchQuery) { } onMount(() => { + reindexNotes() searchQuery = lastSearch eventBus.on("vault", "enter", onInputEnter) eventBus.on("vault", "shift-enter", onInputShiftEnter) diff --git a/src/main.ts b/src/main.ts index 1d36441..fca42cb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,30 +3,21 @@ import { addNoteToReindex, addToIndex, initGlobalSearchIndex, - reindexNotes, removeFromIndex, } from './search' import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' -import { loadSettings, settings, SettingsTab } from './settings' +import { loadSettings, SettingsTab } from './settings' -let mainWindow: { on: any; off: any } | null = null -try { - mainWindow = require('electron').remote.getCurrentWindow() -} -catch (e) { - console.log("Can't load electron, mobile platform") -} - -const onBlur = (): void => { - reindexNotes() -} +// let mainWindow: { on: any; off: any } | null = null +// try { +// mainWindow = require('electron').remote.getCurrentWindow() +// } +// catch (e) { +// console.log("Can't load electron, mobile platform") +// } export default class OmnisearchPlugin extends Plugin { async onload(): Promise { - if (mainWindow) { - mainWindow.on('blur', onBlur) - } - await loadSettings(this) this.addSettingTab(new SettingsTab(this)) @@ -61,13 +52,7 @@ export default class OmnisearchPlugin extends Plugin { ) this.registerEvent( this.app.vault.on('modify', async file => { - if (settings.reindexInRealTime) { - removeFromIndex(file.path) - await addToIndex(file) - } - else { - addNoteToReindex(file) - } + addNoteToReindex(file) }), ) this.registerEvent( @@ -83,9 +68,5 @@ export default class OmnisearchPlugin extends Plugin { }) } - onunload(): void { - if (mainWindow) { - mainWindow.off('blur', onBlur) - } - } + onunload(): void {} } diff --git a/src/search.ts b/src/search.ts index a85403d..c28e2c4 100644 --- a/src/search.ts +++ b/src/search.ts @@ -388,9 +388,13 @@ export function addNoteToReindex(note: TAbstractFile): void { notesToReindex.add(note) } export async function reindexNotes(): Promise { + if (settings.showIndexingNotices && notesToReindex.size > 0) { + new Notice(`Omnisearch - Reindexing ${notesToReindex.size} notes`, 2000) + } for (const note of notesToReindex) { removeFromIndex(note.path) await addToIndex(note) + await wait(0) } notesToReindex.clear() @@ -401,7 +405,7 @@ async function saveIndexToFile(): Promise { if (settings.storeIndexInFile && minisearchInstance && isIndexChanged) { const json = JSON.stringify(minisearchInstance) await app.vault.adapter.write(searchIndexFilePath, json) - console.log('MiniSearch index saved to the file') + console.log('Omnisearch - Index saved on disk') await saveNotesCacheToFile() isIndexChanged = false diff --git a/src/settings.ts b/src/settings.ts index 45f7892..85a6e17 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -10,7 +10,6 @@ interface WeightingSettings { export interface OmnisearchSettings extends WeightingSettings { respectExcluded: boolean - reindexInRealTime: boolean ignoreDiacritics: boolean showIndexingNotices: boolean showShortName: boolean @@ -38,25 +37,6 @@ export class SettingsTab extends PluginSettingTab { new Setting(containerEl).setName('Behavior').setHeading() - // Index in real-time, desktop only - if (require('electron')) { - new Setting(containerEl) - .setName('Reindex in real-time') - .setDesc( - "By default, notes a reindexed when Obsidian focus is lost. Enable this to reindex in real-time. May affect Obsidian's performances when editing large notes.", - ) - .addToggle(toggle => - toggle.setValue(settings.reindexInRealTime).onChange(async v => { - settings.reindexInRealTime = v - await saveSettings(this.plugin) - }), - ) - } - else { - // No real time indexing on mobile - settings.reindexInRealTime = false - } - // Respect excluded files new Setting(containerEl) .setName('Respect Obsidian\'s "Excluded Files"') @@ -193,7 +173,6 @@ export class SettingsTab extends PluginSettingTab { export const DEFAULT_SETTINGS: OmnisearchSettings = { respectExcluded: true, - reindexInRealTime: false, ignoreDiacritics: false, showIndexingNotices: false,