mirror of https://github.com/jumpserver/jumpserver
perf: 优化远程应用navicat连接时,确定有密码输入框后才输入密码
parent
1b4c52bc9f
commit
ced454ca49
|
@ -1,18 +1,17 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
import winreg
|
||||||
import winreg
|
import win32api
|
||||||
import win32api
|
import win32con
|
||||||
|
|
||||||
from pywinauto import Application
|
|
||||||
from pywinauto.controls.uia_controls import ButtonWrapper
|
|
||||||
from pywinauto.keyboard import send_keys
|
|
||||||
|
|
||||||
import const as c
|
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'
|
_default_path = r'C:\Program Files\PremiumSoft\Navicat Premium 16\navicat.exe'
|
||||||
|
|
||||||
|
@ -31,7 +30,8 @@ class AppletApplication(BaseApplication):
|
||||||
self.pid = None
|
self.pid = None
|
||||||
self.app = None
|
self.app = None
|
||||||
|
|
||||||
def clean_up(self):
|
@staticmethod
|
||||||
|
def clean_up():
|
||||||
protocols = (
|
protocols = (
|
||||||
'NavicatMARIADB', 'NavicatMONGODB', 'Navicat',
|
'NavicatMARIADB', 'NavicatMONGODB', 'Navicat',
|
||||||
'NavicatORA', 'NavicatMSSQL', 'NavicatPG'
|
'NavicatORA', 'NavicatMSSQL', 'NavicatPG'
|
||||||
|
@ -43,8 +43,9 @@ class AppletApplication(BaseApplication):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
def launch(self):
|
||||||
def launch():
|
# 清理因为异常未关闭的会话历史记录
|
||||||
|
self.clean_up()
|
||||||
sub_key = r'Software\PremiumSoft\NavicatPremium'
|
sub_key = r'Software\PremiumSoft\NavicatPremium'
|
||||||
try:
|
try:
|
||||||
key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, sub_key)
|
key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, sub_key)
|
||||||
|
@ -60,6 +61,10 @@ class AppletApplication(BaseApplication):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _exec_commands(commands):
|
def _exec_commands(commands):
|
||||||
for command in 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':
|
if command['type'] == 'key':
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
send_keys(' '.join(command['commands']))
|
send_keys(' '.join(command['commands']))
|
||||||
|
@ -67,6 +72,13 @@ class AppletApplication(BaseApplication):
|
||||||
for f in command['commands']:
|
for f in command['commands']:
|
||||||
f()
|
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):
|
def _action_not_remember_password(self):
|
||||||
conn_window = self.app.window(best_match='Dialog'). \
|
conn_window = self.app.window(best_match='Dialog'). \
|
||||||
child_window(title_re='New Connection')
|
child_window(title_re='New Connection')
|
||||||
|
@ -278,7 +290,8 @@ class AppletApplication(BaseApplication):
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'type': 'key',
|
'type': 'key',
|
||||||
'commands': (self.password, c.ENTER)
|
'commands': (self.password, c.ENTER),
|
||||||
|
'pre_check': self._pre_check_is_password_input
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
self._exec_commands(commands)
|
self._exec_commands(commands)
|
||||||
|
|
Loading…
Reference in New Issue