From 919bd26e4ed6f3f0eec8a5bbcc16b35e850445e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mehver=20=7C=20=E8=BF=99=E6=B0=B4=E6=80=8E=E4=B9=88?=
=?UTF-8?q?=E6=B2=A1=E5=91=B3=E5=84=BF=E5=95=8A?=
<75297777+Mehver@users.noreply.github.com>
Date: Thu, 26 Dec 2024 18:20:47 +0800
Subject: [PATCH 01/12] Create .gitignore
---
.idea/.gitignore | 10 ++++++++
.idea/workspace.xml | 62 ---------------------------------------------
CHANGELOG.md | 4 ---
3 files changed, 10 insertions(+), 66 deletions(-)
create mode 100644 .idea/.gitignore
delete mode 100644 .idea/workspace.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..a9d7db9
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,10 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# GitHub Copilot persisted chat sessions
+/copilot/chatSessions
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 5831962..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-
-
-
-
-
v0.6.4English | 简体中文
+English | 简体中文
|
- |
- |
- |
- |
v0.6.4English | 简体中文
@@ -16,16 +16,16 @@|
- |
- |
- |
- |
{ + if (value === null || value === undefined) return defaultValue; + switch (type) { + case 'int': + return parseInt(value, 10) || defaultValue; + case 'float': + return parseFloat(value) || defaultValue; + case 'boolean': + return value === 'true'; + default: + return value; + } +}; + export class ContextProvider extends Component { - state = { - /////////////////////////////////////////////////////////////////////////////////// - drawerOpen: false, - setDrawerOpen: (value) => { - this.setState({drawerOpen: value}); - }, - /////////////////////////////////////////////////////////////////////////////////// - // drawerRL 是用 char 类型保存的可切换状态值, 'l' 表示左侧,'r' 表示右侧 - drawerRL: getCookie('drawerRL') || 'l', - setDrawerRL: (value) => { - this.setState( - {drawerRL: value}, () => { - setCookie('drawerRL', value, 7); - return {drawerRL: value}; - } - ); - }, - /////////////////////////////////////////////////////////////////////////////////// - // tPadSensitivity 是用 float 类型保存的可切换状态值, 是灵敏度系数,默认为 1.0,必须大于 0 - tPadSensitivity: parseFloat(getCookie('tPadSensitivity')) || 1.0, - setTPadSensitivity: (value) => { - this.setState( - {tPadSensitivity: value}, () => { - setCookie('tPadSensitivity', value, 7); - return {tPadSensitivity: value}; - } - ); - }, - /////////////////////////////////////////////////////////////////////////////////// - mWheelSensitivity: parseFloat(getCookie('mWheelSensitivity')) || 1.0, - setMWheelSensitivity: (value) => { - this.setState( - {mWheelSensitivity: value}, () => { - setCookie('mWheelSensitivity', value, 7); - return {mWheelSensitivity: value}; - } - ); - }, - /////////////////////////////////////////////////////////////////////////////////// - buttonSW1: getCookie('buttonSW1') === 'false', - toggleButtonSW1: () => { - this.setState(prevState => { - const newValue = !prevState.buttonSW1; - setCookie('buttonSW1', newValue, 7); - return {buttonSW1: newValue}; - }); - }, - buttonSW4: getCookie('buttonSW4') === 'true', - toggleButtonSW4: () => { - this.setState(prevState => { - const newValue = !prevState.buttonSW4; - setCookie('buttonSW4', newValue, 7); - return {buttonSW4: newValue}; - }); - }, - button23: parseInt(getCookie('button23'), 10) || 0, - setButton23: (value) => { - this.setState( - {button23: value}, () => - setCookie('button23', value, 7)); - }, - ///////////////////////////////////////////////////////////////////////////////// - autoCollapse: getCookie('autoCollapse') === 'true', - toggleAutoCollapse: () => { - this.setState(prevState => { - const newValue = !prevState.autoCollapse; - setCookie('autoCollapse', newValue, 7); - return {autoCollapse: newValue}; - }); - }, - ///////////////////////////////////////////////////////////////////////////////// - mouseWheelMenuType: parseInt(getCookie('mouseWheelMenuType'), 10) || 0, - setMouseWheelMenuType: (value) => { - this.setState( - {mouseWheelMenuType: value}, () => - setCookie('mouseWheelMenuType', value, 7)); - }, - ///////////////////////////////////////////////////////////////////////////////// - sidebarModulesSettingMenu: getCookie('sidebarModulesSettingMenu') === 'false', - toggleSidebarModulesSettingMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarModulesSettingMenu; - setCookie('sidebarModulesSettingMenu', newValue, 7); - return {sidebarModulesSettingMenu: newValue}; - }); - }, - sidebarMouseWheelMenu: getCookie('sidebarMouseWheelMenu') === 'false', - toggleSidebarMouseWheelMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarMouseWheelMenu; - setCookie('sidebarMouseWheelMenu', newValue, 7); - return {sidebarMouseWheelMenu: newValue}; - }); - }, - sidebarKeyboardMenu: getCookie('sidebarKeyboardMenu') === 'false', - toggleSidebarKeyboardMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarKeyboardMenu; - setCookie('sidebarKeyboardMenu', newValue, 7); - return {sidebarKeyboardMenu: newValue}; - }); - }, - sidebarVolumeMenu: getCookie('sidebarVolumeMenu') === 'false', - toggleSidebarVolumeMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarVolumeMenu; - setCookie('sidebarVolumeMenu', newValue, 7); - return {sidebarVolumeMenu: newValue}; - }); - }, - sidebarSettingMenu: getCookie('sidebarSettingMenu') === 'false', - toggleSidebarSettingMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarSettingMenu; - setCookie('sidebarSettingMenu', newValue, 7); - return {sidebarSettingMenu: newValue}; - }); - }, - sidebarThemeMenu: getCookie('sidebarThemeMenu') === 'false', - toggleSidebarThemeMenu: () => { - this.setState(prevState => { - const newValue = !prevState.sidebarThemeMenu; - setCookie('sidebarThemeMenu', newValue, 7); - return {sidebarThemeMenu: newValue}; - }); - }, - ///////////////////////////////////////////////////////////////////////////////// - primaryColor: getCookie('primaryColor') || '#6df', - setPrimaryColor: (value) => { - this.setState( - {primaryColor: value}, () => - setCookie('primaryColor', value, 7)); - }, - secondaryColor: getCookie('secondaryColor') || '#333', - setSecondaryColor: (value) => { - this.setState( - {secondaryColor: value}, () => - setCookie('secondaryColor', value, 7)); - }, - ///////////////////////////////////////////////////////////////////////////////// - // openMenuSW 是用 int 类型保存的可切换状态值,0 表示关闭,1 表示打开键盘菜单,2 表示打开鼠标滚轮菜单,3 表示打开音量菜单... - openMenuSW: parseInt(getCookie('openMenuSW'), 10) || 0, - setOpenMenuSW: (value) => { - this.setState( - {openMenuSW: value}, () => - setCookie('openMenuSW', value, 7)); - }, - /////////////////////////////////////////////////////////////////////////////////// - // keyboardDataSendMod 是用 char 类型保存的可切换状态值 - keyboardDataSendMod: getCookie('keyboardDataSendMod') || 'a', - setKeyboardDataSendMod: (value) => { - this.setState( - {keyboardDataSendMod: value}, () => { - setCookie('keyboardDataSendMod', value, 7); - return {keyboardDataSendMod: value}; - } - ); - }, - /////////////////////////////////////////////////////////////////////////////////// - }; + constructor(props) { + super(props); + const state = {}; + + // 遍历配置,为每个状态项初始化值(优先使用 cookie 值,否则使用默认值) + Object.keys(settingsConfig).forEach(key => { + const {default: def, type, cookie} = settingsConfig[key]; + const cookieValue = cookie ? getCookie(cookie) : undefined; + state[key] = parseValue(cookieValue, type, def); + }); + + // 自动生成更新函数 + Object.keys(settingsConfig).forEach(key => { + const {cookie, toggle} = settingsConfig[key]; + const capitalizedKey = key.charAt(0).toUpperCase() + key.slice(1); - componentDidMount() { - // 从cookie初始化状态 - const buttonSW1 = getCookie('buttonSW1'); - const button23 = getCookie('button23'); - const buttonSW4 = getCookie('buttonSW4'); - const drawerRL = getCookie('drawerRL'); - const tPadSensitivity = getCookie('tPadSensitivity'); - const mWheelSensitivity = getCookie('mWheelSensitivity'); - const autoCollapse = getCookie('autoCollapse'); - const mouseWheelMenuType = getCookie('mouseWheelMenuType'); - const sidebarModulesSettingMenu = getCookie('sidebarModulesSettingMenu'); - const sidebarMouseWheelMenu = getCookie('sidebarMouseWheelMenu'); - const sidebarSettingMenu = getCookie('sidebarSettingMenu'); - const sidebarVolumeMenu = getCookie('sidebarVolumeMenu'); - const sidebarKeyboardMenu = getCookie('sidebarKeyboardMenu'); - const sidebarThemeMenu = getCookie('sidebarThemeMenu'); - const primaryColor = getCookie('primaryColor'); - const secondaryColor = getCookie('secondaryColor'); - const openMenuSW = getCookie('openMenuSW'); - const keyboardDataSendMod = getCookie('keyboardDataSendMod'); - this.setState({ - buttonSW1: buttonSW1 ? buttonSW1 === 'true' : this.state.buttonSW1, - button23: button23 ? parseInt(button23, 10) : this.state.button23, - buttonSW4: buttonSW4 ? buttonSW4 === 'true' : this.state.buttonSW4, - drawerRL: drawerRL || this.state.drawerRL, - tPadSensitivity: tPadSensitivity ? parseFloat(tPadSensitivity) : this.state.tPadSensitivity, - mWheelSensitivity: mWheelSensitivity ? parseFloat(mWheelSensitivity) : this.state.mWheelSensitivity, - autoCollapse: autoCollapse ? autoCollapse === 'true' : this.state.autoCollapse, - mouseWheelMenuType: mouseWheelMenuType ? parseInt(mouseWheelMenuType, 10) : this.state.mouseWheelMenuType, - sidebarModulesSettingMenu: sidebarModulesSettingMenu ? sidebarModulesSettingMenu === 'true' : this.state.sidebarModulesSettingMenu, - sidebarMouseWheelMenu: sidebarMouseWheelMenu ? sidebarMouseWheelMenu === 'true' : this.state.sidebarMouseWheelMenu, - sidebarSettingMenu: sidebarSettingMenu ? sidebarSettingMenu === 'true' : this.state.sidebarSettingMenu, - sidebarVolumeMenu: sidebarVolumeMenu ? sidebarVolumeMenu === 'true' : this.state.sidebarVolumeMenu, - sidebarKeyboardMenu: sidebarKeyboardMenu ? sidebarKeyboardMenu === 'true' : this.state.sidebarKeyboardMenu, - sidebarThemeMenu: sidebarThemeMenu ? sidebarThemeMenu === 'true' : this.state.sidebarThemeMenu, - primaryColor: primaryColor || this.state.primaryColor, - secondaryColor: secondaryColor || this.state.secondaryColor, - openMenuSW: openMenuSW ? parseInt(openMenuSW, 10) : this.state.openMenuSW, - keyboardDataSendMod: keyboardDataSendMod || this.state.keyboardDataSendMod, + // 生成 setter:更新状态并同步 cookie(如果配置了 cookie) + state[`set${capitalizedKey}`] = (value) => { + this.setState({[key]: value}, () => { + if (cookie) { + setCookie(cookie, value, 7); + } + }); + }; + + // 如果配置了 toggle,则生成 toggle 方法 + if (toggle) { + state[`toggle${capitalizedKey}`] = () => { + this.setState(prevState => { + const newValue = !prevState[key]; + if (cookie) { + setCookie(cookie, newValue, 7); + } + return {[key]: newValue}; + }); + }; + } }); + + this.state = state; } render() { diff --git a/ClientBrowserUI/src/utils/Theme.js b/ClientBrowserUI/src/utils/Theme.js index 61e68a2..99ba040 100644 --- a/ClientBrowserUI/src/utils/Theme.js +++ b/ClientBrowserUI/src/utils/Theme.js @@ -1,12 +1,8 @@ -import {createTheme} from "@mui/material/styles"; - -export let primaryColor = '#6df'; -export let primaryColorTrans = 'rgba(102, 204, 255, 0.5)'; -export let secondaryColor = '#333'; -export let secondaryColorTrans = 'rgba(51, 51, 51, 0.5)'; +export let defaultPrimaryColor = '#6DF'; +export let defaultSecondaryColor = '#333'; // 自动检测颜色格式并转换为半透明颜色值 -const convertHexToRGBA = (hex, opacity) => { +export const convertHexToRGBA = (hex, opacity) => { let tempHex = hex.replace('#', ''); // 检测并转换3位十六进制颜色为6位 if (tempHex.length === 3) { @@ -22,63 +18,28 @@ const convertHexToRGBA = (hex, opacity) => { return `rgba(${r}, ${g}, ${b}, ${opacity})`; }; -// 更新主题 -const updateTheme = () => { - customTheme.palette.primary.main = primaryColor; - customTheme.palette.secondary.main = secondaryColor; -}; - -export const setPrimaryColor = (color) => { - const newColorTrans = convertHexToRGBA(color, 0.5); - if (newColorTrans) { - primaryColor = color; - primaryColorTrans = newColorTrans; - updateTheme(); - // 修改 head 中的 - const metaThemeColor = document.querySelector("meta[name=theme-color]"); - if (metaThemeColor) { - metaThemeColor.setAttribute("content", color); - } - // 改变CSS中的background-color - const html = document.querySelector("html"); - const body = document.querySelector("body"); - const fullScreenBackground = document.querySelector(".full-screen-background"); - const appHeader = document.querySelector(".App-header"); - if (html) { - html.style.backgroundColor = color; - } - if (body) { - body.style.backgroundColor = color; - } - if (fullScreenBackground) { - fullScreenBackground.style.backgroundColor = color; - } - if (appHeader) { - appHeader.style.color = color; - } +export const updateColorCSS = (primaryColor, secondaryColor) => { + // 修改 head 中的 + const metaThemeColor = document.querySelector("meta[name=theme-color]"); + if (metaThemeColor) { + metaThemeColor.setAttribute("content", primaryColor); } -}; - -export const setSecondaryColor = (color) => { - const newColorTrans = convertHexToRGBA(color, 0.5); - if (newColorTrans) { - secondaryColor = color; - secondaryColorTrans = newColorTrans; - updateTheme(); - const appHeader = document.querySelector(".App-header"); - if (appHeader) { - appHeader.style.backgroundColor = color; - } + const html = document.querySelector("html"); + const body = document.querySelector("body"); + const fullScreenBackground = document.querySelector(".full-screen-background"); + const appHeader = document.querySelector(".App-header"); + if (html) { + html.style.backgroundColor = primaryColor; } -}; + if (body) { + body.style.backgroundColor = primaryColor; + } + if (fullScreenBackground) { + fullScreenBackground.style.backgroundColor = primaryColor; + } + if (appHeader) { + appHeader.style.color = primaryColor; + appHeader.style.backgroundColor = secondaryColor; + } +} -export let customTheme = createTheme({ - palette: { - primary: { - main: primaryColor, - }, - secondary: { - main: secondaryColor, - }, - }, -}); diff --git a/bin/dev/mac-node16_bullseye-p3000.sh b/bin/DevDockerEnv/mac-node16_bullseye-p3000.sh similarity index 100% rename from bin/dev/mac-node16_bullseye-p3000.sh rename to bin/DevDockerEnv/mac-node16_bullseye-p3000.sh diff --git a/bin/dev/mac-node16_bullseye.sh b/bin/DevDockerEnv/mac-node16_bullseye.sh similarity index 100% rename from bin/dev/mac-node16_bullseye.sh rename to bin/DevDockerEnv/mac-node16_bullseye.sh diff --git a/bin/dev/win-node16_bullseye-p3000.bat b/bin/DevDockerEnv/win-node16_bullseye-p3000.bat similarity index 100% rename from bin/dev/win-node16_bullseye-p3000.bat rename to bin/DevDockerEnv/win-node16_bullseye-p3000.bat diff --git a/bin/dev/win-node16_bullseye.bat b/bin/DevDockerEnv/win-node16_bullseye.bat similarity index 100% rename from bin/dev/win-node16_bullseye.bat rename to bin/DevDockerEnv/win-node16_bullseye.bat diff --git a/bin/dev/win-python3(10)_bullseye-p3000.bat b/bin/DevDockerEnv/win-python3(10)_bullseye-p3000.bat similarity index 100% rename from bin/dev/win-python3(10)_bullseye-p3000.bat rename to bin/DevDockerEnv/win-python3(10)_bullseye-p3000.bat diff --git a/bin/dev/win-python3(10)_bullseye.bat b/bin/DevDockerEnv/win-python3(10)_bullseye.bat similarity index 100% rename from bin/dev/win-python3(10)_bullseye.bat rename to bin/DevDockerEnv/win-python3(10)_bullseye.bat diff --git a/bin/PyInstallerOneFile.bat b/bin/PyInstallerOneFile.bat index 1327b80..6ece652 100644 --- a/bin/PyInstallerOneFile.bat +++ b/bin/PyInstallerOneFile.bat @@ -8,17 +8,11 @@ rd /s /q dist rd /s /q build rd /s /q venv rd /s /q logs +rd /s /q node_modules rd /s /q ClientBrowserUI\build +rd /s /q ClientBrowserUI\node_modules -where docker >nul 2>nul -if %errorlevel% neq 0 ( - cd ClientBrowserUI - npm install - npm run build - cd .. -) else ( - docker run -it --rm -v %cd%:/docker -w /docker node:16-bullseye bash -c "cd ClientBrowserUI; npm i; npm run build; exit" -) +docker run -it --rm -v %cd%:/docker -w /docker node:16-bullseye bash -c "cd ClientBrowserUI; npm i; npm run build; exit" python -m venv venv call venv\Scripts\activate From 7fe3e19421e7344ef8f036991dfd6a9c0e994864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehver=20=7C=20=E8=BF=99=E6=B0=B4=E6=80=8E=E4=B9=88?= =?UTF-8?q?=E6=B2=A1=E5=91=B3=E5=84=BF=E5=95=8A?= <75297777+Mehver@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:18:40 -0400 Subject: [PATCH 10/12] =?UTF-8?q?Set=20up=20i18n=20framework,=20add=20Simp?= =?UTF-8?q?lified=20Chinese=20=E6=B7=BB=E5=8A=A0=E7=AE=80=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/SideBar/KeyboardMenu.jsx | 8 +- .../src/components/SideBar/LanguageMenu.jsx | 61 ++++++++++ ...sSettingMenu.jsx => LayoutSettingMenu.jsx} | 19 +-- .../src/components/SideBar/SettingMenu.jsx | 11 +- .../src/components/SideBar/ThemeMenu.jsx | 5 +- .../src/components/SideBar/index.jsx | 64 ++++++++-- ClientBrowserUI/src/utils/Context.jsx | 4 +- ClientBrowserUI/src/utils/i18n.js | 111 ++++++++++++++++++ 8 files changed, 251 insertions(+), 32 deletions(-) create mode 100644 ClientBrowserUI/src/components/SideBar/LanguageMenu.jsx rename ClientBrowserUI/src/components/SideBar/{ModulesSettingMenu.jsx => LayoutSettingMenu.jsx} (85%) create mode 100644 ClientBrowserUI/src/utils/i18n.js diff --git a/ClientBrowserUI/src/components/SideBar/KeyboardMenu.jsx b/ClientBrowserUI/src/components/SideBar/KeyboardMenu.jsx index 733f3f2..062baf1 100644 --- a/ClientBrowserUI/src/components/SideBar/KeyboardMenu.jsx +++ b/ClientBrowserUI/src/components/SideBar/KeyboardMenu.jsx @@ -20,6 +20,7 @@ import { api_keyboard_pastetext } from "../../api/keyboard"; import {api_get_system_info} from "../../api/system"; +import i18n from '../../utils/i18n'; class KeyboardMenu extends Component { constructor(props) { @@ -133,7 +134,8 @@ class KeyboardMenu extends Component {
v0.6.4v0.6.5English | 简体中文
-v0.6.4v0.6.5English | 简体中文
-