mirror of https://github.com/coder/code-server.git
Add deinit for plugins
This commit is contained in:
parent
3c6fac9ce4
commit
017b1cc633
|
@ -46,7 +46,7 @@ interface Application extends pluginapi.Application {
|
|||
/*
|
||||
* Clone of the above without functions.
|
||||
*/
|
||||
plugin: Omit<Plugin, "init" | "router" | "applications">
|
||||
plugin: Omit<Plugin, "init" | "deinit" | "router" | "applications">
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,6 +254,21 @@ export class PluginAPI {
|
|||
|
||||
return p
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {
|
||||
await Promise.all(
|
||||
Array.from(this.plugins.values()).map(async (p) => {
|
||||
if (!p.deinit) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await p.deinit()
|
||||
} catch (error) {
|
||||
this.logger.error("plugin failed to deinit", field("name", p.name), field("error", error.message))
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface PackageJSON {
|
||||
|
|
|
@ -15,6 +15,7 @@ import { Heart } from "../heart"
|
|||
import { redirect, replaceTemplates } from "../http"
|
||||
import { PluginAPI } from "../plugin"
|
||||
import { getMediaMime, paths } from "../util"
|
||||
import { wrapper } from "../wrapper"
|
||||
import * as apps from "./apps"
|
||||
import * as domainProxy from "./domainProxy"
|
||||
import * as health from "./health"
|
||||
|
@ -148,6 +149,7 @@ export const register = async (
|
|||
await papi.loadPlugins()
|
||||
papi.mount(app, wsApp)
|
||||
app.use("/api/applications", apps.router(papi))
|
||||
wrapper.onDispose(() => papi.dispose())
|
||||
|
||||
app.use(() => {
|
||||
throw new HttpError("Not Found", HttpCode.NotFound)
|
||||
|
|
|
@ -167,6 +167,11 @@ export interface Plugin {
|
|||
*/
|
||||
init(config: PluginConfig): void
|
||||
|
||||
/**
|
||||
* Called when the plugin should dispose/shutdown everything.
|
||||
*/
|
||||
deinit?(): Promise<void>
|
||||
|
||||
/**
|
||||
* Returns the plugin's router.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue