From 4906c14fad45f2ed6c979193a86481024bea31ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Imhof?= Date: Sun, 4 Aug 2024 00:11:09 +0200 Subject: [PATCH] Cleanup when Obsidian is closed by user --- src/jupyter-obsidian.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jupyter-obsidian.ts b/src/jupyter-obsidian.ts index 4c225a1..9a6da47 100644 --- a/src/jupyter-obsidian.ts +++ b/src/jupyter-obsidian.ts @@ -1,4 +1,4 @@ -import { FileSystemAdapter, Notice, Plugin, normalizePath, setIcon, setTooltip } from "obsidian"; +import { FileSystemAdapter, Notice, Plugin, Tasks, Workspace, normalizePath, setIcon, setTooltip } from "obsidian"; import { JupyterEnvironment, JupyterEnvironmentError, JupyterEnvironmentEvent, JupyterEnvironmentStatus, JupyterEnvironmentType } from "./jupyter-env"; import { EmbeddedJupyterView } from "./ui/jupyter-view"; import { DEFAULT_SETTINGS, JupyterSettings, JupyterSettingsTab, PythonExecutableType } from "./jupyter-settings"; @@ -55,6 +55,11 @@ export default class JupyterNotebookPlugin extends Plugin { this.registerExtensions(["ipynb"], "jupyter-view"); this.addSettingTab(new JupyterSettingsTab(this.app, this)); + // Try to unload when Obsidian is closed by the user/the OS + this.app.workspace.on('quit', async (_tasks: Tasks) => { + await this.onunload(); + }); + this.announceUpdate(); }