Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/web-ui-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: web-ui-lint

on:
pull_request:
paths:
- "web/gui/**"
- ".github/workflows/web-ui-lint.yml"
push:
branches: [master, Webui]
paths:
- "web/gui/**"

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: web/gui
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm install --no-audit --no-fund
- run: npm run lint
- run: npm run format:check
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ debug*.py
config.json
secrets.json
*.zip
.env*
!.env.example

# environments
/.venv*
Expand All @@ -38,3 +40,14 @@ pixi.toml
train.bat
debug_report.log
config_diff.txt

# Web UI
web/gui/dist/
web/gui/release/
web/gui/node_modules/
web/gui/public/ui-schema.json
web/gui/src/renderer/types/generated/
web/gui/.vite-port
web/backend/__pycache__/
web/backend/**/__pycache__/
web/backend/generated/
17 changes: 16 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.17
hooks:
# Run the Ruff linter, but not the formatter.
- id: ruff
args: ["--fix"]
types_or: [ python, pyi, jupyter ]

- repo: local
hooks:
- id: eslint
name: ESLint (frontend)
entry: python -m web.scripts.run_eslint
language: system
files: '^web/gui/.*\.(ts|tsx)$'
pass_filenames: false

- id: check-hardcoded-dropdown-options
name: No hardcoded <Select options> outside types/generated/
entry: python -m web.scripts.check_hardcoded_options
language: system
files: '^web/gui/src/renderer/.*\.(ts|tsx)$'
pass_filenames: false

ci:
autofix_prs: false
32 changes: 32 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,38 @@ if errorlevel 1 (
echo %GRN%CUDA is available.%RESET%
)

rem 7) Generate UI schema and build web UI
echo.
echo %CYAN%Generating UI schema...%RESET%
python -m web.scripts.generate_ui_schema
if errorlevel 1 (
echo %YEL%WARNING: UI schema generation failed. Using existing schema.%RESET%
)

echo.
where node >NUL 2>NUL
if errorlevel 1 (
echo %YEL%Node.js not found. Skipping web UI build.%RESET%
echo To use the web UI, install Node.js from https://nodejs.org/ and re-run install.bat
) else (
echo %CYAN%Building web UI...%RESET%
pushd web\gui
call npm install
if errorlevel 1 (
echo %YEL%WARNING: npm install failed. Web UI will not be available.%RESET%
popd
goto :skip_web_build
)
call npm run build:electron
if errorlevel 1 (
echo %YEL%WARNING: Web UI build failed. Web UI will not be available.%RESET%
) else (
echo %GRN%Web UI built successfully.%RESET%
)
popd
)
:skip_web_build

echo.
echo %GRN%**** Install successful^^! ****%RESET%
echo.
Expand Down
35 changes: 35 additions & 0 deletions lib.include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,39 @@ function prepare_runtime_environment {
else
install_requirements_in_active_env_if_necessary
fi

# Regenerate the web UI schema and rebuild the Electron bundle when possible.
print "Generating UI schema..."
if ! run_python_in_active_env -m web.scripts.generate_ui_schema; then
print_warning "UI schema generation failed. Using existing schema."
fi

build_web_ui_if_available
}

# Builds the Electron+React web UI when Node.js is available.
# During "install" runs it builds unconditionally; otherwise only rebuilds
# when a previously built bundle is detected, so regular headless users
# are not forced to install Node.js.
function build_web_ui_if_available {
if ! command -v node &> /dev/null; then
print "Node.js not found. Skipping web UI build."
print "To use the web UI, install Node.js from https://nodejs.org/"
return 0
fi

local gui_dir="${SCRIPT_DIR}/web/gui"
local dist_marker="${gui_dir}/dist/main/main/index.cjs"

if [[ -f "${dist_marker}" ]] || [[ "${1:-}" == "install" ]]; then
print "Building web UI..."
(
cd "${gui_dir}"
npm install || { print_warning "npm install failed. Web UI may be stale."; return 0; }
npm run build:electron || { print_warning "Web UI build failed. Web UI may be stale."; return 0; }
print "Web UI built successfully."
)
else
print "Web UI not previously built. Run start-web-ui.sh to build and launch."
fi
}
80 changes: 80 additions & 0 deletions start-web-ui.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@echo off
cd /d "%~dp0"

