1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Plugins: Add the openNote, openFolder and openTag commands

This commit is contained in:
Laurent Cozic
2020-10-25 17:22:59 +00:00
parent de47cff86d
commit 52d5c32950
10 changed files with 86 additions and 1 deletions

View File

@ -11,6 +11,7 @@ type EnabledCondition = string;
export interface CommandContext {
// The state may also be of type "AppState" (used by the desktop app), which inherits from "State" (used by all apps)
state: State,
dispatch: Function,
}
export interface CommandRuntime {
@ -203,10 +204,20 @@ export default class CommandService extends BaseService {
delete command.runtime;
}
private createContext():CommandContext {
return {
state: this.store_.getState(),
dispatch: (action:any) => {
this.store_.dispatch(action);
},
};
}
public async execute(commandName:string, ...args:any[]):Promise<any | void> {
const command = this.commandByName(commandName);
this.logger().info('CommandService::execute:', commandName, args);
return command.runtime.execute({ state: this.store_.getState() }, ...args);
if (!command.runtime) throw new Error(`Cannot execute a command without a runtime: ${commandName}`);
return command.runtime.execute(this.createContext(), ...args);
}
public scheduleExecute(commandName:string, args:any) {