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
@@ -19,8 +19,6 @@ pyz = PYZ(a.pure)
|
|||||||
exe = EXE(
|
exe = EXE(
|
||||||
pyz,
|
pyz,
|
||||||
a.scripts,
|
a.scripts,
|
||||||
a.binaries,
|
|
||||||
a.datas,
|
|
||||||
[],
|
[],
|
||||||
name='Black Screen Dim',
|
name='Black Screen Dim',
|
||||||
debug=False,
|
debug=False,
|
||||||
@@ -37,3 +35,10 @@ exe = EXE(
|
|||||||
entitlements_file=None,
|
entitlements_file=None,
|
||||||
icon=['icon.ico'],
|
icon=['icon.ico'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
coll = COLLECT(
|
||||||
|
exe,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
name='Black Screen Dim',
|
||||||
|
)
|
||||||
+23
-8
@@ -13,9 +13,12 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import threading
|
||||||
|
|
||||||
import screen_brightness_control as sbc
|
import screen_brightness_control as sbc
|
||||||
|
|
||||||
|
_original_brightness = None
|
||||||
|
|
||||||
LOG = logging.getLogger("black_screen_dim")
|
LOG = logging.getLogger("black_screen_dim")
|
||||||
|
|
||||||
|
|
||||||
@@ -354,14 +357,24 @@ if sys.platform == "win32":
|
|||||||
break
|
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():
|
def main():
|
||||||
setup_logging()
|
setup_logging()
|
||||||
LOG.info("starting Black Screen Dim")
|
LOG.info("starting Black Screen Dim")
|
||||||
original = get_all_brightness()
|
# Show the black overlay FIRST so the screen goes black immediately.
|
||||||
LOG.info("saved brightness: %s", original)
|
# Brightness saving/dimming runs in the background, invisible behind it.
|
||||||
if original is not None:
|
dim_thread = threading.Thread(target=_dim_and_save, daemon=True)
|
||||||
set_all_brightness(0)
|
dim_thread.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
run_overlay()
|
run_overlay()
|
||||||
@@ -370,9 +383,11 @@ def main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception("overlay error: %r", e)
|
LOG.exception("overlay error: %r", e)
|
||||||
finally:
|
finally:
|
||||||
if original is not None:
|
dim_thread.join(timeout=10)
|
||||||
restore_all_brightness(original)
|
orig = _original_brightness
|
||||||
LOG.info("restored brightness: %s", original)
|
if orig is not None:
|
||||||
|
restore_all_brightness(orig)
|
||||||
|
LOG.info("restored brightness: %s", orig)
|
||||||
LOG.info("exiting")
|
LOG.info("exiting")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user