Skip to content
Merged
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
10 changes: 5 additions & 5 deletions bin/emrg.cmd
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@echo off
REM EMRG launcher installed at %USERPROFILE%\.emrg\install\bin\emrg.cmd
REM Phase 4 installer (rant #12) §2:
REM - R60: Windows git lives in install\git\ PATH needs git\cmd + git\mingw64\bin.
REM EMRG launcher -- installed at %USERPROFILE%\.emrg\install\bin\emrg.cmd
REM Phase 4 installer (rant #12) section 2:
REM - R60: Windows git lives in install\git\ -- PATH needs git\cmd + git\mingw64\bin.
REM - R35: %~dp0 under a .lnk shortcut resolves to the .cmd's real location.
REM - R13: PYTHONPATH includes source\ (parent of the emrg package).
REM - R61: source\ is read-only PYTHONDONTWRITEBYTECODE (zero-write acceptance).
REM - R61: source\ is read-only -- PYTHONDONTWRITEBYTECODE (zero-write acceptance).
set SOURCE=%~dp0
set DIR=%SOURCE:~0,-1%
set PREFIX=%DIR%\..
set PATH=%DIR%;%PREFIX%\git\cmd;%PREFIX%\git\mingw64\bin;%PATH%
set PYTHONPATH=%PREFIX%\source;%PREFIX%\lib;%PYTHONPATH%
set PYTHONDONTWRITEBYTECODE=1
REM R90: python.exe 复制品在 bin/,DLL 在 python-dist/ loader 找不到 → 用 python-dist 里的 exe(与 DLL 同目录)
REM R90: python.exe copy lives in bin/, DLLs in python-dist/ -> loader would miss them -> use the exe in python-dist (same dir as DLLs)
set PYEXE=%DIR%\python-dist\python.exe
if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python3.13.exe
"%PYEXE%" -m emrg %*
20 changes: 10 additions & 10 deletions bin/emrgd.cmd
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
@echo off
REM EMRG daemon launcher installed at %USERPROFILE%\.emrg\install\bin\emrgd.cmd
REM Phase 4 installer (rant #12) §2 — same structure as bin\emrg.cmd; entry is
REM EMRG daemon launcher -- installed at %USERPROFILE%\.emrg\install\bin\emrgd.cmd
REM Phase 4 installer (rant #12) section 2 -- same structure as bin\emrg.cmd; entry is
REM the server package. GUI main.js spawns this path (R36 shell:true, R66 windowsHide).
set SOURCE=%~dp0
set DIR=%SOURCE:~0,-1%
set PREFIX=%DIR%\..
set PATH=%DIR%;%PREFIX%\git\cmd;%PREFIX%\git\mingw64\bin;%PATH%
set PYTHONPATH=%PREFIX%\source;%PREFIX%\lib;%PYTHONPATH%
set PYTHONDONTWRITEBYTECODE=1
REM R90: python.exe 复制品在 bin/,DLL 在 python-dist/ loader 找不到 → 用 python-dist 里的 exe(与 DLL 同目录)
REM 无窗口 daemonGUI spawn 此脚本时 python.exe(console 子系统)会新开控制台黑窗;
REM 改优先用 pythonw.exe(GUI 子系统,不开窗口)。日志写 ~/.emrg/emrgd.log
REM (RotatingFileHandler)StreamHandler 仅附加,无控制台不影响日志。
REM R90: python.exe copy lives in bin/, DLLs in python-dist/ -> loader would miss them -> use the exe in python-dist (same dir as DLLs)
REM Windowless daemon: when the GUI spawns this script, python.exe (console subsystem) would open a black console window;
REM prefer pythonw.exe (GUI subsystem, no window). Logs go to ~/.emrg/emrgd.log
REM (RotatingFileHandler); StreamHandler only attaches, no console so logging is unaffected.
set PYEXE=%DIR%\python-dist\pythonw.exe
if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python.exe
if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python3.13.exe
REM R124: `emrgd.cmd stop` — 优雅关闭 daemonrant 2026-08-10T08:50:44 安装器预停止):
REM 复用 CLI `emrg server stop`(协议 shutdown ping-pid SIGTERM 兜底,见
REM emrg/__main__.py _stop_daemon)。pythonw 无控制台,print 丢弃无害,shutdown 无需 stdout
REM 用标签而非括号块,保证 %errorlevel% python 退出后才展开。
REM R124: `emrgd.cmd stop` - graceful daemon shutdown (rant 2026-08-10T08:50:44 installer pre-stop):
REM reuses the CLI `emrg server stop` (protocol shutdown -> ping-pid SIGTERM fallback, see
REM emrg/__main__.py _stop_daemon). pythonw has no console; dropped prints are harmless, shutdown needs no stdout.
REM uses labels not parenthesized blocks so %errorlevel% expands only after python exits.
if /I not "%~1"=="stop" goto :start
"%PYEXE%" -m emrg server stop
exit /b %errorlevel%
Expand Down
14 changes: 7 additions & 7 deletions bin/stop-emrg.cmd
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@echo off
REM stop-emrg.cmd gracefully stop EMRG GUI/TUI/daemon before the installer
REM stop-emrg.cmd -- gracefully stop EMRG GUI/TUI/daemon before the installer
REM overwrites ~\.emrg\install files (rant 2026-08-10T08:50:44: Inno Setup got
REM stuck at "停止已有进程" because the windowless pythonw daemon holds file locks
REM stuck at "stopping existing processes" because the windowless pythonw daemon holds file locks
REM and Inno CloseApplications cannot see it).
REM
REM Order matters (mirrors bin/emrg-uninstall steps 1a/1b):
REM 1. GUI (EMRG.exe): graceful WM_CLOSE first (taskkill without /F), then
REM UNCONDITIONAL /F after the ~5s grace window (host 01:27:07Z: long-lived
REM GUI deferred WM_CLOSE past 5s /F must not be gated on a survivor check)
REM GUI deferred WM_CLOSE past 5s -- /F must not be gated on a survivor check)
REM 2. TUI (python.exe -m emrg): command-line filter (wmic, PowerShell
REM fallback), excludes the daemon (pythonw.exe -m emrg.server)
REM 3. daemon: `emrg server stop` protocol shutdown via the OLD install's CLI
REM (present since #364 version-safe), emrgd.pid poll (<=10s), then
REM (present since #364 -- version-safe), emrgd.pid poll (<=10s), then
REM taskkill /F /PID fallback
REM
REM Returns 0 when nothing EMRG-related survives; 1 if a process could not be
Expand All @@ -23,7 +23,7 @@ set "INSTALL=%EMRG_DIR%\install"

REM --- 1. GUI: graceful WM_CLOSE, then unconditional /F after the grace window ---
REM (host report 2026-08-10T01:27:07Z: a long-lived ~15h GUI session deferred
REM WM_CLOSE past the 5s window two full script runs did not terminate it
REM WM_CLOSE past the 5s window -- two full script runs did not terminate it
REM while a direct `taskkill /IM EMRG.exe` did. => the /F fallback must be
REM UNCONDITIONAL after the wait so an old GUI session can never hold the
REM installer hostage. When the GUI is not running, the graceful taskkill
Expand Down Expand Up @@ -64,8 +64,8 @@ if defined DPID taskkill /F /PID %DPID% >nul 2>&1
:verify
set "EXIT_CODE=0"
tasklist /FI "IMAGENAME eq EMRG.exe" 2>nul | findstr /i "EMRG.exe" >nul && set "EXIT_CODE=1"
REM 括号块内 %-变量 在块解析时展开(set "DPID=" 之后取到旧值/空值)→ 必须用
REM enabledelayedexpansion !DPID!(运行时展开);if defined 本身是运行时判定。
REM %-variables inside a parenthesized block expand at parse time (after set "DPID=" they hold the old/empty value) -> must use
REM enabledelayedexpansion !DPID! (runtime expansion); if defined itself is a runtime check.
if exist "%EMRG_DIR%\emrgd.pid" (
set "DPID="
for /f "usebackq delims=" %%p in ("%EMRG_DIR%\emrgd.pid") do set "DPID=%%p"
Expand Down
Loading