From 23458563597d01823cb3656158034ab664a1d0b8 Mon Sep 17 00:00:00 2001 From: jiangxufeng Date: Mon, 9 Sep 2019 23:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=9C=A8=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=E4=B8=AD=E6=96=87=E5=90=8D?= =?UTF-8?q?=E7=A7=B0url=E7=BC=96=E7=A0=81=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=90=8C=E6=97=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=BB=B6=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- v2rayL-GUI/new_ui.py | 143 ++++++++++++++++++++++--------- v2rayL-GUI/sub2conf_api.py | 8 +- v2rayL-GUI/v2rayL_api.py | 12 ++- v2rayL-GUI/v2rayL_threads.py | 12 +-- v2rayL-GUI/v2rayLui.py | 161 +++++++++++++++-------------------- 6 files changed, 190 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index 5d4d8b1..51b5763 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ v2ray linux 客户端,使用pyqt5编写GUI界面,核心基于v2ray-core - 支持协议:vmess、shadowsocks - 通过`vmess://`、`ss://`分享链接添加配置,通过二维码添加配置 - 导出配置、生成配置分享链接、生成分享二维码 -- 最小化至托盘、检查更新 +- 最小化至托盘、测试延时、检查更新 - ...... 其中vmess支持websocket、mKcp diff --git a/v2rayL-GUI/new_ui.py b/v2rayL-GUI/new_ui.py index f175fe8..edf96e2 100644 --- a/v2rayL-GUI/new_ui.py +++ b/v2rayL-GUI/new_ui.py @@ -234,10 +234,6 @@ def init_ui(self): self.right_bar_layout.addWidget(self.v2rayL_icon, 0, 0, 1, 4, Qt.AlignRight) self.right_bar_layout.addWidget(self.v2rayL_label, 0, 4, 1, 5, Qt.AlignLeft) - # self.right_one_widget = QWidget() - # self.right_one_layout = QGridLayout() - # self.right_one_widget.setLayout(self.right_one_layout) - self.right_up_layout.addWidget(self.right_bar_widget, 0, 0, 1, 9) # self.right_layout.addWidget(self.right_one_widget, 1, 0, 8, 9) @@ -308,27 +304,37 @@ def init_ui(self): self.system_setting_widget = QWidget() self.help_widget = QWidget() self.first_widget = QWidget() - # self.settings1_layout = QGridLayout() - # self.settings1_widget.setLayout(self.settings1_layout) - # - # self.label_peizhi = QLabel("配置") + + # 配置页面 self.config_setting_ui = Ui_Setting1_Form() self.config_setting_ui.setupUi(self.config_setting_widget) self.right_down_layout.addWidget(self.config_setting_widget) - + # 系统设置页面 self.system_setting_ui = Ui_SystemSettings() self.system_setting_ui.setupUi(self.system_setting_widget) self.right_down_layout.addWidget(self.system_setting_widget) + # 版本说明页面 self.help_ui = Ui_HelpUi() self.help_ui.setupUi(self.help_widget) self.right_down_layout.addWidget(self.help_widget) + # 主页连接页面 self.first_ui = Ui_FirstPage() self.first_ui.setupUi(self.first_widget) self.right_down_layout.addWidget(self.first_widget) + # 分享配置窗口 + self.share_ui = QDialog() + self.share_child_ui = Ui_Share_Dialog() + self.share_child_ui.setupUi(self.share_ui) + + # 二维码分享配置窗口 + self.qr_ui = QDialog() + self.qr_child_ui = Ui_Qr_Dialog() + self.qr_child_ui.setupUi(self.qr_ui) + self.current_page = self.first_widget self.config_setting_widget.hide() self.system_setting_widget.hide() @@ -429,7 +435,7 @@ def setupUi(self, Form): "background-color:transparent;") self.lineEdit_2.setText("") self.lineEdit_2.setObjectName("lineEdit_2") - self.lineEdit_2.setPlaceholderText("以vmess://或ss://开头,回车确认") + self.lineEdit_2.setPlaceholderText("以vmess://或ss://开头,以英文;分隔多条,回车确认") self.label_5 = QLabel(Form) self.label_5.setGeometry(QRect(570, 90, 131, 21)) self.label_5.setStyleSheet("font: 13pt \"Purisa\";") @@ -586,6 +592,7 @@ def retranslateUi(self, SystemSettings): self.label_9.setText(_translate("SystemSettings", "1081")) self.label_10.setText(_translate("SystemSettings", "1080")) + class Ui_HelpUi(object): def setupUi(self, HelpUi): HelpUi.setObjectName("HelpUi") @@ -637,42 +644,40 @@ def setupUi(self, Form): self.tableWidget = QTableWidget(Form) self.tableWidget.setGeometry(QRect(0, 60, 770, 320)) self.tableWidget.setObjectName("tableWidget") - self.tableWidget.setColumnCount(6) + self.tableWidget.setColumnCount(7) # self.tableWidget.setRowCount(12) self.label = QLabel(Form) - self.label.setGeometry(QRect(150, 30, 41, 21)) + self.label.setGeometry(QRect(130, 30, 41, 21)) self.label.setStyleSheet('font: 75 14pt "宋体";font-weight:bold;') self.label.setObjectName("label") self.label_2 = QLabel(Form) - self.label_2.setGeometry(QRect(340, 30, 41, 21)) + self.label_2.setGeometry(QRect(335, 30, 41, 21)) self.label_2.setStyleSheet('font: 75 14pt "宋体";font-weight:bold;') self.label_2.setObjectName("label_2") self.label_3 = QLabel(Form) - self.label_3.setGeometry(QRect(500, 30, 41, 21)) + self.label_3.setGeometry(QRect(490, 30, 41, 21)) self.label_3.setStyleSheet('font: 75 14pt "宋体";font-weight:bold;') self.label_3.setObjectName("label_3") self.label_4 = QLabel(Form) - self.label_4.setGeometry(QRect(25, 30, 41, 21)) + self.label_4.setGeometry(QRect(15, 30, 41, 21)) self.label_4.setStyleSheet('font: 75 14pt "宋体";font-weight:bold;') self.label_4.setObjectName("label_4") self.pushButton = QPushButton(Form) - self.pushButton.setGeometry(QRect(150, 400, 111, 31)) + self.pushButton.setGeometry(QRect(200, 400, 111, 31)) self.pushButton.setStyleSheet( "#pushButton{border-width: 0px; border-radius: 15px; background: #1E90FF; outline: none; font-family: Microsoft YaHei; color: white; font-size: 13px; }\n" "#pushButton:hover{ background: #5599FF;}") self.pushButton.setObjectName("pushButton") self.pushButton_1 = QPushButton(Form) - self.pushButton_1.setGeometry(QRect(310, 400, 111, 31)) + self.pushButton_1.setGeometry(QRect(360, 400, 130, 31)) self.pushButton_1.setStyleSheet( "#pushButton_1{border-width: 0px; border-radius: 15px; background: #1E90FF; outline: none; font-family: Microsoft YaHei; color: white; font-size: 13px; }\n" "#pushButton_1:hover{ background: #5599FF;}") self.pushButton_1.setObjectName("pushButton_1") - self.pushButton_2 = QPushButton(Form) - self.pushButton_2.setGeometry(QRect(470, 400, 111, 31)) - self.pushButton_2.setStyleSheet( - "#pushButton_2{border-width: 0px; border-radius: 15px; background: #1E90FF; outline: none; font-family: Microsoft YaHei; color: white; font-size: 13px; }\n" - "#pushButton_2:hover{ background: #5599FF;}") - self.pushButton_2.setObjectName("pushButton_2") + self.time = QLabel(Form) + self.time.setGeometry(QRect(510, 400, 100, 31)) + self.time.setStyleSheet('font: 75 11pt "宋体";font-weight:bold;') + self.time.setObjectName("time") self.tableWidget.setShowGrid(False) self.tableWidget.setFrameShape(QFrame.NoFrame) @@ -685,8 +690,9 @@ def setupUi(self, Form): self.tableWidget.setColumnWidth(1, 200) self.tableWidget.setColumnWidth(2, 200) self.tableWidget.setColumnWidth(3, 100) - self.tableWidget.setColumnWidth(4, 100) - self.tableWidget.setColumnWidth(5, 100) + self.tableWidget.setColumnWidth(4, 80) + self.tableWidget.setColumnWidth(5, 50) + self.tableWidget.setColumnWidth(6, 50) self.tableWidget.verticalHeader().setDefaultSectionSize(40) self.tableWidget.setStyleSheet(''' #tableWidget{ @@ -707,24 +713,12 @@ def setupUi(self, Form): def add_item(self, args): item = QTableWidgetItem(str(args[0])) - # font = QFont() - # font.setPointSize(16) - # item.setFont(font) self.tableWidget.setItem(args[0]-1, 0, item) item = QTableWidgetItem(args[1]) - # font = QFont() - # font.setPointSize(16) - # item.setFont(font) self.tableWidget.setItem(args[0]-1, 1, item) item = QTableWidgetItem(args[2]) - # font = QFont() - # font.setPointSize(16) - # item.setFont(font) self.tableWidget.setItem(args[0]-1, 2, item) item = QTableWidgetItem(args[3]) - # font = QFont() - # font.setPointSize(16) - # item.setFont(font) self.tableWidget.setItem(args[0]-1, 3, item) label_1 = QLabel() if args[4]: @@ -734,7 +728,7 @@ def add_item(self, args): switchBtn.setGeometry(20, 5, 60, 30) switchBtn.checkedChanged.connect(lambda: args[5](args[0]-1, not switchBtn.checked)) self.tableWidget.setCellWidget(args[0]-1, 4, label_1) - button1 = QPushButton("删除配置") + button1 = QPushButton("删除") button1.setObjectName("delbt") button1.setStyleSheet(''' #delbt{border-width: 0px; @@ -750,6 +744,22 @@ def add_item(self, args): ''') button1.clicked.connect(lambda: args[6](args[0]-1)) self.tableWidget.setCellWidget(args[0]-1, 5, button1) + button2 = QPushButton("分享") + button2.setObjectName("delbt") + button2.setStyleSheet(''' + #delbt{border-width: 0px; + border-radius: 15px; + background: #1E90FF; + outline: none; + font-family: Microsoft YaHei; + color: white; + font-size: 13px; + margin:5px; + } + #delbt:hover{ background: #5599FF;} + ''') + button2.clicked.connect(lambda: args[7](args[1])) + self.tableWidget.setCellWidget(args[0]-1, 6, button2) @@ -761,8 +771,61 @@ def retranslateUi(self, Form): self.label_3.setText(_translate("Form", "协议")) self.label_4.setText(_translate("Form", "序号")) self.pushButton.setText(_translate("Form", "更新订阅")) - self.pushButton_1.setText(_translate("Form", "生成分享URI")) - self.pushButton_2.setText(_translate("Form", "生成分享qrcode")) + self.pushButton_1.setText(_translate("Form", "测试当前延时")) + + +class Ui_Share_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(226, 171) + self.label = QLabel(Dialog) + self.label.setGeometry(QRect(20, 20, 191, 17)) + self.label.setStyleSheet("font: 75 13pt \"新宋体\";") + self.label.setObjectName("label") + self.pushButton = QPushButton(Dialog) + self.pushButton.setGeometry(QRect(40, 60, 141, 31)) + self.pushButton.setStyleSheet("#pushButton{border-width: 0px; border-radius: 15px; background: #1E90FF; outline: none; font-family: Microsoft YaHei; color: white; font-size: 13px; }\n" + "#pushButton:hover{ background: #5599FF;}") + self.pushButton.setObjectName("pushButton") + self.pushButton_2 = QPushButton(Dialog) + self.pushButton_2.setGeometry(QRect(40, 110, 141, 31)) + self.pushButton_2.setStyleSheet("#pushButton_2{border-width: 0px; border-radius: 15px; background: #1E90FF; outline: none; font-family: Microsoft YaHei; color: white; font-size: 13px; }\n" + "#pushButton_2:hover{ background: #5599FF;}") + self.pushButton_2.setObjectName("pushButton_2") + + self.retranslateUi(Dialog) + QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "配置分享")) + self.label.setText(_translate("Dialog", "请选择以下一种方式分享")) + self.pushButton.setText(_translate("Dialog", "二维码分享")) + self.pushButton_2.setText(_translate("Dialog", "链接分享")) + + +class Ui_Qr_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(218, 218) + Dialog.setMinimumSize(QSize(218, 218)) + Dialog.setMaximumSize(QSize(218, 218)) + self.gridLayout = QGridLayout(Dialog) + self.gridLayout.setObjectName("gridLayout") + self.label = QLabel(Dialog) + self.label.setEnabled(True) + self.label.setMinimumSize(QSize(200, 200)) + self.label.setMaximumSize(QSize(200, 200)) + self.label.setText("") + self.label.setObjectName("label") + self.gridLayout.addWidget(self.label, 0, 0, 1, 1) + + self.retranslateUi(Dialog) + QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "二维码分享配置")) def main(): app = QApplication(sys.argv) diff --git a/v2rayL-GUI/sub2conf_api.py b/v2rayL-GUI/sub2conf_api.py index 528910b..96aaa07 100755 --- a/v2rayL-GUI/sub2conf_api.py +++ b/v2rayL-GUI/sub2conf_api.py @@ -6,6 +6,7 @@ import json import pickle import requests +import urllib.parse as parse from config import conf_template as conf @@ -40,16 +41,16 @@ def __init__(self, subs_url=None, conf_url=None): def b642conf(self, prot, tp, b64str): if prot == "vmess": - ret = eval(base64.b64decode(b64str).decode()) + ret = eval(parse.unquote(base64.b64decode(b64str).decode())) region = ret['ps'] elif prot == "shadowsocks": string = b64str.split("#") cf = string[0].split("@") if len(cf) == 1: - tmp = base64.b64decode(cf[0]).decode() + tmp = parse.unquote(base64.b64decode(cf[0]).decode()) else: - tmp = base64.b64decode(cf[0]).decode() + "@" + cf[1] + tmp = parse.unquote(base64.b64decode(cf[0]).decode()) + "@" + cf[1] ret = { "method": tmp.split(":")[0], "port": tmp.split(":")[2], @@ -208,6 +209,7 @@ def conf2b64(self, region): if prot == "vmess": return prot+"://"+base64.b64encode(str(tmp).encode()).decode() else: + prot = "ss" return prot+"://"+base64.b64encode("{}:{}@{}:{}".format(tmp["method"], tmp["password"], tmp["add"], tmp["port"]).encode()).decode()+"#"+region diff --git a/v2rayL-GUI/v2rayL_api.py b/v2rayL-GUI/v2rayL_api.py index f263d00..521a440 100755 --- a/v2rayL-GUI/v2rayL_api.py +++ b/v2rayL-GUI/v2rayL_api.py @@ -5,6 +5,7 @@ import subprocess import pickle import re +import requests from sub2conf_api import Sub2Conf, MyException @@ -109,11 +110,14 @@ def addconf(self, uri): def delconf(self, region): self.subs.delconf(region) - def ping(self, addr): + def ping(self): try: - p = subprocess.getoutput(["ping -c 1 "+addr]) - res = re.search("time=(.*?)ms", p) - return res.group(1) + proxy = { + "http": "127.0.0.1:1081", + "https": "127.0.0.1:1081" + } + req = requests.get("http://www.google.com", proxies=proxy, timeout=10) + return req.elapsed.total_seconds()*1000 except: raise MyException("测试超时") diff --git a/v2rayL-GUI/v2rayL_threads.py b/v2rayL-GUI/v2rayL_threads.py index 4bea982..e4d5308 100755 --- a/v2rayL-GUI/v2rayL_threads.py +++ b/v2rayL-GUI/v2rayL_threads.py @@ -103,9 +103,9 @@ class PingThread(QThread): """ sinOut = pyqtSignal(tuple) - def __init__(self, tv=(None, None), parent=None): + def __init__(self, v2ray=None, parent=None): super(PingThread, self).__init__(parent) - self.tableView, self.v2rayL = tv + self.v2rayL = v2ray def __del__(self): # 线程状态改变与线程终止 @@ -113,15 +113,15 @@ def __del__(self): def run(self): try: - row = self.tableView.currentIndex().row() - addr = self.tableView.model().item(row, 1).text() - ret = self.v2rayL.ping(addr) + # # row = self.tableView.currentIndex().row() + # addr = self.tableView.model().item(self.row, 1).text() + ret = self.v2rayL.ping() except MyException as e: self.sinOut.emit(("ping", "@@Fail@@", e.args[0], None)) except AttributeError: self.sinOut.emit(("ping", "@@Fail@@", "请选择需要测试的配置.", None)) else: - self.sinOut.emit(("ping", "@@OK@@", ret.strip(), None)) + self.sinOut.emit(("ping", "@@OK@@", int(ret), None)) class CheckUpdateThread(QThread): diff --git a/v2rayL-GUI/v2rayLui.py b/v2rayL-GUI/v2rayLui.py index 1e5d4f7..292ec8e 100644 --- a/v2rayL-GUI/v2rayLui.py +++ b/v2rayL-GUI/v2rayLui.py @@ -35,30 +35,6 @@ from new_ui import MainUi, SwitchBtn -class Ui_Qr_Dialog(object): - def setupUi(self, Dialog): - Dialog.setObjectName("Dialog") - Dialog.resize(218, 218) - Dialog.setMinimumSize(QSize(218, 218)) - Dialog.setMaximumSize(QSize(218, 218)) - self.gridLayout = QGridLayout(Dialog) - self.gridLayout.setObjectName("gridLayout") - self.label = QLabel(Dialog) - self.label.setEnabled(True) - self.label.setMinimumSize(QSize(200, 200)) - self.label.setMaximumSize(QSize(200, 200)) - self.label.setText("") - self.label.setObjectName("label") - self.gridLayout.addWidget(self.label, 0, 0, 1, 1) - - self.retranslateUi(Dialog) - QMetaObject.connectSlotsByName(Dialog) - - def retranslateUi(self, Dialog): - _translate = QCoreApplication.translate - Dialog.setWindowTitle(_translate("Dialog", "二维码分享配置")) - - class SystemTray(object): # 程序托盘类 def __init__(self, w): @@ -82,6 +58,7 @@ def quitApp(self): if re == QMessageBox.Yes: self.tp.setVisible(False) # 隐藏托盘控件 qApp.quit() # 退出程序 + self.w.v2rayL.disconnect() def act(self, reason): # 主界面显示方法 @@ -109,10 +86,6 @@ def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.init_ui() - # 二维码分享配置窗口 - self.qr_ui = QDialog() - self.qr_child_ui = Ui_Qr_Dialog() - self.qr_child_ui.setupUi(self.qr_ui) self.version = "2.0.2" # 获取api操作 @@ -125,7 +98,7 @@ def __init__(self, parent=None): self.update_addr_start = UpdateSubsThread() self.update_subs_start = UpdateSubsThread() - # self.ping_start = PingThread(tv=(self.tableView, self.v2rayL)) + self.ping_start = PingThread() # 检查版本更新线程 self.check_update_start = CheckUpdateThread(version=self.version) # 更新版本线程 @@ -171,8 +144,7 @@ def __init__(self, parent=None): self.first_ui.pushButton.clicked.connect(self.update_subs) # 更新订阅 self.config_setting_ui.pushButton_2.clicked.connect(self.output_conf) # 导出配置文件 self.config_setting_ui.pushButton.clicked.connect(self.get_conf_from_qr) # 通过二维码导入 - self.first_ui.pushButton_1.clicked.connect(self.output_conf_by_uri) # 生成分享链接 - self.first_ui.pushButton_2.clicked.connect(self.output_conf_by_qr) # 生成分享二维码 + self.first_ui.pushButton_1.clicked.connect(self.start_ping_th) # 测试延时 self.system_setting_ui.checkupdateButton.clicked.connect(self.check_update) # 检查更新 self.config_setting_ui.lineEdit.returnPressed.connect(self.change_subs_addr) # 更新订阅操作 self.config_setting_ui.pushButton_3.clicked.connect(self.change_subs_addr) # 更新订阅操作 @@ -181,23 +153,15 @@ def __init__(self, parent=None): self.disconn_start.sinOut.connect(self.alert) # 得到断开连接反馈 self.update_addr_start.sinOut.connect(self.alert) # 得到反馈 self.update_subs_start.sinOut.connect(self.alert) # 得到反馈 - # self.ping_ui.triggered.connect(self.start_ping_th) # toolbar绑定ping程序 - # self.ping_start.sinOut.connect(self.alert) # 得到反馈 + self.ping_start.sinOut.connect(self.alert) # 得到反馈 self.check_update_start.sinOut.connect(self.alert) self.version_update_start.sinOut.connect(self.alert) # 设置最小化到托盘 SystemTray(self) - # def help(self): - # QMessageBox.about(self, "说明", - # self.tr("1. v2rayL当前版本:v2.0.1\n" - # "2. github地址:https://github.com/jiangxufeng/v2rayL\n" - # "3. 目前支持协议有:Vmess、shadowsocks\n4. 支持通过分享链接、二维码导入和分享配置\n" - # "5. 双击选中配置可直接进行连接\n6. 程序可能存在未测试到的Bug,使用过程中发现Bug请在github提交")) - def check_update(self): - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在检查版本更新. -t 3" + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在检查版本更新." subprocess.call([shell], shell=True) self.check_update_start.start() @@ -211,12 +175,12 @@ def display_all_conf(self): i = 1 for k, v in all_conf.items(): lists.append((i, k, v["add"]+":"+v["port"], v["prot"], - True if k == self.v2rayL.current else False, self.start_conn_th, self.del_conf)) + True if k == self.v2rayL.current else False, self.start_conn_th, + self.del_conf, self.show_share_dialog)) i += 1 self.first_ui.tableWidget.setRowCount(i-1) for i in lists: - # print(i) self.first_ui.add_item(i) def change_subs_addr(self): @@ -233,17 +197,17 @@ def change_subs_addr(self): "是否继续?"), QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Cancel) if choice == QMessageBox.Ok: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在更新订阅地址...... -t 3" + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在更新订阅地址......" subprocess.call([shell], shell=True) self.update_addr_start.start() else: self.config_setting_ui.lineEdit.setText(self.v2rayL.url) else: if url == self.v2rayL.url: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 订阅地址未改变 -t 3" + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 订阅地址未改变" subprocess.call([shell], shell=True) else: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在更新订阅地址...... -t 3" + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 正在更新订阅地址......" subprocess.call([shell], shell=True) self.update_addr_start.start() @@ -263,24 +227,32 @@ def get_conf_from_uri(self): 通过分享链接获取配置 :return: """ - uri = self.config_setting_ui.lineEdit_2.text() - if not uri: + uris = self.config_setting_ui.lineEdit_2.text().split(";") + if not uris: QMessageBox.warning(self, "提示", self.tr("请输入配置分享路径!"), QMessageBox.Ok, QMessageBox.Ok) else: - try: - self.v2rayL.addconf(uri) - except MyException as e: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL '{}'".format("错误: "+e.args[0]) - subprocess.call([shell], shell=True) - self.config_setting_ui.lineEdit_2.setText("") - else: + uris = [x for x in uris if x] + errors = [] + for i in range(len(uris)): + try: + self.v2rayL.addconf(uris[i]) + except MyException as e: + # shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL '{}'".format("错误: "+e.args[0]) + # subprocess.call([shell], shell=True) + # self.config_setting_ui.lineEdit_2.setText("") + errors.append(str(i+1)) + # else: + if not errors: shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 添加配置成功" - subprocess.call([shell], shell=True) - self.v2rayL = V2rayL() - self.display_all_conf() - self.config_setting_ui.lineEdit_2.setText("") + else: + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL " \ + "添加配置成功,其中第{}条配置解析错误,无法添加".format("、".join(errors)) + subprocess.call([shell], shell=True) + self.v2rayL = V2rayL() + self.display_all_conf() + self.config_setting_ui.lineEdit_2.setText("") def get_conf_from_qr(self): """ @@ -378,8 +350,7 @@ def alert(self, tp): self.display_all_conf() elif tp == "ping": - self.status = self.status_format.format(self.v2rayL.current, ("开启" if self.v2rayL.auto else "关闭"))+ "\t\t\t\t\t\t所测延时: {}ms".format(ret) - self.statusbar.showMessage(self.status) + self.first_ui.time.setText(str(ret)+"ms") elif tp == "ckud": if not row: @@ -410,14 +381,12 @@ def alert(self, tp): elif tp == "conn": shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL {}".format(ret) subprocess.call([shell], shell=True) - self.statusbar.showMessage(self.status) - self.connect_ui.setEnabled(True) - self.disconnect_ui.setDisabled(True) + self.display_all_conf() elif tp == "disconn": shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL {}".format(ret) subprocess.call([shell], shell=True) - self.statusbar.showMessage(self.status) + self.display_all_conf() elif tp == "ckud": shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL {}".format(ret) @@ -469,48 +438,52 @@ def change_check_update(self): def start_ping_th(self): """ - 开始ping测延时 + 开始测延时 :return: """ + self.ping_start.v2rayL = self.v2rayL self.ping_start.start() - def output_conf_by_uri(self): + def show_share_dialog(self, region): + self.share_child_ui.pushButton.clicked.connect(lambda: self.output_conf_by_qr(region)) + self.share_child_ui.pushButton_2.clicked.connect(lambda: self.output_conf_by_uri(region)) + self.share_ui.show() + + def output_conf_by_uri(self, region): """ 输出分享链接 :return: """ - if self.v2rayL.current != "未连接至VPN": - ret = self.v2rayL.subs.conf2b64(self.v2rayL.current) - QMessageBox.information(self, "分享链接", self.tr(ret)) - else: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 请连接一个VPN后再选择分享 -t 3" - subprocess.call([shell], shell=True) - - def output_conf_by_qr(self): + # if self.v2rayL.current != "未连接至VPN": + # ret = self.v2rayL.subs.conf2b64(self.v2rayL.current) + # QMessageBox.information(self, "分享链接", self.tr(ret)) + # else: + # shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 请连接一个VPN后再选择分享 -t 3" + # subprocess.call([shell], shell=True) + ret = self.v2rayL.subs.conf2b64(region) + QMessageBox.information(self, "分享链接", self.tr(ret)) + + def output_conf_by_qr(self, region): """ 输出分享二维码 :return: """ - if self.v2rayL.current != "未连接至VPN": - ret = self.v2rayL.subs.conf2b64(self.v2rayL.current) - # 生成二维码 - url = "http://api.k780.com:88/?app=qr.get&data={}".format(ret) - try: - req = requests.get(url) - if req.status_code == 200: - qr = QPixmap() - qr.loadFromData(req.content) - self.qr_child_ui.label.setPixmap(qr) - self.qr_child_ui.label.setScaledContents(True) - self.qr_ui.show() - else: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 服务错误,可能原因:调用API发生错误" - subprocess.call([shell], shell=True) - except: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 服务错误,请将错误在github中提交" + ret = self.v2rayL.subs.conf2b64(region) + # 生成二维码 + url = "http://api.k780.com:88/?app=qr.get&data={}".format(ret) + try: + req = requests.get(url) + if req.status_code == 200: + qr = QPixmap() + qr.loadFromData(req.content) + self.qr_child_ui.label.setPixmap(qr) + self.qr_child_ui.label.setScaledContents(True) + self.qr_ui.show() + else: + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 服务错误,可能原因:调用API发生错误" subprocess.call([shell], shell=True) - else: - shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 请连接一个VPN后再选择分享" + except: + shell = "notify-send -i /etc/v2rayL/images/logo.ico v2rayL 服务错误,请将错误在github中提交" subprocess.call([shell], shell=True)