Run as background service: --tray, --install-autostart#9
Draft
PrEvIeS wants to merge 1 commit intoezbooz:mainfrom
Draft
Run as background service: --tray, --install-autostart#9PrEvIeS wants to merge 1 commit intoezbooz:mainfrom
PrEvIeS wants to merge 1 commit intoezbooz:mainfrom
Conversation
…ostart
Closes the README "Launch as background service when game starts" item.
main.py
- argparse-based dispatch at the entry point: --tray, --install-autostart,
--uninstall-autostart, --quiet (silences console for tray/autostart launches).
- module-level threading.Event _stop_event; monitor_log()'s outer loop now
checks it and uses _stop_event.wait(5.0) instead of time.sleep(5) so the
tray Quit menu can interrupt the watcher cleanly within ~5s.
- run_tray() spins up a daemon worker that calls rpc_connect() + monitor_log(),
then runs pystray.Icon on the main thread (Windows requirement). Quit menu
sets _stop_event and stops the icon; tray status reflects waiting/running/error.
Restart re-execs the current process with the same argv.
- install_autostart() / uninstall_autostart() write/remove a Windows Startup-
folder shortcut at %APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup
via pylnk3.for_file(). The shortcut launches the .exe (frozen) or the
current python interpreter + this script (source install) with --tray --quiet.
- pystray, PIL.Image, and pylnk3 are imported lazily inside the helpers so
`python main.py` (the existing flow) keeps working without the extras.
Helpful sys.exit() messages prompt the user to pip install when missing.
requirements.txt
- documents the new optional extras (pystray, Pillow, pylnk3) as a comment;
required deps (psutil, pypresence) stay byte-identical.
Why
- README has had "Launch as background service when game starts" open since
the project started. Tray + Startup shortcut is the lightest path that
works on Windows without admin rights or Service-Control-Manager wiring.
- All optional dependencies are gated behind argparse flags + lazy imports,
so installs that never use --tray or --install-autostart see zero impact.
How to use
pip install pystray Pillow pylnk3
python main.py --tray # foreground tray icon
python main.py --install-autostart # boot --tray on Windows login
python main.py --uninstall-autostart
PrEvIeS
added a commit
to PrEvIeS/Path-Of-Exile-2-RPC
that referenced
this pull request
May 5, 2026
…in EN/RU/UA The 4-PR upstream campaign (panvex-b6p) is feature-complete on this stacked branch. Updates the user-facing READMEs and CLAUDE.md to reflect the four shipped capabilities: - Official PoE2 client support (Steam + PathOfExile.exe) - Owner auto-pin (party-mate disambiguation) - AFK / DND status with small-image override + restore - Background tray service + Windows Startup shortcut README.md / README.ru.md / README.ua.md - Add explicit Features bullets for all four capabilities. - Flip the To-Do checklist (now 5/5 complete). - RU/UA translations get the new "Run as a background service" section to match the English README that was added during PR-4. CLAUDE.md - Replace the four open-work items with checked-off equivalents and a pointer to the upstream draft PRs (ezbooz#6, ezbooz#7, ezbooz#8, ezbooz#9). Notes that the remaining work is the end-of-campaign Windows live-smoke pass.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the "Launch as background service when game starts" item in the README to-do list. Adds three new CLI flags to
main.pyso users can run the RPC as a Windows tray service that auto-starts on login.The tray menu exposes Status (waiting / running / error), Open log file, Restart, and Quit. Quitting drains the watcher cleanly via a
threading.Event.What changed
main.pyrequirements.txtmain.pyadditions:_stop_event = threading.Event()monitor_log()'s outer loop checks_stop_eventand uses_stop_event.wait(5.0)instead oftime.sleep(5)so Quit can interrupt within ~5srun_tray()— pystray icon + daemon worker thread + Quit/Restart/Open log handlersinstall_autostart()/uninstall_autostart()— pylnk3-backed shortcut at%APPDATA%/Microsoft/Windows/Start Menu/Programs/Startupargparsedispatch at the entry point:--tray,--install-autostart,--uninstall-autostart,--quietOptional dependencies
pystray,Pillow, andpylnk3are imported lazily inside the helpers —python main.py(the existing flow) keeps working with zero new deps. If a user passes--trayor--install-autostartwithout the extras installed, they get a clearpip install ...hint and exit code 1.requirements.txtdocuments the optional install as a comment so the runtime baseline (psutil, pypresence) is byte-identical.Backwards compatibility
main.py(rpc_connect()+monitor_log())time.sleep(5)→_stop_event.wait(5.0), which is functionally equivalent when no flags are setTest plan
python main.py --tray, confirm menu shows, status flips waiting → running once a character logs inpython main.py --install-autostartcreates%APPDATA%/.../Startup/PathOfExile2DiscordRPC.lnk; reboot; tray launches without consolepython main.py --uninstall-autostartremoves the shortcut and exits 0 (or 1 if the shortcut was absent)python main.py(no flags) behaves identically to before this PRpython main.py --traywithoutpystray/Pillowexits 1 with the install hintpython main.py --install-autostartwithoutpylnk3exits 1 with the install hintNotes for review
os.execv(sys.executable, [sys.executable, *sys.argv])so all flags are preserved.pylnk3) and PR-4b (tray, requirespystray+Pillow) if growing the optional-deps surface in one shot is too much.