This commit is contained in:
gfdgd xi 2021-09-11 15:51:23 +08:00
parent 74831ea4c2
commit 8057f2a596
8 changed files with 226 additions and 100 deletions

Binary file not shown.

View File

@ -3,7 +3,7 @@
"https://gitee.com/gfdgd-xi/uengine-runner",
"https://github.com/gfdgd-xi/uengine-runner"
],
"Version": "1.4.2",
"Version": "1.4.3",
"System": "Linuxdeepin/UOS",
"Tips": [
"更多可见https://gitee.com/gfdgd-xi/uengine-runner/wikis",

245
main.py
View File

@ -2,8 +2,8 @@
# 使用系统默认的 python3 运行
###########################################################################################
# 作者gfdgd xi<3025613752@qq.com>
# 版本1.4.0
# 更新时间2021年8月26日
# 版本1.4.3
# 更新时间2021年9月11日开学了
# 感谢anbox、deepin 和 UOS
# 基于 Python3 的 tkinter 构建
# 更新actionchen<917981399@qq.com>
@ -99,7 +99,7 @@ def InstallApk(path: "apk 路径", quit: "是否静默安装" = False):
try:
if not os.path.exists("{}/.local/share/applications/uengine/".format(get_home())):
print("Mkdir")
os.mkdir("{}/.local/share/applications/uengine/".format(get_home()))
os.makedirs("{}/.local/share/applications/uengine/".format(get_home()))
print("start install apk")
global findApkHistory
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
@ -454,61 +454,19 @@ def UengineRestart()->"重启 uengine 服务":
os.system("systemctl restart uengine*")
DisabledAndEnbled(False)
# 运行命令的窗口
class InstallWindow():
# 显示窗口
def ShowWindows(command):
global message
global text
global installTipsText
global progressbar
message = tk.Toplevel()
message.iconphoto(False, tk.PhotoImage(file=iconPath))
messageFrame = ttk.Frame(message)
installTipsText = tk.StringVar()
message.title("正在操作……")
installTipsText.set("正在操作……")
installTips = ttk.Label(messageFrame, textvariable=installTipsText)
progressbar = ttk.Progressbar(messageFrame, length=500, mode='indeterminate')
text = tk.Text(messageFrame)
text.config(background="black", foreground="white")
installTips.pack()
progressbar.pack(fill="x")
text.pack(expand='yes', fill='both')
messageFrame.pack(expand='yes', fill='both')
print("Run!")
threading.Thread(target=InstallWindow.RunCommand, args=[command]).start()
message.mainloop()
# 运行命令并显示
def RunCommand(command):
global message
global text
global progressbar
global installTipsText
InstallWindow.AddText("$>" + command + "\n")
progressbar.start()
result = subprocess.getoutput(command)
InstallWindow.AddText(result)
messagebox.showinfo(title="提示", message="操作完毕!")
installTipsText.set("操作完毕!")
message.title("操作完毕!")
progressbar.stop()
progressbar["value"] = 100
# 特意添加!
DisabledAndEnbled(False)
print("Clean!")
if messagebox.askyesno(title="提示", message="清空完毕,将会在重启后生效,是否要重启?"):
print("reboot")
os.system("reboot")
# 添加文本
def AddText(things):
global text
text.configure(state=tk.NORMAL)
text.insert("end", things)
text.configure(state=tk.DISABLED)
def ScrcpyConnectUengine():
if os.path.exists("/snap/bin/scrcpy"):
threading.Thread(target=os.system, args=["/snap/bin/scrcpy -s '192.168.250.2:5555'"]).start()
return
if messagebox.askyesno(title="提示", message="你没有安装Scrcpy指使用Snap安装\n如果你使用了其他方法安装了Scrcpy可以输入命令“scrcpy -s '192.168.250.2:5555'”,\n是否现在要使用Snap安装Scrcpy"):
if not os.path.exists("/tmp/uengine-runner"):
os.makedirs("/tmp/uengine-runner")
write_txt("/tmp/uengine-runner/InstallScrcpy.sh", '''#!/bin/bash
sudo apt install snapd -y
sudo snap refresh
sudo snap install scrcpy''')
threading.Thread(target=InstallWindow.ShowWindows, args=["chmod 777 /tmp/uengine-runner/InstallScrcpy.sh -Rv && pkexec /tmp/uengine-runner/InstallScrcpy.sh"]).start()
return
# 获取用户桌面目录
def get_desktop_path()->"获取用户桌面目录":
@ -554,7 +512,7 @@ def CleanAllUengineDesktopLink():
if messagebox.askokcancel(title="提示", message="你确定要删除所有的 UEngine 应用快捷方式吗?"):
try:
shutil.rmtree("{}/.local/share/applications/uengine".format(get_home()))
os.mkdir("{}/.local/share/applications/uengine".format(get_home()))
os.makedirs("{}/.local/share/applications/uengine".format(get_home()))
messagebox.showinfo(title="提示", message="删除完毕!")
except:
traceback.print_exc()
@ -632,6 +590,124 @@ def AdbAndroidInstallAppList():
subprocess.getoutput("adb -s 192.168.250.2:5555 shell pm list package -3"),
subprocess.getoutput("adb -s 192.168.250.2:5555 shell pm list packages -f")))
class AdbChangeUengineDisplaySize():
def ShowWindows():
global displayX
global displayY
global displaySize
message = tk.Toplevel()
messageFrame = ttk.Frame(message)
displaySize = tk.StringVar()
displaySize.set("当前 UEngine 屏幕分辨率:正在获取")
displaySizeLabel = ttk.Label(messageFrame, textvariable=displaySize)
input = ttk.Frame(messageFrame)
displayX = ttk.Entry(input)
displayY = ttk.Entry(input)
settingBUtton = ttk.Button(messageFrame, text="设置分辨率", command=AdbChangeUengineDisplaySize.SettingDisplaySize)
message.title("修改 UEngine 分辨率")
message.resizable(0, 0)
message.iconphoto(False, tk.PhotoImage(file=iconPath))
# get screen width and height
screen_width = message.winfo_screenwidth()
screen_height = message.winfo_screenheight()
# calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。
winwith=570
winhigh=236
x = (screen_width/2) - (winwith/2)
y = (screen_height/2) - (winhigh/2)
message.geometry("+{}+{}".format(int(x), int(y)))
displayX.grid(row=0, column=0)
displayY.grid(row=0, column=1)
displaySizeLabel.grid(row=0, column=0)
input.grid(row=1, column=0)
settingBUtton.grid(row=2, column=0)
messageFrame.pack()
threading.Thread(target=AdbChangeUengineDisplaySize.GetUengineDisplaySize).start()
message.mainloop()
def GetUengineDisplaySize():
global displaySize
displaySize.set("当前 UEngine 屏幕分辨率:\n" + subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size"))
#displaySize.set(subprocess.getoutput("adb -s '192.168.250.2:5555' shell wm size"))
def SettingDisplaySize():
global displayX
global displayY
try:
int(displayX.get())
int(displayY.get())
except:
messagebox.showerror(title="错误", message="你输入的数值不正确!")
return
os.system("adb -s '192.168.250.2:5555' shell wm size {}x{}".format(displayX.get(), displayY.get()))
AdbChangeUengineDisplaySize.GetUengineDisplaySize()
messagebox.showinfo(title="提示", message="执行完毕!")
# 运行命令的窗口
class InstallWindow():
# 显示窗口
def ShowWindows(command):
global message
global text
global installTipsText
global progressbar
global runCommand
message = tk.Toplevel()
message.iconphoto(False, tk.PhotoImage(file=iconPath))
messageFrame = ttk.Frame(message)
installTipsText = tk.StringVar()
message.title("正在操作……")
installTipsText.set("正在操作……")
installTips = ttk.Label(messageFrame, textvariable=installTipsText)
progressbar = ttk.Progressbar(messageFrame, length=500, mode='indeterminate')
text = tk.Text(messageFrame)
text.config(background="black", foreground="white")
installTips.pack()
progressbar.pack(fill="x")
text.pack(expand='yes', fill='both')
messageFrame.pack(expand='yes', fill='both')
print("Run!")
threading.Thread(target=InstallWindow.RunCommand, args=[command]).start()
message.mainloop()
# 运行命令并显示
def RunCommand(command):
global message
global text
global progressbar
global installTipsText
InstallWindow.AddText("$>" + command + "\n")
progressbar.start()
result = subprocess.getoutput(command)
InstallWindow.AddText(result)
messagebox.showinfo(title="提示", message="操作完毕!")
installTipsText.set("操作完毕!")
message.title("操作完毕!")
progressbar.stop()
progressbar["value"] = 100
# 特意添加!
DisabledAndEnbled(False)
if command == "pkexec rm -rfv /data/uengine":
print("Clean!")
if messagebox.askyesno(title="提示", message="清空完毕,将会在重启后生效,是否要重启?"):
print("reboot")
os.system("reboot")
# 添加文本
def AddText(things):
global text
text.configure(state=tk.NORMAL)
text.insert("end", things)
text.configure(state=tk.DISABLED)
class ShowTextTipsWindow():
def ShowWindow(things):
message = tk.Toplevel()
@ -749,6 +825,27 @@ class AddNewUengineDesktopLink():
activityName.set(GetApkActivityName(path))
write_txt(get_home() + "/.config/uengine-runner/FindApkName.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
def UseProgram():
global useProgram
useProgram = '''1、UEngine{}
2python3{}
3tkinter{}
4aapt{}
5dpkg{}
6mkdir{}
7echo
8chmod{}
9adb{}
10deepin 终端{}'''.format(subprocess.getoutput("uengine version"),
subprocess.getoutput("python3 --version"),
tk.TkVersion,
subprocess.getoutput("aapt version"),
subprocess.getoutput("dpkg --version"),
subprocess.getoutput("mkdir --version"),
subprocess.getoutput("chmod --version"),
subprocess.getoutput("adb version"),
subprocess.getoutput("deepin-terminal -v"))
###########################
# 程序信息
###########################
@ -776,33 +873,16 @@ iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
desktop = programPath + "/UengineAndroidProgramList.desktop"
desktopName = "UengineAndroidProgramList.desktop"
contribute = "\n".join(information["Contribute"])
useProgram = '''1、UEngine{}
2python3{}
3tkinter{}
4aapt{}
5dpkg{}
6mkdir{}
7echo
8chmod{}
9adb{}
10deepin 终端{}'''.format(subprocess.getoutput("uengine version"),
subprocess.getoutput("python3 --version"),
tk.TkVersion,
subprocess.getoutput("aapt version"),
subprocess.getoutput("dpkg --version"),
subprocess.getoutput("mkdir --version"),
subprocess.getoutput("chmod --version"),
subprocess.getoutput("adb version"),
subprocess.getoutput("deepin-terminal -v"))
useProgram = ""
threading.Thread(target=UseProgram).start()
###########################
# 加载配置
###########################
if not os.path.exists("{}/.local/share/applications/uengine/".format(get_home())):
os.mkdir("{}/.local/share/applications/uengine/".format(get_home()))
os.makedirs("{}/.local/share/applications/uengine/".format(get_home()))
if not os.path.exists(get_home() + "/.config/uengine-runner"): # 如果没有配置文件夹
os.mkdir(get_home() + "/.config/uengine-runner") # 创建配置文件夹
os.makedirs(get_home() + "/.config/uengine-runner") # 创建配置文件夹
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/FindApkNameHistory.json"): # 如果没有配置文件
@ -885,6 +965,9 @@ def showhelp():
def ChgAbout():
HelpStr.set(about)
def ChgDep():
if useProgram == "":
BtnZujian.configure(state=tk.DISABLED)
return
HelpStr.set(useProgram)
def ChgCon():
HelpStr.set(contribute)
@ -987,9 +1070,11 @@ adb.add_separator()
adb.add_cascade(label="adb 服务", menu=adbServer)
adb.add_command(label="显示 adb 连接的设备", command=AdbConnectDeviceShow)
adb.add_separator()
adb.add_command(label="adb 修改 UEngine 分辨率", command=AdbChangeUengineDisplaySize.ShowWindows)
adb.add_command(label="adb 查看 UEngine 应用列表", command=AdbAndroidInstallAppList)
adb.add_command(label="adb 查看 UEngine 资源使用情况", command=AdbCPUAndRAWShowInTer)
adb.add_command(label="打开 adb 连接 UEngine 的终端", command=AdbShellShowInTer)
adb.add_command(label="使用 Scrcpy 连接 UEngine只支持使用snap安装的Scrcpy", command=ScrcpyConnectUengine)
adb.add_separator()
adb.add_cascade(label="UEngine 使用 adb", menu=uengineUseAdb)

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>gfdgd xi</vendor>
<vendor_url>https://gitee.com/gfdgd-xi/uengine-runner/</vendor_url>
<action id="com.deepin.pkexec.installscrcpy">
<message>Authentication is required to Install Scrcpy</message>
<message xml:lang="zh_CN">安装 Scrcpy 需要输入密码</message>
<icon_name>preferences-system</icon_name>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/tmp/uengine-runner/InstallScrcpy.sh</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>

View File

@ -1,6 +1,6 @@
{
"Package": "com.gitee.uengine.runner.spark",
"Update": true,
"Version": "1.4.2",
"Version": "1.4.3",
"Url": "https://gfdgd-xi.github.io/update-program/data/UpdateInformation.json"
}

View File

@ -1,7 +1,7 @@
{
"Package": "spark-uengine-runner",
"Update": true,
"Version": "1.4.2",
"Version": "1.4.3",
"Url": "https://gfdgd-xi.github.io/update-program/data/UpdateInformation.json"
}

View File

@ -187,6 +187,7 @@ def DisabledAndEnbled(choose):
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
a = userChoose[choose]
combobox1.configure(state=a)
check.configure(state=a)
button2.configure(state=a)
button3.configure(state=a)
@ -256,6 +257,7 @@ def GetApkActivityName(apkFilePath):
return line
def GetApkPackageName(apkFilePath):
# 提示:此函数有被为此程序适配而调整,如果需要最原始(无调整的)请使用主程序(此为附属组件)里的函数
info = GetApkInformation(apkFilePath)
for line in info.split('\n'):
if "package:" in line:
@ -264,7 +266,10 @@ def GetApkPackageName(apkFilePath):
line = line.replace("name=", "")
line = line.replace("'", "")
line = line.replace(" ", "")
return line
# 此较为特殊,因为需要判断用户是否要添加前缀
if qianZhui.get() == True:
return "uengine-dc-{}".format(line).lower()
return line.lower()
def GetApkVersion(apkFilePath):
info = GetApkInformation(apkFilePath)
@ -381,7 +386,7 @@ iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
# 加载配置
###########################
if not os.path.exists(get_home() + "/.config/uengine-runner"): # 如果没有配置文件夹
os.mkdir(get_home() + "/.config/uengine-runner") # 创建配置文件夹
os.makedirs(get_home() + "/.config/uengine-runner") # 创建配置文件夹
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApkBuildHistory.json"): # 如果没有配置文件
write_txt(get_home() + "/.config/uengine-runner/FindApkBuildHistory.json", json.dumps({})) # 创建配置文件
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApkBuild.json"): # 如果没有配置文件
@ -396,34 +401,40 @@ findApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/F
# 窗口创建
###########################
win = tk.Tk()
qianZhui = tk.BooleanVar()
window = ttk.Frame(win)
style = ttkthemes.ThemedStyle(win)
style.set_theme("breeze")
win.attributes('-alpha', 0.5)
win.title(title)
win.resizable(0, 0)
win.iconphoto(False, tk.PhotoImage(file=iconPath))
frame2 = ttk.Frame(window)
label1 = ttk.Label(window, text="要打包的 apk 路径:")
combobox1 = ttk.Combobox(window, width=100)
button2 = ttk.Button(window, text="浏览", command=FindApk)
button3 = ttk.Button(frame2, text="打包", command=BuildDeb)
check = ttk.Checkbutton(frame2, variable=qianZhui,text="使用前缀“uengine-dc”")
textbox1 = tk.Text(window, width=100)
menu = tk.Menu(window, background="white") # 设置菜单栏
programmenu = tk.Menu(menu, tearoff=0, background="white") # 设置“程序”菜单栏
menu.add_cascade(label="程序", menu=programmenu)
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
# 设置控件
combobox1['value'] = findApkHistory
textbox1.configure(state=tk.DISABLED)
textbox1.config(foreground='white', background='black')
# 设置窗口
style = ttkthemes.ThemedStyle(win)
style.set_theme("breeze")
win.attributes('-alpha', 0.5)
win.title(title)
win.resizable(0, 0)
win.iconphoto(False, tk.PhotoImage(file=iconPath))
#
win.config(menu=menu) # 显示菜单栏
label1.grid(row=2, column=0)
combobox1.grid(row=2, column=1)
#button1.grid(column=0, row=0)
button2.grid(row=2, column=2)
button3.grid(row=0, column=0)
button3.grid(row=0, column=1)
check.grid(row=0, column=0)
frame2.grid(row=3, columnspa=3)
textbox1.grid(row=4, columnspa=3)
window.pack()

View File

@ -2,8 +2,8 @@
# 使用系统默认的 python3 运行
###########################################################################################
# 作者gfdgd xi
# 版本1.4.2
# 更新时间2021年8月30
# 版本1.4.3
# 更新时间2021年9月11
# 感谢anbox、deepin 和 统信
# 基于 Python3 的 tkinter 构建
###########################################################################################
@ -11,6 +11,7 @@
# 引入所需的库
#################
import os
import threading
import time
import json
import ttkthemes
@ -52,7 +53,16 @@ iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
desktopName = "UengineAndroidProgramList.desktop"
contribute = "\n".join(information["Contribute"])
useProgram = '''1、UEngine{}
useProgram = ""
threading.Thread(target=useProgram).start()
# add sub window
#添加窗口开启关闭开关,防止重复开启
windowflag = "close"
def UseProgram():
global useProgram
useProgram = '''1、UEngine{}
2、python3{}
3、tkinter{}
4、aapt{}
@ -71,10 +81,6 @@ useProgram = '''1、UEngine{}
subprocess.getoutput("adb version"),
subprocess.getoutput("deepin-terminal -v"))
# add sub window
#添加窗口开启关闭开关,防止重复开启
windowflag = "close"
def showhelp():
#define window and frame and button label
@ -127,6 +133,9 @@ def showhelp():
def ChgAbout():
HelpStr.set(about)
def ChgDep():
if useProgram == "":
BtnZujian.configure(state=tk.DISABLED)
return
HelpStr.set(useProgram)
def ChgCon():
HelpStr.set(contribute)