Massive refactor to get rid of the global app.

This commit is contained in:
Simon Cambier
2024-05-25 22:49:50 +02:00
parent bbe7b112ed
commit 6566a2e958
24 changed files with 1532 additions and 1146 deletions

View File

@@ -1,10 +1,11 @@
import * as http from 'http'
import * as url from 'url'
import api from './api'
import { Notice } from 'obsidian'
import { getSettings } from 'src/settings'
import type OmnisearchPlugin from '../main'
import { getApi } from './api'
export function getServer() {
export function getServer(plugin: OmnisearchPlugin) {
const api = getApi(plugin)
const server = http.createServer(async function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader(
@@ -47,7 +48,7 @@ export function getServer() {
},
() => {
console.log(`Omnisearch - Started HTTP server on port ${port}`)
if (getSettings().httpApiNotice) {
if (plugin.settings.httpApiNotice) {
new Notice(`Omnisearch - Started HTTP server on port ${port}`)
}
}
@@ -62,9 +63,8 @@ export function getServer() {
},
close() {
server.close()
const settings = getSettings()
console.log(`Omnisearch - Terminated HTTP server`)
if (settings.httpApiEnabled && settings.httpApiNotice) {
if (plugin.settings.httpApiEnabled && plugin.settings.httpApiNotice) {
new Notice(`Omnisearch - Terminated HTTP server`)
}
},