This commit is contained in:
gfdgd xi 2021-07-02 20:05:01 +08:00
parent 81e2346fc8
commit 0dd7858097
6 changed files with 318 additions and 336 deletions

View File

@ -1,10 +1,10 @@
# uengine 运行器 1.2.0
# uengine 运行器 1.2.1
#### 介绍
使用 Python3 的 tkinter 构建
测试平台UOS 家庭版)
测试平台UOS 家庭版deepin 20.2.2 待测试
(自己美术功底太差,图标直接用 anbox 的了)
@ -13,10 +13,24 @@ i386 和 amd64
#### 更新内容
1.2.1更新内容:
※1、进行了安装方式的修改不使用 adb修复原无法安装和卸载的问题
2、进行了部分优化
3、进行了功能缩水
4、修复 deb 打包错误。
1.2.0更新内容:
1、支持安装自动添加快捷方式、卸载删除快捷方式
2、支持使用包名或 APK 文件卸载程序;
3、支持查看安装的所有包名
4、进行了部分优化
@ -25,7 +39,7 @@ i386 和 amd64
1. 安装所需依赖
```
sudo apt install python3 python3-tk git adb python3-pip aapt
sudo apt install python3 python3-tk git python3-pip aapt uengine
pip3 install pillow
pip3 install ttkthemes
pip3 install pillow -U
@ -58,9 +72,11 @@ pip3 uninstall ttkthemes
#### 使用说明
提示:
1、先连接设备再进行操作
1、需要你有使用 root 权限的能力;
2、支持连接其他 Android 系统操作(需要进行设置)
2、需要安装 uengine 才能使用。
如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
#### 特技

View File

@ -1,9 +1,9 @@
Package: spark-uengine-runner
Version: 1.2.0
Version: 1.2.1
Maintainer: gfdgd xi <3025613752@qq.com>
Homepage: https://gitee.com/gfdgd-xi/uengine-runner
Architecture: all
Priority: optional
Depends: python3, python3-tk, adb, python3-pip, aapt
Depends: python3, python3-tk, python3-pip, aapt, uengine
Description: gfdgd xi make's uengine runner

View File

@ -1,5 +1,3 @@
# !/bin/sh
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade virtualenv
pip3 install pillow
pip3 install ttkthemes
# !/bin/sh
pip3 install --upgrade pillow
pip3 install --upgrade ttkthemes

View File

@ -4,7 +4,7 @@
# 作者gfdgd xi
# 版本1.2.0
# 更新时间2021年5月30日
# 感谢anbox 和 统信
# 感谢anbox、deepin 和 统信
# 基于 Python3 的 tkinter 构建
###########################################################################################
#################
@ -28,39 +28,37 @@ import tkinter.filedialog as filedialog
import PIL.Image as Image
import PIL.ImageTk as ImageTk
def KillAdbProgress():
def UninstallProgram(package):
global fineUninstallApkHistory
#setting = {True: "", False: "-k"}
Return = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(package))
#Return = GetCommandReturn("adb shell pm uninstall {} {}".format(setting[cleanData], package))
if os.path.exists("{}/.local/share/applications/{}.desktop".format(get_home(), package)):
os.remove("{}/.local/share/applications/{}.desktop".format(get_home(), package))
if os.path.exists("{}/{}.desktop".format(get_desktop_path(), package)):
os.remove("{}/{}.desktop".format(get_desktop_path(), package))
fineUninstallApkHistory.append(combobox3.get())
combobox3['value'] = fineUninstallApkHistory
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
return Return
def ButtonClick7():
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApk.json"))["path"])
if path != "" and path != "()":
try:
combobox3.set(path)
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
except:
pass
def ButtonClick8():
DisabledAndEnbled(True)
Return = GetCommandReturn("killall adb")
if Return is "":
Return = "进程已经杀死!"
messagebox.showinfo(title="tips", message=Return)
DisabledAndEnbled(False)
def Button1Click():
if combobox2.get() is "":
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续连接 IP")
return
DisabledAndEnbled(True)
threading.Thread(target=ConnectPhoneIp).start()
def ConnectPhoneIp():
global phoneIp
messagebox.showinfo(title="提示", message=GetCommandReturn("adb connect '{}'".format(combobox2.get())))
phoneIp.append(combobox2.get())
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)
def ConnectPhoneIpDefult(quit = False):
global phoneIp
Return = GetCommandReturn("adb connect '192.168.250.2'")
if quit:
print(Return)
return
messagebox.showinfo(title="提示", message=Return)
phoneIp.append("192.168.250.2")
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
if os.path.exists(combobox3.get()):
path = GetApkPackageName(combobox3.get())
else:
path = combobox3.get()
UninstallProgram(path)
messagebox.showinfo(message="操作执行完毕!", title="提示")
DisabledAndEnbled(False)
def FindApk():
@ -79,24 +77,16 @@ def Button3Install():
DisabledAndEnbled(True)
threading.Thread(target=InstallApk, args=(combobox1.get(),)).start()
def AdbRun():
Return = GetCommandReturn("adb devices").replace("\n", "").replace("List of devices attached", "").replace("* daemon not running; starting now at tcp:5037", "").replace("* daemon started successfully", "")
if Return is "":
return False
return True
def AdbConnect():
return GetCommandReturn("adb devices")
def InstallApk(path, quit = False):
global findApkHistory
if not AdbRun():
'''if not AdbRun():
if quit:
return
messagebox.showinfo(title="提示", message="你没有使用 adb 连接任何设备")
DisabledAndEnbled(False)
return
commandReturn = GetCommandReturn("adb install '{}'".format(path))
return'''
#commandReturn = GetCommandReturn("adb install '{}'".format(path))
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.desktop".format(get_home(), GetApkPackageName(path))
SaveApkIcon(path, iconSavePath)
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
@ -116,17 +106,17 @@ def DisabledAndEnbled(choose):
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
a = userChoose[choose]
combobox1.configure(state=a)
combobox2.configure(state=a)
#combobox2.configure(state=a)
combobox3.configure(state=a)
checkButton1.configure(state=a)
button1.configure(state=a)
#checkButton1.configure(state=a)
#button1.configure(state=a)
button2.configure(state=a)
button3.configure(state=a)
button4.configure(state=a)
#button4.configure(state=a)
button5.configure(state=a)
button6.configure(state=a)
button7.configure(state=a)
button8.configure(state=a)
#button6.configure(state=a)
#button7.configure(state=a)
#button8.configure(state=a)
# 需引入 subprocess
def GetCommandReturn(cmd):
@ -139,9 +129,6 @@ def Button5Click():
def OpenUengineProgramList():
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
def ShowAdbConnect():
messagebox.showinfo(title="提示", message=AdbConnect())
# 显示“关于这个程序”窗口
def about_this_program():
global about
@ -266,9 +253,6 @@ def ShowUseProgram():
global useProgram
messagebox.showinfo(title="{} 使用的程序列表(部分)".format(title), message=useProgram)
def AboutAdb():
messagebox.showinfo(message=GetCommandReturn("adb version"), title="关于 adb")
def GetApkPath(packetName):
return GetCommandReturn("adb shell pm path {}".format(packetName)).replace("package:", "")
@ -365,59 +349,11 @@ def get_desktop_path():
def get_home():
return os.path.expanduser('~')
def UninstallProgram(package, cleanData):
global fineUninstallApkHistory
setting = {True: "", False: "-k"}
Return = GetCommandReturn("adb shell pm uninstall {} {}".format(setting[cleanData], package))
if os.path.exists("{}/.local/share/applications/{}.desktop".format(get_home(), package)):
os.remove("{}/.local/share/applications/{}.desktop".format(get_home(), package))
if os.path.exists("{}/{}.desktop".format(get_desktop_path(), package)):
os.remove("{}/{}.desktop".format(get_desktop_path(), package))
fineUninstallApkHistory.append(combobox3.get())
combobox3['value'] = fineUninstallApkHistory
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
return Return
def ButtonClick7():
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApk.json"))["path"])
if path != "" and path != "()":
try:
combobox3.set(path)
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
except:
pass
def ButtonClick8():
DisabledAndEnbled(True)
if os.path.exists(combobox3.get()):
path = GetApkPackageName(combobox3.get())
else:
path = combobox3.get()
messagebox.showinfo(message=UninstallProgram(path, not checkButtonBool1.get()))
DisabledAndEnbled(False)
def GetAllPackageName():
return GetCommandReturn("adb shell pm list packages")
def ShowAdbInstallPackage():
mess = tk.Toplevel()
message = ttk.Frame(mess)
mess.resizable(0, 0)
mess.title("所有软件包")
textbox1 = tk.Text(message, width=100)
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
textbox1.insert("0.0", GetAllPackageName())
textbox1.configure(state=tk.DISABLED)
textbox1.pack()
button1.pack(side="bottom")
message.pack()
mess.mainloop()
###########################
# 程序信息
###########################
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
version = "1.2.0"
version = "1.2.1"
goodRunSystem = "Linux"
about = '''一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
版本:{}
@ -426,15 +362,15 @@ tkinter 版本:{}
程序官网:{}
©2021-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
tips = '''提示:
1、先连接设备再安装应用
2、支持连接其他 Android 系统操作(需要进行设置)'''
updateThingsString = '''1、支持安装自动添加快捷方式、卸载删除快捷方式
2、支持使用包名或 APK 文件卸载程序
3、支持查看安装的所有包名
4、支持终端连接默认 IP 和安装 APK 文件
5、进行了部分优化'''
1、需要你有使用 root 权限的能力;
2、需要安装 uengine 才能使用。
如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。'''
updateThingsString = '''※1、进行了安装方式的修改不使用 adb修复原无法安装和卸载的问题
2、进行了部分优化
3、进行了功能缩水
4、修复 deb 打包错误。'''
title = "uengine 运行器 {}".format(version)
updateTime = "2021年6月6日"
updateTime = "2021年7月2日考试结束了"
updateThings = "{} 更新内容:\n{}\n更新时间{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
@ -442,8 +378,7 @@ desktopName = "UengineAndroidProgramList.desktop"
useProgram = '''1、uengineanbox
2、Python3
3、tkintertkinter.tk、ttkthemes 和 tkinter.ttk
4、adb
5、aapt
4、aapt
……'''
###########################
@ -451,8 +386,8 @@ useProgram = '''1、uengineanbox
###########################
if not os.path.exists(get_home() + "/.config/uengine-runner"): # 如果没有配置文件夹
os.mkdir(get_home() + "/.config/uengine-runner") # 创建配置文件夹
if not os.path.exists(get_home() + "/.config/uengine-runner/PhoneIp.json"): # 如果没有配置文件
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", json.dumps({})) # 创建配置文件
#if not os.path.exists(get_home() + "/.config/uengine-runner/PhoneIp.json"): # 如果没有配置文件
#write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", json.dumps({})) # 创建配置文件
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApkHistory.json"): # 如果没有配置文件
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json"): # 如果没有配置文件
@ -466,34 +401,13 @@ if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApk.jso
# 设置变量
###########################
findApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkHistory.json")).values())
phoneIp = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/PhoneIp.json")).values())
#phoneIp = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/PhoneIp.json")).values())
fineUninstallApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json")).values())
###########################
# 判断参数
###########################
quit = True
if len(sys.argv) > 1: # 有参数
if "-q" in sys.argv:
quit = True
if "-i" in sys.argv:
if len(sys.argv) >= sys.argv.index("-i") + 2:
InstallApk(sys.argv[sys.argv.index("-i") + 1], quit)
sys.exit()
if "-ci" in sys.argv:
if len(sys.argv) >= sys.argv.index("-ci") + 2:
ConnectPhoneIpDefult(quit)
InstallApk(sys.argv[sys.argv.index("-ci") + 1], quit)
sys.exit()
if "-c" in sys.argv:
ConnectPhoneIpDefult(quit)
sys.exit()
print("帮助:")
print("-c\t连接默认 IP 地址192.168.250.2")
print("-ci APK文件路径\t连接默认 IP 地址并安装 APK 软件包")
print("-i APK文件路径\t安装 APK 软件包")
print("--help 查看帮助")
sys.exit()
# None
###########################
# 窗口创建
@ -511,34 +425,34 @@ frame1 = ttk.Frame(window)
frame2 = ttk.Frame(window)
frame3 = ttk.Frame(window)
label1 = ttk.Label(window, text="要安装的 apk 路径:")
label2 = ttk.Label(window, text="要连接的设备的 IP默认 IP 为 192.168.250.2")
#label2 = ttk.Label(window, text="要连接的设备的 IP默认 IP 为 192.168.250.2")
label3 = ttk.Label(window, text="要卸载的包名或程序对应的 APK 文件:")
combobox1 = ttk.Combobox(window, width=100)
combobox2 = ttk.Combobox(window, width=100)
#combobox2 = ttk.Combobox(window, width=100)
combobox3 = ttk.Combobox(window, width=100)
button1 = ttk.Button(frame1, text="连接设备", command=ConnectPhoneIp)
#button1 = ttk.Button(frame1, text="连接设备", command=ConnectPhoneIp)
button2 = ttk.Button(window, text="浏览", command=FindApk)
button3 = ttk.Button(frame2, text="安装", command=Button3Install)
button4 = ttk.Button(frame1, text="关闭 adb 软件进程", command=KillAdbProgress)
#button4 = ttk.Button(frame1, text="关闭 adb 软件进程", command=KillAdbProgress)
button5 = ttk.Button(frame2, text="打开 uengine 应用列表", command=Button5Click)
button6 = ttk.Button(frame1, text="连接默认 IP", command=ConnectPhoneIpDefult)
#button6 = ttk.Button(frame1, text="连接默认 IP", command=ConnectPhoneIpDefult)
button7 = ttk.Button(window, text="浏览", command=ButtonClick7)
button8 = ttk.Button(frame3, text="卸载", command=ButtonClick8)
checkButton1 = ttk.Checkbutton(frame3, text="保留软件数据", variable=checkButtonBool1)
#checkButton1 = ttk.Checkbutton(frame3, text="保留软件数据", variable=checkButtonBool1)
menu = tk.Menu(window, background="white") # 设置菜单栏
programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏
adb = tk.Menu(menu, tearoff=0, background="white")
#adb = tk.Menu(menu, tearoff=0, background="white")
uengine = tk.Menu(menu, tearoff=0, background="white")
help = tk.Menu(menu, tearoff=0, background="white") # 设置“帮助”菜单栏
menu.add_cascade(label="程序", menu=programmenu)
menu.add_cascade(label="adb", menu=adb)
#menu.add_cascade(label="adb", menu=adb)
menu.add_cascade(label="uengine", menu=uengine)
menu.add_cascade(label="帮助", menu=help)
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
programmenu.add_separator() # 设置分界线
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
adb.add_command(label="adb 连接的设备", command=ShowAdbConnect)
adb.add_command(label="adb 连接的设备的所有软件包", command=ShowAdbInstallPackage)
#adb.add_command(label="adb 连接的设备", command=ShowAdbConnect)
#adb.add_command(label="adb 连接的设备的所有软件包", command=ShowAdbInstallPackage)
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
@ -546,36 +460,106 @@ help.add_separator()
help.add_command(label="小提示", command=helps) # 设置“小提示”项
help.add_command(label="更新内容", command=UpdateThings) # 设置“更新内容”项
help.add_command(label="这个程序使用的程序列表(部分)", command=ShowUseProgram) # 设置“更新内容”项
help.add_command(label="关于 adb", command=AboutAdb) # 设置“关于这个程序”项
#help.add_command(label="关于 adb", command=AboutAdb) # 设置“关于这个程序”项
help.add_command(label="关于这个程序", command=about_this_program) # 设置“关于这个程序”项
menu.configure(activebackground="white")
help.configure(activebackground="white")
uengine.configure(activebackground="white")
adb.configure(activebackground="white")
#adb.configure(activebackground="white")
programmenu.configure(activebackground="white")
# 设置控件
combobox3['value'] = fineUninstallApkHistory
combobox2['value'] = phoneIp
#combobox2['value'] = phoneIp
combobox1['value'] = findApkHistory
#
win.config(menu=menu) # 显示菜单栏
label1.grid(row=2, column=0)
label2.grid(row=0, column=0)
#label2.grid(row=0, column=0)
label3.grid(row=4, column=0)
combobox1.grid(row=2, column=1)
combobox2.grid(row=0, column=1)
#combobox2.grid(row=0, column=1)
combobox3.grid(row=4, column=1)
button1.grid(column=0, row=0)
#button1.grid(column=0, row=0)
button2.grid(row=2, column=2)
button3.grid(row=0, column=0)
button4.grid(column=1, row=0)
#button4.grid(column=1, row=0)
button5.grid(row=0, column=1)
button6.grid(row=0, column=3)
#button6.grid(row=0, column=3)
button7.grid(row=4, column=2)
button8.grid(row=0, column=1)
checkButton1.grid(row=0, column=0)
#checkButton1.grid(row=0, column=0)
frame1.grid(row=1, columnspa=3)
frame2.grid(row=3, columnspa=3)
frame3.grid(row=5, columnspa=3)
window.pack()
win.mainloop()
win.mainloop()
#########################################
# 废弃的代码
#########################################
'''def KillAdbProgress():
DisabledAndEnbled(True)
Return = GetCommandReturn("killall adb")
if Return is "":
Return = "进程已经杀死!"
messagebox.showinfo(title="tips", message=Return)
DisabledAndEnbled(False)'''
'''def Button1Click():
if combobox2.get() is "":
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续连接 IP")
return
DisabledAndEnbled(True)
threading.Thread(target=ConnectPhoneIp).start()'''
'''def ConnectPhoneIp():
global phoneIp
messagebox.showinfo(title="提示", message=GetCommandReturn("adb connect '{}'".format(combobox2.get())))
phoneIp.append(combobox2.get())
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)'''
'''def ConnectPhoneIpDefult(quit = False):
global phoneIp
Return = GetCommandReturn("adb connect '192.168.250.2'")
if quit:
print(Return)
return
messagebox.showinfo(title="提示", message=Return)
phoneIp.append("192.168.250.2")
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)'''
'''def AdbRun():
Return = GetCommandReturn("adb devices").replace("\n", "").replace("List of devices attached", "").replace("* daemon not running; starting now at tcp:5037", "").replace("* daemon started successfully", "")
if Return is "":
return False
return True'''
'''def AdbConnect():
return GetCommandReturn("adb devices")'''
'''def ShowAdbConnect():
messagebox.showinfo(title="提示", message=AdbConnect())'''
'''def AboutAdb():
messagebox.showinfo(message=GetCommandReturn("adb version"), title="关于 adb")'''
'''def GetAllPackageName():
return GetCommandReturn("adb shell pm list packages")'''
'''def ShowAdbInstallPackage():
mess = tk.Toplevel()
message = ttk.Frame(mess)
mess.resizable(0, 0)
mess.title("所有软件包")
textbox1 = tk.Text(message, width=100)
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
textbox1.insert("0.0", GetAllPackageName())
textbox1.configure(state=tk.DISABLED)
textbox1.pack()
button1.pack(side="bottom")
message.pack()
mess.mainloop()'''

308
main.py
View File

@ -4,7 +4,7 @@
# 作者gfdgd xi
# 版本1.2.0
# 更新时间2021年5月30日
# 感谢anbox 和 统信
# 感谢anbox、deepin 和 统信
# 基于 Python3 的 tkinter 构建
###########################################################################################
#################
@ -28,39 +28,37 @@ import tkinter.filedialog as filedialog
import PIL.Image as Image
import PIL.ImageTk as ImageTk
def KillAdbProgress():
def UninstallProgram(package):
global fineUninstallApkHistory
#setting = {True: "", False: "-k"}
Return = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(package))
#Return = GetCommandReturn("adb shell pm uninstall {} {}".format(setting[cleanData], package))
if os.path.exists("{}/.local/share/applications/{}.desktop".format(get_home(), package)):
os.remove("{}/.local/share/applications/{}.desktop".format(get_home(), package))
if os.path.exists("{}/{}.desktop".format(get_desktop_path(), package)):
os.remove("{}/{}.desktop".format(get_desktop_path(), package))
fineUninstallApkHistory.append(combobox3.get())
combobox3['value'] = fineUninstallApkHistory
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
return Return
def ButtonClick7():
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApk.json"))["path"])
if path != "" and path != "()":
try:
combobox3.set(path)
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
except:
pass
def ButtonClick8():
DisabledAndEnbled(True)
Return = GetCommandReturn("killall adb")
if Return is "":
Return = "进程已经杀死!"
messagebox.showinfo(title="tips", message=Return)
DisabledAndEnbled(False)
def Button1Click():
if combobox2.get() is "":
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续连接 IP")
return
DisabledAndEnbled(True)
threading.Thread(target=ConnectPhoneIp).start()
def ConnectPhoneIp():
global phoneIp
messagebox.showinfo(title="提示", message=GetCommandReturn("adb connect '{}'".format(combobox2.get())))
phoneIp.append(combobox2.get())
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)
def ConnectPhoneIpDefult(quit = False):
global phoneIp
Return = GetCommandReturn("adb connect '192.168.250.2'")
if quit:
print(Return)
return
messagebox.showinfo(title="提示", message=Return)
phoneIp.append("192.168.250.2")
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
if os.path.exists(combobox3.get()):
path = GetApkPackageName(combobox3.get())
else:
path = combobox3.get()
UninstallProgram(path)
messagebox.showinfo(message="操作执行完毕!", title="提示")
DisabledAndEnbled(False)
def FindApk():
@ -79,24 +77,16 @@ def Button3Install():
DisabledAndEnbled(True)
threading.Thread(target=InstallApk, args=(combobox1.get(),)).start()
def AdbRun():
Return = GetCommandReturn("adb devices").replace("\n", "").replace("List of devices attached", "").replace("* daemon not running; starting now at tcp:5037", "").replace("* daemon started successfully", "")
if Return is "":
return False
return True
def AdbConnect():
return GetCommandReturn("adb devices")
def InstallApk(path, quit = False):
global findApkHistory
if not AdbRun():
'''if not AdbRun():
if quit:
return
messagebox.showinfo(title="提示", message="你没有使用 adb 连接任何设备")
DisabledAndEnbled(False)
return
commandReturn = GetCommandReturn("adb install '{}'".format(path))
return'''
#commandReturn = GetCommandReturn("adb install '{}'".format(path))
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.desktop".format(get_home(), GetApkPackageName(path))
SaveApkIcon(path, iconSavePath)
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
@ -116,17 +106,17 @@ def DisabledAndEnbled(choose):
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
a = userChoose[choose]
combobox1.configure(state=a)
combobox2.configure(state=a)
#combobox2.configure(state=a)
combobox3.configure(state=a)
checkButton1.configure(state=a)
button1.configure(state=a)
#checkButton1.configure(state=a)
#button1.configure(state=a)
button2.configure(state=a)
button3.configure(state=a)
button4.configure(state=a)
#button4.configure(state=a)
button5.configure(state=a)
button6.configure(state=a)
button7.configure(state=a)
button8.configure(state=a)
#button6.configure(state=a)
#button7.configure(state=a)
#button8.configure(state=a)
# 需引入 subprocess
def GetCommandReturn(cmd):
@ -139,9 +129,6 @@ def Button5Click():
def OpenUengineProgramList():
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
def ShowAdbConnect():
messagebox.showinfo(title="提示", message=AdbConnect())
# 显示“关于这个程序”窗口
def about_this_program():
global about
@ -266,9 +253,6 @@ def ShowUseProgram():
global useProgram
messagebox.showinfo(title="{} 使用的程序列表(部分)".format(title), message=useProgram)
def AboutAdb():
messagebox.showinfo(message=GetCommandReturn("adb version"), title="关于 adb")
def GetApkPath(packetName):
return GetCommandReturn("adb shell pm path {}".format(packetName)).replace("package:", "")
@ -365,59 +349,11 @@ def get_desktop_path():
def get_home():
return os.path.expanduser('~')
def UninstallProgram(package, cleanData):
global fineUninstallApkHistory
setting = {True: "", False: "-k"}
Return = GetCommandReturn("adb shell pm uninstall {} {}".format(setting[cleanData], package))
if os.path.exists("{}/.local/share/applications/{}.desktop".format(get_home(), package)):
os.remove("{}/.local/share/applications/{}.desktop".format(get_home(), package))
if os.path.exists("{}/{}.desktop".format(get_desktop_path(), package)):
os.remove("{}/{}.desktop".format(get_desktop_path(), package))
fineUninstallApkHistory.append(combobox3.get())
combobox3['value'] = fineUninstallApkHistory
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
return Return
def ButtonClick7():
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApk.json"))["path"])
if path != "" and path != "()":
try:
combobox3.set(path)
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
except:
pass
def ButtonClick8():
DisabledAndEnbled(True)
if os.path.exists(combobox3.get()):
path = GetApkPackageName(combobox3.get())
else:
path = combobox3.get()
messagebox.showinfo(message=UninstallProgram(path, not checkButtonBool1.get()))
DisabledAndEnbled(False)
def GetAllPackageName():
return GetCommandReturn("adb shell pm list packages")
def ShowAdbInstallPackage():
mess = tk.Toplevel()
message = ttk.Frame(mess)
mess.resizable(0, 0)
mess.title("所有软件包")
textbox1 = tk.Text(message, width=100)
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
textbox1.insert("0.0", GetAllPackageName())
textbox1.configure(state=tk.DISABLED)
textbox1.pack()
button1.pack(side="bottom")
message.pack()
mess.mainloop()
###########################
# 程序信息
###########################
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
version = "1.2.0"
version = "1.2.1"
goodRunSystem = "Linux"
about = '''一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
版本{}
@ -426,15 +362,15 @@ tkinter 版本:{}
程序官网{}
©2021-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
tips = '''提示:
1先连接设备再安装应用
2支持连接其他 Android 系统操作需要进行设置'''
updateThingsString = '''1、支持安装自动添加快捷方式、卸载删除快捷方式
2支持使用包名或 APK 文件卸载程序
3支持查看安装的所有包名
4支持终端连接默认 IP 和安装 APK 文件
5进行了部分优化'''
1需要你有使用 root 权限的能力
2需要安装 uengine 才能使用
如果想要连接其他手机请使用 1.2.0 以前的版本可以使用 adb 连接'''
updateThingsString = '''※1、进行了安装方式的修改不使用 adb修复原无法安装和卸载的问题
2进行了部分优化
3进行了功能缩水
4修复 deb 打包错误'''
title = "uengine 运行器 {}".format(version)
updateTime = "2021年6月6日"
updateTime = "2021年7月2日考试结束了"
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
@ -442,8 +378,7 @@ desktopName = "UengineAndroidProgramList.desktop"
useProgram = '''1、uengineanbox
2Python3
3tkintertkinter.tkttkthemes tkinter.ttk
4adb
5aapt
4aapt
'''
###########################
@ -451,8 +386,8 @@ useProgram = '''1、uengineanbox
###########################
if not os.path.exists(get_home() + "/.config/uengine-runner"): # 如果没有配置文件夹
os.mkdir(get_home() + "/.config/uengine-runner") # 创建配置文件夹
if not os.path.exists(get_home() + "/.config/uengine-runner/PhoneIp.json"): # 如果没有配置文件
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", json.dumps({})) # 创建配置文件
#if not os.path.exists(get_home() + "/.config/uengine-runner/PhoneIp.json"): # 如果没有配置文件
#write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", json.dumps({})) # 创建配置文件
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApkHistory.json"): # 如果没有配置文件
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json"): # 如果没有配置文件
@ -466,34 +401,13 @@ if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApk.jso
# 设置变量
###########################
findApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkHistory.json")).values())
phoneIp = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/PhoneIp.json")).values())
#phoneIp = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/PhoneIp.json")).values())
fineUninstallApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json")).values())
###########################
# 判断参数
###########################
quit = True
if len(sys.argv) > 1: # 有参数
if "-q" in sys.argv:
quit = True
if "-i" in sys.argv:
if len(sys.argv) >= sys.argv.index("-i") + 2:
InstallApk(sys.argv[sys.argv.index("-i") + 1], quit)
sys.exit()
if "-ci" in sys.argv:
if len(sys.argv) >= sys.argv.index("-ci") + 2:
ConnectPhoneIpDefult(quit)
InstallApk(sys.argv[sys.argv.index("-ci") + 1], quit)
sys.exit()
if "-c" in sys.argv:
ConnectPhoneIpDefult(quit)
sys.exit()
print("帮助:")
print("-c\t连接默认 IP 地址192.168.250.2")
print("-ci APK文件路径\t连接默认 IP 地址并安装 APK 软件包")
print("-i APK文件路径\t安装 APK 软件包")
print("--help 查看帮助")
sys.exit()
# None
###########################
# 窗口创建
@ -511,34 +425,34 @@ frame1 = ttk.Frame(window)
frame2 = ttk.Frame(window)
frame3 = ttk.Frame(window)
label1 = ttk.Label(window, text="要安装的 apk 路径:")
label2 = ttk.Label(window, text="要连接的设备的 IP默认 IP 为 192.168.250.2")
#label2 = ttk.Label(window, text="要连接的设备的 IP默认 IP 为 192.168.250.2")
label3 = ttk.Label(window, text="要卸载的包名或程序对应的 APK 文件:")
combobox1 = ttk.Combobox(window, width=100)
combobox2 = ttk.Combobox(window, width=100)
#combobox2 = ttk.Combobox(window, width=100)
combobox3 = ttk.Combobox(window, width=100)
button1 = ttk.Button(frame1, text="连接设备", command=ConnectPhoneIp)
#button1 = ttk.Button(frame1, text="连接设备", command=ConnectPhoneIp)
button2 = ttk.Button(window, text="浏览", command=FindApk)
button3 = ttk.Button(frame2, text="安装", command=Button3Install)
button4 = ttk.Button(frame1, text="关闭 adb 软件进程", command=KillAdbProgress)
#button4 = ttk.Button(frame1, text="关闭 adb 软件进程", command=KillAdbProgress)
button5 = ttk.Button(frame2, text="打开 uengine 应用列表", command=Button5Click)
button6 = ttk.Button(frame1, text="连接默认 IP", command=ConnectPhoneIpDefult)
#button6 = ttk.Button(frame1, text="连接默认 IP", command=ConnectPhoneIpDefult)
button7 = ttk.Button(window, text="浏览", command=ButtonClick7)
button8 = ttk.Button(frame3, text="卸载", command=ButtonClick8)
checkButton1 = ttk.Checkbutton(frame3, text="保留软件数据", variable=checkButtonBool1)
#checkButton1 = ttk.Checkbutton(frame3, text="保留软件数据", variable=checkButtonBool1)
menu = tk.Menu(window, background="white") # 设置菜单栏
programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏
adb = tk.Menu(menu, tearoff=0, background="white")
#adb = tk.Menu(menu, tearoff=0, background="white")
uengine = tk.Menu(menu, tearoff=0, background="white")
help = tk.Menu(menu, tearoff=0, background="white") # 设置“帮助”菜单栏
menu.add_cascade(label="程序", menu=programmenu)
menu.add_cascade(label="adb", menu=adb)
#menu.add_cascade(label="adb", menu=adb)
menu.add_cascade(label="uengine", menu=uengine)
menu.add_cascade(label="帮助", menu=help)
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
programmenu.add_separator() # 设置分界线
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
adb.add_command(label="adb 连接的设备", command=ShowAdbConnect)
adb.add_command(label="adb 连接的设备的所有软件包", command=ShowAdbInstallPackage)
#adb.add_command(label="adb 连接的设备", command=ShowAdbConnect)
#adb.add_command(label="adb 连接的设备的所有软件包", command=ShowAdbInstallPackage)
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
@ -546,36 +460,106 @@ help.add_separator()
help.add_command(label="小提示", command=helps) # 设置“小提示”项
help.add_command(label="更新内容", command=UpdateThings) # 设置“更新内容”项
help.add_command(label="这个程序使用的程序列表(部分)", command=ShowUseProgram) # 设置“更新内容”项
help.add_command(label="关于 adb", command=AboutAdb) # 设置“关于这个程序”项
#help.add_command(label="关于 adb", command=AboutAdb) # 设置“关于这个程序”项
help.add_command(label="关于这个程序", command=about_this_program) # 设置“关于这个程序”项
menu.configure(activebackground="white")
help.configure(activebackground="white")
uengine.configure(activebackground="white")
adb.configure(activebackground="white")
#adb.configure(activebackground="white")
programmenu.configure(activebackground="white")
# 设置控件
combobox3['value'] = fineUninstallApkHistory
combobox2['value'] = phoneIp
#combobox2['value'] = phoneIp
combobox1['value'] = findApkHistory
#
win.config(menu=menu) # 显示菜单栏
label1.grid(row=2, column=0)
label2.grid(row=0, column=0)
#label2.grid(row=0, column=0)
label3.grid(row=4, column=0)
combobox1.grid(row=2, column=1)
combobox2.grid(row=0, column=1)
#combobox2.grid(row=0, column=1)
combobox3.grid(row=4, column=1)
button1.grid(column=0, row=0)
#button1.grid(column=0, row=0)
button2.grid(row=2, column=2)
button3.grid(row=0, column=0)
button4.grid(column=1, row=0)
#button4.grid(column=1, row=0)
button5.grid(row=0, column=1)
button6.grid(row=0, column=3)
#button6.grid(row=0, column=3)
button7.grid(row=4, column=2)
button8.grid(row=0, column=1)
checkButton1.grid(row=0, column=0)
#checkButton1.grid(row=0, column=0)
frame1.grid(row=1, columnspa=3)
frame2.grid(row=3, columnspa=3)
frame3.grid(row=5, columnspa=3)
window.pack()
win.mainloop()
win.mainloop()
#########################################
# 废弃的代码
#########################################
'''def KillAdbProgress():
DisabledAndEnbled(True)
Return = GetCommandReturn("killall adb")
if Return is "":
Return = "进程已经杀死!"
messagebox.showinfo(title="tips", message=Return)
DisabledAndEnbled(False)'''
'''def Button1Click():
if combobox2.get() is "":
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续连接 IP")
return
DisabledAndEnbled(True)
threading.Thread(target=ConnectPhoneIp).start()'''
'''def ConnectPhoneIp():
global phoneIp
messagebox.showinfo(title="提示", message=GetCommandReturn("adb connect '{}'".format(combobox2.get())))
phoneIp.append(combobox2.get())
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)'''
'''def ConnectPhoneIpDefult(quit = False):
global phoneIp
Return = GetCommandReturn("adb connect '192.168.250.2'")
if quit:
print(Return)
return
messagebox.showinfo(title="提示", message=Return)
phoneIp.append("192.168.250.2")
combobox2['value'] = phoneIp
write_txt(get_home() + "/.config/uengine-runner/PhoneIp.json", str(json.dumps(ListToDictionary(phoneIp)))) # 将历史记录的数组转换为字典并写入
DisabledAndEnbled(False)'''
'''def AdbRun():
Return = GetCommandReturn("adb devices").replace("\n", "").replace("List of devices attached", "").replace("* daemon not running; starting now at tcp:5037", "").replace("* daemon started successfully", "")
if Return is "":
return False
return True'''
'''def AdbConnect():
return GetCommandReturn("adb devices")'''
'''def ShowAdbConnect():
messagebox.showinfo(title="提示", message=AdbConnect())'''
'''def AboutAdb():
messagebox.showinfo(message=GetCommandReturn("adb version"), title="关于 adb")'''
'''def GetAllPackageName():
return GetCommandReturn("adb shell pm list packages")'''
'''def ShowAdbInstallPackage():
mess = tk.Toplevel()
message = ttk.Frame(mess)
mess.resizable(0, 0)
mess.title("所有软件包")
textbox1 = tk.Text(message, width=100)
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
textbox1.insert("0.0", GetAllPackageName())
textbox1.configure(state=tk.DISABLED)
textbox1.pack()
button1.pack(side="bottom")
message.pack()
mess.mainloop()'''

Binary file not shown.