generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
30 lines (24 loc) · 736 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { App, Plugin } from 'obsidian';
export default class RofiHelperPlugin extends Plugin {
async onload() {
console.log('Loading RofiHelperPlugin');
this.registerObsidianProtocolHandler('switch', ({ vault, id, filename }) => {
const app = this.app;
vault = decodeURIComponent(vault);
id = decodeURIComponent(id);
filename = decodeURIComponent(filename); // filenames like "mypath/myfile.md"
if (app.vault.getName() != vault) {
return;
}
app.workspace.iterateAllLeaves(leaf => {
if (leaf.id === id || leaf.view.file?.path === filename) {
app.workspace.setActiveLeaf(leaf, { focus: true });
return;
}
});
});
}
onunload() {
console.log('Unloading RofiHelperPlugin');
}
}