Skip to content

Commit

Permalink
update: support trigger other actions
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Jun 6, 2024
1 parent 6d08240 commit 52dcc31
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ An action has the following settings:
<details style="text-indent: 4em">
<summary>Show supported operations</summary>

| Operation | Description |
| --------------- | ------------------------------------------------------------------------------ |
| `addTag` | Add tag(s) to the target item. |
| `removeTag` | Remove tag(s) from the target item. |
| `toggleTag` | Add tag(s) to the target item if it doesn't have the tag, otherwise remove it. |
| `anotherAction` | Run another custom action. |
| `customScript` | Run a custom script. |
| Operation | Description |
| -------------- | ------------------------------------------------------------------------------ |
| `addTag` | Add tag(s) to the target item. |
| `removeTag` | Remove tag(s) from the target item. |
| `toggleTag` | Add tag(s) to the target item if it doesn't have the tag, otherwise remove it. |
| `otherAction` | Run other custom actions. |
| `customScript` | Run a custom script. |

</details>

- **Data**: The action data.

- For tag operations, it's tags separated by comma
- For custom script, it's the script code.
- For trigger another action, it's the target action's name.
- For trigger other actions, it's the target actions' names (each in one line).

> Click `` in the edit action popup to open editor for multi-line data.
Expand Down
2 changes: 1 addition & 1 deletion addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ prefs-action-operation-add = Add Tags
prefs-action-operation-remove = Remove Tags
prefs-action-operation-toggle = Toggle Tags
prefs-action-operation-script = Script
prefs-action-operation-triggerAction = Trigger Another Action
prefs-action-operation-triggerAction = Trigger Other Actions
prefs-action-edit-title = Edit Action
prefs-action-edit-save = Save
Expand Down
2 changes: 1 addition & 1 deletion addon/locale/it-IT/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ prefs-action-operation-add = Aggiungi Tag
prefs-action-operation-remove = Rimuovi Tag
prefs-action-operation-toggle = Aggiungi/rimuovi Tag
prefs-action-operation-script = Script
prefs-action-operation-triggerAction = Innesca altra azione
prefs-action-operation-triggerAction = Trigger Other Actions
prefs-action-edit-title = Modifica azione
prefs-action-edit-save = Salva
Expand Down
2 changes: 1 addition & 1 deletion addon/locale/zh-CN/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ action-operation-add = 添加标签
action-operation-remove = 移除标签
action-operation-toggle = 切换标签
action-operation-script = 自定义脚本
action-operation-triggerAction = 触发另一个动作
action-operation-triggerAction = 触发其他动作
action-add =
.tooltiptext = 创建新动作
Expand Down
19 changes: 10 additions & 9 deletions src/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,17 @@ async function applyAction(action: ActionData, args: ActionArgs) {
break;
}
case ActionOperationTypes.triggerAction: {
const actions = getActions();
// Find the action by name
const nextAction = Object.values(actions).find(
(_action) => _action.name === action.data,
);
if (nextAction) {
await applyAction(nextAction, args);
return true;
const actions = Object.values(getActions());
const actionNames = action.data.split("\n");
const targetActions = actionNames
.map((name) => actions.find((a) => a.name === name))
.filter((action) => action) as ActionData<ActionOperationTypes>[];
if (targetActions.length === 0) {
return false;
}
for (const action of targetActions) {
await applyAction(action, args);
}
message = `Action ${action.data} not found`;
return false;
}
}
Expand Down

0 comments on commit 52dcc31

Please sign in to comment.