|
@@ -6,6 +6,56 @@ Mousetrap.prototype.stopCallback = function () {
|
|
return false;
|
|
return false;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+function automaCustomEventListener(findWorkflow) {
|
|
|
|
+ window.addEventListener(
|
|
|
|
+ 'automa:execute-workflow',
|
|
|
|
+ ({ detail }) => {
|
|
|
|
+ if (!detail || !detail.id) return;
|
|
|
|
+
|
|
|
|
+ const workflow = findWorkflow(detail.id);
|
|
|
|
+
|
|
|
|
+ if (!workflow) return;
|
|
|
|
+
|
|
|
|
+ workflow.options = {
|
|
|
|
+ data: detail.data || {},
|
|
|
|
+ };
|
|
|
|
+ sendMessage('workflow:execute', workflow, 'background');
|
|
|
|
+ },
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+}
|
|
|
|
+function workflowShortcutsListener(findWorkflow, shortcutsObj) {
|
|
|
|
+ const shortcuts = Object.entries(shortcutsObj);
|
|
|
|
+
|
|
|
|
+ if (shortcuts.length === 0) return;
|
|
|
|
+
|
|
|
|
+ const keyboardShortcuts = shortcuts.reduce((acc, [id, value]) => {
|
|
|
|
+ const workflow = findWorkflow(id);
|
|
|
|
+
|
|
|
|
+ (acc[value] = acc[value] || []).push({
|
|
|
|
+ id,
|
|
|
|
+ workflow,
|
|
|
|
+ activeInInput: workflow.trigger?.activeInInput || false,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return acc;
|
|
|
|
+ }, {});
|
|
|
|
+
|
|
|
|
+ Mousetrap.bind(Object.keys(keyboardShortcuts), ({ target }, command) => {
|
|
|
|
+ const isInputElement =
|
|
|
|
+ ['INPUT', 'SELECT', 'TEXTAREA'].includes(target.tagName) ||
|
|
|
|
+ target?.contentEditable === 'true';
|
|
|
|
+
|
|
|
|
+ keyboardShortcuts[command].forEach((item) => {
|
|
|
|
+ if (!item.activeInInput && isInputElement) return;
|
|
|
|
+
|
|
|
|
+ sendMessage('workflow:execute', item.workflow, 'background');
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
(async () => {
|
|
(async () => {
|
|
try {
|
|
try {
|
|
const { shortcuts, workflows, workflowHosts } =
|
|
const { shortcuts, workflows, workflowHosts } =
|
|
@@ -14,11 +64,7 @@ Mousetrap.prototype.stopCallback = function () {
|
|
'workflows',
|
|
'workflows',
|
|
'workflowHosts',
|
|
'workflowHosts',
|
|
]);
|
|
]);
|
|
- const shortcutsArr = Object.entries(shortcuts || {});
|
|
|
|
-
|
|
|
|
- if (shortcutsArr.length === 0) return;
|
|
|
|
-
|
|
|
|
- const keyboardShortcuts = shortcutsArr.reduce((acc, [id, value]) => {
|
|
|
|
|
|
+ const findWorkflow = (id) => {
|
|
let workflow = workflows.find((item) => item.id === id);
|
|
let workflow = workflows.find((item) => item.id === id);
|
|
|
|
|
|
if (!workflow) {
|
|
if (!workflow) {
|
|
@@ -29,28 +75,11 @@ Mousetrap.prototype.stopCallback = function () {
|
|
if (workflow) workflow.id = workflow.hostId;
|
|
if (workflow) workflow.id = workflow.hostId;
|
|
}
|
|
}
|
|
|
|
|
|
- (acc[value] = acc[value] || []).push({
|
|
|
|
- id,
|
|
|
|
- workflow,
|
|
|
|
- activeInInput: workflow.trigger?.activeInInput || false,
|
|
|
|
- });
|
|
|
|
|
|
+ return workflow;
|
|
|
|
+ };
|
|
|
|
|
|
- return acc;
|
|
|
|
- }, {});
|
|
|
|
-
|
|
|
|
- Mousetrap.bind(Object.keys(keyboardShortcuts), ({ target }, command) => {
|
|
|
|
- const isInputElement =
|
|
|
|
- ['INPUT', 'SELECT', 'TEXTAREA'].includes(target.tagName) ||
|
|
|
|
- target?.contentEditable === 'true';
|
|
|
|
-
|
|
|
|
- keyboardShortcuts[command].forEach((item) => {
|
|
|
|
- if (!item.activeInInput && isInputElement) return;
|
|
|
|
-
|
|
|
|
- sendMessage('workflow:execute', item.workflow, 'background');
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return true;
|
|
|
|
- });
|
|
|
|
|
|
+ automaCustomEventListener(findWorkflow);
|
|
|
|
+ workflowShortcutsListener(findWorkflow, shortcuts || {});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error(error);
|
|
console.error(error);
|
|
}
|
|
}
|