Skip to content

Commit 6ff70eb

Browse files
authored
🐛 修正 src/pages/install/App.tsx closeWindow 代码 (#1435)
* fix: 修正 closeWindow 代码 * Update App.tsx * Update App.tsx
1 parent 1c10827 commit 6ff70eb

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/pages/install/App.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ interface PermissionItem {
4949

5050
type Permission = PermissionItem[];
5151

52+
let closingWindow = false;
5253
const closeWindow = (doBackwards: boolean) => {
5354
if (doBackwards) {
5455
history.go(-1);
@@ -314,7 +315,9 @@ function App() {
314315
};
315316

316317
useEffect(() => {
318+
closingWindow = false; // reset
317319
!loaded && initAsync();
320+
// eslint-disable-next-line react-hooks/exhaustive-deps
318321
}, [searchParams, loaded]);
319322

320323
const [watchFile, setWatchFile] = useState(false);
@@ -455,6 +458,7 @@ function App() {
455458
};
456459

457460
const handleInstall = async (options: { closeAfterInstall?: boolean; noMoreUpdates?: boolean } = {}) => {
461+
if (closingWindow) return;
458462
if (!upsertScript) {
459463
Message.error(t("script_info_load_failed")!);
460464
return;
@@ -498,22 +502,31 @@ function App() {
498502
}
499503

500504
if (shouldClose) {
501-
setTimeout(() => {
502-
closeWindow(doBackwards);
503-
}, 500);
505+
if (!closingWindow) {
506+
closingWindow = true;
507+
setTimeout(() => {
508+
closeWindow(doBackwards);
509+
}, 500);
510+
}
504511
}
505512
} catch (e) {
506513
const errorMessage = scriptInfo?.userSubscribe ? t("subscribe_failed") : t("install_failed");
507514
Message.error(`${errorMessage}: ${e}`);
508515
}
509516
};
510517

511-
const handleClose = (options?: { noMoreUpdates: boolean }) => {
518+
const handleClose = async (options?: { noMoreUpdates: boolean }) => {
519+
if (closingWindow) return;
512520
const { noMoreUpdates = false } = options || {};
513521
if (noMoreUpdates && scriptInfo && !scriptInfo.userSubscribe) {
514-
scriptClient.setCheckUpdateUrl(scriptInfo.uuid, false);
522+
await scriptClient.setCheckUpdateUrl(scriptInfo.uuid, false);
523+
}
524+
if (!closingWindow) {
525+
closingWindow = true;
526+
setTimeout(() => {
527+
closeWindow(doBackwards);
528+
}, 50);
515529
}
516-
closeWindow(doBackwards);
517530
};
518531

519532
const {

0 commit comments

Comments
 (0)