This commit is contained in:
Maxime Cannoodt 2022-06-29 11:08:06 +02:00
parent eeb90b8aca
commit d811966706
4 changed files with 42 additions and 16 deletions

View File

@ -9,6 +9,7 @@ import {
import { NoteSharingService } from "src/NoteSharingService";
import { DEFAULT_SETTINGS, PluginSettings } from "src/obsidian/PluginSettings";
import SettingsTab from "src/obsidian/SettingsTab";
import { SharedNoteSuccessModal } from "src/ui/SharedNoteSuccessModal";
// Remember to rename these classes and interfaces!
@ -27,18 +28,7 @@ export default class NoteSharingPlugin extends Plugin {
this.addSettingTab(new SettingsTab(this.app, this));
// Add note sharing command
this.addCommand({
id: "obsidian-note-sharing-share-note",
name: "Create share link",
checkCallback: (checking: boolean) => {
// Only works on Markdown views
const activeView =
this.app.workspace.getActiveViewOfType(MarkdownView);
if (!activeView) return false;
if (checking) return true;
this.noteSharingService.shareNote(activeView.getViewData());
},
});
this.addCommands();
this.eventRef = this.app.workspace.on(
"file-menu",
@ -62,6 +52,21 @@ export default class NoteSharingPlugin extends Plugin {
this.noteSharingService.serverUrl = this.settings.serverUrl;
}
addCommands() {
this.addCommand({
id: "obsidian-note-sharing-share-note",
name: "Create share link",
checkCallback: (checking: boolean) => {
// Only works on Markdown views
const activeView =
this.app.workspace.getActiveViewOfType(MarkdownView);
if (!activeView) return false;
if (checking) return true;
this.shareNote(activeView.getViewData());
},
});
}
// https://github.dev/platers/obsidian-linter/blob/c30ceb17dcf2c003ca97862d94cbb0fd47b83d52/src/main.ts#L139-L149
onMenuOpenCallback(menu: Menu, file: TAbstractFile, source: string) {
if (file instanceof TFile && file.extension === "md") {
@ -69,11 +74,14 @@ export default class NoteSharingPlugin extends Plugin {
item.setIcon("paper-plane-glyph");
item.setTitle("Share note");
item.onClick(async (evt) => {
this.noteSharingService.shareNote(
await this.app.vault.read(file)
);
this.shareNote(await this.app.vault.read(file));
});
});
}
}
async shareNote(mdText: string) {
const url = await this.noteSharingService.shareNote(mdText);
new SharedNoteSuccessModal(this, url).open();
}
}

View File

@ -9,7 +9,7 @@ export class NoteSharingService {
}
/**
* @param mdView Markdown file to share.
* @param mdText Markdown file to share.
* @returns link to shared note with attached decryption key.
*/
public async shareNote(mdText: string): Promise<string> {

View File

@ -0,0 +1,18 @@
import NoteSharingPlugin from "main";
import { Modal, TextComponent } from "obsidian";
export class SharedNoteSuccessModal extends Modal {
private url: string;
constructor(plugin: NoteSharingPlugin, url: string) {
super(plugin.app);
this.url = url;
this.render();
}
render() {
this.titleEl.innerText = "Shared note";
new TextComponent(this.contentEl).setValue(this.url);
}
}

Binary file not shown.