Skip to content

Commit cb33a01

Browse files
authored
Merge pull request #210 from jason5ng32/dev
Improvements
2 parents 992fc23 + befd3bf commit cb33a01

25 files changed

+474
-281
lines changed

frontend/App.vue

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AdvancedTools ref="advancedToolsRef" />
1414
</div>
1515
</div>
16-
<InfoMask :isInfosLoaded.value="isInfosLoaded" :infoMaskLevel.value="infoMaskLevel"
16+
<InfoMask :showMaskButton.value="showMaskButton" :infoMaskLevel.value="infoMaskLevel"
1717
:toggleInfoMask="toggleInfoMask" />
1818
<QueryIP ref="queryIPRef" />
1919
<HelpModal ref="helpModalRef" />
@@ -61,7 +61,7 @@ const store = useMainStore();
6161
const configs = computed(() => store.configs);
6262
const userPreferences = computed(() => store.userPreferences);
6363
const shouldRefreshEveryThing = computed(() => store.shouldRefreshEveryThing);
64-
const Status = computed(() => store.loadingStatus);
64+
const Status = computed(() => store.mountingStatus);
6565
6666
// Template 里的 Ref
6767
const navBarRef = ref(null);
@@ -88,6 +88,7 @@ const alertMessage = ref("");
8888
const alertTitle = ref("");
8989
const alertToShow = ref(false);
9090
const autoStart = ref(userPreferences.value.autoStart);
91+
const showMaskButton = ref(false);
9192
9293
//
9394
// 加载相关
@@ -103,9 +104,8 @@ hideLoading();
103104
104105
105106
// 事件控制
106-
const loadingControl = (t1 = 0, t2 = 0, t3 = 4000, t4 = 2500) => {
107+
const loadingControl = (t1 = 0, t2 = 2000, t3 = 3000, t4 = 2500) => {
107108
const mountedStatus = Object.values(Status.value).every(Boolean);
108-
setInfosLoaded();
109109
if (mountedStatus) {
110110
setTimeout(() => {
111111
IPCheckRef.value.checkAllIPs();
@@ -120,6 +120,11 @@ const loadingControl = (t1 = 0, t2 = 0, t3 = 4000, t4 = 2500) => {
120120
setTimeout(() => {
121121
dnsLeaksRef.value.checkAllDNSLeakTest(false);
122122
}, t4);
123+
} else {
124+
// 如果不自动运行,将剩余的加载状态设置为 true
125+
store.setLoadingStatus('connectivity', true);
126+
store.setLoadingStatus('webrtc', true);
127+
store.setLoadingStatus('dnsleaktest', true);
123128
}
124129
} else {
125130
// 递归检查
@@ -129,13 +134,6 @@ const loadingControl = (t1 = 0, t2 = 0, t3 = 4000, t4 = 2500) => {
129134
}
130135
};
131136
132-
// 延迟设置 isInfosLoaded.value
133-
const setInfosLoaded = () => {
134-
setTimeout(() => {
135-
isInfosLoaded.value = true;
136-
}, 6000);
137-
};
138-
139137
//
140138
// 刷新相关
141139
//
@@ -153,10 +151,17 @@ const scheduleTimedTasks = (tasks) => {
153151
154152
// 刷新所有
155153
const refreshEverything = () => {
154+
155+
// 重置加载状态
156+
store.setLoadingStatus('connectivity', false);
157+
store.setLoadingStatus('webrtc', false);
158+
store.setLoadingStatus('dnsleaktest', false);
159+
store.setLoadingStatus('ipcheck', false);
160+
156161
const refreshTasks = [
157162
{ action: () => IPCheckRef.value.checkAllIPs(), delay: 0 },
158-
{ action: () => connectivityRef.value.checkAllConnectivity(false, true, true), delay: 2000 },
159-
{ action: () => webRTCRef.value.checkAllWebRTC(true), delay: 4000 },
163+
{ action: () => connectivityRef.value.handelCheckStart(true), delay: 2000 },
164+
{ action: () => webRTCRef.value.checkAllWebRTC(true), delay: 3000 },
160165
{ action: () => dnsLeaksRef.value.checkAllDNSLeakTest(true), delay: 2500 },
161166
{ action: () => refreshingAlert(), delay: 500 },
162167
];
@@ -311,7 +316,7 @@ const ShortcutKeys = (isOriginalSite) => {
311316
return
312317
}
313318
const card = IPCheckRef.value.ipDataCards[num - 1];
314-
scrollToElement("IPInfo-" + num, 171);
319+
scrollToElement("IPInfo-" + num, 300);
315320
IPCheckRef.value.refreshCard(card, num - 1);
316321
trackEvent('ShortCut', 'ShortCut', 'IPCheck');
317322
},
@@ -321,7 +326,7 @@ const ShortcutKeys = (isOriginalSite) => {
321326
keys: "c",
322327
action: () => {
323328
scrollToElement("Connectivity", 80);
324-
connectivityRef.value.checkAllConnectivity(false, true, true);
329+
connectivityRef.value.handelCheckStart(true);
325330
trackEvent('ShortCut', 'ShortCut', 'Connectivity');
326331
},
327332
description: t('shortcutKeys.RefreshConnectivityTests'),
@@ -500,19 +505,17 @@ const loadShortcuts = () => {
500505
}, 2000);
501506
};
502507
508+
// 监控刷新动作
503509
watch(shouldRefreshEveryThing, (newVal) => {
504510
if (newVal) {
505-
navBarRef.value.loaded = false;
506-
isInfosLoaded.value = false;
507511
refreshEverything();
508-
setInfosLoaded();
509512
}
510513
});
511514
512-
watch(isInfosLoaded, (newVal) => {
513-
if (newVal) {
514-
navBarRef.value.loaded = true;
515-
}
515+
// 监控加载状态并传递
516+
watch(() => store.allHasLoaded, (newValue) => {
517+
isInfosLoaded.value = newValue;
518+
showMaskButton.value = true;
516519
});
517520
518521
onMounted(() => {

frontend/components/Advanced.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const fullScreen = () => {
150150
151151
152152
onMounted(() => {
153-
store.setLoadingStatus('advancedtools', true);
153+
store.setMountingStatus('advancedtools', true);
154154
// 监听滚动事件
155155
scrollContainer.value.addEventListener('scroll', handleScroll);
156156

frontend/components/ConnectivityTest.vue

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</template>
4747

4848
<script setup>
49-
import { ref, computed, onMounted, reactive } from 'vue';
49+
import { ref, computed, onMounted, reactive, watch } from 'vue';
5050
import { useMainStore } from '@/store';
5151
import { useI18n } from 'vue-i18n';
5252
import { trackEvent } from '@/utils/use-analytics';
@@ -59,6 +59,7 @@ const isDarkMode = computed(() => store.isDarkMode);
5959
const isMobile = computed(() => store.isMobile);
6060
const userPreferences = computed(() => store.userPreferences);
6161
62+
const alertCrontrol = ref(false);
6263
const alertToShow = ref(false);
6364
const alertStyle = ref("");
6465
const alertTitle = ref("");
@@ -187,53 +188,69 @@ const checkConnectivityHandler = (test, onTestComplete, isManualRun) => {
187188
188189
// 检查所有网络连通性
189190
const checkAllConnectivity = (isAlertToShow, isRefresh, isManualRun) => {
191+
alertToShow.value = isAlertToShow;
192+
return new Promise((resolve, reject) => {
193+
if (isRefresh) {
194+
connectivityTests.forEach((test) => {
195+
test.status = t('connectivity.StatusWait');
196+
test.time = 0;
197+
});
198+
trackEvent('Section', 'RefreshClick', 'Connectivity');
199+
}
190200
191-
if (isRefresh) {
192-
connectivityTests.forEach((test) => {
193-
test.status = t('connectivity.StatusWait');
194-
test.time = 0;
195-
});
196-
trackEvent('Section', 'RefreshClick', 'Connectivity');
197-
}
198-
let totalTests = connectivityTests.length;
199-
let successCount = 0;
200-
let completedCount = 0;
201+
let totalTests = connectivityTests.length;
202+
let successCount = 0;
203+
let completedCount = 0;
204+
let testPromises = [];
201205
202-
const onTestComplete = (isSuccess) => {
203-
if (isSuccess) {
204-
successCount++;
205-
}
206-
completedCount++;
206+
const onTestComplete = (isSuccess) => {
207+
if (isSuccess) {
208+
successCount++;
209+
}
210+
completedCount++;
211+
};
207212
208-
// 只有当所有测试都完成时才做出最终判断
209-
if (completedCount === totalTests) {
210-
alertToShow.value = true;
213+
connectivityTests.forEach((test, index) => {
214+
let testPromise = new Promise((testResolve, testReject) => {
215+
setTimeout(() => {
216+
checkConnectivityHandler(test, (isSuccess) => {
217+
if (isSuccess) {
218+
onTestComplete(true);
219+
testResolve();
220+
} else {
221+
onTestComplete(false);
222+
testReject();
223+
}
224+
}, isManualRun);
225+
}, 50 * index);
226+
});
227+
testPromises.push(testPromise);
228+
});
229+
230+
// 无论如何都会 Resolve
231+
Promise.allSettled(testPromises).then(() => {
211232
if (successCount === totalTests) {
212-
updateConnectivityAlert(true, "success");
233+
updateConnectivityAlert("success");
213234
} else {
214-
updateConnectivityAlert(true, "error");
235+
updateConnectivityAlert("error");
215236
}
216-
}
217-
};
237+
resolve();
238+
});
239+
218240
219-
connectivityTests.forEach((test, index) => {
220-
setTimeout(() => {
221-
checkConnectivityHandler(test, onTestComplete, isManualRun);
222-
}, 50 * index);
241+
isStarted.value = true;
223242
});
243+
};
224244
225-
if ((isAlertToShow || !isStarted.value) && autoShowAltert.value) {
226-
setTimeout(() => {
227-
store.setAlert(alertToShow.value, alertStyle.value, alertMessage.value, alertTitle.value);
228-
}, 4000);
245+
const sendAlert = () => {
246+
if ((alertToShow.value || !isStarted.value) && autoShowAltert.value) {
247+
store.setAlert(alertToShow.value, alertStyle.value, alertMessage.value, alertTitle.value);
229248
}
230-
231-
isStarted.value = true;
232249
};
233250
251+
234252
// 更新通知气泡
235-
const updateConnectivityAlert = (show, type) => {
236-
alertToShow.value = show;
253+
const updateConnectivityAlert = (type) => {
237254
if (type === "success") {
238255
alertStyle.value = "text-success";
239256
alertMessage.value = t('alert.Congrats_Message');
@@ -245,14 +262,19 @@ const updateConnectivityAlert = (show, type) => {
245262
}
246263
};
247264
248-
const handelCheckStart = () => {
249-
setTimeout(() => {
250-
checkAllConnectivity(true, false, false);
251-
}, 2000);
265+
// 主控制函数
266+
const handelCheckStart = async (fromApp = false) => {
267+
if (fromApp) {
268+
await checkAllConnectivity(false, true, true);
269+
} else {
270+
await checkAllConnectivity(true, false, false);
271+
}
272+
// 传递完成状态到 store
273+
store.setLoadingStatus('connectivity', true);
252274
if (autoRefresh.value) {
253-
intervalId.value = setInterval(() => {
275+
intervalId.value = setInterval(async () => {
254276
if (counter.value < maxCounts.value && !manualRun.value) {
255-
checkAllConnectivity(false, false, false);
277+
await checkAllConnectivity(false, false, false);
256278
counter.value++;
257279
} else {
258280
clearInterval(intervalId.value);
@@ -262,7 +284,13 @@ const handelCheckStart = () => {
262284
};
263285
264286
onMounted(() => {
265-
store.setLoadingStatus('connectivity', true);
287+
store.setMountingStatus('connectivity', true);
288+
});
289+
290+
watch(() => store.allHasLoaded, (newValue, oldValue) => {
291+
if (newValue === true) {
292+
sendAlert();
293+
}
266294
});
267295
268296
defineExpose({

0 commit comments

Comments
 (0)