Refactor OC shutdown process, make it actually work

This commit is contained in:
Mateusz Tymek
2026-02-02 17:07:21 +01:00
parent 26154cc21e
commit bf10a5ecd9
3 changed files with 223 additions and 18 deletions

View File

@@ -89,11 +89,14 @@ export default class OpenCodePlugin extends Plugin {
}
});
// Register cleanup handlers for when Obsidian quits
this.registerCleanupHandlers();
console.log("OpenCode plugin loaded");
}
async onunload(): Promise<void> {
this.stopServer();
await this.stopServer();
this.app.workspace.detachLeavesOfType(OPENCODE_VIEW_TYPE);
}
@@ -184,8 +187,8 @@ export default class OpenCodePlugin extends Plugin {
return success;
}
stopServer(): void {
this.processManager.stop();
async stopServer(): Promise<void> {
await this.processManager.stop();
new Notice("OpenCode server stopped");
}
@@ -431,4 +434,13 @@ export default class OpenCodePlugin extends Plugin {
console.log("[OpenCode] Using vault path as project directory:", vaultPath);
return vaultPath;
}
private registerCleanupHandlers(): void {
this.registerEvent(
this.app.workspace.on("quit", () => {
console.log("[OpenCode] Obsidian quitting - performing sync cleanup");
this.stopServer();
})
);
}
}