Skip to content

Commit

Permalink
feat: enable and disable plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Aug 3, 2022
1 parent 9a0305f commit 35f685b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/docs/actions/miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ sidebar_position: 6
---

# Miscellaneous
| / | parameters | explanation |
| -------------- | ------------------------------ | --------------------------------------------------- |
| Exists | <identification\>, exists=true | Copies `1` to clipboard if file exists, `0` if not. |
| Update plugins | updateplugins=true | Updates all community-plugins |
| / | parameters | explanation |
| ---------------------- | ------------------------------ | --------------------------------------------------- |
| Exists | <identification\>, exists=true | Copies `1` to clipboard if file exists, `0` if not. |
| Update plugins | updateplugins=true | Updates all community-plugins |
| Enable custom plugin | enable-plugin | Enable `enable-plugin` plugin |
| Disable custom plugins | disable-plugin | Disable `disable-plugin` plugin |
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export default class AdvancedURI extends Plugin {
parameters.data = await navigator.clipboard.readText();
}

if (parameters["enable-plugin"] || parameters["disable-plugin"]) {
this.handlePluginManagement(parameters);
}

if (parameters.workspace || parameters.saveworkspace == "true") {
this.handleWorkspace(parameters);

Expand Down Expand Up @@ -274,6 +278,14 @@ export default class AdvancedURI extends Plugin {
}
}

handlePluginManagement(parameters: Parameters): void {
if (parameters["enable-plugin"]) {
this.app.plugins.enablePlugin(parameters["enable-plugin"]);
} else if (parameters["disable-plugin"]) {
this.app.plugins.disablePlugin(parameters["disable-plugin"]);
}
}

async handleCommand(parameters: Parameters) {
if (parameters.filepath) {
if (parameters.mode) {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ declare module 'obsidian' {
plugins: {
[key: string]: PluginManifest;
};
enablePlugin(plugin: string): void;
disablePlugin(plugin: string): void;
};
internalPlugins: {
plugins: {
Expand Down Expand Up @@ -106,6 +108,8 @@ export interface Parameters {
line?: number;
newpane?: "true" | "false";
clipboard?: "true";
"enable-plugin"?: string;
"disable-plugin"?: string;
}

export interface HookParameters {
Expand Down

0 comments on commit 35f685b

Please sign in to comment.