Cleaning old cache files
This commit is contained in:
@@ -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 pdfCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/pdfCache.data`
|
||||||
export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json`
|
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 = {
|
export const EventNames = {
|
||||||
ToggleExcerpts: 'toggle-excerpts',
|
ToggleExcerpts: 'toggle-excerpts',
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
43
src/main.ts
43
src/main.ts
@@ -1,12 +1,17 @@
|
|||||||
import { Plugin, TFile } from 'obsidian'
|
import { Notice, Plugin, TFile } from 'obsidian'
|
||||||
import * as Search from './search'
|
import * as Search from './search'
|
||||||
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
|
||||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
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 { registerAPI } from '@vanakat/plugin-api'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
import { loadSearchHistory } from './search-history'
|
import { loadSearchHistory } from './search-history'
|
||||||
import { isFilePlaintext, showWelcomeNotice } from './utils'
|
import { isFilePlaintext } from './utils'
|
||||||
import * as NotesIndex from './notes-index'
|
import * as NotesIndex from './notes-index'
|
||||||
import { cacheManager } from './cache-manager'
|
import { cacheManager } from './cache-manager'
|
||||||
import { pdfManager } from './pdf-manager'
|
import { pdfManager } from './pdf-manager'
|
||||||
@@ -21,7 +26,7 @@ function _registerAPI(plugin: OmnisearchPlugin): void {
|
|||||||
|
|
||||||
export default class OmnisearchPlugin extends Plugin {
|
export default class OmnisearchPlugin extends Plugin {
|
||||||
async onload(): Promise<void> {
|
async onload(): Promise<void> {
|
||||||
|
await cleanOldCacheFiles()
|
||||||
await loadSettings(this)
|
await loadSettings(this)
|
||||||
await loadSearchHistory()
|
await loadSearchHistory()
|
||||||
await cacheManager.loadNotesCache()
|
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 = `<strong>Omnisearch has been updated</strong>
|
||||||
|
New beta feature: PDF search 🔎📄
|
||||||
|
<small>Toggle "<i>BETA - Index PDFs</i>" in Omnisearch settings page.</small>`
|
||||||
|
})
|
||||||
|
new Notice(welcome, 30000)
|
||||||
|
}
|
||||||
|
settings.welcomeMessage = code
|
||||||
|
|
||||||
|
plugin.saveData(settings)
|
||||||
|
}
|
||||||
|
|||||||
17
src/utils.ts
17
src/utils.ts
@@ -192,23 +192,6 @@ export function getExtension(path: string): string {
|
|||||||
return split[split.length - 1]
|
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 = `<strong>Omnisearch has been updated</strong>
|
|
||||||
New beta feature: PDF search 🔎📄
|
|
||||||
<small>Toggle "<i>BETA - Index PDFs</i>" in Omnisearch settings page.</small>`
|
|
||||||
})
|
|
||||||
new Notice(welcome, 30000)
|
|
||||||
}
|
|
||||||
settings.welcomeMessage = code
|
|
||||||
|
|
||||||
plugin.saveData(settings)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function md5(data: BinaryLike): string {
|
export function md5(data: BinaryLike): string {
|
||||||
return createHash('md5').update(data).digest('hex')
|
return createHash('md5').update(data).digest('hex')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user