Skip to content

Commit e84aeed

Browse files
committed
feat: apply review
1 parent 0b532a2 commit e84aeed

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

main.ts

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,35 @@
1-
import { App, Editor, FileView, MarkdownPreviewView, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile, View, renderResults } from 'obsidian';
2-
// Remember to rename these classes and interfaces!
3-
1+
import { Notice, Plugin, TFile } from 'obsidian';
42

53
export default class MarkmapToCsvPlugin extends Plugin {
64

75
async onload() {
8-
// This creates an icon in the left ribbon.
9-
const markMapToCsvIconE1 = this.addRibbonIcon('dice', 'Markmap to csv Plugin', (evt: MouseEvent) => {
10-
// Called when the user clicks the icon.
11-
new Notice('This is a notice!');
12-
});
13-
// Perform additional things with the ribbon
14-
markMapToCsvIconE1.addClass('markmap2csv-plugin-ribbon-class');
15-
16-
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
17-
const statusBarItemEl = this.addStatusBarItem();
18-
statusBarItemEl.setText('Status Bar Text');
19-
206
console.log('loading MarkmapToCSVPlugin');
217

228
this.addCommand({
239
id: 'convert-markmap-to-csv',
2410
name: 'Convert Markmap to CSV',
25-
callback: async () => {
11+
checkCallback: (checking) => {
2612
const file = this.app.workspace.getActiveFile()
27-
if (!file) {
28-
new Notice('ERROR: Please open a Markmap file to convert.');
29-
return;
13+
if (!file || file.extension !== "md") {
14+
return false;
3015
}
3116

32-
if (file.extension !== "md") {
33-
new Notice('ERROR: Please open markdown file to convert.');
34-
return;
17+
if(!checking) {
18+
this.app.vault.read(file).then(
19+
async (markdownData) => {
20+
const csvData = this.convertMarkmapToCSV(markdownData);
21+
await this.saveCsvToFile(file, csvData);
22+
}
23+
).catch((err) => {
24+
new Notice(`ERROR: failed to read file ${file.basename}`)
25+
throw err
26+
});
3527
}
3628

37-
const markdownData = await this.app.vault.read(file);
38-
const csvData = this.convertMarkmapToCSV(markdownData);
39-
await this.saveCsvToFile(file, csvData);
29+
return true;
30+
4031
}
4132
});
42-
43-
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
44-
// Using this function will automatically remove the event listener when this plugin is disabled.
45-
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
46-
console.log('click', evt);
47-
});
48-
49-
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
50-
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
5133
}
5234

5335
onunload() {

manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
"description": "Converts Markmap data to CSV format.",
88
"authorUrl": "https://github.com/pj4316",
99
"fundingUrl": "https://github.com/sponsors/pj4316",
10-
"dependencies": [],
1110
"isDesktopOnly": false
1211
}

0 commit comments

Comments
 (0)