Skip to content

Commit

Permalink
Added Simple Interface mode by default
Browse files Browse the repository at this point in the history
  • Loading branch information
MaelImhof committed Sep 6, 2024
1 parent c6598dc commit fab71d4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docs/content/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Whether to use Jupyter Lab or Jupyter Notebook.
Note that if the Jupyter server is running while you change this setting, you will need to stop it and start it again for the new value to take effect.

Default value is Jupyter Lab.
#### Simple Interface

Jupyter Lab provides an appearance setting called `Simple Interface`. It hides unnecessary UI elements for the user to concentrate on the file that is being edited. No Jupyter tabs, no sidebars, just the file.

This setting defines whether notebooks should be opened in `Simple Interface` mode by default.

**Has no effect** if the [[#Jupyter environment type|environment type]] is Jupyter Notebook.

Default value is enabled (meaning all notebooks will be opened in `Simple Interface` mode).
#### Delete Jupyter checkpoints

When working with notebooks, Jupyter generates checkpoint files. This creates a new `.ipynb_checkpoints` directory in each directory where you have a notebook opened. It becomes messy very fast.
Expand Down
33 changes: 30 additions & 3 deletions src/jupyter-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ export class JupyterEnvironment {
private jupyterTimoutListener: Debouncer<unknown[], unknown> = debounce(this.onJupyterTimeout.bind(this), this.jupyterTimeoutMs, true);
private jupyerTimedOut: boolean = false;

constructor(private readonly path: string, private printDebug: boolean, private pythonExecutable: string, private jupyterTimeoutMs: number, private type: JupyterEnvironmentType, private customConfigFolderPath: string|null) { }
constructor(
private readonly path: string,
private printDebug: boolean,
private pythonExecutable: string,
private jupyterTimeoutMs: number,
private type: JupyterEnvironmentType,
private customConfigFolderPath: string|null,
private useSimpleMode: boolean
) { }

public on(event: JupyterEnvironmentEvent, callback: (env: JupyterEnvironment) => void) {
this.events.on(event, callback);
Expand Down Expand Up @@ -181,6 +189,14 @@ export class JupyterEnvironment {
return this.customConfigFolderPath;
}

public setUseSimpleMode(value: boolean) {
this.useSimpleMode = value;
}

public getUseSimpleMode(): boolean {
return this.useSimpleMode;
}

public getJupyterTimeoutMs(): number {
return this.jupyterTimeoutMs;
}
Expand Down Expand Up @@ -214,14 +230,25 @@ export class JupyterEnvironment {
}

/**
* @param file The path of the file relative to the Jupyter environment's working directy.
* @param file The path of the file relative to the Jupyter environment's working directory.
*/
public getFileUrl(file: string): string|null {
if (!this.isRunning()) {
return null;
}

return `http://localhost:${this.jupyterPort}/${this.runningType === JupyterEnvironmentType.NOTEBOOK ? "notebooks" : "lab/tree"}/${file}?token=${this.jupyterToken}`;
return "http://localhost:" + this.jupyterPort + "/"
+ (
this.runningType === JupyterEnvironmentType.NOTEBOOK
? "notebooks"
: (
this.useSimpleMode
? "doc/tree"
: "lab/tree"
)
) + "/"
+ file
+ "?token=" + this.jupyterToken;
}

public exit() {
Expand Down
9 changes: 8 additions & 1 deletion src/jupyter-obsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default class JupyterNotebookPlugin extends Plugin {
DEFAULT_SETTINGS.pythonExecutable === PythonExecutableType.PYTHON ? "python" : DEFAULT_SETTINGS.pythonExecutablePath,
DEFAULT_SETTINGS.jupyterTimeoutMs,
DEFAULT_SETTINGS.jupyterEnvType,
null
null,
DEFAULT_SETTINGS.useSimpleMode
);
private envProperlyInitialized = false;
private startEnvOnceInitialized = false;
Expand Down Expand Up @@ -230,6 +231,12 @@ export default class JupyterNotebookPlugin extends Plugin {
this.env.setType(value);
}

public async setUseSimpleMode(value: boolean) {
this.settings.useSimpleMode = value;
await this.saveSettings();
this.env.setUseSimpleMode(value);
}

public async setDeleteCheckpoints(value: boolean) {
this.settings.deleteCheckpoints = value;
await this.saveSettings();
Expand Down
12 changes: 12 additions & 0 deletions src/jupyter-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface JupyterSettings {
pythonExecutablePath: string;
startJupyterAuto: boolean;
jupyterEnvType: JupyterEnvironmentType;
useSimpleMode: boolean;
deleteCheckpoints: boolean;
moveCheckpointsToTrash: boolean;
/**
Expand All @@ -45,6 +46,7 @@ export const DEFAULT_SETTINGS: JupyterSettings = {
pythonExecutablePath: "",
startJupyterAuto: true,
jupyterEnvType: JupyterEnvironmentType.LAB,
useSimpleMode: true,
deleteCheckpoints: false,
moveCheckpointsToTrash: true,
checkpointsFolder: "",
Expand Down Expand Up @@ -150,6 +152,16 @@ export class JupyterSettingsTab extends PluginSettingTab {
}
}).bind(this));
}).bind(this));
new Setting(this.containerEl)
.setName("Simple interface")
.setDesc("Whether to use Jupyter's Simple Interface mode when opening a notebook.")
.addToggle(((toggle: ToggleComponent) => {
toggle
.setValue(this.plugin.settings.useSimpleMode)
.onChange((async (value: boolean) => {
await this.plugin.setUseSimpleMode(value);
}).bind(this))
}).bind(this));
new Setting(this.containerEl)
.setName("Delete Jupyter checkpoints")
.setDesc("To keep your Obsidian vault clean. Does not work retroactively. Restarting Jupyter is required for the setting to take effect.")
Expand Down

0 comments on commit fab71d4

Please sign in to comment.