Cleaned some warnings from the deprecated global app object
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
} from 'src/globals'
|
||||
import { getCtrlKeyLabel, loopIndex } from 'src/tools/utils'
|
||||
import { onDestroy, onMount, tick } from 'svelte'
|
||||
import { MarkdownView } from 'obsidian'
|
||||
import { MarkdownView, App } from 'obsidian'
|
||||
import ModalContainer from './ModalContainer.svelte'
|
||||
import {
|
||||
OmnisearchInFileModal,
|
||||
@@ -24,6 +24,7 @@
|
||||
export let parent: OmnisearchVaultModal | null = null
|
||||
export let singleFilePath = ''
|
||||
export let previousQuery: string | undefined
|
||||
export let app: App
|
||||
|
||||
let searchQuery: string
|
||||
let groupedOffsets: number[] = []
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { MarkdownView, Notice, TFile } from 'obsidian'
|
||||
import { App, MarkdownView, Notice, TFile } from 'obsidian'
|
||||
import { onDestroy, onMount, tick } from 'svelte'
|
||||
import InputSearch from './InputSearch.svelte'
|
||||
import ModalContainer from './ModalContainer.svelte'
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
export let modal: OmnisearchVaultModal
|
||||
export let previousQuery: string | undefined
|
||||
export let app: App
|
||||
|
||||
let selectedIndex = 0
|
||||
let historySearchIndex = 0
|
||||
let searchQuery: string | undefined
|
||||
@@ -296,6 +298,7 @@
|
||||
<ModalContainer>
|
||||
{#each resultNotes as result, i}
|
||||
<ResultItemVault
|
||||
app="{app}"
|
||||
selected="{i === selectedIndex}"
|
||||
note="{result}"
|
||||
on:mousemove="{_ => (selectedIndex = i)}"
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
removeDiacritics,
|
||||
} from '../tools/utils'
|
||||
import ResultItemContainer from './ResultItemContainer.svelte'
|
||||
import { TFile, setIcon } from 'obsidian'
|
||||
import { TFile, setIcon, App } from 'obsidian'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { stringsToRegex, getMatches, makeExcerpt, highlightText } from 'src/tools/text-processing'
|
||||
|
||||
export let selected = false
|
||||
export let note: ResultNote
|
||||
export let app: App
|
||||
|
||||
let imagePath: string | null = null
|
||||
let title = ''
|
||||
|
||||
@@ -164,6 +164,7 @@ export class OmnisearchVaultModal extends OmnisearchModal {
|
||||
const cmp = new ModalVault({
|
||||
target: this.modalEl,
|
||||
props: {
|
||||
app,
|
||||
modal: this,
|
||||
previousQuery: query || selectedText || previous || '',
|
||||
},
|
||||
@@ -189,6 +190,7 @@ export class OmnisearchInFileModal extends OmnisearchModal {
|
||||
const cmp = new ModalInFile({
|
||||
target: this.modalEl,
|
||||
props: {
|
||||
app,
|
||||
modal: this,
|
||||
singleFilePath: file.path,
|
||||
parent: parent,
|
||||
|
||||
20
src/main.ts
20
src/main.ts
@@ -1,4 +1,4 @@
|
||||
import { Notice, Platform, Plugin } from 'obsidian'
|
||||
import { App, Notice, Platform, Plugin } from 'obsidian'
|
||||
import {
|
||||
OmnisearchInFileModal,
|
||||
OmnisearchVaultModal,
|
||||
@@ -46,7 +46,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
return
|
||||
}
|
||||
|
||||
await cleanOldCacheFiles()
|
||||
await cleanOldCacheFiles(this.app)
|
||||
await OmnisearchCache.clearOldDatabases()
|
||||
|
||||
registerAPI(this)
|
||||
@@ -66,7 +66,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
id: 'show-modal',
|
||||
name: 'Vault search',
|
||||
callback: () => {
|
||||
new OmnisearchVaultModal(app).open()
|
||||
new OmnisearchVaultModal(this.app).open()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -75,12 +75,12 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
name: 'In-file search',
|
||||
editorCallback: (_editor, view) => {
|
||||
if (view.file) {
|
||||
new OmnisearchInFileModal(app, view.file).open()
|
||||
new OmnisearchInFileModal(this.app, view.file).open()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
app.workspace.onLayoutReady(async () => {
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
// Listeners to keep the search index up-to-date
|
||||
this.registerEvent(
|
||||
this.app.vault.on('create', file => {
|
||||
@@ -155,7 +155,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
|
||||
addRibbonButton(): void {
|
||||
this.ribbonButton = this.addRibbonIcon('search', 'Omnisearch', _evt => {
|
||||
new OmnisearchVaultModal(app).open()
|
||||
new OmnisearchVaultModal(this.app).open()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
private async populateIndex(): Promise<void> {
|
||||
console.time('Omnisearch - Indexing total time')
|
||||
indexingStep.set(IndexingStepType.ReadingFiles)
|
||||
const files = app.vault.getFiles().filter(f => isFileIndexable(f.path))
|
||||
const files = this.app.vault.getFiles().filter(f => isFileIndexable(f.path))
|
||||
console.log(`Omnisearch - ${files.length} files total`)
|
||||
console.log(
|
||||
`Omnisearch - Cache is ${isCacheEnabled() ? 'enabled' : 'disabled'}`
|
||||
@@ -243,7 +243,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
* Read the files and feed them to Minisearch
|
||||
*/
|
||||
|
||||
async function cleanOldCacheFiles() {
|
||||
async function cleanOldCacheFiles(app: App) {
|
||||
const toDelete = [
|
||||
`${app.vault.configDir}/plugins/omnisearch/searchIndex.json`,
|
||||
`${app.vault.configDir}/plugins/omnisearch/notesCache.json`,
|
||||
@@ -264,12 +264,12 @@ async function cleanOldCacheFiles() {
|
||||
function registerAPI(plugin: OmnisearchPlugin): void {
|
||||
// Url scheme for obsidian://omnisearch?query=foobar
|
||||
plugin.registerObsidianProtocolHandler('omnisearch', params => {
|
||||
new OmnisearchVaultModal(app, params.query).open()
|
||||
new OmnisearchVaultModal(plugin.app, params.query).open()
|
||||
})
|
||||
|
||||
// Public api
|
||||
// @ts-ignore
|
||||
globalThis['omnisearch'] = api
|
||||
// Deprecated
|
||||
;(app as any).plugins.plugins.omnisearch.api = api
|
||||
;(plugin.app as any).plugins.plugins.omnisearch.api = api
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export class SettingsTab extends PluginSettingTab {
|
||||
plugin: OmnisearchPlugin
|
||||
|
||||
constructor(plugin: OmnisearchPlugin) {
|
||||
super(app, plugin)
|
||||
super(plugin.app, plugin)
|
||||
this.plugin = plugin
|
||||
|
||||
showExcerpt.subscribe(async v => {
|
||||
@@ -88,7 +88,7 @@ export class SettingsTab extends PluginSettingTab {
|
||||
const { containerEl } = this
|
||||
containerEl.empty()
|
||||
|
||||
if (app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1') {
|
||||
if (this.app.loadLocalStorage(K_DISABLE_OMNISEARCH) == '1') {
|
||||
const span = containerEl.createEl('span')
|
||||
span.innerHTML = `<strong style="color: var(--text-accent)">⚠️ OMNISEARCH IS DISABLED ⚠️</strong>`
|
||||
}
|
||||
@@ -556,9 +556,9 @@ export class SettingsTab extends PluginSettingTab {
|
||||
.addToggle(toggle =>
|
||||
toggle.setValue(isPluginDisabled()).onChange(async v => {
|
||||
if (v) {
|
||||
app.saveLocalStorage(K_DISABLE_OMNISEARCH, '1')
|
||||
this.app.saveLocalStorage(K_DISABLE_OMNISEARCH, '1')
|
||||
} else {
|
||||
app.saveLocalStorage(K_DISABLE_OMNISEARCH) // No value = unset
|
||||
this.app.saveLocalStorage(K_DISABLE_OMNISEARCH) // No value = unset
|
||||
}
|
||||
new Notice('Omnisearch - Disabled. Please restart Obsidian.')
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as http from 'http'
|
||||
import * as url from 'url'
|
||||
import api from './api'
|
||||
import { Notice } from 'obsidian'
|
||||
import { saveSettings, settings } from 'src/settings'
|
||||
import { settings } from 'src/settings'
|
||||
|
||||
export function getServer() {
|
||||
const server = http.createServer(async function (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user