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
This commit is contained in:
1 parent
0027ca57fc
commit
dc2f754f86
2 files changed
+30
-10
No files matched your search
+23
-8
@@ -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")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user