Skip to content

Commit

Permalink
Windows-specific fix for raise_mpv flashing orange.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalton3 committed Jan 16, 2020
1 parent e5170b9 commit 4ab7532
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions plex_mpv_shim/win_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import win32gui
import traceback

def windowEnumerationHandler(hwnd, top_windows):
top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))

def raise_mpv():
results = []
top_windows = []
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
if "mpv" in i[1].lower():
win32gui.ShowWindow(i[0],5)
win32gui.SetForegroundWindow(i[0])
break
# This workaround is madness. Apparently SetForegroundWindow
# won't work randomly, so I have to call ShowWindow twice.
# Once to hide the window, and again to successfully raise the window.
try:
top_windows = []
fg_win = win32gui.GetForegroundWindow()
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
if " - mpv" in i[1].lower():
if i[0] != fg_win:
win32gui.ShowWindow(i[0], 6) # Minimize
win32gui.ShowWindow(i[0], 9) # Un-minimize
break

except Exception:
print("Could not raise MPV.")
traceback.print_exc()

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='plex-mpv-shim',
version='1.6.0',
version='1.6.1',
author="Ian Walton",
author_email="[email protected]",
description="Cast media from Plex Mobile and Web apps to MPV. (Unofficial)",
Expand Down

0 comments on commit 4ab7532

Please sign in to comment.