Reputation: 1
I am working on a Python-based application that uses pywebview
for rendering the UI and win32gui
to manage the window. My application ensures that only a single instance can run at a time by using a mutex. When a second instance is launched, it restores the existing application's window if it is minimized or hidden behind other screens.
The issue arises when trying to restore a minimized window. Using the following code:
hwnd = win32gui.FindWindow(None, 'Kiosk App')
if hwnd:
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
win32gui.SetForegroundWindow(hwnd)
This successfully brings the minimized window to the foreground. However, the content of the restored application becomes blank, rendering the UI unusable. The application still responds to interactions like closing the window, but the WebView content is not re-rendered.
hwnd
handle correctly references the existing application window.win32gui.ShowWindow
and win32gui.SetForegroundWindow
calls work as expected in bringing the application forward.Below is the relevant part of the code where I handle the restoration:
try:
handle = win32event.CreateMutex(None, True, mutex_name)
last_error = win32api.GetLastError()
if last_error == winerror.ERROR_ALREADY_EXISTS:
print("Another instance of the Kiosk application is already running.")
hwnd = win32gui.FindWindow(None, 'Kiosk App')
if hwnd:
win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
win32gui.SetForegroundWindow(hwnd)
sys.exit(0)
start_app('./ui/index.html', './keyboard/index.html')
pywebview==4.1
pywin32
Based on recommendations and suggestions, I have already tried several approaches to resolve the issue, but none have worked so far:
Refreshing the WebView Content:
I attempted to reload the WebView content dynamically when restoring the minimized application window. However, this didn't resolve the blank screen issue.
Changing Window Visibility States:
I experimented with various win32gui.ShowWindow
flags, such as SW_RESTORE
, SW_SHOW
, and SW_SHOWNORMAL
, to restore the window properly. While these flags bring the window to the foreground, the content inside the WebView remains blank.
Recreating the WebView:
I tried destroying and recreating the WebView instance dynamically during restoration. While this approach worked partially, it caused other issues, such as losing the application state and user data.
Ensuring Foreground State:
I confirmed that the application window was correctly set to the foreground using win32gui.SetForegroundWindow
. The issue persists despite the application being in focus.
Despite these attempts, the WebView remains blank when the minimized application is restored. I am now seeking guidance on any specific approach I might have missed or any insights into how WebView rendering might be affected by window restoration using win32gui
.
Upvotes: 0
Views: 34