Skip to content

Commit

Permalink
chore: move to mv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Dec 20, 2022
1 parent d35ef44 commit 490cc39
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
11 changes: 9 additions & 2 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import BackgroundUtils from './BackgroundUtils';
import BackgroundWorkflowUtils from './BackgroundWorkflowUtils';
import BackgroundEventsListeners from './BackgroundEventsListeners';

const isFirefox = BROWSER_TYPE === 'firefox';

browser.alarms.onAlarm.addListener(BackgroundEventsListeners.onAlarms);

browser.commands.onCommand.addListener(BackgroundEventsListeners.onCommand);
Expand All @@ -31,8 +33,7 @@ browser.webNavigation.onHistoryStateUpdated.addListener(
BackgroundEventsListeners.onHistoryStateUpdated
);

const contextMenu =
BROWSER_TYPE === 'firefox' ? browser.menus : browser.contextMenus;
const contextMenu = isFirefox ? browser.menus : browser.contextMenus;
if (contextMenu && contextMenu.onClicked) {
contextMenu.onClicked.addListener(
BackgroundEventsListeners.onContextMenuClicked
Expand Down Expand Up @@ -228,4 +229,10 @@ if (!isMV2) {
});

keepAlive();
} else if (!isFirefox) {
const sandboxIframe = document.createElement('iframe');
sandboxIframe.src = '/sandbox.html';
sandboxIframe.id = 'sandbox';

document.body.appendChild(sandboxIframe);
}
5 changes: 5 additions & 0 deletions src/lib/tmpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as tmpl from '@n8n_io/riot-tmpl';

tmpl.brackets.set('{{ }}');

export default tmpl;
32 changes: 10 additions & 22 deletions src/manifest.chrome.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"manifest_version": 3,
"manifest_version": 2,
"name": "Automa",
"action": {
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon-128.png"
},
"background": {
"service_worker": "background.bundle.js",
"type": "module"
"scripts": ["background.bundle.js"]
},
"icons": {
"128": "icon-128.png"
Expand Down Expand Up @@ -52,29 +51,18 @@
"alarms",
"storage",
"debugger",
"scripting",
"<all_urls>",
"webNavigation",
"unlimitedStorage"
],
"host_permissions": [
"<all_urls>"
],
"web_accessible_resources": [
{
"resources": [
"/elementSelector.css",
"/Inter-roman-latin.var.woff2",
"/icon-128.png",
"/locales/*",
"elementSelector.bundle.js"
],
"matches": ["<all_urls>"]
}
"/elementSelector.css",
"/Inter-roman-latin.var.woff2",
"/icon-128.png",
"/locales/*",
"elementSelector.bundle.js"
],
"sandbox": {
"pages": ["/sandbox.html"]
},
"content_security_policy": {
"sandbox": "sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';"
"pages": ["/sandbox.html", "uiSandbox.html"]
}
}
4 changes: 1 addition & 3 deletions src/sandbox/utils/handleBlockExpression.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as tmpl from '@n8n_io/riot-tmpl';
import tmpl from '@/lib/tmpl';
import functions from '@/workflowEngine/templating/templatingFunctions';

tmpl.brackets.set('{{ }}');

const templatingFunctions = Object.keys(functions).reduce((acc, funcName) => {
acc[`$${funcName}`] = functions[funcName];

Expand Down
5 changes: 4 additions & 1 deletion src/workflowEngine/templating/renderString.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import browser from 'webextension-polyfill';
import { messageSandbox } from '../helper';
import mustacheReplacer from './mustacheReplacer';

const isFirefox = BROWSER_TYPE === 'firefox';
const isMV2 = browser.runtime.getManifest().manifest_version === 2;

export default async function (str, data, isPopup = true) {
if (!str || typeof str !== 'string') return '';
Expand All @@ -16,7 +18,8 @@ export default async function (str, data, isPopup = true) {

let renderedValue = {};
const evaluateJS = str.startsWith('!!');
if (evaluateJS && !isFirefox && isPopup) {

if (evaluateJS && !isFirefox && (isMV2 || isPopup)) {
const refKeysRegex =
/(variables|table|secrets|loopData|workflow|googleSheets|globalData)@/g;
const strToRender = str.replace(refKeysRegex, '$1.');
Expand Down

0 comments on commit 490cc39

Please sign in to comment.