def connect(self, handle=None, **kwargs):
        """
        Connect to window and set it foreground

        Args:
            **kwargs: optional arguments

        Returns:
            None

        """
        if handle:
            handle = int(handle)
            self.app = self._app.connect(handle=handle)
            self._top_window = self.app.window(handle=handle).wrapper_object()
        else:
            for k in ["process", "timeout"]:
                if k in kwargs:
                    kwargs[k] = int(kwargs[k])
            self.app = self._app.connect(**kwargs)
            self._top_window = self.app.top_window().wrapper_object()
        if kwargs.get("foreground", True) in (True, "True", "true"):
            try:
                self.set_foreground()
            except pywintypes.error as e:
                # pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')
                # If you are not running with administrator privileges, it may fail, but this error can be ignored.
                pass

        Connect to window and set it foreground

        Args:
            **kwargs: optional arguments

        Returns:
            None

        
airtest/core/win/win.py