Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to player command ergonomics #42

Merged
merged 1 commit into from
May 20, 2024
Merged
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
28 changes: 13 additions & 15 deletions src/obsidian/TTSPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export default class TTSPlugin extends Plugin {
);

// Also add an editor command that can perform the same play selection
// This will always initiate a new audio
this.addCommand({
id: "play-selection",
name: "Play selection",
editorCheckCallback: (checking, editor: Editor, view: MarkdownView) => {
if (checking) {
return editor.getSelection().length > 0 || !!editor.getCursor("head");
return true;
}
this.bridge.triggerSelection(view.file, editor);
},
Expand All @@ -62,25 +63,22 @@ export default class TTSPlugin extends Plugin {
this.bridge.playSelection(),
);

// This adds a simple command that can be triggered anywhere to resume last track
// this pause/resumes the current audio, or initiates a new audio if nothing is playing
this.addCommand({
id: "resume",
name: "Resume",
id: "play-pause",
name: "Play/pause",
checkCallback: (checking) => {
const active = this.player.activeText;
if (checking) {
return !!active;
return true;
}
if (!active) {
this.bridge.playSelection();
} else if (this.player.activeText?.isPlaying) {
this.player.activeText?.pause();
} else {
this.player.activeText?.play();
}
this.player.activeText?.play();
},
});

// This adds an editor command that can perform some operation on the current editor instance
this.addCommand({
id: "pause",
name: "Pause",
editorCallback: (editor: Editor, view: MarkdownView) => {
this.player.activeText?.pause();
},
});

Expand Down
Loading