Skip to content

Commit fe96990

Browse files
committed
🐛 修复include、GM.*和ExternalMessage问题
1 parent 1067285 commit fe96990

File tree

21 files changed

+205
-66
lines changed

21 files changed

+205
-66
lines changed

build/pack.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ str = str.replace(/"version": "(.*?)"/, `"version": "${manifest.version}"`);
3333
fs.writeFileSync("./src/manifest.json", str);
3434

3535
// 处理configSystem version
36-
let configSystem = fs.readFileSync("./src/pkg/config/config.ts").toString();
36+
let configSystem = fs.readFileSync("./src/app/const.ts").toString();
3737
// 如果是由github action的分支触发的构建,在版本中再加上commit id
3838
if (process.env.GITHUB_REF_TYPE === "branch") {
3939
package.version += `+${process.env.GITHUB_SHA.substring(0, 7)}`;
4040
}
4141
configSystem = configSystem.replace(
42-
/\/\* version \*\/ "(.*?)"/,
43-
`/* version */ "${package.version}"`
42+
/ExtVersion = "(.*?)";/,
43+
`ExtVersion = "${package.version}";`
4444
);
45-
fs.writeFileSync("./src/pkg/config/config.ts", configSystem);
45+
fs.writeFileSync("./src/app/const.ts", configSystem);
4646

4747
execSync("npm run build", { stdio: "inherit" });
4848

src/app/const.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const ExtVersion = "0.10.0-alpha.1";
2+
3+
export const Server = "https://sc.icodef.com/";
4+
5+
export const ExternalWhitelist = [
6+
"greasyfork.org",
7+
"scriptcat.org",
8+
"tampermonkey.net.cn",
9+
"openuserjs.org",
10+
];
11+
12+
export const ExternalMessage = "externalMessage";

src/app/service/system/manager.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { ExternalMessage, ExtVersion, Server } from "@App/app/const";
12
import IoC from "@App/app/ioc";
23
import { MessageHander } from "@App/app/message/message";
4+
import { ScriptDAO } from "@App/app/repo/scripts";
35
import { SystemConfig } from "@App/pkg/config/config";
46
import Manager from "../manager";
57

@@ -8,17 +10,18 @@ import Manager from "../manager";
810
export class SystemManager extends Manager {
911
systemConfig: SystemConfig;
1012

13+
scriptDAO: ScriptDAO;
14+
1115
constructor(message: MessageHander, systemConfig: SystemConfig) {
12-
super(message);
16+
super(message, "system");
17+
this.scriptDAO = new ScriptDAO();
1318
this.systemConfig = systemConfig;
1419
}
1520

1621
init() {
1722
// 两小时检查一次更新
1823
const checkUpdate = () => {
19-
fetch(
20-
`${this.systemConfig.server}api/v1/system/version?version=${this.systemConfig.version}`
21-
)
24+
fetch(`${Server}api/v1/system/version?version=${ExtVersion}`)
2225
.then((resp) => resp.json())
2326
.then((resp: { data: { notice: string; version: string } }) => {
2427
chrome.storage.local.get(["notice"], (items) => {
@@ -50,6 +53,33 @@ export class SystemManager extends Manager {
5053
}
5154
});
5255
}
56+
// 处理
57+
this.message.setHandler(
58+
ExternalMessage,
59+
async (
60+
_action,
61+
{
62+
action,
63+
name,
64+
namespace,
65+
}: { action: string; name: string; namespace: string }
66+
) => {
67+
if (action === "isInstalled") {
68+
const script = await this.scriptDAO.findByNameAndNamespace(
69+
name,
70+
namespace
71+
);
72+
if (script) {
73+
return Promise.resolve({
74+
installed: true,
75+
version: script.metadata.version && script.metadata.version[0],
76+
});
77+
}
78+
return Promise.resolve({ installed: false });
79+
}
80+
return Promise.resolve(false);
81+
}
82+
);
5383
}
5484

5585
getNotice(): Promise<{ notice: string; isRead: boolean }> {

src/inject.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const logger = new LoggerCore({
1818

1919
message.setHandler("pageLoad", (_action, data) => {
2020
logger.logger().debug("inject start");
21-
22-
const runtime = new InjectRuntime(data.scripts, flag);
23-
21+
const runtime = new InjectRuntime(message, data.scripts, flag);
2422
runtime.start();
2523
});

src/pages/components/ScriptStorage/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const ScriptStorage: React.FC<{
4545
// 监听值变化
4646
const channel = valueCtrl.watchValue(script);
4747
channel.setHandler((value: Value) => {
48-
console.log("value changed", value);
4948
setData((prev) => {
5049
const index = prev.findIndex((item) => item.key === value.key);
5150
if (index === -1) {

src/pages/components/UserConfigPanel/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const UserConfigPanel: React.FC<{
159159
placeholder={item.description}
160160
>
161161
{options!.map((option) => (
162-
<Select.Option value={option}>
162+
<Select.Option key={option} value={option}>
163163
{option}
164164
</Select.Option>
165165
))}

src/pages/components/layout/MainLayout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ const MainLayout: React.FC<{
7575
</Space>
7676
</a>
7777
</Menu.Item>
78-
<Menu.Item key="dark">
78+
<Menu.Item key="background">
7979
<a href="#/script/editor?template=background">
8080
<RiTerminalBoxLine /> 添加后台脚本
8181
</a>
8282
</Menu.Item>
83-
<Menu.Item key="auto">
83+
<Menu.Item key="crontab">
8484
<a href="#/script/editor?template=crontab">
8585
<RiTimerLine /> 添加定时脚本
8686
</a>
8787
</Menu.Item>
88-
<Menu.Item key="auto">
88+
<Menu.Item key="link">
8989
<IconLink /> 链接导入
9090
</Menu.Item>
9191
</Menu>

src/pages/components/layout/Sider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (!hash.length) {
2626

2727
const Sider: React.FC = () => {
2828
const [menuSelect, setMenuSelect] = useState(hash);
29-
const [collapsed, setCollapsed] = useState(true);
29+
const [collapsed, setCollapsed] = useState(false);
3030

3131
return (
3232
<HashRouter>

src/pages/options/routes/Logger.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ function Subscribe() {
147147
<Card
148148
bordered={false}
149149
title="运行日志"
150-
style={{
151-
padding: 8,
152-
}}
153150
extra={
154151
<Space size="large">
155152
<DatePicker.RangePicker

src/pages/options/routes/ScriptList.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
RiPlayFill,
4444
RiSettings3Fill,
4545
RiStopFill,
46+
RiUploadCloudFill,
4647
} from "react-icons/ri";
4748
import { Link, useNavigate, useSearchParams } from "react-router-dom";
4849
import ScriptController from "@App/app/service/script/controller";
@@ -615,6 +616,13 @@ function ScriptList() {
615616
}}
616617
/>
617618
))}
619+
<Button
620+
type="text"
621+
icon={<RiUploadCloudFill />}
622+
style={{
623+
color: "var(--color-text-2)",
624+
}}
625+
/>
618626
</Button.Group>
619627
);
620628
},

0 commit comments

Comments
 (0)