import React, { useState } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import { Copy, Check, Terminal, Shield, Cpu, RefreshCw, Layers, GitBranch, Hammer } from 'lucide-react'; import { SetupStep } from '../types'; type TabId = 'mint_ubuntu' | 'arch' | 'fedora' | 'dev'; export default function SetupGuide() { const [activeTab, setActiveTab] = useState('mint_ubuntu'); const [copiedText, setCopiedText] = useState(null); const handleCopy = (text: string, id: string) => { navigator.clipboard.writeText(text); setCopiedText(id); setTimeout(() => setCopiedText(null), 2000); }; const installSteps: Record, SetupStep[]> = { mint_ubuntu: [ { id: 1, title: "Cài đặt VietC (Pre-built)", description: "Chạy lệnh dưới đây để tự động tải về, cài đặt phụ thuộc và biên dịch VietC trên hệ thống của bạn.", command: `git clone https://github.com/vndangkhoa/vietc.git /tmp/vietc \\ && cd /tmp/vietc && sudo ./install.sh`, notes: "Script tự động phát hiện distro, cài đặt dependencies, build và cấu hình udev rules cho uinput." }, { id: 2, title: "Gỡ cài đặt (Uninstall)", description: "Xoá hoàn toàn VietC khỏi hệ thống, bao gồm binary, service và udev rules.", command: `curl -sSL https://raw.githubusercontent.com/vndangkhoa/vietc/main/uninstall.sh | sudo bash`, notes: "Lệnh này sẽ xoá /usr/local/bin/vietc, systemd service và các file cấu hình." } ], arch: [ { id: 1, title: "Cài đặt VietC (Pre-built)", description: "Tự động clone, build và cài đặt VietC trên Arch Linux.", command: `git clone https://github.com/vndangkhoa/vietc.git /tmp/vietc \\ && cd /tmp/vietc && sudo ./install.sh`, notes: "Script hỗ trợ pacman, tự động cài đặt base-devel và các thư viện cần thiết." }, { id: 2, title: "Gỡ cài đặt (Uninstall)", description: "Xoá VietC hoàn toàn khỏi hệ thống Arch.", command: `curl -sSL https://raw.githubusercontent.com/vndangkhoa/vietc/main/uninstall.sh | sudo bash`, } ], fedora: [ { id: 1, title: "Cài đặt VietC (Pre-built)", description: "Tự động clone, build và cài đặt VietC trên Fedora.", command: `git clone https://github.com/vndangkhoa/vietc.git /tmp/vietc \\ && cd /tmp/vietc && sudo ./install.sh`, notes: "Script hỗ trợ dnf, tự động cài đặt Development Tools và thư viện X11." }, { id: 2, title: "Gỡ cài đặt (Uninstall)", description: "Xoá VietC hoàn toàn khỏi hệ thống Fedora.", command: `curl -sSL https://raw.githubusercontent.com/vndangkhoa/vietc/main/uninstall.sh | sudo bash`, } ] }; const devSteps: SetupStep[] = [ { id: 1, title: "Clone mã nguồn", description: "Nhánh main chứa code mới nhất.", command: `git clone https://github.com/vndangkhoa/vietc.git cd vietc`, }, { id: 2, title: "Cài đặt Rust (nếu chưa có)", description: "Dùng rustup để cài Rust toolchain mới nhất.", command: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source "$HOME/.cargo/env"`, notes: "Kiểm tra với 'rustc --version' và 'cargo --version'." }, { id: 3, title: "Cài đặt hệ thống phụ thuộc", description: "Thư viện dev cho X11, evdev và dbus.", command: `sudo apt install build-essential pkg-config libx11-dev libxtst-dev \\ libevdev-dev libdbus-1-dev libwayland-dev wl-clipboard`, notes: "Trên Fedora: dnf install; trên Arch: pacman -S. Xem install.sh để biết chi tiết." }, { id: 4, title: "Biên dịch (debug)", description: "Build nhanh không tối ưu, phù hợp khi phát triển.", command: `cargo build`, notes: "Binary ở target/debug/vietc. Chạy thử: ./target/debug/vietc" }, { id: 5, title: "Biên dịch (release - tối ưu)", description: "Build với tối ưu hóa cho hiệu năng cao nhất.", command: `cargo build --release`, notes: "Binary ở target/release/vietc. Chạy thử: ./target/release/vietc" }, { id: 6, title: "Cấp quyền uinput", description: "VietC cần quyền ghi /dev/uinput. Thêm user vào group input và uinput.", command: `sudo gpasswd -a $USER input sudo groupadd -f uinput sudo gpasswd -a $USER uinput echo 'KERNEL=="uinput", GROUP="uinput", MODE="0660", OPTIONS+="static_node=uinput"' | sudo tee /etc/udev/rules.d/99-vietc.rules sudo udevadm control --reload-rules && sudo udevadm trigger`, notes: "Đăng xuất và đăng nhập lại (hoặc reboot) để group có hiệu lực." }, { id: 7, title: "Chạy thử (không cần cài đặt)", description: "Chạy trực tiếp từ thư mục build, không cần systemd service.", command: `./target/release/vietc`, notes: "Tắt bằng Ctrl+C. Có thể chạy ở chế độ nền với '&' và dùng 'fg' để đưa lên foreground." } ]; const tabs: { id: TabId; label: string; icon?: React.ReactNode }[] = [ { id: 'mint_ubuntu', label: 'Mint / Ubuntu' }, { id: 'arch', label: 'Arch Linux' }, { id: 'fedora', label: 'Fedora' }, { id: 'dev', label: 'Dev Build', icon: }, ]; return (
{/* Section Header */}
NATIVE LINUX INTEGRATION Hướng Dẫn Cài Đặt VietC

Vì VietC là bộ gõ mức thấp (System & Application level) không phụ thuộc IBus hay Fcitx5, việc cài đặt sẽ tác động trực tiếp lên driver uinput hệ thống để đạt tốc độ gõ tuyệt đối.

{/* Tabs */}
{tabs.map((tab) => ( ))}
{/* Content */} {activeTab === 'dev' ? (

Build từ mã nguồn (dành cho Developer)

Các bước dưới đây hướng dẫn bạn tự biên dịch VietC từ source, chạy thử mà không cần cài đặt system-wide. Phù hợp cho developer muốn đóng góp hoặc tùy chỉnh.

{devSteps.map((step, idx) => ( {idx !== devSteps.length - 1 && (
)}
0{step.id}

{step.title}

{step.description}

{step.command && (
BASH TERMINAL
{step.command}
)} {step.notes && (
Lưu ý: {step.notes}
)}
))}
) : (
{installSteps[activeTab].map((step, idx) => ( {idx !== installSteps[activeTab].length - 1 && (
)}
0{step.id}

{step.title}

{step.description}

{step.command && (
BASH TERMINAL
{step.command}
)} {step.notes && (
Lưu ý: {step.notes}
)}
))}
)} {/* Architecture graphic */}

Mô Hình Hoạt Động Khác Biệt của VietC

OLD

IBus / Fcitx5

Hoạt động ở Application Layer qua cơ chế giao tiếp DBus phức tạp. Khi gõ trong Terminal ảo, các lệnh Backspace/Delete giả lập thường bị trễ hoặc nuốt ký tự gây lỗi nhân đôi hoặc mất chữ.

NEW

VietC (uinput + evdev)

Chặn (grab) sự kiện gốc từ bàn phím vật lý thông qua driver evdev, sau đó tự tính toán bằng State Machine và xuất ra bàn phím ảo mới thông qua uinput.

WIN

Trải Nghiệm "Như Bay"

Độ trễ phản hồi phím Keystroke: 0ms và giải phóng nút <1ms. Gõ tiếng Việt gốc 100% không bị lag, không kén Terminal nào (Alacritty, Kitty, GNOME Terminal, v.v.).

); }