diff --git a/hide_commands/__init__.py b/hide_commands/__init__.py index f36d7748f..3f71258af 100644 --- a/hide_commands/__init__.py +++ b/hide_commands/__init__.py @@ -1 +1 @@ -from .commands import (SetResolution, SetPosition) \ No newline at end of file +from .commands import SetPosition, SetResolution diff --git a/hide_commands/commands.py b/hide_commands/commands.py index f23090a2c..4abfcd95b 100644 --- a/hide_commands/commands.py +++ b/hide_commands/commands.py @@ -9,23 +9,23 @@ """ import logging - from tkinter import ttk +from selenium.webdriver import Firefox + from openwpm.commands.types import BaseCommand from openwpm.config import BrowserParams, ManagerParams from openwpm.socket_interface import ClientSocket -from selenium.webdriver import Firefox - -def get_screen_resolution(driver): +def get_screen_resolution(driver: Firefox) -> list[int]: return driver.execute_script("return [screen.width, screen.height];") - + class SetResolution(BaseCommand): - """ Sets the browser window resolution """ - def __init__(self, width, height) -> None: + """Sets the browser window resolution""" + + def __init__(self, width: int, height: int) -> None: self.logger = logging.getLogger("openwpm") self.width = width self.height = height @@ -39,22 +39,22 @@ def execute( browser_params: BrowserParams, manager_params: ManagerParams, extension_socket: ClientSocket, - ): - + ) -> None: self.logger.info(f"Setting window resolution to {self.width} x {self.height} ") driver.set_window_size(self.width, self.height) - + resolution = get_screen_resolution(driver) if resolution[0] <= self.width or resolution[1] <= self.height: self.logger.warn( - f"Browser window resolution ({self.width} x {self.height}) exceeds " + - f"screen resolution ({resolution[0]} x {resolution[1]})") - - + f"Browser window resolution ({self.width} x {self.height}) exceeds " + + f"screen resolution ({resolution[0]} x {resolution[1]})" + ) + class SetPosition(BaseCommand): - """ Sets the browser window position """ - def __init__(self, x, y) -> None: + """Sets the browser window position""" + + def __init__(self, x: int, y: int) -> None: self.logger = logging.getLogger("openwpm") self.x = x self.y = y @@ -68,6 +68,5 @@ def execute( browser_params: BrowserParams, manager_params: ManagerParams, extension_socket: ClientSocket, - ): - - driver.set_window_position(self.x, self.y, windowHandle='current') \ No newline at end of file + ) -> None: + driver.set_window_position(self.x, self.y, windowHandle="current")