Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

# Ignore local Warp guidance file
WARP.md
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

## Description

Session Notes allows users to create and manage temporary notes and per session notes directly in Obsidian. Temporary notes are automatically deleted when closed, and session notes are deleted when the Obsidian app is closed.
Session Notes allows users to create and manage temporary notes and per-session notes directly in Obsidian. Temporary notes are automatically deleted when you switch away from them, and session notes are automatically deleted when the Obsidian app is closed.

Key features:
## Features
- **Temporary Notes**: Quickly create a note that will be deleted once you switch away from it.
- **Session Notes**: Create session notes that persist through the session and are automatically deleted when the app closes.

- **Ribbon Button (optional)**: Toggle visibility of session notes in the workspace using a ribbon icon. You can show/hide this button from the plugin settings.
- **Open on Startup (optional)**: Automatically create and open a Session Note when Obsidian starts.

## Default Hotkeys
The plugin provides the following default key bindings out of the box:
- Open a temporary note: `Ctrl+Shift+;`
- Open a session note: `Ctrl+Shift+'`

You can customize these in Obsidian via **Settings → Hotkeys** by searching for "Session Notes" and changing the bindings as desired.

## Installation

### From GitHub

1. Download the latest release from the [Releases](https://github.com/tabibyte/session-notes/releases) page.
2. Extract the files and place them in your Obsidian plugins folder:
2. Extract the files and place them in your Obsidian plugins folder.
3. Restart Obsidian.
4. Open Settings > Community Plugins, and enable **Session Notes**.

### Customization
4. Open Settings → Community Plugins, and enable **Session Notes**.

You can customize the hotkeys for creating session or temporary notes by navigating to **Settings > Hotkeys** in Obsidian and modifying the corresponding commands.
## Settings
Open **Settings → Community Plugins → Session Notes** to configure:
- "Show ribbon button" — show/hide the ribbon icon that toggles Session Notes visibility.
- "Shows Session Note on Startup" — automatically create and open a Session Note on app start.
125 changes: 123 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
import { Plugin, TFile} from 'obsidian';
import { Plugin, TFile, PluginSettingTab, Setting } from 'obsidian';

interface SNoteSettings {
showRibbonButton: boolean;
showSessionNoteOnStartup: boolean;
}

const DEFAULT_SETTINGS: SNoteSettings = {
showRibbonButton: true,
showSessionNoteOnStartup: false,
};

export default class SNote extends Plugin {
private sessionNotes: TFile[] = [];
private tempNote?: TFile;

settings: SNoteSettings = DEFAULT_SETTINGS;
private ribbonEl?: HTMLElement;

async onload() {
await this.loadSettings();

// Auto-open a Session Note on startup if enabled, after layout is ready
this.app.workspace.onLayoutReady(() => {
if (this.settings.showSessionNoteOnStartup) {
this.openSessionNote();
}
});

// Commands
this.addCommand({
id: 'open-temp-note',
name: 'Open a temporary note (delete on change)',
hotkeys: [{ modifiers: ['Ctrl', 'Shift'], key: ';' }],
callback: () => this.openTempNote(),
});

this.addCommand({
id: 'open-session-note',
name: 'Open a session note (delete on app close)',
hotkeys: [{ modifiers: ['Ctrl', 'Shift'], key: '\'' }],
callback: () => this.openSessionNote(),
});

// Ribbon (conditionally added based on settings)
this.updateRibbon();

// Settings tab
this.addSettingTab(new SNoteSettingTab(this.app, this));

// Lifecycle hooks
window.addEventListener('beforeunload', (event) => {
if (this.sessionNotes.length === 0) {
return;
Expand Down Expand Up @@ -77,7 +109,96 @@ export default class SNote extends Plugin {
window.close();
}

// Toggle show/hide of session notes in the workspace
toggleSessionNotesVisibility() {
const sessionSet = new Set(this.sessionNotes.map((f) => f.path));
const leaves = this.app.workspace.getLeavesOfType('markdown');

// Are any session notes currently open?
const sessionLeaves = leaves.filter((l: any) => l?.view?.file && sessionSet.has(l.view.file.path));

if (sessionLeaves.length > 0) {
// Hide: close all leaves that display session notes
sessionLeaves.forEach((l: any) => l.detach());
} else if (this.sessionNotes.length > 0) {
// Show: open the most recent session note
const last = this.sessionNotes[this.sessionNotes.length - 1];
const leaf = this.app.workspace.getLeaf();
leaf.openFile(last);
} else {
// No session notes yet; create and open one
this.openSessionNote();
}
}

updateRibbon() {
if (this.settings.showRibbonButton) {
if (!this.ribbonEl) {
this.ribbonEl = this.addRibbonIcon('dice', 'Toggle Session Notes', () => this.toggleSessionNotesVisibility());
}
} else {
if (this.ribbonEl) {
this.ribbonEl.remove();
this.ribbonEl = undefined;
}
}
}

async loadSettings() {
const data = await this.loadData();
this.settings = Object.assign({}, DEFAULT_SETTINGS, data);
}

async saveSettings() {
await this.saveData(this.settings);
}

onunload() {
window.removeEventListener('beforeunload', () => this.deleteSessionNotes());
// Note: removing the beforeunload listener here would require keeping a handle to the bound function.
if (this.ribbonEl) {
this.ribbonEl.remove();
this.ribbonEl = undefined;
}
}
}

class SNoteSettingTab extends PluginSettingTab {
plugin: SNote;

constructor(app: any, plugin: SNote) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const { containerEl } = this;
containerEl.empty();

containerEl.createEl('h2', { text: 'Session Notes Settings' });

new Setting(containerEl)
.setName('Show ribbon button')
.setDesc('Show a ribbon icon to toggle visibility of session notes in the workspace.')
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.showRibbonButton)
.onChange(async (value) => {
this.plugin.settings.showRibbonButton = value;
await this.plugin.saveSettings();
this.plugin.updateRibbon();
})
);

new Setting(containerEl)
.setName('Shows Session Note on Startup')
.setDesc('Automatically create and open a Session Note when Obsidian starts.')
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.showSessionNoteOnStartup)
.onChange(async (value) => {
this.plugin.settings.showSessionNoteOnStartup = value;
await this.plugin.saveSettings();
})
);
}
}
Loading