From eb4c84125037ff9434c2f917c9bf82053510456d Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 30 Sep 2022 22:48:15 +0200 Subject: [PATCH] Added welcome message --- src/main.ts | 5 ++++- src/settings.ts | 4 ++++ src/utils.ts | 23 ++++++++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 072d9f8..e0c804c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,7 +6,7 @@ import { eventBus } from './globals' import { registerAPI } from '@vanakat/plugin-api' import api from './api' import { loadSearchHistory } from './search-history' -import { isFileIndexable } from './utils' +import {isFileIndexable, showWelcomeNotice} from './utils' import { addNoteToReindex, addToIndex, removeFromIndex } from './notes-index' function _registerAPI(plugin: OmnisearchPlugin): void { @@ -22,6 +22,7 @@ export default class OmnisearchPlugin extends Plugin { // additional files to index by Omnisearch await loadSettings(this) + this.registerExtensions(settings.indexedFileTypes, 'markdown') await loadSearchHistory() @@ -83,6 +84,8 @@ export default class OmnisearchPlugin extends Plugin { await initGlobalSearchIndex() }) + + showWelcomeNotice(this) } onunload(): void {} diff --git a/src/settings.ts b/src/settings.ts index 88885c3..be58fa0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -25,6 +25,8 @@ export interface OmnisearchSettings extends WeightingSettings { showCreateButton: boolean CtrlJK: boolean CtrlNP: boolean + + welcomeMessage: string } /** @@ -308,6 +310,8 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = { CtrlNP: false, storeIndexInFile: false, + + welcomeMessage: '' } as const export let settings = Object.assign({}, DEFAULT_SETTINGS) as OmnisearchSettings diff --git a/src/utils.ts b/src/utils.ts index 492050a..d90d50e 100644 --- a/src/utils.ts +++ b/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 { excerptAfter, excerptBefore, @@ -8,7 +9,6 @@ import { regexStripQuotes, regexYaml, } from './globals' -import type { SearchMatch } from './globals' import { settings } from './settings' export function highlighter(str: string): string { @@ -174,7 +174,8 @@ export function getCtrlKeyLabel(): 'ctrl' | '⌘' { export function isFileIndexable(path: string): boolean { return ( - path.endsWith('.md') || (settings.indexPDFs && path.endsWith('.pdf')) || + path.endsWith('.md') || + (settings.indexPDFs && path.endsWith('.pdf')) || settings.indexedFileTypes.some(t => path.endsWith(`.${t}`)) ) } @@ -183,3 +184,19 @@ export function getExtension(path: string): string { const split = path.split('.') 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 = `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) +} \ No newline at end of file