diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 000000000..e69de29bb
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 000000000..9f514856e
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 000000000..105ce2da2
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..7e8347393
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 000000000..e08f87919
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..94a25f7f4
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/viser.iml b/.idea/viser.iml
new file mode 100644
index 000000000..8b8c39547
--- /dev/null
+++ b/.idea/viser.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 000000000..fe74052a2
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1702614150119
+
+
+ 1702614150119
+
+
+
+
\ No newline at end of file
diff --git a/src/viser/_client_autobuild.py b/src/viser/_client_autobuild.py
index 9483bf0c1..de95d3248 100644
--- a/src/viser/_client_autobuild.py
+++ b/src/viser/_client_autobuild.py
@@ -1,5 +1,5 @@
import subprocess
-import sys
+import sys,os
from pathlib import Path
import psutil
@@ -56,19 +56,83 @@ def ensure_client_is_built() -> None:
# Install nodejs and build if necessary. We assume bash is installed.
if build:
- env_dir = _install_sandboxed_node()
- npx_path = env_dir / "bin" / "npx"
- subprocess.run(
- args=(
- "bash -c '"
- f"source {env_dir / 'bin' / 'activate'};"
- f"{npx_path} yarn install;"
- f"{npx_path} yarn run build;"
- "'"
- ),
- cwd=client_dir,
- shell=True,
- )
+ if os.name == "nt":
+ print("Build on windows")
+ env_dir = _install_sandboxed_node_win()
+ env_dir_abs = env_dir / "Scripts"
+ # 1. 构建 Windows 路径
+ npx_path = env_dir_abs / "npx.cmd"
+ yarn_install_cmd = f"{npx_path} yarn install"
+ yarn_build_cmd = f"{npx_path} yarn run build"
+ # 激活 Node 环境并运行 yarn 命令
+ subprocess.run(["cmd", "/c", yarn_install_cmd], cwd=env_dir_abs, shell=True)
+ print('install yarn done!!!!!!!')
+ subprocess.run(["cmd", "/c", yarn_build_cmd], cwd=env_dir_abs, shell=True)
+ print('build yarn done!!!!!!')
+ # print('构建成功!!!!!!!!!!!!!!!!')
+ else:
+ print("Build on other platforms")
+ env_dir = _install_sandboxed_node()
+ npx_path = env_dir / "bin" / "npx"
+ subprocess.run(
+ args=(
+ "bash -c '"
+ f"source {env_dir / 'bin' / 'activate'};"
+ f"{npx_path} yarn install;"
+ f"{npx_path} yarn run build;"
+ "'"
+ ),
+ cwd=client_dir,
+ shell=True,
+ )
+
+def _install_sandboxed_node_win() -> Path:
+ """Install a sandboxed copy of nodejs using nodeenv, and return a path to the
+ environment root."""
+ # 1 Set the node environment path
+ env_dir = client_dir / ".nodeenv"
+ if (env_dir / "Scripts" / "npx.cmd").exists():
+ rich.print("[bold](viser)[/bold] nodejs is set up!")
+ return env_dir
+ ####### Installing a node you can run in cmd :
+ # Administrator permissions Open cmd
+ # conda activate your python
+ # python -m nodeenv --node=20.4.0 path\to\your\extern\viser\src\viser\client\.nodeenv
+ result = subprocess.run(
+ [sys.executable, "-m", "nodeenv", "--node=20.4.0", env_dir],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE
+ )
+ try:
+ # 首先尝试 UTF-8 编码
+ error_output = result.stderr.decode('utf-8')
+ except UnicodeDecodeError:
+ try:
+ # 如果 UTF-8 失败,尝试使用 GBK 编码(适用于中文 Windows 系统)
+ error_output = result.stderr.decode('gbk')
+ except UnicodeDecodeError:
+ # 如果其他编码也失败,使用 'replace' 选项替换无法解码的字符
+ error_output = result.stderr.decode('utf-8', errors='replace')
+
+ print(f"Link error: {error_output}")
+ print('\n###############\n')
+ print(f"About unable to create link error: Failed to create nodejs.exe link ")
+ print(
+ " NOTE: This error does not affect the build process and can be fixed manually if necessary.")
+ print(
+ " 1. Open Command Prompt with Administrator privileges\n 2. Navigate to the .nodeenv\\Scripts directory in your project")
+ print(
+ " 3. Run the command 'mklink nodejs.exe node.exe' to create the symbolic link\n 4. After this, it should be okay")
+ print('\n###############\n')
+
+ print('node installation complete\n安装node完成!!!!!!!!!!!!!')
+ subprocess.run(
+ args=[env_dir / "Scripts" / "npm.cmd", "install", "yarn"],
+ input="y\n".encode(),
+ )
+ print('install yarn done')
+ assert (env_dir / "Scripts" / "npx.cmd").exists()
+ return env_dir
def _install_sandboxed_node() -> Path: