Ver código fonte

feat: close window when no workflows run

Ahmad Kholid 2 anos atrás
pai
commit
f2265d2484

+ 1 - 1
src/background/BackgroundWorkflowTriggers.js

@@ -19,7 +19,7 @@ async function executeWorkflow(workflowData, options) {
     return;
   }
 
-  await BackgroundUtils.openDashboard('', false);
+  await BackgroundUtils.openDashboard('?fromBackground=true', false);
   await BackgroundUtils.sendMessageToDashboard('workflow:execute', {
     data: workflowData,
     options,

+ 1 - 1
src/background/index.js

@@ -117,7 +117,7 @@ message.on('workflow:execute', async (workflowData, sender) => {
   const context = workflowData.settings.execContext;
   const isMV2 = browser.runtime.getManifest().manifest_version === 2;
   if (!isMV2 && (!context || context === 'popup')) {
-    await BackgroundUtils.openDashboard('', false);
+    await BackgroundUtils.openDashboard('?fromBackground=true', false);
     await BackgroundUtils.sendMessageToDashboard('workflow:execute', {
       data: workflowData,
       options: workflowData.option,

+ 1 - 1
src/components/newtab/shared/SharedCodemirror.vue

@@ -72,7 +72,7 @@ const updateListener = EditorView.updateListener.of((event) => {
 const customExtension = Array.isArray(props.extensions)
   ? props.extensions
   : [props.extensions];
-console.log(langs[props.lang]);
+
 const state = EditorState.create({
   doc: props.modelValue,
   extensions: [

+ 23 - 11
src/newtab/App.vue

@@ -57,9 +57,9 @@
   <app-survey />
 </template>
 <script setup>
-import { ref, reactive } from 'vue';
+import { ref, reactive, watch } from 'vue';
 import { useI18n } from 'vue-i18n';
-import { useRouter } from 'vue-router';
+import { useRouter, useRoute } from 'vue-router';
 import { compare } from 'compare-versions';
 import { useHead } from '@vueuse/head';
 import browser from 'webextension-polyfill';
@@ -89,19 +89,16 @@ import iconFirefox from '@/assets/svg/logoFirefox.svg';
 import iconChrome from '@/assets/svg/logo.svg';
 import SharedPermissionsModal from '@/components/newtab/shared/SharedPermissionsModal.vue';
 
-let icon;
-if (window.location.protocol === 'moz-extension:') {
-  icon = iconFirefox;
-} else {
-  icon = iconChrome;
-}
-
 const iconElement = document.createElement('link');
 iconElement.rel = 'icon';
-iconElement.href = icon;
+iconElement.href =
+  window.location.protocol === 'moz-extension' ? iconFirefox : iconChrome;
 document.head.appendChild(iconElement);
 
+window.fromBackground = window.location.href.includes('?fromBackground=true');
+
 const { t } = useI18n();
+const route = useRoute();
 const store = useStore();
 const theme = useTheme();
 const router = useRouter();
@@ -255,7 +252,8 @@ browser.runtime.onMessage.addListener(({ type, data }) => {
 browser.storage.local.onChanged.addListener(({ workflowStates }) => {
   if (!workflowStates) return;
 
-  workflowStore.states = Object.values(workflowStates.newValue);
+  const states = Object.values(workflowStates.newValue);
+  workflowStore.states = states;
 });
 
 useHead(() => {
@@ -301,6 +299,20 @@ window.addEventListener('message', ({ data }) => {
     });
 });
 
+watch(
+  () => workflowStore.popupStates,
+  () => {
+    if (
+      !window.fromBackground ||
+      workflowStore.popupStates.length !== 0 ||
+      route.name !== 'workflows'
+    )
+      return;
+
+    window.close();
+  }
+);
+
 (async () => {
   try {
     workflowState.storage = {

+ 2 - 0
src/workflowEngine/index.js

@@ -160,6 +160,8 @@ export function executeWorkflow(workflowData, options) {
     return;
   }
 
+  if (window) window.fromBackground = false;
+
   browser.tabs
     .query({ active: true, currentWindow: true })
     .then(async ([tab]) => {