Added welcome message
This commit is contained in:
@@ -6,7 +6,7 @@ import { eventBus } 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 { isFileIndexable } from './utils'
|
import {isFileIndexable, showWelcomeNotice} from './utils'
|
||||||
import { addNoteToReindex, addToIndex, removeFromIndex } from './notes-index'
|
import { addNoteToReindex, addToIndex, removeFromIndex } from './notes-index'
|
||||||
|
|
||||||
function _registerAPI(plugin: OmnisearchPlugin): void {
|
function _registerAPI(plugin: OmnisearchPlugin): void {
|
||||||
@@ -22,6 +22,7 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
// additional files to index by Omnisearch
|
// additional files to index by Omnisearch
|
||||||
|
|
||||||
await loadSettings(this)
|
await loadSettings(this)
|
||||||
|
|
||||||
this.registerExtensions(settings.indexedFileTypes, 'markdown')
|
this.registerExtensions(settings.indexedFileTypes, 'markdown')
|
||||||
await loadSearchHistory()
|
await loadSearchHistory()
|
||||||
|
|
||||||
@@ -83,6 +84,8 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
|
|
||||||
await initGlobalSearchIndex()
|
await initGlobalSearchIndex()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
showWelcomeNotice(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload(): void {}
|
onunload(): void {}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export interface OmnisearchSettings extends WeightingSettings {
|
|||||||
showCreateButton: boolean
|
showCreateButton: boolean
|
||||||
CtrlJK: boolean
|
CtrlJK: boolean
|
||||||
CtrlNP: boolean
|
CtrlNP: boolean
|
||||||
|
|
||||||
|
welcomeMessage: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,6 +310,8 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
|||||||
CtrlNP: false,
|
CtrlNP: false,
|
||||||
|
|
||||||
storeIndexInFile: false,
|
storeIndexInFile: false,
|
||||||
|
|
||||||
|
welcomeMessage: ''
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export let settings = Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings
|
export let settings = Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings
|
||||||
|
|||||||
23
src/utils.ts
23
src/utils.ts
@@ -1,4 +1,5 @@
|
|||||||
import { Platform, type CachedMetadata } from 'obsidian'
|
import { type CachedMetadata, Notice, Platform, Plugin } from 'obsidian'
|
||||||
|
import type { SearchMatch } from './globals'
|
||||||
import {
|
import {
|
||||||
excerptAfter,
|
excerptAfter,
|
||||||
excerptBefore,
|
excerptBefore,
|
||||||
@@ -8,7 +9,6 @@ import {
|
|||||||
regexStripQuotes,
|
regexStripQuotes,
|
||||||
regexYaml,
|
regexYaml,
|
||||||
} from './globals'
|
} from './globals'
|
||||||
import type { SearchMatch } from './globals'
|
|
||||||
import { settings } from './settings'
|
import { settings } from './settings'
|
||||||
|
|
||||||
export function highlighter(str: string): string {
|
export function highlighter(str: string): string {
|
||||||
@@ -174,7 +174,8 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
|
|||||||
|
|
||||||
export function isFileIndexable(path: string): boolean {
|
export function isFileIndexable(path: string): boolean {
|
||||||
return (
|
return (
|
||||||
path.endsWith('.md') || (settings.indexPDFs && path.endsWith('.pdf')) ||
|
path.endsWith('.md') ||
|
||||||
|
(settings.indexPDFs && path.endsWith('.pdf')) ||
|
||||||
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
|
settings.indexedFileTypes.some(t => path.endsWith(`.${t}`))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -183,3 +184,19 @@ export function getExtension(path: string): string {
|
|||||||
const split = path.split('.')
|
const split = path.split('.')
|
||||||
return split[split.length - 1]
|
return split[split.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showWelcomeNotice(plugin: Plugin) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user