Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 10.0.18363.836: Has no IVirtualDesktopManagerInternal2 manager #39

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyvda/com_defns.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def get_windows_build() -> int:

if not os.getenv("READTHEDOCS"):
build = get_windows_build()
BUILD_OVER_19041 = build >= 19041
BUILD_OVER_20231 = build >= 20231
BUILD_OVER_21313 = build >= 21313
BUILD_OVER_22449 = build >= 22449
BUILD_OVER_22621 = build >= 22621
BUILD_OVER_22631 = build >= 22631
else:
BUILD_OVER_19041 = False
BUILD_OVER_20231 = False
BUILD_OVER_21313 = False
BUILD_OVER_22449 = False
Expand Down
13 changes: 13 additions & 0 deletions pyvda/pyvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
IApplicationView,
IVirtualDesktop,
IVirtualDesktop2,
BUILD_OVER_19041,
BUILD_OVER_21313,
)
from .utils import Managers
Expand Down Expand Up @@ -323,10 +324,16 @@ def name(self) -> str:

Returns:
str: The desktop name.

Raises:
NotImplementedError: If the Windows version is < 19041.
"""
if BUILD_OVER_21313:
return str(self._virtual_desktop.GetName())

if not BUILD_OVER_19041:
raise NotImplementedError(f"{VirtualDesktop.name.__name__} is not supported on < 19041 versions")

array = managers.manager_internal.get_all_desktops()
for vd in array.iter(IVirtualDesktop2):
if self.id == vd.GetID():
Expand All @@ -339,7 +346,13 @@ def rename(self, name: str):

Args:
name: The new name for this desktop.

Raises:
NotImplementedError: If the Windows version is < 19041.
"""
if not BUILD_OVER_19041:
raise NotImplementedError(f"{VirtualDesktop.rename.__name__} is not supported on < 19041 versions")

if BUILD_OVER_21313:
managers.manager_internal.SetName(self._virtual_desktop, HSTRING(name))
else:
Expand Down
3 changes: 2 additions & 1 deletion pyvda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
IServiceProvider,
CLSID_ImmersiveShell,
CLSID_VirtualDesktopManagerInternal,
BUILD_OVER_19041,
BUILD_OVER_21313,
)

Expand Down Expand Up @@ -68,7 +69,7 @@ def __init__(self):
self.pinned_apps = get_pinned_apps()

# Old interface only used for SetName
if not BUILD_OVER_21313:
if not BUILD_OVER_21313 and BUILD_OVER_19041:
self.manager_internal2 = get_vd_manager_internal2()

@staticmethod
Expand Down
11 changes: 11 additions & 0 deletions tests/test_desktop_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import time
import win32gui
import threading
import pytest

from pyvda.com_defns import BUILD_OVER_19041

current_window = AppView.current()
current_desktop = VirtualDesktop.current()
Expand Down Expand Up @@ -93,6 +96,13 @@ def test_create_and_remove_desktop():
time.sleep(1) # Got to wait for the animation before we can return
current_desktop.go()


@pytest.mark.xfail(
condition=not BUILD_OVER_19041,
reason="<=18363 has no IVirtualDesktopManagerInternal2 manager",
raises=NotImplementedError,
strict=True
)
def test_desktop_names():
current_name = current_desktop.name
test_name = "pyvda testing"
Expand All @@ -101,6 +111,7 @@ def test_desktop_names():
current_desktop.rename(current_name)
assert current_desktop.name == current_name, f"Wanted '{current_name}', got '{current_desktop.name}'"


def test_move_and_go_threads():
error: Optional[Exception] = None
def f():
Expand Down