From 89463e27066799531f3acdae4d52101ae17d0352 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 7 Aug 2026 18:29:53 +0800 Subject: [PATCH] Add Windows autostart setup --- .gitignore | 1 + setup_autostart.bat | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 setup_autostart.bat diff --git a/.gitignore b/.gitignore index 9c0dd20..7c989b6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ wheels/ *.egg-info tests/resource/ docutranslate/output/ +logs/ # Shared glossary runtime data data/ # Virtual environments diff --git a/setup_autostart.bat b/setup_autostart.bat new file mode 100644 index 0000000..0305ede --- /dev/null +++ b/setup_autostart.bat @@ -0,0 +1,45 @@ +@echo off +setlocal + +cd /d "%~dp0" + +set "TASK_NAME=DocuTranslate" +set "PROJECT_DIR=%~dp0" +set "RUN_BAT=%PROJECT_DIR%run.bat" +set "LOG_DIR=%PROJECT_DIR%logs" +set "LOG_FILE=%LOG_DIR%\autostart.log" + +if not exist "%RUN_BAT%" ( + echo [ERROR] Cannot find "%RUN_BAT%". + pause + exit /b 1 +) + +if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" + +REM Create a startup task. Run this file as Administrator. +REM The task runs as SYSTEM, so it can start after reboot before desktop login. +schtasks /Create ^ + /TN "%TASK_NAME%" ^ + /SC ONSTART ^ + /RU SYSTEM ^ + /RL HIGHEST ^ + /TR "cmd.exe /c cd /d ""%PROJECT_DIR%"" && ""%RUN_BAT%"" >> ""%LOG_FILE%"" 2>&1" ^ + /F + +if not "%ERRORLEVEL%"=="0" ( + echo. + echo [ERROR] Failed to create scheduled task. Please run this file as Administrator. + pause + exit /b 1 +) + +echo. +echo [OK] Scheduled task "%TASK_NAME%" has been created. +echo [OK] It will run "%RUN_BAT%" at system startup. +echo [OK] Log file: "%LOG_FILE%" +echo. +echo You can start it now with: +echo schtasks /Run /TN "%TASK_NAME%" +echo. +pause