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