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 9, 2024
2 parents 11c95f1 + fcfb3ac commit 1c37d44
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 47 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.1.0",
"react-icons": "^4.4.0",
"react-icons": "^5.2.1",
"react-joyride": "^2.5.5",
"react-router-dom": "^6.3.0",
"semver": "^7.3.8",
Expand All @@ -61,7 +61,7 @@
"@types/crypto-js": "^4.1.1",
"@types/eslint": "^8.4.10",
"@types/jest": "^28.1.6",
"@types/lodash": "^4.14.194",
"@types/lodash": "^4.17.6",
"@types/pako": "^2.0.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
Expand Down
22 changes: 13 additions & 9 deletions src/app/message/content.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LoggerCore from "../logger/core";
import { Channel } from "./channel";
import {
ChannelManager,
Expand Down Expand Up @@ -107,15 +108,6 @@ export default class MessageContent

nativeSend(data: any): void {
let detail = data;
if (typeof cloneInto !== "undefined") {
try {
// eslint-disable-next-line no-undef
detail = cloneInto(detail, document.defaultView);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
}
}

// 特殊处理relatedTarget
if (detail.data && typeof detail.data.relatedTarget === "object") {
Expand All @@ -135,6 +127,18 @@ export default class MessageContent
document.dispatchEvent(ev);
}

if (typeof cloneInto !== "undefined") {
try {
LoggerCore.getLogger().info("nativeSend");
// eslint-disable-next-line no-undef
detail = cloneInto(detail, document.defaultView);
} catch (e) {
// eslint-disable-next-line no-console
console.log(e);
LoggerCore.getLogger().info("error data");
}
}

const ev = new CustomEvent((this.isContent ? "fd" : "ct") + this.eventId, {
detail,
});
Expand Down
4 changes: 4 additions & 0 deletions src/app/service/script/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export default class ScriptEventListener {
script.selfMetadata = oldScript.selfMetadata;
}
}
// 判断一些undefined的字段
if (!script.config) {
script.config = undefined;
}
return new Promise((resolve, reject) => {
this.dao.save(script).then(
() => {
Expand Down
14 changes: 12 additions & 2 deletions src/locales/ach-UG/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"create_user_script": "crwdns5824:0crwdne5824:0",
"create_background_script": "crwdns5826:0crwdne5826:0",
"create_scheduled_script": "crwdns5828:0crwdne5828:0",
"import_by_local": "crwdns6892:0crwdne6892:0",
"import_local_failure": "crwdns6894:0crwdne6894:0",
"import_local_success": "crwdns6896:0crwdne6896:0",
"create_script": "crwdns5830:0crwdne5830:0",
"user_guide": "crwdns5832:0crwdne5832:0",
"api_docs": "crwdns5834:0crwdne5834:0",
Expand Down Expand Up @@ -348,5 +351,12 @@
"guide_setting_title": "crwdns6498:0crwdne6498:0",
"guide_setting_content": "crwdns6500:0crwdne6500:0",
"guide_setting_sync_title": "crwdns6502:0crwdne6502:0",
"guide_setting_sync_content": "crwdns6504:0crwdne6504:0"
}
"guide_setting_sync_content": "crwdns6900:0crwdne6900:0",
"auto": "crwdns6902:0crwdne6902:0",
"hide": "crwdns6904:0crwdne6904:0",
"resize_column_width": "crwdns6906:0crwdne6906:0",
"collapse": "crwdns6908:0crwdne6908:0",
"expand": "crwdns6910:0crwdne6910:0",
"menu_expand_num_before": "crwdns6912:0crwdne6912:0",
"menu_expand_num_after": "crwdns6914:0crwdne6914:0"
}
18 changes: 14 additions & 4 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"create_user_script": "Create User Script",
"create_background_script": "Create Background Script",
"create_scheduled_script": "Create Scheduled Script",
"import_by_local": "Local Imported",
"import_local_failure": "Local import failed",
"import_local_success": "Local import success",
"create_script": "Create Script",
"user_guide": "User Guide",
"api_docs": "API Docs",
Expand Down Expand Up @@ -106,8 +109,8 @@
},
"enable": "Enable",
"script_list_enable_width": 120,
"script_list_last_updated_width": 0,
"script_list_apply_to_run_status_width": 0,
"script_list_last_updated_width": 140,
"script_list_apply_to_run_status_width": 160,
"subscribe_list_enable_width": 120,
"disable": "Disable",
"name": "Name",
Expand Down Expand Up @@ -348,5 +351,12 @@
"guide_setting_title": "Settings",
"guide_setting_content": "The settings mainly include language, script synchronization, update frequency, and other common options.",
"guide_setting_sync_title": "Update and Sync",
"guide_setting_sync_content": "The script synchronization feature allows you to easily sync the script content of this device to the cloud. If you select the option to sync deletions, when a script is deleted on this device, it will also be deleted from the cloud. You can also update the script version here to get more powerful features."
}
"guide_setting_sync_content": "The script synchronization feature allows you to easily sync the script content of this device to the cloud. If you select the option to sync deletions, when a script is deleted on this device, it will also be deleted from the cloud. You can also update the script version here to get more powerful features.",
"auto": "Auto",
"hide": "Hide",
"resize_column_width": "Resize Column",
"collapse": "Collapse",
"expand": "Expand",
"menu_expand_num_before": "Menu item more than",
"menu_expand_num_after": "Auto-hide."
}
9 changes: 7 additions & 2 deletions src/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"create_user_script": "新建普通脚本",
"create_background_script": "新建后台脚本",
"create_scheduled_script": "新建定时脚本",
"import_by_local": "本地导入",
"import_local_failure": "本地导入失败",
"import_local_success": "本地导入成功",
"create_script": "新建脚本",
"user_guide": "使用指南",
"api_docs": "API文档",
Expand Down Expand Up @@ -353,5 +356,7 @@
"hide": "隐藏",
"resize_column_width": "调整列宽",
"collapse": "收起",
"expand": "展开"
}
"expand": "展开",
"menu_expand_num_before": "菜单项超过",
"menu_expand_num_after": "个时,自动隐藏"
}
14 changes: 12 additions & 2 deletions src/locales/zh-TW/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"create_user_script": "新建普通腳本",
"create_background_script": "新建後台腳本",
"create_scheduled_script": "新建定時腳本",
"import_by_local": "本地导入",
"import_local_failure": "本地导入失败",
"import_local_success": "本地导入成功",
"create_script": "新建腳本",
"user_guide": "使用指南",
"api_docs": "API文檔",
Expand Down Expand Up @@ -348,5 +351,12 @@
"guide_setting_title": "設置",
"guide_setting_content": "設置中主要包含了語言、腳本同步、更新頻率等常用設置項",
"guide_setting_sync_title": "更新與同步",
"guide_setting_sync_content": "腳本同步功能可以方便的將本設備的腳本內容同步至雲端,如果勾選同步刪除選項,則當本設備腳本刪除時,也會從刪除雲端對應的腳本。你也可以在此更新腳本的版本獲得更加強大的功能。"
}
"guide_setting_sync_content": "脚本同步功能可以方便的将本设备的脚本内容同步至云端,如果有多台设备请勾选同步删除选项,当本设备脚本删除时,会从云端删除对应的脚本,也会将其它设备的脚本删除。",
"auto": "自动",
"hide": "隐藏",
"resize_column_width": "调整列宽",
"collapse": "收起",
"expand": "展开",
"menu_expand_num_before": "菜单项超过",
"menu_expand_num_after": "个时,自动隐藏"
}
45 changes: 45 additions & 0 deletions src/pages/components/layout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
RiTerminalBoxLine,
RiTimerLine,
RiPlayListAddLine,
RiImportLine,
} from "react-icons/ri";
import "./index.css";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -131,6 +132,50 @@ const MainLayout: React.FC<{
<RiTimerLine /> {t("create_scheduled_script")}
</a>
</Menu.Item>
<Menu.Item
key="import_local"
onClick={() => {
const el = document.getElementById("import-local");
el!.onchange = (e: Event) => {
const scriptCtl = IoC.instance(
ScriptController
) as ScriptController;
try {
// 获取文件
// @ts-ignore
const file = e.target.files[0];
// 实例化 FileReader对象
const reader = new FileReader();
reader.onload = async (processEvent) => {
// 创建blob url
const blob = new Blob(
// @ts-ignore
[processEvent.target!.result],
{
type: "application/javascript",
}
);
const url = URL.createObjectURL(blob);
await scriptCtl.importByUrl(url);
Message.success(t("import_local_success"));
};
// 调用readerAsText方法读取文本
reader.readAsText(file);
} catch (error) {
Message.error(`${t("import_local_failure")}: ${e}`);
}
};
el!.click();
}}
>
<input
id="import-local"
type="file"
style={{ display: "none" }}
accept=".js"
/>
<RiImportLine /> {t("import_by_local")}
</Menu.Item>
<Menu.Item
key="link"
onClick={() => {
Expand Down
15 changes: 8 additions & 7 deletions src/pages/options/routes/ScriptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,23 @@ function ScriptList() {
},
],
onFilter: (value, row) => row.status === value,
render: (col, item: ListType, index) => {
render: (col, item: ListType) => {
return (
<Switch
checked={item.status === SCRIPT_STATUS_ENABLE}
loading={item.loading}
disabled={item.loading}
onChange={(checked) => {
setScriptList((list) => {
list[index].loading = true;
return [...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);
let p: Promise<any>;
if (checked) {
p = scriptCtrl.enable(item.id).then(() => {
Expand Down Expand Up @@ -689,10 +694,6 @@ function ScriptList() {

newColumns.forEach((item) => {
switch (item.width) {
case 0:
item.width = 0;
dealColumns.push(item);
break;
case -1:
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/pages/options/routes/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function Setting() {
</Select>
</Space>
<Space>
菜单项超过
{t("menu_expand_num_before")}:
<Input
style={{ width: "64px" }}
type="number"
Expand All @@ -105,7 +105,7 @@ function Setting() {
systemConfig.menuExpandNum = parseInt(val, 10);
}}
/>
个时,自动隐藏
{t("menu_expand_num_after")}
</Space>
</Space>
</Card>
Expand Down
Loading

0 comments on commit 1c37d44

Please sign in to comment.