Skip to content

Commit

Permalink
🐛 优化系统弹出更新逻辑延长至60s并添加停止逻辑 #137
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Feb 6, 2023
1 parent 4576795 commit 38921da
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/app/service/script/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import IoC from "@App/app/ioc";
import LoggerCore from "@App/app/logger/core";
import Logger from "@App/app/logger/logger";
import { SystemConfig } from "@App/pkg/config/config";
import { checkSilenceUpdate, ltever } from "@App/pkg/utils/utils";
import {
checkSilenceUpdate,
ltever,
openInCurrentTab,
} from "@App/pkg/utils/utils";
import Manager from "../manager";
import { Script, SCRIPT_STATUS_DISABLE, ScriptDAO } from "../../repo/scripts";
import ScriptEventListener from "./event";
Expand Down Expand Up @@ -118,9 +122,7 @@ export class ScriptManager extends Manager {
// 清理缓存
Cache.getInstance().del(CacheKey.scriptInfo(info.uuid));
}, 60 * 1000);
chrome.tabs.create({
url: `/src/install.html?uuid=${info.uuid}`,
});
openInCurrentTab(`/src/install.html?uuid=${info.uuid}`);
});
}

Expand Down
16 changes: 12 additions & 4 deletions src/pages/install/description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ export default function Description() {
if (t > 0) {
return t - 1;
}
closeWindow();
return 0;
if (t === 0) {
closeWindow();
}
return t;
});
}, 1000);
}, [countdown]);
Expand Down Expand Up @@ -308,9 +310,15 @@ export default function Description() {
type="primary"
status="danger"
size="small"
onClick={closeWindow}
onClick={() => {
if (countdown === -1) {
closeWindow();
} else {
setCountdown(-1);
}
}}
>
关闭{countdown !== -1 && <>({countdown})</>}
{countdown === -1 ? "关闭" : `停止(${countdown})`}
</Button>
</Space>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/options/routes/ScriptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ function ScriptList() {
}
},
className: "max-w-[240px]",
render: (col) => {
render: (col, item: ListType) => {
return (
<Tooltip content={col} position="tl">
<Link
to={`/script/editor/${col.id}`}
to={`/script/editor/${item.id}`}
style={{
textDecoration: "none",
}}
Expand Down
21 changes: 21 additions & 0 deletions src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,24 @@ export function calculateMd5(blob: Blob) {
};
});
}

// 在当前页后打开一个新页面
export function openInCurrentTab(url: string) {
chrome.tabs.query(
{
active: true,
},
(tabs) => {
if (tabs.length) {
chrome.tabs.create({
url,
index: tabs[0].index + 1,
});
} else {
chrome.tabs.create({
url,
});
}
}
);
}

0 comments on commit 38921da

Please sign in to comment.