Skip to content

Commit 38921da

Browse files
committed
🐛 优化系统弹出更新逻辑延长至60s并添加停止逻辑 #137
1 parent 4576795 commit 38921da

4 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/app/service/script/manager.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import IoC from "@App/app/ioc";
66
import LoggerCore from "@App/app/logger/core";
77
import Logger from "@App/app/logger/logger";
88
import { SystemConfig } from "@App/pkg/config/config";
9-
import { checkSilenceUpdate, ltever } from "@App/pkg/utils/utils";
9+
import {
10+
checkSilenceUpdate,
11+
ltever,
12+
openInCurrentTab,
13+
} from "@App/pkg/utils/utils";
1014
import Manager from "../manager";
1115
import { Script, SCRIPT_STATUS_DISABLE, ScriptDAO } from "../../repo/scripts";
1216
import ScriptEventListener from "./event";
@@ -118,9 +122,7 @@ export class ScriptManager extends Manager {
118122
// 清理缓存
119123
Cache.getInstance().del(CacheKey.scriptInfo(info.uuid));
120124
}, 60 * 1000);
121-
chrome.tabs.create({
122-
url: `/src/install.html?uuid=${info.uuid}`,
123-
});
125+
openInCurrentTab(`/src/install.html?uuid=${info.uuid}`);
124126
});
125127
}
126128

src/pages/install/description.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ export default function Description() {
101101
if (t > 0) {
102102
return t - 1;
103103
}
104-
closeWindow();
105-
return 0;
104+
if (t === 0) {
105+
closeWindow();
106+
}
107+
return t;
106108
});
107109
}, 1000);
108110
}, [countdown]);
@@ -308,9 +310,15 @@ export default function Description() {
308310
type="primary"
309311
status="danger"
310312
size="small"
311-
onClick={closeWindow}
313+
onClick={() => {
314+
if (countdown === -1) {
315+
closeWindow();
316+
} else {
317+
setCountdown(-1);
318+
}
319+
}}
312320
>
313-
关闭{countdown !== -1 && <>({countdown})</>}
321+
{countdown === -1 ? "关闭" : `停止(${countdown})`}
314322
</Button>
315323
</Space>
316324
</div>

src/pages/options/routes/ScriptList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ function ScriptList() {
217217
}
218218
},
219219
className: "max-w-[240px]",
220-
render: (col) => {
220+
render: (col, item: ListType) => {
221221
return (
222222
<Tooltip content={col} position="tl">
223223
<Link
224-
to={`/script/editor/${col.id}`}
224+
to={`/script/editor/${item.id}`}
225225
style={{
226226
textDecoration: "none",
227227
}}

src/pkg/utils/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,24 @@ export function calculateMd5(blob: Blob) {
272272
};
273273
});
274274
}
275+
276+
// 在当前页后打开一个新页面
277+
export function openInCurrentTab(url: string) {
278+
chrome.tabs.query(
279+
{
280+
active: true,
281+
},
282+
(tabs) => {
283+
if (tabs.length) {
284+
chrome.tabs.create({
285+
url,
286+
index: tabs[0].index + 1,
287+
});
288+
} else {
289+
chrome.tabs.create({
290+
url,
291+
});
292+
}
293+
}
294+
);
295+
}

0 commit comments

Comments
 (0)