-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.py
1024 lines (954 loc) · 49.9 KB
/
mainwindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# 依据 GPLV3 开源
import os
import sys
import time
import json
import numpy
import base64
import shutil
import random
import zipfile
import requests
import threading
import traceback
import webbrowser
import subprocess
try:
import matplotlib
except:
os.system("python3 -m pip install --upgrade matplotlib --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple")
os.system("python3 -m pip install --upgrade matplotlib --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple --break-system-packages")
import matplotlib
import updatekiller
import urllib.parse as parse
import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore
import PyQt5.QtWidgets as QtWidgets
from getxmlimg import getsavexml
from Model import *
# 需引入 subprocess
# 运行系统命令并获取返回值
def GetCommandReturn(cmd: "命令")->"运行系统命令并获取返回值":
# cmd 是要获取输出的命令
return subprocess.getoutput(cmd)
# 获取 aapt 的所有信息
def GetApkInformation(apkFilePath: "apk 所在路径")->"获取 aapt 的所有信息":
return GetCommandReturn("aapt dump badging '{}'".format(apkFilePath))
# 获取 apk 包名
def GetApkPackageName(apkFilePath: "apk 所在路径")->"获取 apk 包名":
info = GetApkInformation(apkFilePath)
for line in info.split('\n'):
if "package:" in line:
line = line[0: line.index("versionCode='")]
line = line.replace("package:", "")
line = line.replace("name=", "")
line = line.replace("'", "")
line = line.replace(" ", "")
return line
# 读取 Waydroid 日志
def ReadWaydroidLog():
if not os.path.exists("/var/lib/waydroid/waydroid.log"):
QtWidgets.QMessageBox.critical(mainwindow, "错误", "无法正确读取 Waydroid 日志文件,请检查是否正常安装 Waydroid")
return
QtWidgets.QInputDialog.getMultiLineText(mainwindow, "Waydroid 日志", "", readtxt("/var/lib/waydroid/waydroid.log"))
# 读取文本文档
def readtxt(path: "路径")->"读取文本文档":
f = open(path, "r") # 设置文件对象
str = f.read() # 获取内容
f.close() # 关闭文本对象
return str # 返回结果
def WriteTxt(path: str, things: str):
with open(path, "w") as file:
file.write(things)
def GetSystemVersion():
systemInformation = readtxt("/etc/os-release")
for systemInformation in systemInformation.split('\n'):
if "PRETTY_NAME=" in systemInformation:
return systemInformation.replace("PRETTY_NAME=", "").replace('"', '')
def RunBash(bashCommand: str):
# 因为 Terminal 读取的返回值肯定有问题,所以得用折中的方案
tmpBashPath = f"/tmp/waydroid-runner-{random.randint(0, 1000)}.sh"
WriteTxt(tmpBashPath, f"""#!/bin/bash
{bashCommand}
if [[ $? != 0 ]]; then
zenity --error --text=脚本出现错误 --no-wrap
rm '{tmpBashPath}' -f
exit 1
fi
zenity --info --text=执行成功! --no-wrap
rm '{tmpBashPath}' -f""")
OpenTerminal(f"bash '{tmpBashPath}'")
#os.remove(tmpBashPath)
def DisabledAndEnbled(status: bool):
apkPath.setDisabled(status)
apkPathBrowser.setDisabled(status)
installButton.setDisabled(status)
removeButton.setDisabled(status)
class UninstallApk(QtCore.QThread):
info = QtCore.pyqtSignal(str)
error = QtCore.pyqtSignal(str)
combo = QtCore.pyqtSignal(int)
def __init__(self, package) -> None:
self.package = package
super().__init__()
def run(self):
global findApkHistory
result = os.system(f"waydroid app remove '{self.package}'")
if result:
self.error.emit(f"卸载失败!请检查 Waydroid 安装正常以及选择 APK 对应包名是否存在/输入包名存在\n命令返回值:{result}")
DisabledAndEnbled(False)
return
try:
if findApkHistory[-1] != apkPath.currentText():
findApkHistory.append(apkPath.currentText())
except:
findApkHistory.append(apkPath.currentText())
self.combo.emit(0)
try:
WriteTxt(homePath + "/.config/waydroid-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
except:
traceback.print_exc()
self.error.emit(traceback.format_exc())
self.info.emit("执行完成!若卸载成功则会在一段时间后自动在启动器移除 .desktop 文件")
DisabledAndEnbled(False)
# 数组转字典
def ListToDictionary(list: "需要转换的数组")->"数组转字典":
dictionary = {}
for i in range(len(list)):
dictionary[i] = list[i]
return dictionary
class InstallApk(QtCore.QThread):
info = QtCore.pyqtSignal(str)
error = QtCore.pyqtSignal(str)
combo = QtCore.pyqtSignal(int)
def __init__(self, path, quit = False) -> None:
self.path = path
self.quit = quit
super().__init__()
def run(self):
print(self.path)
print(f"waydroid app install '{self.path}'")
result = os.system(f"waydroid app install '{self.path}'")>>8
if result:
self.error.emit(f"安装失败!请检查 Waydroid 安装正常以及是否支持该 APK\n命令返回值:{result}")
DisabledAndEnbled(False)
return
try:
if findApkHistory[-1] != apkPath.currentText():
findApkHistory.append(apkPath.currentText())
except:
findApkHistory.append(apkPath.currentText())
self.combo.emit(0)
try:
WriteTxt(homePath + "/.config/waydroid-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
except:
traceback.print_exc()
self.error.emit(traceback.format_exc())
self.info.emit("执行完成!若安装成功则会在一段时间后自动在启动器生成 .desktop 文件")
DisabledAndEnbled(False)
def ErrorBox(error):
QtWidgets.QMessageBox.critical(widget, "错误", error)
def InformationBox(info):
QtWidgets.QMessageBox.information(widget, "提示", info)
def UpdateCombobox(tmp):
apkPath.clear()
apkPath.addItems(findApkHistory)
try:
apkPath.setEditText(findApkHistory[-1])
except:
pass
def UninstallApkButton():
global install
DisabledAndEnbled(True)
package = apkPath.currentText()
if os.path.exists(package):
package = GetApkPackageName(package)
install = UninstallApk(package)
install.info.connect(InformationBox)
install.error.connect(ErrorBox)
install.combo.connect(UpdateCombobox)
install.start()
def InstallApkButton():
global install
DisabledAndEnbled(True)
install = InstallApk(apkPath.currentText())
install.info.connect(InformationBox)
install.error.connect(ErrorBox)
install.combo.connect(UpdateCombobox)
install.start()
# 浏览 apk
def BrowserApk():
path = QtWidgets.QFileDialog.getOpenFileName(mainwindow, "选择APK", json.loads(readtxt(homePath + "/.config/waydroid-runner/FindApk.json"))["path"], "APK 文件(*.apk);;所有文件(*.*)")
if path[0] == "":
return
apkPath.setCurrentText(path[0])
try:
WriteTxt(homePath + "/.config/waydroid-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
except:
pass
# 获取软件的中文名称
def GetApkChineseLabel(apkFilePath)->"获取软件的中文名称":
info = GetApkInformation(apkFilePath)
name = None
for line in info.split('\n'):
if "application-label-zh:" in line:
line = line.replace("application-label-zh:", "")
line = line.replace("'", "")
return line
if "application-label:" in line:
line = line.replace("application-label:", "")
line = line.replace("'", "")
name = line
return name
# 检测是否在 Wayland 下运行程序
def CheckWaylandRun(waylandUnShow=False):
if os.getenv("XDG_SESSION_TYPE") == "x11":
QtWidgets.QMessageBox.warning(mainwindow, "警告", "当前您使用的是 X11 桌面环境,而 Waydroid 需要在 Wayland 环境下运行\n请你使用支持 Wayland 的桌面环境并开启 Wayland 支持或使用 Sway 或 Weston 运行\n目前运行器支持自动开启 Sway 或 Weston 运行 Waydroid")
if not waylandUnShow:
QtWidgets.QMessageBox.information(mainwindow, "提示", "您当前在 Wayland 环境")
# 保存apk图标
def SaveApkIcon(apkFilePath, iconSavePath)->"保存 apk 文件的图标":
try:
if os.path.exists(iconSavePath):
os.remove(iconSavePath)
info = GetApkInformation(apkFilePath)
for line in info.split('\n'):
if "application:" in line:
xmlpath = line.split(":")[-1].split()[-1].split("=")[-1].replace("'","")
if xmlpath.endswith('.xml'):
xmlsave = getsavexml()
print(xmlpath)
xmlsave.savexml(apkFilePath,xmlpath,iconSavePath)
return
else:
zip = zipfile.ZipFile(apkFilePath)
iconData = zip.read(xmlpath)
with open(iconSavePath, 'w+b') as saveIconFile:
saveIconFile.write(iconData)
return
print("None Icon! Show defult icon")
shutil.copy(programPath + "/defult.svg", iconSavePath)
except:
traceback.print_exc()
print("Error, show defult icon")
shutil.copy(programPath + "/defult.svg", iconSavePath)
# 获取 apk Activity
def GetApkActivityName(apkFilePath: "apk 所在路径")->"获取 apk Activity":
info = GetApkInformation(apkFilePath)
for line in info.split('\n'):
if "launchable-activity" in line:
line = line[0: line.index("label='")]
line = line.replace("launchable-activity: ", "")
line = line.replace("'", "")
line = line.replace(" ", "")
line = line.replace("name=", "")
line = line.replace("label=", "")
line = line.replace("icon=", "")
return line
return f"{GetApkPackageName(apkFilePath)}.Main"
# 更新窗口
class UpdateWindow():
data = {}
update = None
def ShowWindow():
UpdateWindow.update = QtWidgets.QMainWindow()
updateWidget = QtWidgets.QWidget()
updateWidgetLayout = QtWidgets.QGridLayout()
versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:")
updateText = QtWidgets.QTextBrowser()
ok = QtWidgets.QPushButton("更新(更新过程中会关闭这个应用的所有进程)")
ok.clicked.connect(UpdateWindow.Update)
cancel = QtWidgets.QPushButton("取消")
cancel.clicked.connect(UpdateWindow.update.close)
ok.setDisabled(True)
try:
UpdateWindow.data = json.loads(requests.get("http://update.gfdgdxi.top/waydroid-runner/update.json").text)
versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:{UpdateWindow.data['Version']}\n更新内容:")
if UpdateWindow.data["Version"] == version:
updateText.setText("此为最新版本,无需更新")
ok.setDisabled(True)
else:
# 版本号读取(防止出现高版本号提示要“升级”到低版本号的问题)
localVersionList = version.split(".")
webVersionList = UpdateWindow.data['Version'].split(".")
for i in range(len(localVersionList)):
local = int(localVersionList[i])
web = int(webVersionList[i])
if web < local:
updateText.setHtml(f"""<p>此为最新版本,无需更新,但似乎您当前使用的程序版本比云端版本还要高。</p>
<p>出现这个问题可能会有如下几种情况:</p>
<p>1、使用编译或者内测版本</p>
<p>2、自己修改了程序版本</p>
<p>3、作者忘记更新云端上的更新信息了</p>
<p>如果是第三种情况,请反馈到此:https://gitee.com/gfdgd-xi/waydroid-runner/issues/I7JVH7</p>
<p><img src='{programPath}/Icon/doge.png'></p>""")
ok.setDisabled(True)
break
if web > local:
updateText.setText(UpdateWindow.data["New"].replace("\\n", "\n"))
ok.setEnabled(True)
break
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(updateWidget, "错误", "无法连接服务器!")
updateWidgetLayout.addWidget(versionLabel, 0, 0, 1, 1)
updateWidgetLayout.addWidget(updateText, 1, 0, 1, 3)
updateWidgetLayout.addWidget(ok, 2, 2, 1, 1)
updateWidgetLayout.addWidget(cancel, 2, 1, 1, 1)
updateWidget.setLayout(updateWidgetLayout)
UpdateWindow.update.setCentralWidget(updateWidget)
UpdateWindow.update.setWindowTitle("检查 Waydroid 运行器更新")
UpdateWindow.update.setWindowIcon(QtGui.QIcon(iconPath))
UpdateWindow.update.resize(updateWidget.frameGeometry().width(), int(updateWidget.frameGeometry().height() * 1.5))
UpdateWindow.update.show()
def Update():
if os.path.exists("/tmp/waydroid-runner/update"):
shutil.rmtree("/tmp/waydroid-runner/update")
os.makedirs("/tmp/waydroid-runner/update")
try:
print(UpdateWindow.data["Url"])
WriteTxt("/tmp/waydroid-runner/update.sh", f"""#!/bin/bash
echo 删除多余的安装包
rm -rfv /tmp/waydroid-runner/update/*
echo 关闭“Waydroid 运行器”
python3 "{programPath}/updatekiller.py"
echo 下载安装包
wget -P /tmp/waydroid-runner/update {UpdateWindow.data["Url"][0]}
echo 安装安装包
dpkg -i /tmp/waydroid-runner/update/*
echo 修复依赖关系
apt install -f -y
notify-send -i "{iconPath}" "更新完毕!"
zenity --info --text=\"更新完毕!\" --ellipsize
""")
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(widget, "错误,无法继续更新", traceback.format_exc())
OpenTerminal(f"pkexec bash /tmp/waydroid-runner/update.sh")
# 获取 APK 版本
def GetApkVersion(apkFilePath):
info = GetApkInformation(apkFilePath)
for line in info.split('\n'):
if "package:" in line:
if "compileSdkVersion='" in line:
line = line.replace(line[line.index("compileSdkVersion='"): -1], "")
if "platform" in line:
line = line.replace(line[line.index("platform"): -1], "")
line = line.replace(line[0: line.index("versionName='")], "")
line = line.replace("versionName='", "")
line = line.replace("'", "")
line = line.replace(" ", "")
return line
image = None
class ApkInformation():
message = None
def ShowWindows():
global fullInformation
global path
global tab1
path = apkPath.currentText()
if os.system("which aapt") >> 8:
QtWidgets.QMessageBox.critical(widget, "错误", "系统未安装 aapt")
return
package = GetApkPackageName(path)
if package == None or package == "":
QtWidgets.QMessageBox.critical(widget, "错误", "APK 文件不存在或错误!")
return
ApkInformation.message = QtWidgets.QMainWindow()
messageWidget = QtWidgets.QWidget()
messageLayout = QtWidgets.QVBoxLayout()
ApkInformation.message.setWindowTitle("“{}“的Apk信息".format(GetApkChineseLabel(path)))
tab = QtWidgets.QTabWidget()
tab1 = QtWidgets.QWidget()
tab2 = QtWidgets.QWidget()
tab.addTab(tab1, "简化版")
tab1Layout = QtWidgets.QGridLayout()
SaveApkIcon(path, "/tmp/waydroid-runner-android-app-icon.png")
simpleInformation = QtWidgets.QLabel(f"""
<p align='center'><img width='256' src='/tmp/waydroid-runner-android-app-icon.png'></p>
<p>包名:{GetApkPackageName(path)}</p>
<p>中文名:{GetApkChineseLabel(path)}</p>
<p>Activity:{GetApkActivityName(path)}</p>
<p>版本:{GetApkVersion(path)}</p>""")
seeFen = QtWidgets.QPushButton("查看程序评分情况")
updFen = QtWidgets.QPushButton("上传程序评分情况")
#seeFen.setEnabled(map)
seeFen.clicked.connect(ApkInformation.ShowMap)
updFen.clicked.connect(ApkInformation.UpdateMark)
tab1Layout.addWidget(simpleInformation, 0, 0, 1, 3)
tab1Layout.addWidget(seeFen, 1, 1, 1, 1)
tab1Layout.addWidget(updFen, 2, 1, 1, 1)
tab1.setLayout(tab1Layout)
tab.addTab(tab2, "完整版")
tab2Layout = QtWidgets.QVBoxLayout()
fullInformation = QtWidgets.QTextBrowser()
fullInformation.setText(GetApkInformation(path))
tab2Layout.addWidget(fullInformation)
tab2.setLayout(tab2Layout)
messageLayout.addWidget(tab)
messageWidget.setLayout(messageLayout)
ApkInformation.message.setCentralWidget(messageWidget)
ApkInformation.message.setWindowIcon(QtGui.QIcon(iconPath))
ApkInformation.message.setWindowTitle("APK 信息")
ApkInformation.message.show()
return
def UpdateMark():
chooseWindow = QtWidgets.QMessageBox()
chooseWindow.setWindowTitle("选择评分")
chooseWindow.setText(f"""选择应用“{GetApkChineseLabel(path)}”的使用评分。建议参考如下规范进行评分:
含有不良信息(-1分):含有违法违规信息(如果有就不要选择其它选项了)
0星:完全无法使用,连安装都有问题
1星:完全无法使用,但是能正常安装
2星:可以打开,但只能使用一点点功能
3星:勉强能使用,运行也不大流畅
4星:大部分功能正常,运行流畅(可能会有点小卡)
5星:完全正常且非常流畅,没有任何功能和性能问题,就和直接在手机上用一样
""")
choices=["含有不良信息", "0分", "1分", "2分", "3分", "4分", "5分", "取消"]
button0 = chooseWindow.addButton(choices[0], QtWidgets.QMessageBox.ActionRole)
button1 = chooseWindow.addButton(choices[1], QtWidgets.QMessageBox.ActionRole)
button2 = chooseWindow.addButton(choices[2], QtWidgets.QMessageBox.ActionRole)
button3 = chooseWindow.addButton(choices[3], QtWidgets.QMessageBox.ActionRole)
button4 = chooseWindow.addButton(choices[4], QtWidgets.QMessageBox.ActionRole)
button5 = chooseWindow.addButton(choices[5], QtWidgets.QMessageBox.ActionRole)
button6 = chooseWindow.addButton(choices[6], QtWidgets.QMessageBox.ActionRole)
button7 = chooseWindow.addButton(choices[7], QtWidgets.QMessageBox.ActionRole)
button0.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(0)))
button1.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(1)))
button2.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(2)))
button3.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(3)))
button4.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(4)))
button5.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(5)))
button6.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(6)))
button7.clicked.connect(lambda: ApkInformation.UpdateMarkInternet(int(7)))
chooseWindow.exec_()
return
def UpdateMarkInternet(choose):
print(choose)
if choose == None or choose == 7:
return
try:
QtWidgets.QMessageBox.information(widget, "提示", requests.post(base64.b64decode("aHR0cDovLzEyMC4yNS4xNTMuMTQ0L3VlbmdpbmUtcnVubmVyL2FwcC9jaGVjay9hZGQucGhw"), {"Package": GetApkPackageName(path), "Type": choose}).text)
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(widget, "错误", "无法连接服务器!")
def ShowMap():
package = GetApkPackageName(path)
if package == None or package == "":
QtWidgets.QMessageBox.critical(widget, "错误", "APK 不存在或错误")
return
try:
data = json.loads(requests.get("http://data.download.gfdgdxi.top/uengineapp/" + package +"/data.json").text)
print(data)
except:
QtWidgets.QMessageBox.information(widget, "提示", "此程序暂时没有评分,欢迎您贡献第一个评分!")
return
index = numpy.arange(len(data))
print(index)
chinese = GetApkChineseLabel(path)
fig = matplotlib.pylab.figure()
fig.canvas.set_window_title("“" + chinese + "”的用户评分(数据只供参考)")
fonts = matplotlib.font_manager.FontProperties(fname='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc') # 用于支持中文显示,需要依赖fonts-noto-cjk
matplotlib.pylab.barh(index, data)
matplotlib.pylab.yticks(index, ["不良信息", "0分", "1分", "2分", "3分", "4分", "5分"], fontproperties=fonts)
matplotlib.pylab.xlabel("用户评分数", fontproperties=fonts)
matplotlib.pylab.ylabel("等级", fontproperties=fonts)
matplotlib.pylab.title("“" + chinese + "”的用户评分(数据只供参考)", fontproperties=fonts)
matplotlib.pylab.show(block=True)
# 用户自行保存
def SaveIconToOtherPath():
apkPath = apkPath.currentText()
if apkPath == "":
QtWidgets.QMessageBox.critical(widget, "错误", "APK 不存在或错误")
return
path = QtWidgets.QFileDialog.getSaveFileName(widget, "保存图标", "icon.png", "PNG 图片(*.png);;所有文件(*.*)", json.loads(readtxt(homePath + "/.config/waydroid-runner/SaveApkIcon.json"))["path"])[0]
if not path == "":
try:
SaveApkIcon(apkPath, path)
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(widget, "错误", "图标保存失败!")
return
#WriteTxt(homePath + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
#findApkHistory.append(ComboInstallPath.currentText())
UpdateCombobox(0)
#WriteTxt(homePath + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
QtWidgets.QMessageBox.information(widget, "提示", "保存成功!")
class X11Chooser:
def __init__(self):
pass
def show(self):
self.window = QtWidgets.QWidget()
self.layout = QtWidgets.QGridLayout()
self.swayOption = QtWidgets.QRadioButton("Sway")
self.weston = QtWidgets.QRadioButton("Weston")
self.disabledGPU = QtWidgets.QCheckBox("禁止 Sway 调用 GPU")
self.ok = QtWidgets.QPushButton("确定")
self.layout.addWidget(self.swayOption, 0, 0)
self.layout.addWidget(self.weston, 0, 1)
self.layout.addWidget(self.disabledGPU, 1, 0, 1, 2)
self.layout.addWidget(self.ok, 2, 0, 1, 2)
self.ok.clicked.connect(self.OkClicked)
self.window.setLayout(self.layout)
# 根据系统实际情况选择
if not os.system("which weston"):
self.weston.setChecked(True)
else:
self.weston.setEnabled(False)
self.disabledGPU.setEnabled(False)
if not os.system("which sway"):
self.swayOption.setChecked(True)
else:
self.swayOption.setEnabled(False)
# 读取内容判断选项
if os.path.exists(homePath + "/.config/waydroid-runner/x11-set"):
try:
things = readtxt(homePath + "/.config/waydroid-runner/x11-set").replace(" ", "").replace("\n", "")
if things == "sway":
self.swayOption.setChecked(True)
else:
self.weston.setChecked(True)
except:
traceback.print_exc()
if os.path.exists(homePath + "/.config/waydroid-runner/disable-gpu"):
try:
things = readtxt(homePath + "/.config/waydroid-runner/x11-set").replace(" ", "").replace("\n", "")
if things == "1":
self.disabledGPU.setChecked(True)
else:
self.disabledGPU.setChecked(False)
except:
traceback.print_exc()
self.window.setWindowTitle("Wayland 兼容选择")
self.window.show()
def OkClicked(self):
try:
WriteTxt(homePath + "/.config/waydroid-runner/x11-set", "weston" if self.weston.isChecked() else "sway"
if self.swayOption.isChecked() else "weston")
WriteTxt(homePath + "/.config/waydroid-runner/disable-gpu", "1" if self.disabledGPU.isChecked() else "0")
QtWidgets.QMessageBox.information(self.window, "成功", "设置已保存")
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(self.window, "错误", traceback.format_exc())
# 关于窗口
helpWindow = None
def showhelp():
global helpWindow
helpWindow = QtWidgets.QMainWindow()
helpWidget = QtWidgets.QWidget()
helpLayout = QtWidgets.QGridLayout()
def ChgLog():
HelpStr.setHtml(updateThingsString)
def ChgAbout(event):
HelpStr.setHtml(about)
def ChgCon():
HelpStr.setHtml(contribute)
def ChgTips():
HelpStr.setHtml(tips)
def ChgGPLV3():
try:
with open(f"{programPath}/LICENSE", "r") as file:
things = file.read()
try:
HelpStr.setMarkdown(things)
except:
# 旧版 QT 不支持 Markdown
traceback.print_exc()
HelpStr.setText(things)
except:
traceback.print_exc()
HelpStr.setText(traceback.print_exc())
BtnReadme = QtWidgets.QPushButton("使用说明")
BtnLog = QtWidgets.QPushButton("更新内容")
BtnGongxian = QtWidgets.QPushButton("谢明列表")
BtnAbout = QtWidgets.QPushButton("关于")
BtnGPLV3 = QtWidgets.QPushButton("程序开源许可证")
HelpStr = QtWidgets.QTextBrowser()
BtnReadme.clicked.connect(ChgTips)
BtnLog.clicked.connect(ChgLog)
BtnGongxian.clicked.connect(ChgCon)
BtnAbout.clicked.connect(ChgAbout)
BtnGPLV3.clicked.connect(ChgGPLV3)
ChgTips()
helpLayout.addWidget(BtnReadme, 0, 0, 1, 1)
helpLayout.addWidget(BtnLog, 1, 0, 1, 1)
helpLayout.addWidget(BtnGongxian, 2, 0, 1, 1)
helpLayout.addWidget(BtnGPLV3, 3, 0, 1, 1)
helpLayout.addWidget(BtnAbout, 4, 0, 1, 1)
helpLayout.addWidget(HelpStr, 0, 1, 10, 1)
helpWidget.setLayout(helpLayout)
helpWindow.setCentralWidget(helpWidget)
helpWindow.setFixedSize(int(helpWindow.frameSize().width() * 0.9), int(helpWindow.frameSize().height() * 1.5))
helpWindow.setWindowTitle(f"{windowTitle}——帮助")
helpWindow.setWindowIcon(QtGui.QIcon(iconPath))
helpWindow.show()
return
# 环境变量
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
information = json.loads(readtxt(programPath + "/information.json"))
SystemVersion = GetSystemVersion()
programUrl = information["Url"][0]
version = information["Version"]
goodRunSystem = information["System"]
iconPath = "{}/runner.svg".format(os.path.split(os.path.realpath(__file__))[0])
updateThingsString = ""
homePath = os.getenv("HOME")
about = f'''<p align="center"><img width=256 src="{iconPath}"/></p>
<p>介绍:Waydroid运行器是可以通过GUI形式半自动配置Waydroid的工具,使用户使用Waydroid更为方便。Waydroid本身存在很多因AOSP未考虑PC用户而产生的问题(如没有自带Houdini,默认英语,默认非小窗模式)而使用户使用起来非常难受,本运行器支持以GUI形式自动化安装以及配置Waydroid,并会创建快捷控制的快捷方式,可以用于玩游戏/刷视频/Android开发等。</p>
<p>程序开源许可证:GPLV3</p>
<p>版本:{version}</p>
<p>适用平台:{goodRunSystem}</p>
<p>Qt 版本:{QtCore.qVersion()}</p>
<p>程序官网:{programUrl}</p>
<p>系统版本:{SystemVersion}</p>
<p>安装包构建时间:{information['Time']}</p>
<p>QQ 群:872491938</p>
<h1>©2023-{time.strftime("%Y")} gfdgd xi、Bail、LFRon</h1>'''
tips = ""
contribute = ""
for i in information["Tips"]:
tips += f"<p>{i}</p>"
for i in information["Update"]:
updateThingsString += f"<p>{i}</p>"
for i in information["Contribute"]:
contribute += f"<p>{i}</p>"
iconPath = f"{programPath}"
windowTitle = f"Waydroid 运行器 {version}"
###########################
# 加载配置
###########################
app = QtWidgets.QApplication(sys.argv)
if not os.path.exists(homePath + "/.config/waydroid-runner"): # 如果没有配置文件夹
os.makedirs(homePath + "/.config/waydroid-runner") # 创建配置文件夹
if not os.path.exists(homePath + "/.config/waydroid-runner/FindApkHistory.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindApkNameHistory.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindApkNameHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindApkActivityHistory.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindApkActivityHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindUninstallApkHistory.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindUninstallApkHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindApkName.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindApkName.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindApk.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/FindUninstallApk.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/FindUninstallApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/SaveApkIcon.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/SaveApkIcon.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/SaveApk.json"): # 如果没有配置文件
WriteTxt(homePath + "/.config/waydroid-runner/SaveApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
if not os.path.exists(homePath + "/.config/waydroid-runner/setting.json"):
WriteTxt(homePath + "/.config/waydroid-runner/setting.json", json.dumps({"SaveApk": int(1)}))
defultProgramList = {
"SaveApk": 1,
"AutoScreenConfig": False,
"ChooseProgramType": False,
"Theme": ""
}
try:
settingConf = json.loads(readtxt(homePath + "/.config/waydroid-runner/setting.json"))
change = False
for i in defultProgramList.keys():
if not i in settingConf:
change = True
settingConf[i] = defultProgramList[i]
if change:
WriteTxt(homePath + "/.config/waydroid-setting.json", json.dumps(settingConf))
except:
traceback.print_exc()
app = QtWidgets.QApplication(sys.argv)
QtWidgets.QMessageBox.critical(None, "错误", f"无法读取配置,无法继续\n{traceback.format_exc()}")
sys.exit(1)
findApkHistory = list(json.loads(readtxt(homePath + "/.config/waydroid-runner/FindApkHistory.json")).values())
fineUninstallApkHistory = list(json.loads(readtxt(homePath + "/.config/waydroid-runner/FindUninstallApkHistory.json")).values())
findApkNameHistory = list(json.loads(readtxt(homePath + "/.config/waydroid-runner/FindApkNameHistory.json")).values())
findApkActivityHistory = list(json.loads(readtxt(homePath + "/.config/waydroid-runner/FindApkActivityHistory.json")).values())
# 环境检测
if os.system("which waydroid"):
if QtWidgets.QMessageBox.question(None, "提示", "您还未安装 Waydroid,是否立即安装?") == QtWidgets.QMessageBox.Yes:
RunBash(f"bash '{programPath}/Runner_tools/Waydroid_Installer/Install-cn.sh'")
sys.exit()
try:
threading.Thread(target=requests.get, args=[parse.unquote(base64.b64decode("aHR0cDovLzEyMC4yNS4xNTMuMTQ0L3dheWRyb2lkLXJ1bm5lci9vcGVuL0luc3RhbGwucGhw").decode("utf-8")) + "?Version=" + version]).start()
except:
pass
# 窗口
mainwindow = QtWidgets.QMainWindow()
CheckWaylandRun(True)
widget = QtWidgets.QWidget()
widgetLayout = QtWidgets.QGridLayout()
# 权重
size = QtWidgets.QSizePolicy()
size.setHorizontalPolicy(0)
### 创建控件
## 安装 apk
apkPath = QtWidgets.QComboBox()
appStore = QtWidgets.QPushButton("应用商店")
apkPathBrowser = QtWidgets.QPushButton("浏览")
installButton = QtWidgets.QPushButton("安装")
removeButton = QtWidgets.QPushButton("卸载")
infoButton = QtWidgets.QPushButton("详情")
saveIcon = QtWidgets.QPushButton("保存图标")
# 设置属性
apkPath.setEditable(True)
apkPathBrowser.clicked.connect(BrowserApk)
installButton.clicked.connect(InstallApkButton)
removeButton.clicked.connect(UninstallApkButton)
infoButton.clicked.connect(ApkInformation.ShowWindows)
saveIcon.clicked.connect(SaveIconToOtherPath)
appStore.clicked.connect(lambda: threading.Thread(target=os.system, args=[f"python3 '{programPath}/AutoConfig.py'"]).start())
apkPathBrowser.setSizePolicy(size)
installButton.setSizePolicy(size)
appStore.setSizePolicy(size)
# layout
apkInstallLayout = QtWidgets.QGridLayout()
apkInstallLayout.addWidget(apkPath, 0, 0, 1, 2)
apkInstallLayout.addWidget(appStore, 1, 0)
apkInstallLayout.addWidget(apkPathBrowser, 0, 2)
apkInstallLayout.addWidget(installButton, 0, 3)
apkInstallLayout.addWidget(removeButton, 1, 2)
apkInstallLayout.addWidget(infoButton, 1, 3)
apkInstallLayout.addWidget(saveIcon, 2, 2)
## info
waydroidStatus = QtWidgets.QLabel("Waydroid:已安装")
magiskDeltaInstallStatus = QtWidgets.QLabel("Magisk Delta:已安装")
libkoudiniInstallStatus = QtWidgets.QLabel("Libhoudini:已安装")
lsPosedInstallStatus = QtWidgets.QLabel("LSPosed:已安装")
wideVineInstallStatus = QtWidgets.QLabel("Widevine:已安装")
# layout
infoLayout = QtWidgets.QGridLayout()
infoLayout.addWidget(QtWidgets.QLabel("<hr><p><b>Waydroid 信息:</b></p>"), 0, 0, 1, 2)
infoLayout.addWidget(waydroidStatus, 1, 0)
infoLayout.addWidget(magiskDeltaInstallStatus, 1, 1)
infoLayout.addWidget(lsPosedInstallStatus, 2, 0)
infoLayout.addWidget(libkoudiniInstallStatus, 2, 1)
infoLayout.addWidget(wideVineInstallStatus, 3, 0)
## 大 layout
widgetLayout.addLayout(apkInstallLayout, 2, 0)
widgetLayout.addLayout(infoLayout, 3, 0)
widget.setLayout(widgetLayout)
mainwindow.setWindowTitle(windowTitle)
mainwindow.setCentralWidget(widget)
## 菜单栏
menu = mainwindow.menuBar()
programMenu = menu.addMenu("程序(&W)")
waydroidMenu = menu.addMenu("Waydroid(&W)")
configMenu = menu.addMenu("容器配置(&C)")
helpMenu = menu.addMenu("帮助(&H)")
# 程序栏
#settingProgramAction = QtWidgets.QAction("设置程序")
checkWayland = QtWidgets.QAction("检测是否是在 Wayland 下运行该程序")
installSway = QtWidgets.QAction("安装 Sway")
installWeston = QtWidgets.QAction("安装 Weston")
exitProgramAction = QtWidgets.QAction("退出程序")
#programMenu.addAction(settingProgramAction)
programMenu.addAction(checkWayland)
programMenu.addSeparator()
programMenu.addAction(installSway)
programMenu.addAction(installWeston)
programMenu.addSeparator()
programMenu.addAction(exitProgramAction)
checkWayland.triggered.connect(CheckWaylandRun)
exitProgramAction.triggered.connect(sys.exit)
# Waydroid 栏
waydroidAutoSetting = QtWidgets.QAction("一键安装/设置 Waydroid")
waydroidAutoSetting.setDisabled(True)
installWaydroidCNAction = QtWidgets.QAction("安装 Waydroid 本体(国内源)")
installWaydroidAction = QtWidgets.QAction("安装 Waydroid 本体(官方源)")
waydroidStatus = QtWidgets.QAction("Waydroid 状态")
waydroidLog = QtWidgets.QAction("查看 Waydroid 日志")
restartWaydroidContainer = QtWidgets.QAction("重启 Waydroid 服务进程")
iconManager = QtWidgets.QAction("快捷方式管理工具")
waydroidRemoveAllDesktop = QtWidgets.QAction("移除所有 Waydroid 快捷方式")
waydroidShowFullUI = QtWidgets.QAction("显示 Waydroid Android 完整界面")
waydroidGetAndroidId = QtWidgets.QAction("获取Waydroid的安卓id")
waydroidChangeGPU = QtWidgets.QAction("切换 GPU")
if os.getenv("XDG_SESSION_TYPE") == "x11":
waydroidRunInX11Setting = QtWidgets.QAction("X11 运行 Waydroid 设置")
waydroidRunInX11SettingWindow = X11Chooser()
else:
waydroidRunInX11Setting = QtWidgets.QAction("X11 运行 Waydroid 设置(Wayland 无需设置)")
waydroidRunInX11Setting.setDisabled(True)
waydroidMenu.addAction(waydroidAutoSetting)
waydroidMenu.addAction(waydroidRunInX11Setting)
waydroidMenu.addSeparator()
waydroidMenu.addAction(installWaydroidCNAction)
waydroidMenu.addAction(installWaydroidAction)
waydroidMenu.addSeparator()
waydroidMenu.addAction(waydroidStatus)
waydroidMenu.addAction(waydroidLog)
waydroidMenu.addSeparator()
waydroidMenu.addAction(restartWaydroidContainer)
waydroidSession = waydroidMenu.addMenu("Waydroid Session")
waydroidSessionStart = QtWidgets.QAction("开启")
waydroidSessionStop = QtWidgets.QAction("关闭")
waydroidSessionStart.triggered.connect(lambda: threading.Thread(target=os.system, args=["waydroid session start && zenity --info --text=运行完成! --no-wrap"]).start())
waydroidSessionStop.triggered.connect(lambda: threading.Thread(target=os.system, args=["waydroid session stop && zenity --info --text=运行完成! --no-wrap"]).start())
waydroidSession.addAction(waydroidSessionStart)
waydroidSession.addAction(waydroidSessionStop)
waydroidMenu.addSeparator()
waydroidMenu.addAction(iconManager)
waydroidMenu.addAction(waydroidRemoveAllDesktop)
waydroidMenu.addSeparator()
waydroidMenu.addAction(waydroidShowFullUI)
waydroidMenu.addSeparator()
waydroidMenu.addAction(waydroidGetAndroidId)
waydroidMenu.addAction(waydroidChangeGPU)
waydroidAutoSetting.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/auto-setting.py'"]).start())
installWaydroidCNAction.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"bash '{programPath}/Runner_tools/Waydroid_Installer/Install-cn.sh'"]).start())
installWaydroidAction.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"bash '{programPath}/Runner_tools/Waydroid_Installer/Install.sh'"]))
waydroidStatus.triggered.connect(lambda: QtWidgets.QInputDialog.getMultiLineText(mainwindow, "Waydroid 状态", "", subprocess.getoutput("waydroid status")))
waydroidLog.triggered.connect(ReadWaydroidLog)
restartWaydroidContainer.triggered.connect(lambda: os.system("systemctl restart waydroid-container.service && zenity --info --text=运行完成! --no-wrap"))
iconManager.triggered.connect(lambda: threading.Thread(target=os.system, args=[f"python3 '{programPath}/BuildDesktop.py'"]).start())
waydroidRemoveAllDesktop.triggered.connect(lambda: os.system("rm ~/.local/share/applications/waydroid.*.desktop -fv && zenity --info --text=删除完成! --no-wrap"))
waydroidShowFullUI.triggered.connect(lambda: threading.Thread(target=os.system, args=["waydroid show-full-ui"]).start())
waydroidChangeGPU.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"echo '请在下方输入您的sudo密码' && sudo clear && sudo bash '{programPath}/Runner_tools/SystemConfigs/waydroid-choose-gpu.sh'"]).start())
waydroidGetAndroidId.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/Android-id-reader/android-id.py'"]).start())
waydroidRunInX11Setting.triggered.connect(waydroidRunInX11SettingWindow.show)
# 容器配置栏
downloadImageCN = QtWidgets.QAction("下载 Waydroid 容器镜像")
magiskInstall = QtWidgets.QAction("安装 Magisk")
libhoudiniInstall = QtWidgets.QAction("安装 Libhoudini 翻译器")
widevineInstall = QtWidgets.QAction("安装 Widevine")
waydroidLaguage = QtWidgets.QAction("设置 Waydroid 容器语言为中文")
waydroidClipboard = QtWidgets.QAction("开启Waydroid剪切板互通功能")
#multiWindowsSet = QtWidgets.QAction("开启 Waydroid 多窗口")
#doNotRotate = QtWidgets.QAction("")
waydroidAppListShow = QtWidgets.QAction("显示 Waydroid 安装的所有应用")
waydroidUpgradImage = QtWidgets.QAction("升级 Waydroid 容器(只限使用官方镜像安装方法)")
waydroidShell = QtWidgets.QAction("进入 Waydroid Shell")
#configMenu.addAction(downloadImageCN)
#configMenu.addSeparator()
configMenu.addAction(magiskInstall)
configMenu.addAction(libhoudiniInstall)
configMenu.addAction(widevineInstall)
configMenu.addSeparator()
configMenu.addAction(waydroidLaguage)
configMenu.addAction(waydroidClipboard)
configMenu.addSeparator()
#configMenu.addAction(multiWindowsSet)
multiWindowsSet = configMenu.addMenu("设置 Waydroid 多窗口")
multiWindowsSetTips0 = QtWidgets.QAction("注:启用该功能后可能出现无法正常显示主界面的问题")
multiWindowsSetTips1 = QtWidgets.QAction("目前只支持部分桌面环境,不支持 Sway/Weston")
multiWindowsSetOn = QtWidgets.QAction("开启多窗口")
multiWindowsSetOff = QtWidgets.QAction("关闭多窗口")
multiWindowsSetTips0.setDisabled(True)
multiWindowsSetTips1.setDisabled(True)
multiWindowsSet.addAction(multiWindowsSetTips0)
multiWindowsSet.addAction(multiWindowsSetTips1)
multiWindowsSet.addSeparator()
multiWindowsSet.addAction(multiWindowsSetOn)
multiWindowsSet.addAction(multiWindowsSetOff)
#configMenu.addAction(doNotRotate)
doNotRotate = configMenu.addMenu("设置屏幕方向自动旋转")
doNotRotateTips = QtWidgets.QAction("此功能默认开启")
doNotRotateOn = QtWidgets.QAction("开启")
doNotRotateOff = QtWidgets.QAction("关闭")
doNotRotateTips.setDisabled(True)
doNotRotate.addAction(doNotRotateTips)
doNotRotate.addSeparator()
doNotRotate.addAction(doNotRotateOn)
doNotRotate.addAction(doNotRotateOff)
doNotRotateOn.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/Off-function/Allow-rotate.py'"]).start())
doNotRotateOff.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/SystemConfigs/Do-not-rotate.py'"]).start())
waydroidClipboard.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/SystemConfigs/Clipboard-enable.py'"]).start()) #剪切板添加(试验性功能!)
waydroidRepairUnshowMouse = configMenu.addMenu("修复 Waydroid 多窗口在部分桌面环境无法显示鼠标的问题")
waydroidRepairUnshowMouseTips = QtWidgets.QAction("此功能默认关闭(如果能正常显示鼠标指针请别开启该功能)")
waydroidRepairUnshowMouseOn = QtWidgets.QAction("开启")
waydroidRepairUnshowMouseOff = QtWidgets.QAction("关闭")
waydroidRepairUnshowMouseOn.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/SystemConfigs/Show-cursor.py'"]).start())
waydroidRepairUnshowMouseOff.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/Off-function/Off-cursor.py'"]).start())
waydroidRepairUnshowMouseTips.setDisabled(True)
waydroidRepairUnshowMouse.addAction(waydroidRepairUnshowMouseTips)
waydroidRepairUnshowMouse.addSeparator()
waydroidRepairUnshowMouse.addAction(waydroidRepairUnshowMouseOn)
waydroidRepairUnshowMouse.addAction(waydroidRepairUnshowMouseOff)
configMenu.addSeparator()
configMenu.addAction(waydroidAppListShow)
quicklyOpen = configMenu.addMenu("应用快捷打开")
waydroidSetting = QtWidgets.QAction("Waydroid 设置")
waydroidFileManager = QtWidgets.QAction("Waydroid 文件")
waydroidBrowser = QtWidgets.QAction("Waydroid 浏览器")
waydroidSetting.triggered.connect(lambda: os.system("waydroid app launch com.android.settings"))
waydroidFileManager.triggered.connect(lambda: os.system("waydroid app launch com.android.documentsui"))
waydroidBrowser.triggered.connect(lambda: os.system("waydroid app launch org.lineageos.jelly"))
quicklyOpen.addAction(waydroidSetting)
quicklyOpen.addAction(waydroidFileManager)
quicklyOpen.addAction(waydroidBrowser)
configMenu.addSeparator()
waydroidContainer = configMenu.addMenu("Waydroid 容器控制")
waydroidContainerStart = QtWidgets.QAction("开启")
waydroidContainerStop = QtWidgets.QAction("关闭")
waydroidContainerRestart = QtWidgets.QAction("重新启动")
waydroidContainerFreeze = QtWidgets.QAction("Freeze")
waydroidContainerUnfreeze = QtWidgets.QAction("Unfreeze")
waydroidContainer.addAction(waydroidContainerStart)
waydroidContainer.addAction(waydroidContainerStop)
waydroidContainer.addAction(waydroidContainerRestart)
waydroidContainer.addAction(waydroidContainerFreeze)
waydroidContainer.addAction(waydroidContainerUnfreeze)
configMenu.addAction(waydroidUpgradImage)
configMenu.addSeparator()
configMenu.addAction(waydroidShell)
downloadImageCN.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"bash '{programPath}/Runner_tools/Waydroid_Image_Installer/Install.sh'"]).start())
libhoudiniInstall.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"bash '{programPath}/Runner_tools/Libhoudini_installer/Install.sh'"]).start())
magiskInstall.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/Magisk_Installer/Magisk.py'"]).start())
widevineInstall.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"bash '{programPath}/Runner_tools/Widevine_Installer/Install.sh'"]).start())
waydroidLaguage.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"pkexec python3 '{programPath}/Runner_tools/SystemConfigs/Language.py'"]).start())
#doNotRotate.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/SystemConfigs/Do-not-rotate.py'"]).start())
multiWindowsSetOn.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/SystemConfigs/Multi_windows.py'"]).start())
multiWindowsSetOff.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"python3 '{programPath}/Runner_tools/Off-function/Off-windows-mode.py'"]).start())
waydroidAppListShow.triggered.connect(lambda: QtWidgets.QInputDialog.getMultiLineText(mainwindow, "应用列表", "", subprocess.getoutput("waydroid app list")))
waydroidUpgradImage.triggered.connect(lambda: threading.Thread(target=RunBash, args=[f"pkexec waydroid upgrade"]).start())
waydroidShell.triggered.connect(lambda: threading.Thread(target=OpenTerminal, args=[f"pkexec waydroid shell"]).start())
waydroidContainerStart.triggered.connect(lambda: threading.Thread(target=os.system, args=["pkexec waydroid container start"]).start())
waydroidContainerStop.triggered.connect(lambda: threading.Thread(target=os.system, args=["pkexec waydroid container stop"]).start())
waydroidContainerRestart.triggered.connect(lambda: threading.Thread(target=os.system, args=["pkexec waydroid container restart"]).start())
waydroidContainerFreeze.triggered.connect(lambda: threading.Thread(target=os.system, args=["pkexec waydroid container freeze"]).start())
waydroidContainerUnfreeze.triggered.connect(lambda: threading.Thread(target=os.system, args=["pkexec waydroid container unfreeze"]).start())
# 帮助 栏
helpAction = QtWidgets.QAction("程序帮助")
uploadBugAction = QtWidgets.QAction("问题反馈")
updateProgram = QtWidgets.QAction("更新程序")
programWebsite = QtWidgets.QAction("程序地址")
aboutThisProgramAction = QtWidgets.QAction("关于本程序(&A)")
helpAction.triggered.connect(showhelp)
programWebsite.triggered.connect(lambda: webbrowser.open_new_tab("https://gitee.com/gfdgd-xi/waydroid-runner"))
updateProgram.triggered.connect(UpdateWindow.ShowWindow)
uploadBugAction.triggered.connect(lambda: threading.Thread(target=os.system, args=[f"python3 '{programPath}/waydroid-runner-update-bug'"]).start())
aboutThisProgramAction.triggered.connect(showhelp)
helpMenu.addAction(helpAction)
helpMenu.addAction(uploadBugAction)
helpMenu.addSeparator()
helpMenu.addAction(programWebsite)
helpMenu.addSeparator()
helpMenu.addAction(updateProgram)
helpMenu.addAction(aboutThisProgramAction)
## 窗口属性
mainwindow.setWindowIcon(QtGui.QIcon(iconPath))
mainwindow.show()
mainwindow.resize(int(mainwindow.frameGeometry().width() * 1.8), int(mainwindow.frameGeometry().height()))