Showing
1 changed file
with
53 additions
and
48 deletions
@@ -2,16 +2,26 @@ | @@ -2,16 +2,26 @@ | ||
2 | <el-tabs> | 2 | <el-tabs> |
3 | <el-tab-pane label="Debugger Apps"> | 3 | <el-tab-pane label="Debugger Apps"> |
4 | <div class="app-list"> | 4 | <div class="app-list"> |
5 | - <template v-for="(app, key) in QX_DEBUG_APPS" :key="key"> | 5 | + <template v-for="(app, key) in debuggerApps" :key="key"> |
6 | <div class="app-list-item"> | 6 | <div class="app-list-item"> |
7 | <div class="app-list-item__content"> | 7 | <div class="app-list-item__content"> |
8 | - <el-input placeholder="子应用名称" v-model="app.name"></el-input> | 8 | + <el-input placeholder="子应用名称" v-model="app.name"> </el-input> |
9 | <el-input placeholder="子应用地址" v-model="app.entry"></el-input> | 9 | <el-input placeholder="子应用地址" v-model="app.entry"></el-input> |
10 | </div> | 10 | </div> |
11 | <div class="app-list-item__btn"> | 11 | <div class="app-list-item__btn"> |
12 | + <el-button | ||
13 | + v-if="app.debugging" | ||
14 | + type="" | ||
15 | + @click="handleDebugging(key)" | ||
16 | + > | ||
17 | + <VideoPause style="width: 1em; height: 1em" /> | ||
18 | + </el-button> | ||
19 | + <el-button v-else type="" @click="handleDebugging(key)"> | ||
20 | + <VideoPlay style="width: 1em; height: 1em" /> | ||
21 | + </el-button> | ||
12 | <el-button type="" @click="deleteItem(key)">-</el-button> | 22 | <el-button type="" @click="deleteItem(key)">-</el-button> |
13 | <el-button | 23 | <el-button |
14 | - v-if="key === QX_DEBUG_APPS.length - 1" | 24 | + v-if="key === debuggerApps.length - 1" |
15 | type="" | 25 | type="" |
16 | @click="add" | 26 | @click="add" |
17 | >+</el-button | 27 | >+</el-button |
@@ -24,14 +34,9 @@ | @@ -24,14 +34,9 @@ | ||
24 | <el-button @click="start(true)" | 34 | <el-button @click="start(true)" |
25 | ><Refresh style="width: 1em; height: 1em" /> | 35 | ><Refresh style="width: 1em; height: 1em" /> |
26 | </el-button> | 36 | </el-button> |
27 | - <el-button | ||
28 | - v-if="DEVELOPER_MODE == 1 && filterDebuggerApps.length" | ||
29 | - @click="end" | ||
30 | - > | 37 | + <el-button v-if="debuggerStatus" @click="end"> |
31 | <VideoPause style="width: 1em; height: 1em; margin-right: 8px" /> | 38 | <VideoPause style="width: 1em; height: 1em; margin-right: 8px" /> |
32 | - <el-tooltip content="关闭调试模式,会同步关闭开发者模式" placement=""> | ||
33 | - 关闭调试 | ||
34 | - </el-tooltip> | 39 | + 结束调试 |
35 | </el-button> | 40 | </el-button> |
36 | <el-button v-else @click="start" | 41 | <el-button v-else @click="start" |
37 | ><VideoPlay style="width: 1em; height: 1em; margin-right: 8px" /> | 42 | ><VideoPlay style="width: 1em; height: 1em; margin-right: 8px" /> |
@@ -44,49 +49,58 @@ | @@ -44,49 +49,58 @@ | ||
44 | 49 | ||
45 | <script setup> | 50 | <script setup> |
46 | import { reactive, ref, computed, watchEffect } from "vue"; | 51 | import { reactive, ref, computed, watchEffect } from "vue"; |
52 | +const defaultApps = [{ name: "", entry: "", debugging: false }]; | ||
47 | 53 | ||
48 | const { sessionStorage } = | 54 | const { sessionStorage } = |
49 | chrome.extension.getBackgroundPage().backgroundState || {}; | 55 | chrome.extension.getBackgroundPage().backgroundState || {}; |
50 | 56 | ||
51 | -const defaultApps = [{ name: "", entry: "" }]; | ||
52 | - | ||
53 | -const sessionDebuggerApps = JSON.parse( | ||
54 | - sessionStorage.QX_DEBUG_APPS || JSON.stringify(defaultApps) | 57 | +const debuggerApps = ref( |
58 | + JSON.parse( | ||
59 | + window.localStorage.getItem("qx-debugger-apps") || | ||
60 | + JSON.stringify(defaultApps) | ||
61 | + ) | ||
55 | ); | 62 | ); |
56 | 63 | ||
57 | -const QX_DEBUG_APPS = reactive( | ||
58 | - sessionDebuggerApps.length ? sessionDebuggerApps : defaultApps | 64 | +const debuggerStatus = ref( |
65 | + JSON.parse(window.localStorage.getItem("qx-debugger-status") || "false") | ||
59 | ); | 66 | ); |
60 | 67 | ||
61 | const filterDebuggerApps = computed(() => | 68 | const filterDebuggerApps = computed(() => |
62 | - QX_DEBUG_APPS.filter((item) => item.name && item.entry) | 69 | + debuggerApps.value.filter((app) => app.name && app.entry && app.debugging) |
63 | ); | 70 | ); |
64 | 71 | ||
65 | -const DEVELOPER_MODE = ref(sessionStorage.DEVELOPER_MODE === "1"); | 72 | +watchEffect(() => { |
73 | + window.localStorage.setItem( | ||
74 | + "qx-debugger-apps", | ||
75 | + JSON.stringify(debuggerApps.value || defaultApps) | ||
76 | + ); | ||
77 | + | ||
78 | + chrome.runtime.sendMessage({ | ||
79 | + type: "setSessionStorage", | ||
80 | + key: "QX_DEBUG_APPS", | ||
81 | + value: JSON.stringify(filterDebuggerApps.value), | ||
82 | + }); | ||
83 | +}); | ||
66 | 84 | ||
67 | -console.log("sessionStorage", sessionStorage); | 85 | + |
86 | +const DEVELOPER_MODE = ref(sessionStorage.DEVELOPER_MODE === "1"); | ||
68 | 87 | ||
69 | function add() { | 88 | function add() { |
70 | - QX_DEBUG_APPS.push({ name: "", entry: "" }); | 89 | + debuggerApps.value.push(defaultApps[0]); |
71 | } | 90 | } |
72 | 91 | ||
73 | function deleteItem(index) { | 92 | function deleteItem(index) { |
74 | - QX_DEBUG_APPS.splice(index, 1); | ||
75 | - | ||
76 | - if (index == 0 && !QX_DEBUG_APPS.length) { | ||
77 | - QX_DEBUG_APPS.push({ name: "", entry: "" }); | ||
78 | - } | ||
79 | -} | 93 | + debuggerApps.value.splice(index, 1); |
80 | 94 | ||
81 | -function validate(refresh) { | ||
82 | - if (filterDebuggerApps.value.length || refresh) { | ||
83 | - return true; | 95 | + if (index == 0 && !debuggerApps.length) { |
96 | + debuggerApps.value.push({ name: "", entry: "" }); | ||
84 | } | 97 | } |
85 | - | ||
86 | - return false; | ||
87 | } | 98 | } |
88 | 99 | ||
89 | -async function save() { | 100 | +async function start() { |
101 | + chrome.runtime.sendMessage({ type: "reload" }); | ||
102 | + debuggerStatus.value = true; | ||
103 | + window.localStorage.setItem("qx-debugger-status", "true"); | ||
90 | chrome.runtime.sendMessage({ | 104 | chrome.runtime.sendMessage({ |
91 | type: "setSessionStorage", | 105 | type: "setSessionStorage", |
92 | key: "QX_DEBUG_APPS", | 106 | key: "QX_DEBUG_APPS", |
@@ -94,30 +108,21 @@ async function save() { | @@ -94,30 +108,21 @@ async function save() { | ||
94 | }); | 108 | }); |
95 | } | 109 | } |
96 | 110 | ||
97 | -async function start(refresh) { | ||
98 | - if (validate(refresh)) { | ||
99 | - DEVELOPER_MODE.value = "1"; | ||
100 | - save(); | ||
101 | - chrome.runtime.sendMessage({ | ||
102 | - type: "setSessionStorage", | ||
103 | - key: "DEVELOPER_MODE", | ||
104 | - value: "1", | ||
105 | - }); | ||
106 | - | ||
107 | - chrome.runtime.sendMessage({ type: "reload" }); | ||
108 | - } | ||
109 | -} | ||
110 | - | ||
111 | async function end() { | 111 | async function end() { |
112 | - DEVELOPER_MODE.value = null; | 112 | + debuggerStatus.value = false; |
113 | + window.localStorage.setItem("qx-debugger-status", "false"); | ||
113 | 114 | ||
114 | chrome.runtime.sendMessage({ | 115 | chrome.runtime.sendMessage({ |
115 | type: "removeSessionStorage", | 116 | type: "removeSessionStorage", |
116 | - key: "DEVELOPER_MODE", | 117 | + key: "QX_DEBUG_APPS", |
117 | }); | 118 | }); |
118 | 119 | ||
119 | chrome.runtime.sendMessage({ type: "reload" }); | 120 | chrome.runtime.sendMessage({ type: "reload" }); |
120 | } | 121 | } |
122 | + | ||
123 | +function handleDebugging(index) { | ||
124 | + debuggerApps.value[index].debugging = !debuggerApps.value[index].debugging; | ||
125 | +} | ||
121 | </script> | 126 | </script> |
122 | 127 | ||
123 | <style> | 128 | <style> |