Skip to content

Commit

Permalink
https://github.com/juliang22/ObsidianTimestampNotes/issues/31
Browse files Browse the repository at this point in the history
  • Loading branch information
zuluwi committed Jun 29, 2023
1 parent dac1265 commit 2a5be79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
23 changes: 13 additions & 10 deletions main.js

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class TimestampPlugin extends Plugin {
this.addCommand({
id: 'pause-player',
name: 'Pause player',
editorCallback: (editor: Editor, view: MarkdownView) => {
callback: () => {
this.setPlaying(!this.player.props.playing)
}
});
Expand All @@ -148,7 +148,7 @@ export default class TimestampPlugin extends Plugin {
this.addCommand({
id: 'seek-forward',
name: 'Seek Forward',
editorCallback: (editor: Editor, view: MarkdownView) => {
callback: () => {
if (this.player) this.player.seekTo(this.player.getCurrentTime() + parseInt(this.settings.forwardSeek));
}
});
Expand All @@ -157,7 +157,7 @@ export default class TimestampPlugin extends Plugin {
this.addCommand({
id: 'seek-backward',
name: 'Seek Backward',
editorCallback: (editor: Editor, view: MarkdownView) => {
callback: () => {
if (this.player) this.player.seekTo(this.player.getCurrentTime() - parseInt(this.settings.backwardsSeek));
}
});
Expand Down Expand Up @@ -194,6 +194,9 @@ export default class TimestampPlugin extends Plugin {
id: "add-subtitles",
name: "Add subtitle file",
callback: async () => {
if (!this.player) {
return new Notice("Player is not working right now")
}
var input = document.createElement("input");
input.type = "file";
input.accept = ".srt,.vtt";
Expand All @@ -213,6 +216,7 @@ export default class TimestampPlugin extends Plugin {
input.click();
},
});

this.addCommand({
id: "video-snapshot",
name: "Take and copy to clipboard snapshot from video",
Expand Down Expand Up @@ -262,16 +266,16 @@ export default class TimestampPlugin extends Plugin {

// This is called when a valid url is found => it activates the View which loads the React view
async activateView(url: string, editor: Editor) {
this.app.workspace.detachLeavesOfType(VIDEO_VIEW);

await this.app.workspace.getRightLeaf(false).setViewState({
type: VIDEO_VIEW,
active: true,
});

this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(VIDEO_VIEW)[0]
);
// this.app.workspace.detachLeavesOfType(VIDEO_VIEW);
if (this.app.workspace.getLeavesOfType(VIDEO_VIEW).length == 0) {
await this.app.workspace.getRightLeaf(false).setViewState({
type: VIDEO_VIEW,
active: true,
});
}
// this.app.workspace.revealLeaf(
// this.app.workspace.getLeavesOfType(VIDEO_VIEW)[0]
// );

// This triggers the React component to be loaded
this.app.workspace.getLeavesOfType(VIDEO_VIEW).forEach(async (leaf) => {
Expand Down

0 comments on commit 2a5be79

Please sign in to comment.