set "OT_DEV="
for %%a in (%*) do (
if "%%a"=="--dev" set "OT_DEV=1"
)

if not exist "scripts\train_ui.py" (
echo Error: train_ui.py does not exist, you have done something very wrong. Reclone the repository.
goto :end
)

if not defined PYTHON (
where python >NUL 2>NUL
if errorlevel 1 (
echo Error: Python is not installed or not in PATH
goto :end
)
set PYTHON=python
)
if not defined VENV_DIR (set "VENV_DIR=%~dp0venv")

:check_venv
dir "%VENV_DIR%" > NUL 2> NUL
if not errorlevel 1 goto :activate_venv
echo venv not found, please run install.bat first
goto :end

:activate_venv
echo activating venv %VENV_DIR%
if not exist "%VENV_DIR%\Scripts\python.exe" (
echo Error: Python executable not found in virtual environment
goto :end
)
set PYTHON="%VENV_DIR%\Scripts\python.exe" -X utf8
echo Using Python %PYTHON%

REM Disable Xet (buggy) - https://github.com/Nerogar/OneTrainer/issues/949
if not defined HF_HUB_DISABLE_XET (
set "HF_HUB_DISABLE_XET=1"
)

:check_python_version
%PYTHON% --version
if errorlevel 1 (
echo Error: Failed to get Python version
goto :end
)
%PYTHON% "%~dp0scripts\util\version_check.py" 3.10 3.14 2>&1
if errorlevel 1 (
goto :end
)

:check_node
where node >NUL 2>NUL
if errorlevel 1 (
echo Error: Node.js is not installed or not in PATH
echo Please install Node.js from https://nodejs.org/
goto :end
)

:check_gui_built
if not exist "web\gui\dist\main\main\index.cjs" (
echo Error: Web GUI has not been built yet.
echo Please run install.bat or update.bat first to build the web UI.
goto :end
)

:launch
echo Starting OneTrainer Web UI...
cd web\gui
call npx electron .
cd ..\..
if errorlevel 1 (
echo Error: Web UI exited with code %ERRORLEVEL%
)

:end
pause
36 changes: 36 additions & 0 deletions start-web-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -e

source "${BASH_SOURCE[0]%/*}/lib.include.sh"

for arg in "$@"; do
if [[ "$arg" == "--dev" ]]; then
export OT_DEV=1
fi
done

# Xet is buggy - https://github.com/Nerogar/OneTrainer/issues/949
if [[ -z "${HF_HUB_DISABLE_XET+x}" ]]; then
export HF_HUB_DISABLE_XET=1
fi

prepare_runtime_environment

if ! command -v node &> /dev/null; then
echo "Error: Node.js is not installed or not in PATH"
echo "Please install Node.js from https://nodejs.org/"
exit 1
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [[ ! -f "$SCRIPT_DIR/web/gui/dist/main/main/index.cjs" ]]; then
echo "Error: Web GUI has not been built yet."
echo "Please run install.sh or update.sh first to build the web UI."
exit 1
fi

echo "Starting OneTrainer Web UI..."
cd "$SCRIPT_DIR/web/gui"
npx electron .
35 changes: 35 additions & 0 deletions update.bat
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ if errorlevel 1 (
goto :end_error
)

REM Regenerate UI schema and rebuild web UI if previously built
echo.
echo Generating UI schema...
"%PYTHON%" -m web.scripts.generate_ui_schema
if errorlevel 1 (
echo WARNING: UI schema generation failed. Using existing schema.
)
REM Reset errorlevel so schema failure does not affect exit code
cmd /c "exit /b 0"

where node >NUL 2>NUL
if errorlevel 1 (
echo Node.js not found. Skipping web UI rebuild.
) else (
if exist "web\gui\dist\main\main\index.cjs" (
echo Rebuilding web UI...
pushd web\gui
call npm install
if errorlevel 1 (
echo WARNING: npm install failed. Web UI may be stale.
popd
goto :end_success
)
call npm run build:electron
if errorlevel 1 (
echo WARNING: Web UI rebuild failed. Web UI may be stale.
) else (
echo Web UI rebuilt successfully.
)
popd
) else (
echo Web UI not previously built. Run start-web-ui.bat to launch.
)
)

:end_success
echo.
echo ***********
Expand Down
Loading