From 8057f2a596f6884894f730a99594ed230203eb95 Mon Sep 17 00:00:00 2001 From: gfdgd xi <3025613752@qq.com> Date: Sat, 11 Sep 2021 15:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/getxmlimg.cpython-37.pyc | Bin 3192 -> 3192 bytes information.json | 2 +- main.py | 245 ++++++++++++------ pkexec/com.deepin.pkexec.installscrcpy.policy | 21 ++ setting-new.json | 2 +- setting.json | 2 +- uengine-apk-builder | 31 ++- uengine-runner-about | 23 +- 8 files changed, 226 insertions(+), 100 deletions(-) create mode 100644 pkexec/com.deepin.pkexec.installscrcpy.policy diff --git a/__pycache__/getxmlimg.cpython-37.pyc b/__pycache__/getxmlimg.cpython-37.pyc index 20ff321f019a4f686448d0003f0fa637b1ee09d9..3b6c41dcaadc7bb2305717cbaba89aa570331bb4 100644 GIT binary patch delta 20 acmew%@k4^!iI -# 版本: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:{} +2、python3:{} +3、tkinter:{} +4、aapt:{} +5、dpkg:{} +6、mkdir:{} +7、echo +8、chmod:{} +9、adb:{} +10、deepin 终端:{}'''.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:{} -2、python3:{} -3、tkinter:{} -4、aapt:{} -5、dpkg:{} -6、mkdir:{} -7、echo -8、chmod:{} -9、adb:{} -10、deepin 终端:{}'''.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) diff --git a/pkexec/com.deepin.pkexec.installscrcpy.policy b/pkexec/com.deepin.pkexec.installscrcpy.policy new file mode 100644 index 0000000..c8abc1b --- /dev/null +++ b/pkexec/com.deepin.pkexec.installscrcpy.policy @@ -0,0 +1,21 @@ + + + + gfdgd xi + https://gitee.com/gfdgd-xi/uengine-runner/ + + Authentication is required to Install Scrcpy + 安装 Scrcpy 需要输入密码 + preferences-system + + no + no + auth_admin_keep + + /tmp/uengine-runner/InstallScrcpy.sh + true + + + \ No newline at end of file diff --git a/setting-new.json b/setting-new.json index 947fc53..df22307 100755 --- a/setting-new.json +++ b/setting-new.json @@ -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" } \ No newline at end of file diff --git a/setting.json b/setting.json index eb69668..6d79538 100755 --- a/setting.json +++ b/setting.json @@ -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" } \ No newline at end of file diff --git a/uengine-apk-builder b/uengine-apk-builder index fbaf1ba..9949d94 100755 --- a/uengine-apk-builder +++ b/uengine-apk-builder @@ -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() diff --git a/uengine-runner-about b/uengine-runner-about index c4330e7..440f333 100755 --- a/uengine-runner-about +++ b/uengine-runner-about @@ -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)