blob: dc542fab95195fd25f149c9a6b718244c7d995e3 [file] [log] [blame]
Adrià Vilanova Martínez1e10d192021-12-31 16:01:13 +01001import {createApp} from 'vue';
2
3import {isOptionEnabled} from '../../../common/optionsUtils.js';
4
5import {addButtonToThreadListActions, shouldAddBtnToActionBar} from './../utils/common.js';
6import Overlay from './components/Overlay.vue';
7import VueMaterialAdapter from './vma.js';
8
9const wfDebugId = 'twpt-workflows';
10
11export default class Workflows {
12 constructor() {
13 this.overlayApp = null;
14 this.overlayVm = null;
15 }
16
17 createOverlay() {
18 let menuEl = document.createElement('div');
19 document.body.appendChild(menuEl);
20
21 this.overlayApp = createApp(Overlay);
22 this.overlayApp.use(VueMaterialAdapter);
23 this.overlayVm = this.overlayApp.mount(menuEl);
24 }
25
26 switchMenu(menuBtn) {
27 if (this.overlayApp === null) this.createOverlay();
28 if (!this.overlayVm.shown) {
29 let rect = menuBtn.getBoundingClientRect();
30 this.overlayVm.position = [rect.left + rect.width, rect.bottom];
31 this.overlayVm.shown = true;
32 } else {
33 this.overlayVm.shown = false;
34 }
35 }
36
37 addThreadListBtnIfEnabled(readToggle) {
38 isOptionEnabled('workflows').then(isEnabled => {
39 if (isEnabled) {
40 let tooltip = chrome.i18n.getMessage('inject_workflows_menubtn');
41 let btn = addButtonToThreadListActions(
42 readToggle, 'more_vert', wfDebugId, tooltip);
43 btn.addEventListener('click', () => {
44 this.switchMenu(btn);
45 });
46 }
47 });
48 }
49
50 shouldAddThreadListBtn(node) {
51 return shouldAddBtnToActionBar(wfDebugId, node);
52 }
53};