From dc2f754f863bf67db079966e413b6cdaef39deb8 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 16 Sep 2026 16:39:20 +0200 Subject: [PATCH] Optimize startup: show black overlay first, dim brightness in a background thread; switch to one-folder PyInstaller build (no on-launch extraction) - black screen now appears immediately (window creation), while the slow screen-brightness-control WMI queries (get+set) run in a daemon thread and are invisible behind the black overlay - one-folder COLLECT build removes the ~2-3s one-file archive extraction --- Black Screen Dim.spec | 9 +++++++-- black_screen_dim.py | 31 +++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Black Screen Dim.spec b/Black Screen Dim.spec index 91ab276..c3256f9 100644 --- a/Black Screen Dim.spec +++ b/Black Screen Dim.spec @@ -19,8 +19,6 @@ pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, - a.binaries, - a.datas, [], name='Black Screen Dim', debug=False, @@ -37,3 +35,10 @@ exe = EXE( entitlements_file=None, icon=['icon.ico'], ) + +coll = COLLECT( + exe, + a.binaries, + a.datas, + name='Black Screen Dim', +) diff --git a/black_screen_dim.py b/black_screen_dim.py index a7e9bc1..e3cc1b2 100644 --- a/black_screen_dim.py +++ b/black_screen_dim.py @@ -13,9 +13,12 @@ import logging import os import sys import tempfile +import threading import screen_brightness_control as sbc +_original_brightness = None + LOG = logging.getLogger("black_screen_dim") @@ -354,14 +357,24 @@ if sys.platform == "win32": break +def _dim_and_save(): + """Save current brightness and dim all monitors in the background so the + black overlay can appear instantly; the dimming itself is invisible.""" + global _original_brightness + orig = get_all_brightness() + _original_brightness = orig + LOG.info("saved brightness: %s", orig) + if orig is not None: + set_all_brightness(0) + + def main(): setup_logging() LOG.info("starting Black Screen Dim") - original = get_all_brightness() - LOG.info("saved brightness: %s", original) - if original is not None: - set_all_brightness(0) - + # Show the black overlay FIRST so the screen goes black immediately. + # Brightness saving/dimming runs in the background, invisible behind it. + dim_thread = threading.Thread(target=_dim_and_save, daemon=True) + dim_thread.start() try: if sys.platform == "win32": run_overlay() @@ -370,9 +383,11 @@ def main(): except Exception as e: LOG.exception("overlay error: %r", e) finally: - if original is not None: - restore_all_brightness(original) - LOG.info("restored brightness: %s", original) + dim_thread.join(timeout=10) + orig = _original_brightness + if orig is not None: + restore_all_brightness(orig) + LOG.info("restored brightness: %s", orig) LOG.info("exiting")