diff --git a/CliClient/tests/support/plugins/content_script/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/content_script/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/content_script/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/content_script/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/content_script/api/types.ts b/CliClient/tests/support/plugins/content_script/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/content_script/api/types.ts +++ b/CliClient/tests/support/plugins/content_script/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/dialog/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/dialog/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/dialog/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/dialog/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/dialog/api/types.ts b/CliClient/tests/support/plugins/dialog/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/dialog/api/types.ts +++ b/CliClient/tests/support/plugins/dialog/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/events/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/events/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/events/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/events/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/events/api/types.ts b/CliClient/tests/support/plugins/events/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/events/api/types.ts +++ b/CliClient/tests/support/plugins/events/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/json_export/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/json_export/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/json_export/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/json_export/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/json_export/api/types.ts b/CliClient/tests/support/plugins/json_export/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/json_export/api/types.ts +++ b/CliClient/tests/support/plugins/json_export/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/multi_selection/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/multi_selection/api/types.ts b/CliClient/tests/support/plugins/multi_selection/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/multi_selection/api/types.ts +++ b/CliClient/tests/support/plugins/multi_selection/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/register_command/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/register_command/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/register_command/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/register_command/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/register_command/api/types.ts b/CliClient/tests/support/plugins/register_command/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/register_command/api/types.ts +++ b/CliClient/tests/support/plugins/register_command/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/register_command/src/index.ts b/CliClient/tests/support/plugins/register_command/src/index.ts index da2a2cdfab..37ed5613a3 100644 --- a/CliClient/tests/support/plugins/register_command/src/index.ts +++ b/CliClient/tests/support/plugins/register_command/src/index.ts @@ -21,6 +21,15 @@ joplin.plugins.register({ }, }); + // Commands that return a result and take argument can only be used + // programmatically, so it's not necessary to set a label and icon. + await joplin.commands.register({ + name: 'commandWithResult', + execute: async (arg1:string, arg2:number) => { + return 'I got: ' + arg1 + ' and ' + arg2; + }, + }); + // Add the first command to the note toolbar await joplin.views.toolbarButtons.create('testCommand1', ToolbarButtonLocation.NoteToolbar); @@ -30,5 +39,9 @@ joplin.plugins.register({ // Also add the commands to the menu await joplin.views.menuItems.create('testCommand1', MenuItemLocation.Tools, { accelerator: 'CmdOrCtrl+Alt+Shift+B' }); await joplin.views.menuItems.create('testCommand2', MenuItemLocation.Tools); + + console.info('Running command with arguments...'); + const result = await joplin.commands.execute('commandWithResult', 'abcd', 123); + console.info('Result was: ' + result); }, }); diff --git a/CliClient/tests/support/plugins/selected_text/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/selected_text/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/selected_text/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/selected_text/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/selected_text/api/types.ts b/CliClient/tests/support/plugins/selected_text/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/selected_text/api/types.ts +++ b/CliClient/tests/support/plugins/selected_text/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/settings/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/settings/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/settings/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/settings/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/settings/api/types.ts b/CliClient/tests/support/plugins/settings/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/settings/api/types.ts +++ b/CliClient/tests/support/plugins/settings/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/toc/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/toc/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/toc/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/toc/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/toc/api/types.ts b/CliClient/tests/support/plugins/toc/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/toc/api/types.ts +++ b/CliClient/tests/support/plugins/toc/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/CliClient/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts b/CliClient/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts index f5a56a6167..0dc680e3b3 100644 --- a/CliClient/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts +++ b/CliClient/tests/support/plugins/withExternalModules/api/JoplinCommands.d.ts @@ -30,7 +30,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - execute(commandName: string, ...args: any[]): Promise; + execute(commandName: string, ...args: any[]): Promise; /** * desktop Registers a new command. * diff --git a/CliClient/tests/support/plugins/withExternalModules/api/types.ts b/CliClient/tests/support/plugins/withExternalModules/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/CliClient/tests/support/plugins/withExternalModules/api/types.ts +++ b/CliClient/tests/support/plugins/withExternalModules/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects diff --git a/ReactNativeClient/lib/services/CommandService.ts b/ReactNativeClient/lib/services/CommandService.ts index 50c4a2fa20..bc8541f821 100644 --- a/ReactNativeClient/lib/services/CommandService.ts +++ b/ReactNativeClient/lib/services/CommandService.ts @@ -14,7 +14,7 @@ export interface CommandContext { } export interface CommandRuntime { - execute(context:CommandContext, ...args:any[]):Promise + execute(context:CommandContext, ...args:any[]):Promise enabledCondition?: EnabledCondition; // Used for the (optional) toolbar button title mapStateToTitle?(state:any):string, diff --git a/ReactNativeClient/lib/services/plugins/api/JoplinCommands.ts b/ReactNativeClient/lib/services/plugins/api/JoplinCommands.ts index 79443a8580..c697ce2137 100644 --- a/ReactNativeClient/lib/services/plugins/api/JoplinCommands.ts +++ b/ReactNativeClient/lib/services/plugins/api/JoplinCommands.ts @@ -33,7 +33,7 @@ export default class JoplinCommands { * await joplin.commands.execute('newFolder', "SOME_FOLDER_ID"); * ``` */ - async execute(commandName: string, ...args:any[]):Promise { + async execute(commandName: string, ...args:any[]):Promise { return CommandService.instance().execute(commandName, ...args); } diff --git a/ReactNativeClient/lib/services/plugins/api/types.ts b/ReactNativeClient/lib/services/plugins/api/types.ts index 34f8be7197..a0636920c1 100644 --- a/ReactNativeClient/lib/services/plugins/api/types.ts +++ b/ReactNativeClient/lib/services/plugins/api/types.ts @@ -9,9 +9,12 @@ export interface Command { name: string /** - * Label to be displayed on menu items or keyboard shortcut editor for example + * Label to be displayed on menu items or keyboard shortcut editor for example. + * If it is missing, it's assumed it's a private command, to be called programmatically only. + * In that case the command will not appear in the shortcut editor or command panel, and logically + * should not be used as a menu item. */ - label: string + label?: string /** * Icon to be used on toolbar buttons for example @@ -19,9 +22,9 @@ export interface Command { iconName?: string, /** - * Code to be ran when the command is executed. It maybe return a result. + * Code to be ran when the command is executed. It may return a result. */ - execute(props:any):Promise + execute(...args:any[]):Promise /** * Defines whether the command should be enabled or disabled, which in turns affects