From ced454ca4913106ac5f4ff155f47c68e8b48180e Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Tue, 14 Feb 2023 18:37:29 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E5=BA=94=E7=94=A8navicat=E8=BF=9E=E6=8E=A5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E5=AE=9A=E6=9C=89=E5=AF=86=E7=A0=81=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86=E5=90=8E=E6=89=8D=E8=BE=93=E5=85=A5=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/applets/navicat/app.py | 39 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/terminal/applets/navicat/app.py b/apps/terminal/applets/navicat/app.py index 561d6f978..5311fbc7c 100644 --- a/apps/terminal/applets/navicat/app.py +++ b/apps/terminal/applets/navicat/app.py @@ -1,18 +1,17 @@ import os -import sys import time -if sys.platform == 'win32': - import winreg - import win32api - - from pywinauto import Application - from pywinauto.controls.uia_controls import ButtonWrapper - from pywinauto.keyboard import send_keys +import winreg +import win32api +import win32con import const as c -from common import wait_pid, BaseApplication +from pywinauto import Application +from pywinauto.controls.uia_controls import ButtonWrapper +from pywinauto.keyboard import send_keys + +from common import wait_pid, BaseApplication, _messageBox _default_path = r'C:\Program Files\PremiumSoft\Navicat Premium 16\navicat.exe' @@ -31,7 +30,8 @@ class AppletApplication(BaseApplication): self.pid = None self.app = None - def clean_up(self): + @staticmethod + def clean_up(): protocols = ( 'NavicatMARIADB', 'NavicatMONGODB', 'Navicat', 'NavicatORA', 'NavicatMSSQL', 'NavicatPG' @@ -43,8 +43,9 @@ class AppletApplication(BaseApplication): except Exception: pass - @staticmethod - def launch(): + def launch(self): + # 清理因为异常未关闭的会话历史记录 + self.clean_up() sub_key = r'Software\PremiumSoft\NavicatPremium' try: key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, sub_key) @@ -60,6 +61,10 @@ class AppletApplication(BaseApplication): @staticmethod def _exec_commands(commands): for command in commands: + pre_check = command.get('pre_check', lambda: True) + if not pre_check(): + _messageBox('程序启动异常,请重新连接!!', 'Error', win32con.MB_DEFAULT_DESKTOP_ONLY) + return if command['type'] == 'key': time.sleep(0.5) send_keys(' '.join(command['commands'])) @@ -67,6 +72,13 @@ class AppletApplication(BaseApplication): for f in command['commands']: f() + def _pre_check_is_password_input(self): + try: + self.app.window(best_match='Connection Password') + except Exception: + return False + return True + def _action_not_remember_password(self): conn_window = self.app.window(best_match='Dialog'). \ child_window(title_re='New Connection') @@ -278,7 +290,8 @@ class AppletApplication(BaseApplication): }, { 'type': 'key', - 'commands': (self.password, c.ENTER) + 'commands': (self.password, c.ENTER), + 'pre_check': self._pre_check_is_password_input } ]) self._exec_commands(commands)