diff --git a/src/globals.ts b/src/globals.ts index 0a19881..953cc3b 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -17,6 +17,9 @@ export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/not export const pdfCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/pdfCache.data` export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json` +export const oldSearchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json` +export const oldNnotesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json` + export const EventNames = { ToggleExcerpts: 'toggle-excerpts', } as const diff --git a/src/main.ts b/src/main.ts index bd54e63..f6def97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,17 @@ -import { Plugin, TFile } from 'obsidian' +import { Notice, Plugin, TFile } from 'obsidian' import * as Search from './search' import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' import { loadSettings, settings, SettingsTab, showExcerpt } from './settings' -import { eventBus, EventNames } from './globals' +import { + eventBus, + EventNames, + oldNnotesCacheFilePath, + oldSearchIndexFilePath, +} from './globals' import { registerAPI } from '@vanakat/plugin-api' import api from './api' import { loadSearchHistory } from './search-history' -import { isFilePlaintext, showWelcomeNotice } from './utils' +import { isFilePlaintext } from './utils' import * as NotesIndex from './notes-index' import { cacheManager } from './cache-manager' import { pdfManager } from './pdf-manager' @@ -21,7 +26,7 @@ function _registerAPI(plugin: OmnisearchPlugin): void { export default class OmnisearchPlugin extends Plugin { async onload(): Promise { - + await cleanOldCacheFiles() await loadSettings(this) await loadSearchHistory() await cacheManager.loadNotesCache() @@ -100,3 +105,33 @@ export default class OmnisearchPlugin extends Plugin { }) } } + +async function cleanOldCacheFiles() { + if (await app.vault.adapter.exists(oldSearchIndexFilePath)) { + try { + await app.vault.adapter.remove(oldSearchIndexFilePath) + } catch (e) {} + } + if (await app.vault.adapter.exists(oldNnotesCacheFilePath)) { + try { + await app.vault.adapter.remove(oldNnotesCacheFilePath) + } catch (e) {} + } +} + +function showWelcomeNotice(plugin: Plugin) { + return + const code = '1.6.0' + if (settings.welcomeMessage !== code) { + const welcome = new DocumentFragment() + welcome.createSpan({}, span => { + span.innerHTML = `Omnisearch has been updated +New beta feature: PDF search 🔎📄 +Toggle "BETA - Index PDFs" in Omnisearch settings page.` + }) + new Notice(welcome, 30000) + } + settings.welcomeMessage = code + + plugin.saveData(settings) +} diff --git a/src/utils.ts b/src/utils.ts index 936d450..42f68a0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -192,23 +192,6 @@ export function getExtension(path: string): string { return split[split.length - 1] } -export function showWelcomeNotice(plugin: Plugin) { - return - const code = '1.6.0' - if (settings.welcomeMessage !== code) { - const welcome = new DocumentFragment() - welcome.createSpan({}, span => { - span.innerHTML = `Omnisearch has been updated -New beta feature: PDF search 🔎📄 -Toggle "BETA - Index PDFs" in Omnisearch settings page.` - }) - new Notice(welcome, 30000) - } - settings.welcomeMessage = code - - plugin.saveData(settings) -} - export function md5(data: BinaryLike): string { return createHash('md5').update(data).digest('hex') }