Skip to content

Commit

Permalink
Merge branch 'main' into develop/mv3
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	src/manifest.json
  • Loading branch information
CodFrm committed Jul 30, 2024
2 parents 1c37d44 + cd749af commit ff7d356
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 29 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
plugins: ["react", "@typescript-eslint", "prettier"],
rules: {
"no-restricted-syntax": "off",
"react/require-default-props": "off",
"react/jsx-filename-extension": [1, { extensions: [".tsx"] }],
"no-unused-expressions": ["error", { allowShortCircuit: true }],
"react/jsx-props-no-spreading": "off",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions src/app/message/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ export default class MessageContent
this.nativeSend(data);
});
this.relatedTarget = new Map<number, Element>();
document.addEventListener(
window.addEventListener(
(isContent ? "ct" : "fd") + eventId,
(event: unknown) => {
if (event instanceof MutationEvent) {
this.relatedTarget.set(
parseInt(event.prevValue, 10),
<Element>event.relatedNode
);
if (event instanceof MouseEvent) {
this.relatedTarget.set(event.clientX, <Element>event.relatedTarget);
return;
}
const message = (<
Expand Down Expand Up @@ -116,15 +113,11 @@ export default class MessageContent
delete detail.data.relatedTarget;
detail.data.relatedTarget = Math.ceil(Math.random() * 1000000);
// 可以使用此种方式交互element
const ev = document.createEvent("MutationEvent");
ev.initMutationEvent(
(this.isContent ? "fd" : "ct") + this.eventId,
false,
false,
target,
detail.data.relatedTarget.toString()
);
document.dispatchEvent(ev);
const ev = new MouseEvent((this.isContent ? "fd" : "ct") + this.eventId, {
clientX: detail.data.relatedTarget,
relatedTarget: target,
});
window.dispatchEvent(ev);
}

if (typeof cloneInto !== "undefined") {
Expand All @@ -142,7 +135,7 @@ export default class MessageContent
const ev = new CustomEvent((this.isContent ? "fd" : "ct") + this.eventId, {
detail,
});
document.dispatchEvent(ev);
window.dispatchEvent(ev);
}

public send(action: string, data: any) {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/components/ScriptMenuList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { RiPlayFill, RiStopFill } from "react-icons/ri";
import RuntimeController from "@App/runtime/content/runtime";
import { useTranslation } from "react-i18next";
import { SystemConfig } from "@App/pkg/config/config";
import { ScriptIcons } from "@App/pages/options/routes/utils";

const CollapseItem = Collapse.Item;

Expand Down Expand Up @@ -159,8 +160,10 @@ const ScriptMenuList: React.FC<{
textOverflow: "ellipsis",
whiteSpace: "nowrap",
color: item.runNum === 0 ? "rgb(var(--gray-5))" : "",
lineHeight: "20px",
}}
>
<ScriptIcons script={item} size={20} />
{item.name}
</span>
</Space>
Expand Down
18 changes: 9 additions & 9 deletions src/pages/options/routes/ScriptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ import { useTranslation } from "react-i18next";
import { nextTime, semTime } from "@App/pkg/utils/utils";
import { i18nName } from "@App/locales/locales";
import { SystemConfig } from "@App/pkg/config/config";
import { getValues, ListHomeRender, scriptListSort } from "./utils";
import {
getValues,
ListHomeRender,
ScriptIcons,
scriptListSort,
} from "./utils";

type ListType = Script & { loading?: boolean };

Expand Down Expand Up @@ -162,16 +167,9 @@ function ScriptList() {
loading={item.loading}
disabled={item.loading}
onChange={(checked) => {
setScriptList((list) => {
return list.map((script) => {
if (script.id === item.id) {
script.loading = true;
}
return script;
});
});
setScriptList((list) => {
const index = list.findIndex((script) => script.id === item.id);
list[index].loading = true;
let p: Promise<any>;
if (checked) {
p = scriptCtrl.enable(item.id).then(() => {
Expand Down Expand Up @@ -257,8 +255,10 @@ function ScriptList() {
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
lineHeight: "20px",
}}
>
<ScriptIcons script={item} size={20} />
{i18nName(item)}
</Text>
</Link>
Expand Down
35 changes: 33 additions & 2 deletions src/pages/options/routes/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable import/prefer-default-export */
import React from "react";
import IoC from "@App/app/ioc";
import { Script, ScriptDAO } from "@App/app/repo/scripts";
import { Metadata, Script, ScriptDAO } from "@App/app/repo/scripts";
import ValueManager from "@App/app/service/value/manager";
import { Button, Space, Tooltip } from "@arco-design/web-react";
import { Avatar, Button, Space, Tooltip } from "@arco-design/web-react";
import {
IconBug,
IconCode,
Expand Down Expand Up @@ -190,3 +190,34 @@ export function getValues(script: Script) {
return newValues;
});
}

export type ScriptIconsProps = {
script: { name: string; metadata: Metadata };
size?: number;
style?: React.CSSProperties;
};

export function ScriptIcons({ script, size = 32, style }: ScriptIconsProps) {
style = style || {};
style.display = style.display || "inline-block";
style.marginRight = style.marginRight || "8px";
let icon = "";
if (script.metadata.icon) {
[icon] = script.metadata.icon;
} else if (script.metadata.iconurl) {
[icon] = script.metadata.iconurl;
} else if (script.metadata.icon64) {
[icon] = script.metadata.icon64;
} else if (script.metadata.icon64url) {
[icon] = script.metadata.icon64url;
}
if (icon) {
return (
<Avatar size={size || 32} shape="square" style={style}>
<img src={icon} alt={script?.name} />
</Avatar>
);
}
// eslint-disable-next-line react/jsx-no-useless-fragment
return <></>;
}
5 changes: 5 additions & 0 deletions src/runtime/background/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ScriptDAO,
ScriptRunResouce,
SCRIPT_RUN_STATUS_RUNNING,
Metadata,
} from "@App/app/repo/scripts";
import ResourceManager from "@App/app/service/resource/manager";
import ValueManager from "@App/app/service/value/manager";
Expand Down Expand Up @@ -47,6 +48,7 @@ export type ScriptMenu = {
enable: boolean;
updatetime: number;
hasUserConfig: boolean;
metadata: Metadata;
runStatus?: SCRIPT_RUN_STATUS;
runNum: number;
runNumByIframe: number;
Expand Down Expand Up @@ -319,6 +321,7 @@ export default class Runtime extends Manager {
name: i18nName(item.script),
enable: item.script.status === SCRIPT_STATUS_ENABLE,
updatetime: item.script.updatetime || item.script.createtime,
metadata: item.script.metadata,
hasUserConfig: !!item.script.config,
runNum: item.runNum,
runNumByIframe: item.runNumByIframe,
Expand All @@ -332,6 +335,7 @@ export default class Runtime extends Manager {
name: i18nName(script),
enable: script.status === SCRIPT_STATUS_ENABLE,
updatetime: script.updatetime || script.createtime,
metadata: item.script.metadata,
hasUserConfig: !!script?.config,
runNum: item.runNum,
runNumByIframe: item.runNumByIframe,
Expand Down Expand Up @@ -364,6 +368,7 @@ export default class Runtime extends Manager {
name: item.name,
enable: item.status === SCRIPT_STATUS_ENABLE,
updatetime: item.updatetime || item.createtime,
metadata: item.metadata,
runStatus: item.runStatus,
hasUserConfig: !!item.config,
runNum:
Expand Down

0 comments on commit ff7d356

Please sign in to comment.