Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d01423853a | |||
| d486fa55d8 | |||
|
|
73d1e3b484 | ||
| ce52b8579a | |||
| fcc37f707e | |||
| 908177b69d | |||
| 89702f681e | |||
| 7786c7b855 | |||
|
|
2c75309d75 | ||
| 38b19ed2d2 | |||
| dcc92846be | |||
| ec8e48aff3 | |||
| 35db9dc361 | |||
| 2da3e3962b | |||
| d749ece476 | |||
| 7beb35d1de | |||
| de71e3b01e | |||
| 0dd7858097 | |||
| 81e2346fc8 | |||
| 1b74fcde2f | |||
| b07d24202e | |||
| 85cf28d552 | |||
| 1c83689a6b | |||
| e6680c9340 | |||
| cd80f32a4b |
131
README.md
@@ -1,46 +1,141 @@
|
||||
# uengine 运行器
|
||||
# uengine 运行器 1.3.1
|
||||
|
||||
#### 介绍
|
||||
### 介绍
|
||||
新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的Uengine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
|
||||

|
||||
(测试平台:UOS 家庭版,deepin 20.2.2,UOS 专业版 1040)
|
||||
(自己美术功底太差,图标直接用 anbox 的了)
|
||||
|
||||
使用 Python3 的 tkinter 构建
|
||||
### 更新内容
|
||||
|
||||
(测试平台:UOS 家庭版)
|
||||
#### V1.3.1:
|
||||
**※1、修复打包问题,防止部分用户安装出错的问题;**
|
||||
**※2、修复了程序无法提取图标时可以提取默认图标使用;**
|
||||

|
||||
|
||||
(自己美术功底太差,图标直接用 anbox 的了)
|
||||
#### V1.3.0:
|
||||
**※1、修改了界面布局;**
|
||||
**※2、修复大多数新安装普通用户的路图标及启动菜单文件路径不存在导致安装APK报错的bugs;**
|
||||
3、删除少量冗余代码,调整代码顺序;
|
||||
4、支持提取 apk 图标。
|
||||

|
||||
|
||||
#### 软件架构
|
||||
i386 和 amd64
|
||||
#### V1.2.3:
|
||||
1、调整部分控件名称;
|
||||
2、调整界面布局及界面风格;
|
||||

|
||||
|
||||
#### V1.2.2:
|
||||
1、对程序错误的显示更加人性化;
|
||||
2、对 icon 的获取方式进行了升级;
|
||||
3、增加了注释、删除部分冗余代码。
|
||||

|
||||
|
||||
#### 源码安装教程
|
||||
#### V1.2.1:
|
||||
**※1、进行了安装方式的修改(不使用 adb),修复原无法安装和卸载的问题;**
|
||||
2、进行了部分优化;
|
||||
3、进行了功能缩水;
|
||||
4、修复 deb 打包错误。
|
||||

|
||||
|
||||
#### V1.2.0:
|
||||
1、支持安装自动添加快捷方式、卸载删除快捷方式;
|
||||
2、支持使用包名或 APK 文件卸载程序;
|
||||
3、支持查看安装的所有包名;
|
||||
4、进行了部分优化
|
||||

|
||||
|
||||
### 源码安装教程
|
||||
按下 <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>T</kbd> 打开终端,按以下内容操作:
|
||||
1. 安装所需依赖
|
||||
|
||||
```
|
||||
sudo apt install python3 python3-tk git adb
|
||||
```bash
|
||||
sudo apt install python3 python3-tk git python3-pip aapt uengine
|
||||
python3 -m pip install ttkthemes
|
||||
```
|
||||
|
||||
2. 下载本程序
|
||||
|
||||
```
|
||||
```bash
|
||||
git clone https://gitee.com/gfdgd-xi/uengine-runner.git
|
||||
```
|
||||
|
||||
3. 运行本程序
|
||||
|
||||
```
|
||||
cd uengine-runner
|
||||
chmod 777 main.py
|
||||
```bash
|
||||
sudo mkdir /opt/apps/uengine-runner
|
||||
sudo cp uengine-runner /opt/apps/uengine-runner -rv
|
||||
sudo cp getxmlimg.py /opt/apps/uengine-runner -rv
|
||||
sudo cp icon.png /opt/apps/uengine-runner -rv
|
||||
chmod 777 /opt/apps/uengine-runner/main.py
|
||||
sudo cp /opt/apps/uengine-runner/main.py /usr/bin/uengine-runner
|
||||
./main.py
|
||||
```
|
||||
|
||||
4. 卸载本程序
|
||||
```bash
|
||||
sudo rm /usr/bin/uengine-runner -v
|
||||
sudo rm /opt/apps/uengine-runner/ -rfv
|
||||
pip3 uninstall ttkthemes
|
||||
```
|
||||
|
||||
#### 使用说明
|
||||
### 使用说明
|
||||
1、需要你有使用 root 权限的能力;
|
||||
2、需要安装 uengine 才能使用,UOS建议在商店安装一个安卓应用,让系统自动安装uengine及相关的依赖包;
|
||||
3、提取 apk 图标的 apk 路径以“安装 apk”那栏为准;
|
||||
4、如果报错是有关产生 .deksotp 文件有关,一般可以打开程序列表运行。如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
|
||||
|
||||
提示:
|
||||
### 故障排除
|
||||
提 issue 最好,当然有些问题自己无法解决,请大佬 push 一下
|
||||
如果出现故障,尝试终端运行,如果是可以自行解决的问题,就**自行解决**,如果可以就**提 issues 并提供解决方案**,不行就**提 isscue 并提供程序和终端报错以及程序版本**
|
||||
|
||||
None
|
||||
### 已知问题
|
||||

|
||||
部分 app 无法读取出图片,已知:
|
||||
| 程序 | 下载链接 |
|
||||
| :-: | :-: |
|
||||
| Firefox For Android | https://www.firefox.com.cn/download/ |
|
||||
| 网易云音乐 For Android | https://music.163.com/#/download |
|
||||
| 抖音 | https://www.wandoujia.com/apps/7461948 |
|
||||
| 360 手机浏览器 | https://mse.360.cn/ |
|
||||
| E-Go | 忘了 |
|
||||
| 其他待测试…… | 其他待测试…… |
|
||||
**注意:提取不出图标不代表未安装成功!**
|
||||
|
||||
|
||||
#### 特技
|
||||
### 贡献
|
||||
我非常欢迎大家的贡献
|
||||
有通过贡献的开发者列表:
|
||||
| 开发者 | 邮箱 |
|
||||
| :-: | :-: |
|
||||
| gfdgd xi | 3025613752@qq.com |
|
||||
| actionchen | 917981399@qq.com |
|
||||
|
||||
### 相关项目
|
||||
| 项目名称 | 项目地址 |
|
||||
| :-: | :-:|
|
||||
| uengine-installer | https://gitee.com/Maicss/uengine-installer |
|
||||
| uengine APK 打包器 | https://gitee.com/gfdgd-xi/uengine-apk-builder |
|
||||
|
||||
### 附测试生成图标无问题列表:
|
||||
**至于能不能用就不测试了,这暂时不是重点**
|
||||
| 程序 | 下载链接 |
|
||||
|:-:|:-:|
|
||||
| QQ 全家桶(完整版、极速版、Android Pad 版) | https://im.qq.com |
|
||||
| TIM | 忘了 |
|
||||
| 微信 | https://weixin.qq.com |
|
||||
| 百度翻译 | 忘了 |
|
||||
| 百度网盘 | https://pan.baidu.com |
|
||||
| 腾讯课堂 | 忘了 |
|
||||
| 抖音极速版 | 忘了 |
|
||||
| 豌豆荚 | 忘了 |
|
||||
| 小猿口算 | 忘了 |
|
||||
| Hyperbowl | 忘了 |
|
||||
| bilibili | https://d.bilibili.com/download_app.html?bsource=app_bili |
|
||||
| 蓝奏云 | https://up.woozooo.com/lanzouh5.apk |
|
||||
| QQ 音乐(完整版、Android Pad 版、TV 版、车载版) | https://y.qq.com/download/index.html |
|
||||
| 360 手机卫士(完整版、极速版) | https://shouji.360.cn/v6/index.html |
|
||||
| 360 清理大师(稳定版、尝鲜版) | http://shouji.360.cn/360cleandroid/ |
|
||||
| 360 手机助手 | http://sj.360.cn/index.html |
|
||||
| WPS Office For Android | https://www.wps.cn/ |
|
||||
| 钉钉 for android | https://page.dingtalk.com/wow/dingtalk/act/download?spm=a3140.8196062.0.0.6f4c5c3dWBhYUM |
|
||||
BIN
__pycache__/getxmlimg.cpython-37.pyc
Normal file
@@ -1,9 +1,9 @@
|
||||
Package: spark-uengine-runner
|
||||
Version: 1.0.0
|
||||
Maintainer: gfdgd xi <3025613752@qq.com>
|
||||
Version: 1.3.1
|
||||
Maintainer: gfdgd xi <3025613752@qq.com>, actionchen<917981399@qq.com>
|
||||
Homepage: https://gitee.com/gfdgd-xi/uengine-runner
|
||||
Architecture: all
|
||||
Priority: optional
|
||||
Depends: python3, python3-tk, adb, python3-pip
|
||||
Depends: python3, python3-tk, python3-pip, aapt, uengine, python3-pil, python3-setuptools
|
||||
Description: gfdgd xi make's uengine runner
|
||||
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
# !/bin/sh
|
||||
sudo pip3 install --upgrade pip
|
||||
sudo pip3 install --upgrade virtualenv
|
||||
pip3 install pillow
|
||||
# !/bin/sh
|
||||
python3 -m pip install --upgrade ttkthemes
|
||||
@@ -1,46 +1,102 @@
|
||||
# uengine 运行器
|
||||
# uengine 运行器 1.3.0
|
||||
|
||||
#### 介绍
|
||||
### 介绍
|
||||
新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的Uengine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
|
||||

|
||||
(测试平台:UOS 家庭版,deepin 20.2.2)
|
||||
(自己美术功底太差,图标直接用 anbox 的了)
|
||||
|
||||
使用 Python3 的 tkinter 构建
|
||||
### 更新内容
|
||||
|
||||
(测试平台:UOS 家庭版)
|
||||
#### V1.3.0:
|
||||
**※1、修改了界面布局;**
|
||||
**※2、修复大多数新安装普通用户的路图标及启动菜单文件路径不存在导致安装APK报错的bugs;**
|
||||
3、删除少量冗余代码,调整代码顺序;
|
||||
4、支持提取 apk 图标。
|
||||

|
||||
|
||||
(自己美术功底太差,图标直接用 anbox 的了)
|
||||
#### V1.2.3:
|
||||
1、调整部分控件名称;
|
||||
2、调整界面布局及界面风格;
|
||||

|
||||
|
||||
#### 软件架构
|
||||
i386 和 amd64
|
||||
#### V1.2.2:
|
||||
1、对程序错误的显示更加人性化;
|
||||
2、对 icon 的获取方式进行了升级;
|
||||
3、增加了注释、删除部分冗余代码。
|
||||

|
||||
|
||||
#### V1.2.1:
|
||||
**※1、进行了安装方式的修改(不使用 adb),修复原无法安装和卸载的问题;**
|
||||
2、进行了部分优化;
|
||||
3、进行了功能缩水;
|
||||
4、修复 deb 打包错误。
|
||||

|
||||
|
||||
#### 源码安装教程
|
||||
#### V1.2.0:
|
||||
1、支持安装自动添加快捷方式、卸载删除快捷方式;
|
||||
2、支持使用包名或 APK 文件卸载程序;
|
||||
3、支持查看安装的所有包名;
|
||||
4、进行了部分优化
|
||||

|
||||
|
||||
### 源码安装教程
|
||||
|
||||
1. 安装所需依赖
|
||||
|
||||
```
|
||||
sudo apt install python3 python3-tk git adb
|
||||
```bash
|
||||
sudo apt install python3 python3-tk git python3-pip aapt uengine
|
||||
python3 -m pip install ttkthemes
|
||||
```
|
||||
|
||||
2. 下载本程序
|
||||
|
||||
```
|
||||
```bash
|
||||
git clone https://gitee.com/gfdgd-xi/uengine-runner.git
|
||||
```
|
||||
|
||||
3. 运行本程序
|
||||
|
||||
```
|
||||
cd uengine-runner
|
||||
chmod 777 main.py
|
||||
```bash
|
||||
sudo mkdir /opt/apps/uengine-runner
|
||||
sudo cp uengine-runner /opt/apps/uengine-runner -rv
|
||||
sudo cp getxmlimg.py /opt/apps/uengine-runner -rv
|
||||
sudo cp icon.png /opt/apps/uengine-runner -rv
|
||||
chmod 777 /opt/apps/uengine-runner/main.py
|
||||
sudo cp /opt/apps/uengine-runner/main.py /usr/bin/uengine-runner
|
||||
./main.py
|
||||
```
|
||||
|
||||
4. 卸载本程序
|
||||
```bash
|
||||
sudo rm /usr/bin/uengine-runner -v
|
||||
sudo rm /opt/apps/uengine-runner/ -rfv
|
||||
pip3 uninstall ttkthemes
|
||||
```
|
||||
|
||||
#### 使用说明
|
||||
### 使用说明
|
||||
1、需要你有使用 root 权限的能力;
|
||||
2、需要安装 uengine 才能使用;
|
||||
3、提取 apk 图标的 apk 路径以“安装 apk”那栏为准;
|
||||
4、如果报错是有关产生 .deksotp 文件有关,一般可以打开程序列表运行。如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
|
||||
|
||||
提示:
|
||||
### 故障排除
|
||||
提 isscue 最好,当然有些问题自己无法解决,请大佬 push 一下
|
||||
如果出现故障,尝试终端运行,如果是可以自行解决的问题,就**自行解决**,如果可以就**提 issues 并提供解决方案**,不行就**提 isscue 并提供程序和终端报错以及程序版本**
|
||||
|
||||
None
|
||||
### 已知问题
|
||||
暂未发现
|
||||
|
||||
### 贡献
|
||||
我非常欢迎大家的贡献
|
||||
有通过贡献的开发者列表:
|
||||
| 开发者 | 邮箱 |
|
||||
| :-: | :-: |
|
||||
| gfdgd xi | 3025613752@qq.com |
|
||||
| actionchen | 917981399@qq.com |
|
||||
|
||||
#### 特技
|
||||
|
||||
### 相关项目
|
||||
| 项目名称 | 项目地址 |
|
||||
| :-: | :-:|
|
||||
| uengine-installer | https://gitee.com/Maicss/uengine-installer |
|
||||
| uengine APK 打包器 | https://gitee.com/gfdgd-xi/uengine-apk-builder |
|
||||
BIN
build/opt/apps/uengine-runner/defult.png
Executable file
|
After Width: | Height: | Size: 312 KiB |
115
build/opt/apps/uengine-runner/getxmlimg.py
Normal file
@@ -0,0 +1,115 @@
|
||||
import PIL.Image as Image
|
||||
import PIL.ImageDraw as ImageDraw
|
||||
import zipfile
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
class getsavexml():
|
||||
|
||||
def savexml(self,apkFilePath,xmlpath,iconSavePath):
|
||||
cmddumpid = "aapt dump xmltree "+ apkFilePath + " " + xmlpath
|
||||
print(cmddumpid)
|
||||
xmltree = subprocess.getoutput(cmddumpid)
|
||||
xmls = xmltree.splitlines()
|
||||
# find strs ,print next line
|
||||
def FindStrs(lines,strs):
|
||||
i=0
|
||||
while i < len(lines):
|
||||
if re.search(strs,lines[i]):
|
||||
tmpstr = lines[i+1]
|
||||
i += 1
|
||||
Resultstr = tmpstr.split(":")[-1].split("=")[-1].split("0x")[-1]
|
||||
return Resultstr
|
||||
else:
|
||||
i += 1
|
||||
#从apk的信息中获取前后景图片的ID号
|
||||
backimgid = FindStrs(xmls,"background")
|
||||
foreimgid = FindStrs(xmls,"foreground")
|
||||
print(backimgid)
|
||||
print(foreimgid)
|
||||
|
||||
# 直接从apk resource文件获取前后两层图片路径及ID字符串
|
||||
resource = subprocess.getoutput("aapt dump --values resources " + apkFilePath + "| grep -iE -A1 " + "\"" + backimgid + "|" + foreimgid + "\"")
|
||||
resourcelines = resource.splitlines()
|
||||
print(resourcelines)
|
||||
|
||||
# 从过滤出的字符串中获取所有相同ID的图片路径
|
||||
def Findpicpath(lines,imgid):
|
||||
i=0
|
||||
Resultstr = []
|
||||
while i < len(lines):
|
||||
if re.search(imgid,lines[i]) and re.search("string8",lines[i+1]) :
|
||||
print(lines[i+1])
|
||||
tmpstr = lines[i+1].replace("\"","")
|
||||
i += 1
|
||||
Resultstr.append(tmpstr.split()[-1])
|
||||
else:
|
||||
i += 1
|
||||
return Resultstr
|
||||
|
||||
#获取所有带前后图片ID的图片路径(相同背景或者前景的图片ID但分辨率不一样)
|
||||
backimgs = Findpicpath(resourcelines,backimgid)
|
||||
foreimgs = Findpicpath(resourcelines,foreimgid)
|
||||
|
||||
#获取分辨率最高的图片路径
|
||||
def getmaxsize(imgs):
|
||||
j = 0
|
||||
size=(0,0)
|
||||
zipapk = zipfile.ZipFile(apkFilePath)
|
||||
while j < len(imgs):
|
||||
img = Image.open(zipapk.open(imgs[j]))
|
||||
print(imgs[j])
|
||||
print(img.size)
|
||||
if size < img.size:
|
||||
size = img.size
|
||||
imgpath = imgs[j]
|
||||
j += 1
|
||||
return imgpath
|
||||
|
||||
# 获取到文件列表后,进行比较分辨率,选取分辨率最高的张图片
|
||||
iconbackpath = getmaxsize(backimgs)
|
||||
iconforepath = getmaxsize(foreimgs)
|
||||
print(iconbackpath + " " + iconforepath)
|
||||
|
||||
#从APK文件获取最终图片
|
||||
zipapk = zipfile.ZipFile(apkFilePath)
|
||||
iconback = zipapk.open(iconbackpath)
|
||||
iconfore = zipapk.open(iconforepath)
|
||||
|
||||
|
||||
# 叠加图片,mask 设置前景为蒙版
|
||||
iconbackimg = Image.open(iconback).convert("RGBA")
|
||||
iconforeimg = Image.open(iconfore).convert("RGBA")
|
||||
iconbackimg.paste(iconforeimg,mask=iconforeimg)
|
||||
|
||||
|
||||
# 圆角图片函数,网上拷贝的
|
||||
def circle_corner(img, radii): #把原图片变成圆角,这个函数是从网上找的,原址 https://www.pyget.cn/p/185266
|
||||
"""
|
||||
圆角处理
|
||||
:param img: 源图象。
|
||||
:param radii: 半径,如:30。
|
||||
:return: 返回一个圆角处理后的图象。
|
||||
"""
|
||||
# 画圆(用于分离4个角)
|
||||
circle = Image.new('L', (radii * 2, radii * 2), 0) # 创建一个黑色背景的画布
|
||||
draw = ImageDraw.Draw(circle)
|
||||
draw.ellipse((0, 0, radii * 2, radii * 2), fill=255) # 画白色圆形
|
||||
# 原图
|
||||
img = img.convert("RGBA")
|
||||
w, h = img.size
|
||||
# 画4个角(将整圆分离为4个部分)
|
||||
alpha = Image.new('L', img.size, 255)
|
||||
alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0)) # 左上角
|
||||
alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0)) # 右上角
|
||||
alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii)) # 右下角
|
||||
alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii)) # 左下角
|
||||
# alpha.show()
|
||||
img.putalpha(alpha) # 白色区域透明可见,黑色区域不可见
|
||||
return img
|
||||
|
||||
# 圆角半径1/8边长,保存icon图片
|
||||
w,h = iconbackimg.size
|
||||
iconimg = circle_corner(iconbackimg,int(w/8))
|
||||
iconimg.save(iconSavePath)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
# 使用系统默认的 python3 运行
|
||||
###########################################################################################
|
||||
# 作者:gfdgd xi
|
||||
# 版本:1.0.0
|
||||
# 更新时间:2021年
|
||||
# 感谢:
|
||||
# 作者:gfdgd xi<3025613752@qq.com>
|
||||
# 版本:1.3.0
|
||||
# 更新时间:2021年8月08日
|
||||
# 感谢:anbox、deepin 和 UOS
|
||||
# 基于 Python3 的 tkinter 构建
|
||||
# 更新:actionchen<917981399@qq.com>
|
||||
###########################################################################################
|
||||
#################
|
||||
# 引入所需的库
|
||||
@@ -15,119 +16,179 @@ import sys
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
import zipfile
|
||||
import traceback
|
||||
import threading
|
||||
import ttkthemes
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.messagebox as messagebox
|
||||
import tkinter.filedialog as filedialog
|
||||
import PIL.Image as Image
|
||||
import PIL.ImageTk as ImageTk
|
||||
from getxmlimg import getsavexml
|
||||
from tkinter.constants import TOP
|
||||
|
||||
def KillAdbProgress():
|
||||
DisabledAndEnbled(True)
|
||||
Return = GetCommandReturn("killall adb")
|
||||
if Return is "":
|
||||
Return = "OK!"
|
||||
messagebox.showinfo(title="tips", message=Return)
|
||||
DisabledAndEnbled(False)
|
||||
# 卸载程序
|
||||
def UninstallProgram(package: "apk 包名")->"卸载程序":
|
||||
try:
|
||||
global fineUninstallApkHistory
|
||||
Return = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(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(ComboUninstallPath.get())
|
||||
ComboUninstallPath['value'] = fineUninstallApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
return Return
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
def Button1Click():
|
||||
if combobox2.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
def BtnFindUninstallApkClk():
|
||||
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:
|
||||
ComboUninstallPath.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
except:
|
||||
pass
|
||||
|
||||
def ButtonClick8():
|
||||
if ComboUninstallPath.get() is "":
|
||||
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续卸载 APK")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=ConnectPhoneIp).start()
|
||||
|
||||
def ConnectPhoneIp():
|
||||
global phoneIp
|
||||
messagebox.showinfo(title="tips", 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)))) # 将历史记录的数组转换为字典并写入
|
||||
if os.path.exists(ComboUninstallPath.get()):
|
||||
path = GetApkPackageName(ComboUninstallPath.get())
|
||||
else:
|
||||
path = ComboUninstallPath.get()
|
||||
UninstallProgram(path)
|
||||
messagebox.showinfo(message="操作执行完毕!", title="提示")
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def FindApk():
|
||||
# 浏览窗口
|
||||
# temp strs
|
||||
temppath=""
|
||||
def FindApk()->"浏览窗口":
|
||||
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApk.json"))["path"])
|
||||
if not path is "":
|
||||
combobox1.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
global temppath
|
||||
temppath = path
|
||||
print("apk path is find:" + path)
|
||||
if path != "" and path != "()":
|
||||
try:
|
||||
ComboInstallPath.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
except:
|
||||
pass
|
||||
|
||||
def Button3Install():
|
||||
if combobox1.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
if ComboInstallPath.get() is "":
|
||||
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续安装 APK")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=InstallApk, args=(combobox1.get(),)).start()
|
||||
threading.Thread(target=InstallApk, args=(ComboInstallPath.get(),)).start()
|
||||
|
||||
def InstallApk(path):
|
||||
global findApkHistory
|
||||
messagebox.showinfo(title="Tips", message=GetCommandReturn("adb install '{}'".format(path)))
|
||||
findApkHistory.append(combobox1.get())
|
||||
combobox1['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
# 安装应用
|
||||
def InstallApk(path: "apk 路径", quit: "是否静默安装" = False):
|
||||
try:
|
||||
print("start install apk")
|
||||
global findApkHistory
|
||||
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
|
||||
print("start install apk12")
|
||||
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(path))
|
||||
tempstr1 = iconSavePath
|
||||
print("start install apk1")
|
||||
iconSaveDir = os.path.dirname(iconSavePath)
|
||||
if not os.path.exists(iconSaveDir):
|
||||
os.makedirs(iconSaveDir,exist_ok=True)
|
||||
SaveApkIcon(path, iconSavePath)
|
||||
print("start install apk2")
|
||||
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
||||
"{}/{}.desktop".format(get_desktop_path(), GetApkPackageName(path)))
|
||||
print("start install apk3")
|
||||
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
||||
"{}/.local/share/applications/{}.desktop".format(get_home(), GetApkPackageName(path)))
|
||||
print("\nprint install complete")
|
||||
if quit:
|
||||
print(commandReturn)
|
||||
return
|
||||
messagebox.showinfo(title="提示", message="操作完成!")
|
||||
findApkHistory.append(ComboInstallPath.get())
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def DisabledAndEnbled(choose):
|
||||
# 禁用或启动所有控件
|
||||
def DisabledAndEnbled(choose: "启动或者禁用")->"禁用或启动所有控件":
|
||||
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
|
||||
a = userChoose[choose]
|
||||
combobox1.configure(state=a)
|
||||
combobox2.configure(state=a)
|
||||
button1.configure(state=a)
|
||||
button2.configure(state=a)
|
||||
button3.configure(state=a)
|
||||
button4.configure(state=a)
|
||||
button5.configure(state=a)
|
||||
ComboInstallPath.configure(state=a)
|
||||
ComboUninstallPath.configure(state=a)
|
||||
BtnFindApk.configure(state=a)
|
||||
BtnInstall.configure(state=a)
|
||||
BtnShowUengineApp.configure(state=a)
|
||||
BtnUninstallApkBrowser.configure(state=a)
|
||||
BtnUninstall.configure(state=a)
|
||||
Btngeticon.configure(state=a)
|
||||
|
||||
# 需引入 subprocess
|
||||
def GetCommandReturn(cmd):
|
||||
# 运行系统命令并获取返回值
|
||||
def GetCommandReturn(cmd: "命令")->"运行系统命令并获取返回值":
|
||||
# cmd 是要获取输出的命令
|
||||
return subprocess.getoutput(cmd)
|
||||
|
||||
def Button5Click():
|
||||
threading.Thread(target=OpenUengineProgramList).start()
|
||||
|
||||
def OpenUengineProgramList():
|
||||
# 打开“uengine 所有程序列表”
|
||||
def OpenUengineProgramList()->"打开“uengine 所有程序列表”":
|
||||
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
||||
|
||||
# 显示“关于这个程序”窗口
|
||||
def about_this_program():
|
||||
def about_this_program()->"显示“关于这个程序”窗口":
|
||||
global about
|
||||
global title
|
||||
global iconPath
|
||||
message = tk.Toplevel()
|
||||
message.title("关于 {}".format(title))
|
||||
message.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
mess = tk.Toplevel()
|
||||
message = ttk.Frame(mess)
|
||||
mess.resizable(0, 0)
|
||||
mess.title("关于 {}".format(title))
|
||||
#mess.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
img = ImageTk.PhotoImage(Image.open(iconPath))
|
||||
label1 = ttk.Label(message, image=img)
|
||||
LabApkPath = ttk.Label(message, image=img)
|
||||
label2 = ttk.Label(message, text=about)
|
||||
button1 = ttk.Button(message, text="确定", command=message.withdraw)
|
||||
label1.pack()
|
||||
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
|
||||
LabApkPath.pack()
|
||||
label2.pack()
|
||||
button1.pack(side="bottom")
|
||||
message.mainloop()
|
||||
message.pack()
|
||||
mess.mainloop()
|
||||
|
||||
# 显示“提示”窗口
|
||||
def helps():
|
||||
def helps()->"显示“提示”窗口":
|
||||
global tips
|
||||
messagebox.showinfo(title="提示", message=tips)
|
||||
|
||||
# 显示更新内容窗口
|
||||
def UpdateThings():
|
||||
def UpdateThings()->"显示更新内容窗口":
|
||||
messagebox.showinfo(title="更新内容", message=updateThings)
|
||||
|
||||
# 打开程序官网
|
||||
def OpenProgramURL():
|
||||
def OpenProgramURL()->"打开程序官网":
|
||||
webbrowser.open_new_tab(programUrl)
|
||||
|
||||
# 重启本应用程序
|
||||
def ReStartProgram():
|
||||
def ReStartProgram()->"重启本应用程序":
|
||||
python = sys.executable
|
||||
os.execl(python, python, * sys.argv)
|
||||
|
||||
def CleanProgramHistory():
|
||||
# 清理历史记录
|
||||
def CleanProgramHistory()->"清理历史记录":
|
||||
try:
|
||||
if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"):
|
||||
shutil.rmtree(get_home() + "/.config/uengine-runner")
|
||||
@@ -137,16 +198,18 @@ def CleanProgramHistory():
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home():
|
||||
def get_home()->"获取用户主目录":
|
||||
return os.path.expanduser('~')
|
||||
|
||||
def SendUengineAndroidListForDesktop():
|
||||
# 发送“启动 uengine 所有程序”的 .desktop 文件到桌面
|
||||
def SendUengineAndroidListForDesktop()->"发送“启动 uengine 所有程序”的 .desktop 文件到桌面":
|
||||
global desktop
|
||||
global desktopName
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"):
|
||||
DisabledAndEnbled(False)
|
||||
return
|
||||
shutil.copy(desktop, get_desktop_path())
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
@@ -156,7 +219,7 @@ def SendUengineAndroidListForDesktop():
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path():
|
||||
def get_desktop_path()->"获取用户桌面目录":
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
@@ -170,11 +233,13 @@ def get_desktop_path():
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
def SendUengineAndroidListForLauncher():
|
||||
# 发送“启动 uengine 所有程序”的 .desktop 文件到启动器
|
||||
def SendUengineAndroidListForLauncher()->"发送“启动 uengine 所有程序”的 .desktop 文件到启动器":
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"):
|
||||
DisabledAndEnbled(False)
|
||||
return
|
||||
if not os.path.exists("{}/.local/share/applications/".format(get_home())):
|
||||
os.makedirs("{}/.local/share/applications/".format(get_home()))
|
||||
@@ -187,113 +252,448 @@ def SendUengineAndroidListForLauncher():
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 数组转字典
|
||||
def ListToDictionary(list):
|
||||
def ListToDictionary(list: "需要转换的数组")->"数组转字典":
|
||||
dictionary = {}
|
||||
for i in range(len(list)):
|
||||
dictionary[i] = list[i]
|
||||
return dictionary
|
||||
|
||||
# 读取文本文档
|
||||
def readtxt(path):
|
||||
def readtxt(path: "路径")->"读取文本文档":
|
||||
f = open(path, "r") # 设置文件对象
|
||||
str = f.read() # 获取内容
|
||||
f.close() # 关闭文本对象
|
||||
return str # 返回结果
|
||||
|
||||
# 写入文本文档
|
||||
def write_txt(path, things):
|
||||
def write_txt(path: "路径", things: "内容")->"写入文本文档":
|
||||
TxtDir = os.path.dirname(path)
|
||||
print(TxtDir)
|
||||
if not os.path.exists(TxtDir):
|
||||
os.makedirs(TxtDir,exist_ok=True)
|
||||
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
|
||||
file.write(things) # 写入文本
|
||||
file.close() # 关闭文本对象
|
||||
|
||||
# 显示本程序所有使用的程序
|
||||
def ShowUseProgram()->"显示本程序所有使用的程序":
|
||||
global title
|
||||
global useProgram
|
||||
messagebox.showinfo(title="{} 使用的程序列表(部分)".format(title), message=useProgram)
|
||||
|
||||
# 获取 aapt 的所有信息
|
||||
def GetApkInformation(apkFilePath: "apk 所在路径")->"获取 aapt 的所有信息":
|
||||
return GetCommandReturn("aapt dump badging '{}'".format(apkFilePath))
|
||||
|
||||
# 获取 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
|
||||
|
||||
# 获取 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
|
||||
|
||||
# 生成 uengine 启动文件到桌面
|
||||
def BuildUengineDesktop(packageName: "软件包名", activityName: "activity", showName: "显示名称", iconPath: "程序图标所在目录", savePath:".desktop 文件保存路径")->"生成 uengine 启动文件到桌面":
|
||||
things = '''[Desktop Entry]
|
||||
Categories=app;
|
||||
Encoding=UTF-8
|
||||
Exec=/usr/bin/uengine-launch.sh --action=android.intent.action.MAIN --package={} --component={}
|
||||
GenericName={}
|
||||
Icon={}
|
||||
MimeType=
|
||||
Name={}
|
||||
StartupWMClass={}
|
||||
Terminal=false
|
||||
Type=Application
|
||||
'''.format(packageName, activityName, showName, iconPath, showName, showName)
|
||||
write_txt(savePath, things)
|
||||
|
||||
# 获取软件的中文名称
|
||||
def GetApkChineseLabel(apkFilePath)->"获取软件的中文名称":
|
||||
info = GetApkInformation(apkFilePath)
|
||||
for line in info.split('\n'):
|
||||
if "application-label:" in line:
|
||||
line = line.replace("application-label:", "")
|
||||
line = line.replace("'", "")
|
||||
return line
|
||||
|
||||
# 获取图标在包内的路径
|
||||
#def GetApkIconInApk(apkFilePath)->"获取图标在包内的路径":
|
||||
|
||||
#合并两个函数到一起
|
||||
def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标":
|
||||
try:
|
||||
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)
|
||||
else:
|
||||
zip = zipfile.ZipFile(apkFilePath)
|
||||
iconData = zip.read(xmlpath)
|
||||
with open(iconSavePath, 'w+b') as saveIconFile:
|
||||
saveIconFile.write(iconData)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
print("Error, show defult icon")
|
||||
shutil.copy(programPath + "/defult.png", iconSavePath)
|
||||
|
||||
def saveicon():
|
||||
global temppath
|
||||
global tempstr1
|
||||
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(temppath))
|
||||
print(iconSavePath+"iconpaths")
|
||||
SaveApkIcon(temppath, iconSavePath)
|
||||
|
||||
def SaveIconToOtherPath():
|
||||
apkPath = ComboInstallPath.get()
|
||||
if apkPath == "":
|
||||
messagebox.showerror(title="错误", message="你没有选择 apk 文件")
|
||||
return
|
||||
path = filedialog.asksaveasfilename(title="保存图标", filetypes=[("PNG 图片", "*.png"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/SaveApkIcon.json"))["path"])
|
||||
if not path == "":
|
||||
try:
|
||||
SaveApkIcon(apkPath, path)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message="本程序不支持保存该 apk 的图标")
|
||||
return
|
||||
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
findApkHistory.append(ComboInstallPath.get())
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
messagebox.showinfo(title="提示", message="保存成功!")
|
||||
|
||||
## 获取 apk 文件的图标(部分程序不支持)
|
||||
# def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标(部分程序不支持)":
|
||||
# zip = zipfile.ZipFile(apkFilePath)
|
||||
# iconData = zip.read(GetApkIconInApk(apkFilePath))
|
||||
# with open(iconSavePath, 'w+b') as saveIconFile:
|
||||
# saveIconFile.write(iconData)
|
||||
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path()->"获取用户桌面目录":
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home()->"获取用户主目录":
|
||||
return os.path.expanduser('~')
|
||||
|
||||
###########################
|
||||
# 程序信息
|
||||
###########################
|
||||
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
|
||||
version = "1.0.0"
|
||||
goodRunSystem = "Linux"
|
||||
about = '''一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
||||
版本:{}
|
||||
适用平台:{}
|
||||
tkinter 版本:{}
|
||||
程序官网:{}
|
||||
©2021-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
|
||||
tips = '''提示:
|
||||
1、None'''
|
||||
updateThingsString = ''''''
|
||||
title = "uengine 运行器 {}".format(version)
|
||||
updateTime = "2021年"
|
||||
version = "1.3.1"
|
||||
goodRunSystem = "Linux(deepin/UOS)"
|
||||
aaptVersion = GetCommandReturn("aapt version")
|
||||
about = ''' 一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
||||
|
||||
版本 :{}
|
||||
|
||||
适用平台 :{}
|
||||
|
||||
tkinter版本:{}
|
||||
|
||||
aapt 版本 :{}
|
||||
|
||||
程序官网 :{}
|
||||
|
||||
©2021-{}'''.format(version, goodRunSystem, tk.TkVersion, aaptVersion,programUrl, time.strftime("%Y"))
|
||||
tips = ''' 新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的Uengine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
|
||||
|
||||
安装APK:
|
||||
点浏览按钮,选中需要安装的APK,然后点安装按钮
|
||||
|
||||
卸载APK:
|
||||
在卸载APK下面的输入框内输入需要卸载的APK包名,点卸载按钮,如果无法获取包名,可以通过浏览APK文件程序自动获取包名进行卸载。
|
||||
|
||||
保存APK图标:
|
||||
在安装APK下面的输入框浏览或输入APK的路径,然后点击“保存图标”按钮,选择保存位置即可
|
||||
|
||||
打开Uengine应用列表:
|
||||
打开系统已安装的应用列表(安卓界面)
|
||||
|
||||
提示:
|
||||
1、需要你有使用 root 权限的能力;
|
||||
2、需要安装 uengine 才能使用;
|
||||
3、提取 apk 图标的 apk 路径以“安装 apk”那栏为准;
|
||||
4、如果报错是有关产生 .deksotp 文件有关,一般可以打开程序列表运行。如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
|
||||
|
||||
'''
|
||||
updateThingsString = '''V1.3.1:
|
||||
※1、修复打包问题,防止部分用户安装出错的问题;
|
||||
※2、修复了程序无法提取图标时可以提取默认图标使用;
|
||||
|
||||
V1.3.0:
|
||||
※1、修改了界面布局;
|
||||
※2、修复大多数新安装普通用户的路图标及启动菜单文件路径不存在导致安装APK报错的bugs;
|
||||
3、删除少量冗余代码,调整代码顺序;
|
||||
4、支持提取 apk 图标。
|
||||
|
||||
V1.2.3
|
||||
1、调整部分控件名称;
|
||||
2、调整界面布局及界面风格;
|
||||
|
||||
V1.2.2
|
||||
1、对程序错误的显示更加人性化;
|
||||
2、对 icon 的获取方式进行了升级;
|
||||
3、增加了注释、删除部分冗余代码。
|
||||
|
||||
V1.2.1:
|
||||
※1、进行了安装方式的修改(不使用 adb),修复原无法安装和卸载的问题;
|
||||
2、进行了部分优化;
|
||||
3、进行了功能缩水;
|
||||
4、修复 deb 打包错误。'''
|
||||
title = "uengine 安装器 {}".format(version)
|
||||
updateTime = "2021年08月08日"
|
||||
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
|
||||
iconPath = "/opt/apps/uengine-runner/icon.png"
|
||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
|
||||
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
|
||||
desktopName = "UengineAndroidProgramList.desktop"
|
||||
contribute = '''gfdgd xi<3025613752@qq.com>
|
||||
actionchen<917981399@qq.com>'''
|
||||
useProgram = '''1、uengine相关软件包(基于anbox开发)
|
||||
2、Python3
|
||||
3、tkinter(tkinter.tk、ttkthemes 和 tkinter.ttk)
|
||||
4、aapt
|
||||
……'''
|
||||
|
||||
###########################
|
||||
# 加载配置
|
||||
###########################
|
||||
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/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"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", json.dumps({})) # 创建配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/SaveApkIcon.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
|
||||
###########################
|
||||
# 设置变量
|
||||
###########################
|
||||
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())
|
||||
fineUninstallApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json")).values())
|
||||
|
||||
# add sub window
|
||||
#添加窗口开启关闭开关,防止重复开启
|
||||
windowflag = "close"
|
||||
|
||||
def showhelp():
|
||||
|
||||
#define window and frame and button label
|
||||
#
|
||||
global windowflag
|
||||
if windowflag == "close":
|
||||
helpwindow=tk.Toplevel()
|
||||
helpwindow.resizable(0, 0)
|
||||
helpwindow.title("帮助")
|
||||
|
||||
|
||||
# get screen width and height
|
||||
screen_width = helpwindow.winfo_screenwidth()
|
||||
screen_height = helpwindow.winfo_screenheight()
|
||||
# calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。
|
||||
winwith=490
|
||||
winhigh=600
|
||||
x = (screen_width/2) - (winwith/2)
|
||||
y = (screen_height/2) - (winhigh/2)
|
||||
|
||||
helpwindow.geometry("490x650"+"+{:.0f}+{:.0f}".format(x, y))
|
||||
|
||||
style = ttkthemes.ThemedStyle(helpwindow)
|
||||
style.set_theme("breeze")
|
||||
|
||||
|
||||
|
||||
Frmroot=ttk.Frame(helpwindow)
|
||||
FrmMenu = ttk.Frame(Frmroot)
|
||||
FrmText = ttk.Frame(Frmroot)
|
||||
|
||||
LabFrmText=ttk.LabelFrame(FrmText,text="帮助",height=800,borderwidth=3)
|
||||
HelpStr = tk.StringVar()
|
||||
HelpStr.set(tips)
|
||||
LabText = ttk.Label(LabFrmText, textvariable=HelpStr,width=50)
|
||||
LabText.config(wraplength=350)
|
||||
|
||||
def on_closing():
|
||||
global windowflag
|
||||
windowflag = "close"
|
||||
print(windowflag)
|
||||
helpwindow.destroy()
|
||||
|
||||
|
||||
|
||||
# define button func
|
||||
def ChgLog():
|
||||
HelpStr.set(updateThingsString)
|
||||
def ChgAbout():
|
||||
HelpStr.set(about)
|
||||
def ChgDep():
|
||||
HelpStr.set(useProgram)
|
||||
def ChgCon():
|
||||
HelpStr.set(contribute)
|
||||
def ChgTips():
|
||||
HelpStr.set(tips)
|
||||
LabText.config(wraplength=350)
|
||||
|
||||
BtnReadme = ttk.Button(FrmMenu, text="使用说明",width=14,command=ChgTips)
|
||||
BtnLog = ttk.Button(FrmMenu, text="更新内容",width=14,command=ChgLog)
|
||||
BtnZujian = ttk.Button(FrmMenu, text="程序依赖的组件",width=14,command=ChgDep)
|
||||
BtnGongxian = ttk.Button(FrmMenu, text="有贡献的开发者",width=14,command=ChgCon)
|
||||
BtnAbout = ttk.Button(FrmMenu, text="关于",width=14,command=ChgAbout)
|
||||
|
||||
|
||||
#layout
|
||||
FrmMenu.grid(row=0,column=0,sticky=tk.NW)
|
||||
BtnReadme.grid(row=0,column=0,sticky=tk.NW,padx=3)
|
||||
BtnLog.grid(row=1,column=0,sticky=tk.NW,padx=3)
|
||||
BtnZujian.grid(row=2,column=0,sticky=tk.NW,padx=3)
|
||||
BtnGongxian.grid(row=3,column=0,sticky=tk.NW,padx=3)
|
||||
BtnAbout.grid(row=4,column=0,sticky=tk.NW,padx=3)
|
||||
|
||||
FrmText.grid(row=0,column=1,sticky=tk.NW)
|
||||
LabFrmText.grid(row=0,column=0,sticky=tk.NW,padx=3,pady=3)
|
||||
LabText.grid(row=0,column=0,sticky=tk.NW)
|
||||
|
||||
Frmroot.pack()
|
||||
windowflag = "open"
|
||||
print(windowflag)
|
||||
#helpwindow.mainloop()
|
||||
helpwindow.protocol("WM_DELETE_WINDOW", on_closing)
|
||||
|
||||
|
||||
###########################
|
||||
# 窗口创建
|
||||
###########################
|
||||
window = tk.Tk()
|
||||
window.title(title)
|
||||
window.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
frame1 = ttk.Frame(window)
|
||||
frame2 = ttk.Frame(window)
|
||||
label1 = ttk.Label(window, text="要安装的 apk 路径:")
|
||||
label2 = ttk.Label(window, text="要连接的设备的 IP(默认 IP 为 192.168.250.2):")
|
||||
combobox1 = ttk.Combobox(window, width=100)
|
||||
combobox2 = ttk.Combobox(window, width=100)
|
||||
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="Kill Adb Progress", command=KillAdbProgress)
|
||||
button5 = ttk.Button(frame2, text="Open uengine Program List", command=Button5Click)
|
||||
menu = tk.Menu(window) # 设置菜单栏
|
||||
programmenu = tk.Menu(menu, tearoff=0) # 设置“程序”菜单栏
|
||||
win = tk.Tk() # 创建窗口
|
||||
|
||||
# 设置窗口
|
||||
style = ttkthemes.ThemedStyle(win)
|
||||
style.set_theme("breeze")
|
||||
window = ttk.Frame(win)
|
||||
win.attributes('-alpha', 0.5)
|
||||
win.title(title)
|
||||
win.resizable(0, 0)
|
||||
win.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
|
||||
# get screen width and height
|
||||
screen_width = win.winfo_screenwidth()
|
||||
screen_height = win.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)
|
||||
|
||||
win.geometry(""+"+{:.0f}+{:.0f}".format(x, y))
|
||||
|
||||
# 创建控件
|
||||
FrmInstall = ttk.Frame(window)
|
||||
FrmUninstall = ttk.Frame(window)
|
||||
LabApkPath = ttk.Label(window, text="安装APK:")
|
||||
LabUninstallPath = ttk.Label(window, text="卸载APK:")
|
||||
ComboInstallPath = ttk.Combobox(window, width=50)
|
||||
ComboUninstallPath = ttk.Combobox(window, width=50)
|
||||
BtnFindApk = ttk.Button(FrmInstall, text="浏览", command=FindApk)
|
||||
BtnInstall = ttk.Button(FrmInstall, text="安装", command=Button3Install)
|
||||
BtnShowUengineApp = ttk.Button(window, text="打开 uengine 应用列表", command=Button5Click)
|
||||
BtnUninstallApkBrowser = ttk.Button(FrmUninstall, text="浏览", command=BtnFindUninstallApkClk)
|
||||
BtnUninstall = ttk.Button(FrmUninstall, text="卸载", command=ButtonClick8)
|
||||
Btngeticon = ttk.Button(window, text="保存图标", command=SaveIconToOtherPath)
|
||||
# 设置菜单栏
|
||||
menu = tk.Menu(window, background="white")
|
||||
|
||||
programmenu = 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="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) # 设置“退出程序”项
|
||||
uengine = tk.Menu(menu, tearoff=0)
|
||||
menu.add_cascade(label="uengine", menu=uengine)
|
||||
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”
|
||||
|
||||
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
|
||||
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
|
||||
help = tk.Menu(menu, tearoff=0) # 设置“帮助”菜单栏
|
||||
menu.add_cascade(label="帮助", menu=help)
|
||||
|
||||
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
|
||||
help.add_separator()
|
||||
help.add_command(label="小提示", command=helps) # 设置“小提示”项
|
||||
help.add_command(label="更新内容", command=UpdateThings) # 设置“更新内容”项
|
||||
help.add_command(label="关于这个程序", command=about_this_program) # 设置“关于这个程序”项
|
||||
help.add_command(label="帮助", command=showhelp) # 设置“关于这个程序”项
|
||||
|
||||
menu.configure(activebackground="dodgerblue")
|
||||
help.configure(activebackground="dodgerblue")
|
||||
uengine.configure(activebackground="dodgerblue")
|
||||
programmenu.configure(activebackground="dodgerblue")
|
||||
|
||||
# 设置控件
|
||||
combobox2['value'] = phoneIp
|
||||
combobox1['value'] = findApkHistory
|
||||
#
|
||||
window.config(menu=menu) # 显示菜单栏
|
||||
label1.grid(row=2, column=0)
|
||||
label2.grid(row=0, column=0)
|
||||
combobox1.grid(row=2, column=1)
|
||||
combobox2.grid(row=0, column=1)
|
||||
button1.grid(column=0, row=0)
|
||||
button2.grid(row=2, column=2)
|
||||
button3.grid(row=0, column=0)
|
||||
button4.grid(column=1, row=0)
|
||||
button5.grid(row=0, column=1)
|
||||
frame1.grid(row=1, columnspa=3)
|
||||
frame2.grid(row=3, columnspa=3)
|
||||
window.mainloop()
|
||||
ComboUninstallPath['value'] = fineUninstallApkHistory
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
# 显示控件
|
||||
win.config(menu=menu) # 显示菜单栏
|
||||
|
||||
|
||||
|
||||
LabApkPath.grid(row=1, column=0,sticky= tk.W,padx=3)
|
||||
ComboInstallPath.grid(row=2, column=0,padx=3)
|
||||
|
||||
|
||||
FrmInstall.grid(row=2, column=1,padx=3)
|
||||
BtnFindApk.grid(row=0, column=0)
|
||||
BtnInstall.grid(row=0, column=1)
|
||||
|
||||
LabUninstallPath.grid(row=3, column=0,sticky= tk.W,padx=3)
|
||||
ComboUninstallPath.grid(row=4, column=0,padx=3)
|
||||
|
||||
FrmUninstall.grid(row=4, column=1,padx=3)
|
||||
BtnUninstallApkBrowser.grid(row=0, column=0)
|
||||
BtnUninstall.grid(row=0, column=1)
|
||||
|
||||
BtnShowUengineApp.grid(row=5, column=0,sticky= tk.W,padx=3,pady=2)
|
||||
|
||||
Btngeticon.grid(row=3, column=1,sticky= tk.W,padx=3,pady=2)
|
||||
|
||||
window.pack()
|
||||
|
||||
win.mainloop()
|
||||
|
||||
@@ -1,299 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# 使用系统默认的 python3 运行
|
||||
###########################################################################################
|
||||
# 作者:gfdgd xi
|
||||
# 版本:1.0.0
|
||||
# 更新时间:2021年
|
||||
# 感谢:
|
||||
# 基于 Python3 的 tkinter 构建
|
||||
###########################################################################################
|
||||
#################
|
||||
# 引入所需的库
|
||||
#################
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
import traceback
|
||||
import threading
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.messagebox as messagebox
|
||||
import tkinter.filedialog as filedialog
|
||||
import PIL.Image as Image
|
||||
import PIL.ImageTk as ImageTk
|
||||
|
||||
def KillAdbProgress():
|
||||
DisabledAndEnbled(True)
|
||||
Return = GetCommandReturn("killall adb")
|
||||
if Return is "":
|
||||
Return = "OK!"
|
||||
messagebox.showinfo(title="tips", message=Return)
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def Button1Click():
|
||||
if combobox2.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=ConnectPhoneIp).start()
|
||||
|
||||
def ConnectPhoneIp():
|
||||
global phoneIp
|
||||
messagebox.showinfo(title="tips", 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 FindApk():
|
||||
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApk.json"))["path"])
|
||||
if not path is "":
|
||||
combobox1.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
|
||||
def Button3Install():
|
||||
if combobox1.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=InstallApk, args=(combobox1.get(),)).start()
|
||||
|
||||
def InstallApk(path):
|
||||
global findApkHistory
|
||||
messagebox.showinfo(title="Tips", message=GetCommandReturn("adb install '{}'".format(path)))
|
||||
findApkHistory.append(combobox1.get())
|
||||
combobox1['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def DisabledAndEnbled(choose):
|
||||
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
|
||||
a = userChoose[choose]
|
||||
combobox1.configure(state=a)
|
||||
combobox2.configure(state=a)
|
||||
button1.configure(state=a)
|
||||
button2.configure(state=a)
|
||||
button3.configure(state=a)
|
||||
button4.configure(state=a)
|
||||
button5.configure(state=a)
|
||||
|
||||
# 需引入 subprocess
|
||||
def GetCommandReturn(cmd):
|
||||
# cmd 是要获取输出的命令
|
||||
return subprocess.getoutput(cmd)
|
||||
|
||||
def Button5Click():
|
||||
threading.Thread(target=OpenUengineProgramList).start()
|
||||
|
||||
def OpenUengineProgramList():
|
||||
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
||||
|
||||
# 显示“关于这个程序”窗口
|
||||
def about_this_program():
|
||||
global about
|
||||
global title
|
||||
global iconPath
|
||||
message = tk.Toplevel()
|
||||
message.title("关于 {}".format(title))
|
||||
message.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
img = ImageTk.PhotoImage(Image.open(iconPath))
|
||||
label1 = ttk.Label(message, image=img)
|
||||
label2 = ttk.Label(message, text=about)
|
||||
button1 = ttk.Button(message, text="确定", command=message.withdraw)
|
||||
label1.pack()
|
||||
label2.pack()
|
||||
button1.pack(side="bottom")
|
||||
message.mainloop()
|
||||
|
||||
# 显示“提示”窗口
|
||||
def helps():
|
||||
global tips
|
||||
messagebox.showinfo(title="提示", message=tips)
|
||||
|
||||
# 显示更新内容窗口
|
||||
def UpdateThings():
|
||||
messagebox.showinfo(title="更新内容", message=updateThings)
|
||||
|
||||
# 打开程序官网
|
||||
def OpenProgramURL():
|
||||
webbrowser.open_new_tab(programUrl)
|
||||
|
||||
# 重启本应用程序
|
||||
def ReStartProgram():
|
||||
python = sys.executable
|
||||
os.execl(python, python, * sys.argv)
|
||||
|
||||
def CleanProgramHistory():
|
||||
try:
|
||||
if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"):
|
||||
shutil.rmtree(get_home() + "/.config/uengine-runner")
|
||||
ReStartProgram()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home():
|
||||
return os.path.expanduser('~')
|
||||
|
||||
def SendUengineAndroidListForDesktop():
|
||||
global desktop
|
||||
global desktopName
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"):
|
||||
return
|
||||
shutil.copy(desktop, get_desktop_path())
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path():
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
def SendUengineAndroidListForLauncher():
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"):
|
||||
return
|
||||
if not os.path.exists("{}/.local/share/applications/".format(get_home())):
|
||||
os.makedirs("{}/.local/share/applications/".format(get_home()))
|
||||
shutil.copy(desktop, "{}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
os.system("chmod 755 {}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 数组转字典
|
||||
def ListToDictionary(list):
|
||||
dictionary = {}
|
||||
for i in range(len(list)):
|
||||
dictionary[i] = list[i]
|
||||
return dictionary
|
||||
|
||||
# 读取文本文档
|
||||
def readtxt(path):
|
||||
f = open(path, "r") # 设置文件对象
|
||||
str = f.read() # 获取内容
|
||||
f.close() # 关闭文本对象
|
||||
return str # 返回结果
|
||||
|
||||
# 写入文本文档
|
||||
def write_txt(path, things):
|
||||
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
|
||||
file.write(things) # 写入文本
|
||||
file.close() # 关闭文本对象
|
||||
|
||||
###########################
|
||||
# 程序信息
|
||||
###########################
|
||||
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
|
||||
version = "1.0.0"
|
||||
goodRunSystem = "Linux"
|
||||
about = '''一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
||||
版本:{}
|
||||
适用平台:{}
|
||||
tkinter 版本:{}
|
||||
程序官网:{}
|
||||
©2021-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
|
||||
tips = '''提示:
|
||||
1、None'''
|
||||
updateThingsString = ''''''
|
||||
title = "uengine 运行器 {}".format(version)
|
||||
updateTime = "2021年"
|
||||
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
|
||||
iconPath = "/opt/apps/uengine-runner/icon.png"
|
||||
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
|
||||
desktopName = "UengineAndroidProgramList.desktop"
|
||||
|
||||
###########################
|
||||
# 加载配置
|
||||
###########################
|
||||
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/FindApkHistory.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
|
||||
###########################
|
||||
# 设置变量
|
||||
###########################
|
||||
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())
|
||||
|
||||
###########################
|
||||
# 窗口创建
|
||||
###########################
|
||||
window = tk.Tk()
|
||||
window.title(title)
|
||||
window.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
frame1 = ttk.Frame(window)
|
||||
frame2 = ttk.Frame(window)
|
||||
label1 = ttk.Label(window, text="要安装的 apk 路径:")
|
||||
label2 = ttk.Label(window, text="要连接的设备的 IP(默认 IP 为 192.168.250.2):")
|
||||
combobox1 = ttk.Combobox(window, width=100)
|
||||
combobox2 = ttk.Combobox(window, width=100)
|
||||
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="Kill Adb Progress", command=KillAdbProgress)
|
||||
button5 = ttk.Button(frame2, text="Open uengine Program List", command=Button5Click)
|
||||
menu = tk.Menu(window) # 设置菜单栏
|
||||
programmenu = tk.Menu(menu, tearoff=0) # 设置“程序”菜单栏
|
||||
menu.add_cascade(label="程序", menu=programmenu)
|
||||
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
|
||||
programmenu.add_separator() # 设置分界线
|
||||
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
|
||||
uengine = tk.Menu(menu, tearoff=0)
|
||||
menu.add_cascade(label="uengine", menu=uengine)
|
||||
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
|
||||
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
|
||||
help = tk.Menu(menu, tearoff=0) # 设置“帮助”菜单栏
|
||||
menu.add_cascade(label="帮助", menu=help)
|
||||
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
|
||||
help.add_separator()
|
||||
help.add_command(label="小提示", command=helps) # 设置“小提示”项
|
||||
help.add_command(label="更新内容", command=UpdateThings) # 设置“更新内容”项
|
||||
help.add_command(label="关于这个程序", command=about_this_program) # 设置“关于这个程序”项
|
||||
# 设置控件
|
||||
combobox2['value'] = phoneIp
|
||||
combobox1['value'] = findApkHistory
|
||||
#
|
||||
window.config(menu=menu) # 显示菜单栏
|
||||
label1.grid(row=2, column=0)
|
||||
label2.grid(row=0, column=0)
|
||||
combobox1.grid(row=2, column=1)
|
||||
combobox2.grid(row=0, column=1)
|
||||
button1.grid(column=0, row=0)
|
||||
button2.grid(row=2, column=2)
|
||||
button3.grid(row=0, column=0)
|
||||
button4.grid(column=1, row=0)
|
||||
button5.grid(row=0, column=1)
|
||||
frame1.grid(row=1, columnspa=3)
|
||||
frame2.grid(row=3, columnspa=3)
|
||||
window.mainloop()
|
||||
1
build/usr/bin/uengine-runner
Symbolic link
@@ -0,0 +1 @@
|
||||
/opt/apps/uengine-runner/uengine-runner
|
||||
@@ -0,0 +1,11 @@
|
||||
[Desktop Entry]
|
||||
Categories=System;
|
||||
Comment=uengine(anbox) 程序菜单
|
||||
Encoding=UTF-8
|
||||
Exec=/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
|
||||
Icon=/opt/apps/uengine-runner/icon.png
|
||||
MimeType=
|
||||
Name=uengine 程序菜单
|
||||
StartupWMClass=uengine 程序菜单
|
||||
Terminal=false
|
||||
Type=Application
|
||||
BIN
defult.png
Executable file
|
After Width: | Height: | Size: 312 KiB |
118
getxmlimg.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import PIL.Image as Image
|
||||
import PIL.ImageDraw as ImageDraw
|
||||
import zipfile
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
class getsavexml():
|
||||
|
||||
def savexml(self,apkFilePath,xmlpath,iconSavePath):
|
||||
cmddumpid = "aapt dump xmltree "+ apkFilePath + " " + xmlpath
|
||||
print(cmddumpid)
|
||||
xmltree = subprocess.getoutput(cmddumpid)
|
||||
xmls = xmltree.splitlines()
|
||||
# find strs ,print next line
|
||||
def FindStrs(lines,strs):
|
||||
i=0
|
||||
while i < len(lines):
|
||||
if re.search(strs,lines[i]):
|
||||
tmpstr = lines[i+1]
|
||||
i += 1
|
||||
Resultstr = tmpstr.split(":")[-1].split("=")[-1].split("0x")[-1]
|
||||
return Resultstr
|
||||
else:
|
||||
i += 1
|
||||
#从apk的信息中获取前后景图片的ID号
|
||||
backimgid = FindStrs(xmls,"background")
|
||||
foreimgid = FindStrs(xmls,"foreground")
|
||||
print(backimgid)
|
||||
print(foreimgid)
|
||||
|
||||
# 直接从apk resource文件获取前后两层图片路径及ID字符串
|
||||
resource = subprocess.getoutput("aapt dump --values resources " + apkFilePath + "| grep -iE -A1 " + "\"" + backimgid + "|" + foreimgid + "\"")
|
||||
resourcelines = resource.splitlines()
|
||||
print(resourcelines)
|
||||
|
||||
# 从过滤出的字符串中获取所有相同ID的图片路径
|
||||
def Findpicpath(lines,imgid):
|
||||
i=0
|
||||
Resultstr = []
|
||||
while i < len(lines):
|
||||
if re.search(imgid,lines[i]) and re.search("string8",lines[i+1]) :
|
||||
print(lines[i+1])
|
||||
tmpstr = lines[i+1].replace("\"","")
|
||||
i += 1
|
||||
Resultstr.append(tmpstr.split()[-1])
|
||||
else:
|
||||
i += 1
|
||||
return Resultstr
|
||||
|
||||
#获取所有带前后图片ID的图片路径(相同背景或者前景的图片ID但分辨率不一样)
|
||||
backimgs = Findpicpath(resourcelines,backimgid)
|
||||
foreimgs = Findpicpath(resourcelines,foreimgid)
|
||||
print(backimgs)
|
||||
print(foreimgs)
|
||||
#获取分辨率最高的图片路径
|
||||
def getmaxsize(imgs):
|
||||
j = 0
|
||||
size=(0,0)
|
||||
zipapk = zipfile.ZipFile(apkFilePath)
|
||||
imgpath = ""
|
||||
while j < len(imgs):
|
||||
print(imgs[j])
|
||||
img = Image.open(zipapk.open(imgs[j]))
|
||||
print(imgs[j])
|
||||
print(img.size)
|
||||
if size < img.size:
|
||||
size = img.size
|
||||
imgpath = imgs[j]
|
||||
j += 1
|
||||
return imgpath
|
||||
|
||||
# 获取到文件列表后,进行比较分辨率,选取分辨率最高的张图片
|
||||
iconbackpath = getmaxsize(backimgs)
|
||||
iconforepath = getmaxsize(foreimgs)
|
||||
print(iconbackpath + " " + iconforepath)
|
||||
|
||||
#从APK文件获取最终图片
|
||||
zipapk = zipfile.ZipFile(apkFilePath)
|
||||
iconback = zipapk.open(iconbackpath)
|
||||
iconfore = zipapk.open(iconforepath)
|
||||
|
||||
|
||||
# 叠加图片,mask 设置前景为蒙版
|
||||
iconbackimg = Image.open(iconback).convert("RGBA")
|
||||
iconforeimg = Image.open(iconfore).convert("RGBA")
|
||||
iconbackimg.paste(iconforeimg,mask=iconforeimg)
|
||||
|
||||
|
||||
# 圆角图片函数,网上拷贝的
|
||||
def circle_corner(img, radii): #把原图片变成圆角,这个函数是从网上找的,原址 https://www.pyget.cn/p/185266
|
||||
"""
|
||||
圆角处理
|
||||
:param img: 源图象。
|
||||
:param radii: 半径,如:30。
|
||||
:return: 返回一个圆角处理后的图象。
|
||||
"""
|
||||
# 画圆(用于分离4个角)
|
||||
circle = Image.new('L', (radii * 2, radii * 2), 0) # 创建一个黑色背景的画布
|
||||
draw = ImageDraw.Draw(circle)
|
||||
draw.ellipse((0, 0, radii * 2, radii * 2), fill=255) # 画白色圆形
|
||||
# 原图
|
||||
img = img.convert("RGBA")
|
||||
w, h = img.size
|
||||
# 画4个角(将整圆分离为4个部分)
|
||||
alpha = Image.new('L', img.size, 255)
|
||||
alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0)) # 左上角
|
||||
alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0)) # 右上角
|
||||
alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii)) # 右下角
|
||||
alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii)) # 左下角
|
||||
# alpha.show()
|
||||
img.putalpha(alpha) # 白色区域透明可见,黑色区域不可见
|
||||
return img
|
||||
|
||||
# 圆角半径1/8边长,保存icon图片
|
||||
w,h = iconbackimg.size
|
||||
iconimg = circle_corner(iconbackimg,int(w/8))
|
||||
iconimg.save(iconSavePath)
|
||||
|
||||
702
main.py
@@ -1,11 +1,699 @@
|
||||
[Desktop Entry]
|
||||
Categories=System;
|
||||
Comment=uengine(anbox) 程序菜单
|
||||
#!/usr/bin/env python3
|
||||
# 使用系统默认的 python3 运行
|
||||
###########################################################################################
|
||||
# 作者:gfdgd xi<3025613752@qq.com>
|
||||
# 版本:1.3.0
|
||||
# 更新时间:2021年8月08日
|
||||
# 感谢:anbox、deepin 和 UOS
|
||||
# 基于 Python3 的 tkinter 构建
|
||||
# 更新:actionchen<917981399@qq.com>
|
||||
###########################################################################################
|
||||
#################
|
||||
# 引入所需的库
|
||||
#################
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
import zipfile
|
||||
import traceback
|
||||
import threading
|
||||
import ttkthemes
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.messagebox as messagebox
|
||||
import tkinter.filedialog as filedialog
|
||||
from getxmlimg import getsavexml
|
||||
from tkinter.constants import TOP
|
||||
|
||||
# 卸载程序
|
||||
def UninstallProgram(package: "apk 包名")->"卸载程序":
|
||||
try:
|
||||
global fineUninstallApkHistory
|
||||
Return = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(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(ComboUninstallPath.get())
|
||||
ComboUninstallPath['value'] = fineUninstallApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", str(json.dumps(ListToDictionary(fineUninstallApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
return Return
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
def BtnFindUninstallApkClk():
|
||||
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:
|
||||
ComboUninstallPath.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
except:
|
||||
pass
|
||||
|
||||
def ButtonClick8():
|
||||
if ComboUninstallPath.get() is "":
|
||||
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续卸载 APK")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
if os.path.exists(ComboUninstallPath.get()):
|
||||
path = GetApkPackageName(ComboUninstallPath.get())
|
||||
else:
|
||||
path = ComboUninstallPath.get()
|
||||
UninstallProgram(path)
|
||||
messagebox.showinfo(message="操作执行完毕!", title="提示")
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 浏览窗口
|
||||
# temp strs
|
||||
temppath=""
|
||||
def FindApk()->"浏览窗口":
|
||||
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApk.json"))["path"])
|
||||
global temppath
|
||||
temppath = path
|
||||
print("apk path is find:" + path)
|
||||
if path != "" and path != "()":
|
||||
try:
|
||||
ComboInstallPath.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
except:
|
||||
pass
|
||||
|
||||
def Button3Install():
|
||||
if ComboInstallPath.get() is "":
|
||||
messagebox.showerror(title="提示", message="信息没有填写完整,无法继续安装 APK")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=InstallApk, args=(ComboInstallPath.get(),)).start()
|
||||
|
||||
# 安装应用
|
||||
def InstallApk(path: "apk 路径", quit: "是否静默安装" = False):
|
||||
try:
|
||||
print("start install apk")
|
||||
global findApkHistory
|
||||
commandReturn = GetCommandReturn("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(path))
|
||||
print("start install apk12")
|
||||
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(path))
|
||||
tempstr1 = iconSavePath
|
||||
print("start install apk1")
|
||||
iconSaveDir = os.path.dirname(iconSavePath)
|
||||
if not os.path.exists(iconSaveDir):
|
||||
os.makedirs(iconSaveDir,exist_ok=True)
|
||||
SaveApkIcon(path, iconSavePath)
|
||||
print("start install apk2")
|
||||
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
||||
"{}/{}.desktop".format(get_desktop_path(), GetApkPackageName(path)))
|
||||
print("start install apk3")
|
||||
BuildUengineDesktop(GetApkPackageName(path), GetApkActivityName(path), GetApkChineseLabel(path), iconSavePath,
|
||||
"{}/.local/share/applications/{}.desktop".format(get_home(), GetApkPackageName(path)))
|
||||
print("\nprint install complete")
|
||||
if quit:
|
||||
print(commandReturn)
|
||||
return
|
||||
messagebox.showinfo(title="提示", message="操作完成!")
|
||||
findApkHistory.append(ComboInstallPath.get())
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 禁用或启动所有控件
|
||||
def DisabledAndEnbled(choose: "启动或者禁用")->"禁用或启动所有控件":
|
||||
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
|
||||
a = userChoose[choose]
|
||||
ComboInstallPath.configure(state=a)
|
||||
ComboUninstallPath.configure(state=a)
|
||||
BtnFindApk.configure(state=a)
|
||||
BtnInstall.configure(state=a)
|
||||
BtnShowUengineApp.configure(state=a)
|
||||
BtnUninstallApkBrowser.configure(state=a)
|
||||
BtnUninstall.configure(state=a)
|
||||
Btngeticon.configure(state=a)
|
||||
|
||||
# 需引入 subprocess
|
||||
# 运行系统命令并获取返回值
|
||||
def GetCommandReturn(cmd: "命令")->"运行系统命令并获取返回值":
|
||||
# cmd 是要获取输出的命令
|
||||
return subprocess.getoutput(cmd)
|
||||
|
||||
def Button5Click():
|
||||
threading.Thread(target=OpenUengineProgramList).start()
|
||||
|
||||
# 打开“uengine 所有程序列表”
|
||||
def OpenUengineProgramList()->"打开“uengine 所有程序列表”":
|
||||
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
||||
|
||||
# 显示“关于这个程序”窗口
|
||||
def about_this_program()->"显示“关于这个程序”窗口":
|
||||
global about
|
||||
global title
|
||||
global iconPath
|
||||
mess = tk.Toplevel()
|
||||
message = ttk.Frame(mess)
|
||||
mess.resizable(0, 0)
|
||||
mess.title("关于 {}".format(title))
|
||||
#mess.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
img = ImageTk.PhotoImage(Image.open(iconPath))
|
||||
LabApkPath = ttk.Label(message, image=img)
|
||||
label2 = ttk.Label(message, text=about)
|
||||
button1 = ttk.Button(message, text="确定", command=mess.withdraw)
|
||||
LabApkPath.pack()
|
||||
label2.pack()
|
||||
button1.pack(side="bottom")
|
||||
message.pack()
|
||||
mess.mainloop()
|
||||
|
||||
# 显示“提示”窗口
|
||||
def helps()->"显示“提示”窗口":
|
||||
global tips
|
||||
messagebox.showinfo(title="提示", message=tips)
|
||||
|
||||
# 显示更新内容窗口
|
||||
def UpdateThings()->"显示更新内容窗口":
|
||||
messagebox.showinfo(title="更新内容", message=updateThings)
|
||||
|
||||
# 打开程序官网
|
||||
def OpenProgramURL()->"打开程序官网":
|
||||
webbrowser.open_new_tab(programUrl)
|
||||
|
||||
# 重启本应用程序
|
||||
def ReStartProgram()->"重启本应用程序":
|
||||
python = sys.executable
|
||||
os.execl(python, python, * sys.argv)
|
||||
|
||||
# 清理历史记录
|
||||
def CleanProgramHistory()->"清理历史记录":
|
||||
try:
|
||||
if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"):
|
||||
shutil.rmtree(get_home() + "/.config/uengine-runner")
|
||||
ReStartProgram()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home()->"获取用户主目录":
|
||||
return os.path.expanduser('~')
|
||||
|
||||
# 发送“启动 uengine 所有程序”的 .desktop 文件到桌面
|
||||
def SendUengineAndroidListForDesktop()->"发送“启动 uengine 所有程序”的 .desktop 文件到桌面":
|
||||
global desktop
|
||||
global desktopName
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"):
|
||||
DisabledAndEnbled(False)
|
||||
return
|
||||
shutil.copy(desktop, get_desktop_path())
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path()->"获取用户桌面目录":
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
# 发送“启动 uengine 所有程序”的 .desktop 文件到启动器
|
||||
def SendUengineAndroidListForLauncher()->"发送“启动 uengine 所有程序”的 .desktop 文件到启动器":
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"):
|
||||
DisabledAndEnbled(False)
|
||||
return
|
||||
if not os.path.exists("{}/.local/share/applications/".format(get_home())):
|
||||
os.makedirs("{}/.local/share/applications/".format(get_home()))
|
||||
shutil.copy(desktop, "{}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
os.system("chmod 755 {}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 数组转字典
|
||||
def ListToDictionary(list: "需要转换的数组")->"数组转字典":
|
||||
dictionary = {}
|
||||
for i in range(len(list)):
|
||||
dictionary[i] = list[i]
|
||||
return dictionary
|
||||
|
||||
# 读取文本文档
|
||||
def readtxt(path: "路径")->"读取文本文档":
|
||||
f = open(path, "r") # 设置文件对象
|
||||
str = f.read() # 获取内容
|
||||
f.close() # 关闭文本对象
|
||||
return str # 返回结果
|
||||
|
||||
# 写入文本文档
|
||||
def write_txt(path: "路径", things: "内容")->"写入文本文档":
|
||||
TxtDir = os.path.dirname(path)
|
||||
print(TxtDir)
|
||||
if not os.path.exists(TxtDir):
|
||||
os.makedirs(TxtDir,exist_ok=True)
|
||||
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
|
||||
file.write(things) # 写入文本
|
||||
file.close() # 关闭文本对象
|
||||
|
||||
# 显示本程序所有使用的程序
|
||||
def ShowUseProgram()->"显示本程序所有使用的程序":
|
||||
global title
|
||||
global useProgram
|
||||
messagebox.showinfo(title="{} 使用的程序列表(部分)".format(title), message=useProgram)
|
||||
|
||||
# 获取 aapt 的所有信息
|
||||
def GetApkInformation(apkFilePath: "apk 所在路径")->"获取 aapt 的所有信息":
|
||||
return GetCommandReturn("aapt dump badging '{}'".format(apkFilePath))
|
||||
|
||||
# 获取 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
|
||||
|
||||
# 获取 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
|
||||
|
||||
# 生成 uengine 启动文件到桌面
|
||||
def BuildUengineDesktop(packageName: "软件包名", activityName: "activity", showName: "显示名称", iconPath: "程序图标所在目录", savePath:".desktop 文件保存路径")->"生成 uengine 启动文件到桌面":
|
||||
things = '''[Desktop Entry]
|
||||
Categories=app;
|
||||
Encoding=UTF-8
|
||||
Exec=/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
|
||||
Icon=/opt/apps/uengine-runner/icon.png
|
||||
Exec=/usr/bin/uengine-launch.sh --action=android.intent.action.MAIN --package={} --component={}
|
||||
GenericName={}
|
||||
Icon={}
|
||||
MimeType=
|
||||
Name=uengine 程序菜单
|
||||
StartupWMClass=uengine 程序菜单
|
||||
Name={}
|
||||
StartupWMClass={}
|
||||
Terminal=false
|
||||
Type=Application
|
||||
'''.format(packageName, activityName, showName, iconPath, showName, showName)
|
||||
write_txt(savePath, things)
|
||||
|
||||
# 获取软件的中文名称
|
||||
def GetApkChineseLabel(apkFilePath)->"获取软件的中文名称":
|
||||
info = GetApkInformation(apkFilePath)
|
||||
for line in info.split('\n'):
|
||||
if "application-label:" in line:
|
||||
line = line.replace("application-label:", "")
|
||||
line = line.replace("'", "")
|
||||
return line
|
||||
|
||||
# 获取图标在包内的路径
|
||||
#def GetApkIconInApk(apkFilePath)->"获取图标在包内的路径":
|
||||
|
||||
#合并两个函数到一起
|
||||
def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标":
|
||||
try:
|
||||
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)
|
||||
else:
|
||||
zip = zipfile.ZipFile(apkFilePath)
|
||||
iconData = zip.read(xmlpath)
|
||||
with open(iconSavePath, 'w+b') as saveIconFile:
|
||||
saveIconFile.write(iconData)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
print("Error, show defult icon")
|
||||
shutil.copy(programPath + "/defult.png", iconSavePath)
|
||||
|
||||
def saveicon():
|
||||
global temppath
|
||||
global tempstr1
|
||||
iconSavePath = "{}/.local/share/icons/hicolor/256x256/apps/{}.png".format(get_home(), GetApkPackageName(temppath))
|
||||
print(iconSavePath+"iconpaths")
|
||||
SaveApkIcon(temppath, iconSavePath)
|
||||
|
||||
def SaveIconToOtherPath():
|
||||
apkPath = ComboInstallPath.get()
|
||||
if apkPath == "":
|
||||
messagebox.showerror(title="错误", message="你没有选择 apk 文件")
|
||||
return
|
||||
path = filedialog.asksaveasfilename(title="保存图标", filetypes=[("PNG 图片", "*.png"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/SaveApkIcon.json"))["path"])
|
||||
if not path == "":
|
||||
try:
|
||||
SaveApkIcon(apkPath, path)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message="本程序不支持保存该 apk 的图标")
|
||||
return
|
||||
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
findApkHistory.append(ComboInstallPath.get())
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
messagebox.showinfo(title="提示", message="保存成功!")
|
||||
|
||||
## 获取 apk 文件的图标(部分程序不支持)
|
||||
# def SaveApkIcon(apkFilePath, iconSavePath)->"获取 apk 文件的图标(部分程序不支持)":
|
||||
# zip = zipfile.ZipFile(apkFilePath)
|
||||
# iconData = zip.read(GetApkIconInApk(apkFilePath))
|
||||
# with open(iconSavePath, 'w+b') as saveIconFile:
|
||||
# saveIconFile.write(iconData)
|
||||
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path()->"获取用户桌面目录":
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home()->"获取用户主目录":
|
||||
return os.path.expanduser('~')
|
||||
|
||||
###########################
|
||||
# 程序信息
|
||||
###########################
|
||||
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
|
||||
version = "1.3.1"
|
||||
goodRunSystem = "Linux(deepin/UOS)"
|
||||
aaptVersion = GetCommandReturn("aapt version")
|
||||
about = ''' 一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
||||
|
||||
版本 :{}
|
||||
|
||||
适用平台 :{}
|
||||
|
||||
tkinter版本:{}
|
||||
|
||||
aapt 版本 :{}
|
||||
|
||||
程序官网 :{}
|
||||
|
||||
©2021-{}'''.format(version, goodRunSystem, tk.TkVersion, aaptVersion,programUrl, time.strftime("%Y"))
|
||||
tips = ''' 新版本Deepin/UOS发布后,可以在应用商店安装部分官方已适配的安卓应用,对爱好者来说,不能自己安装APK软件包始终差点意思,本程序可以为Deepin/UOS上的Uengine安卓运行环境安装自定义APK软件包,并能发送安装的APK包启动菜单到桌面或系统菜单。
|
||||
|
||||
安装APK:
|
||||
点浏览按钮,选中需要安装的APK,然后点安装按钮
|
||||
|
||||
卸载APK:
|
||||
在卸载APK下面的输入框内输入需要卸载的APK包名,点卸载按钮,如果无法获取包名,可以通过浏览APK文件程序自动获取包名进行卸载。
|
||||
|
||||
保存APK图标:
|
||||
在安装APK下面的输入框浏览或输入APK的路径,然后点击“保存图标”按钮,选择保存位置即可
|
||||
|
||||
打开Uengine应用列表:
|
||||
打开系统已安装的应用列表(安卓界面)
|
||||
|
||||
提示:
|
||||
1、需要你有使用 root 权限的能力;
|
||||
2、需要安装 uengine 才能使用;
|
||||
3、提取 apk 图标的 apk 路径以“安装 apk”那栏为准;
|
||||
4、如果报错是有关产生 .deksotp 文件有关,一般可以打开程序列表运行。如果想要连接其他手机,请使用 1.2.0 以前的版本,可以使用 adb 连接。
|
||||
|
||||
'''
|
||||
updateThingsString = '''V1.3.1:
|
||||
※1、修复打包问题,防止部分用户安装出错的问题;
|
||||
※2、修复了程序无法提取图标时可以提取默认图标使用;
|
||||
|
||||
V1.3.0:
|
||||
※1、修改了界面布局;
|
||||
※2、修复大多数新安装普通用户的路图标及启动菜单文件路径不存在导致安装APK报错的bugs;
|
||||
3、删除少量冗余代码,调整代码顺序;
|
||||
4、支持提取 apk 图标。
|
||||
|
||||
V1.2.3
|
||||
1、调整部分控件名称;
|
||||
2、调整界面布局及界面风格;
|
||||
|
||||
V1.2.2
|
||||
1、对程序错误的显示更加人性化;
|
||||
2、对 icon 的获取方式进行了升级;
|
||||
3、增加了注释、删除部分冗余代码。
|
||||
|
||||
V1.2.1:
|
||||
※1、进行了安装方式的修改(不使用 adb),修复原无法安装和卸载的问题;
|
||||
2、进行了部分优化;
|
||||
3、进行了功能缩水;
|
||||
4、修复 deb 打包错误。'''
|
||||
title = "uengine 安装器 {}".format(version)
|
||||
updateTime = "2021年08月08日"
|
||||
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
|
||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||
iconPath = "{}/icon.png".format(os.path.split(os.path.realpath(__file__))[0])
|
||||
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
|
||||
desktopName = "UengineAndroidProgramList.desktop"
|
||||
contribute = '''gfdgd xi<3025613752@qq.com>
|
||||
actionchen<917981399@qq.com>'''
|
||||
useProgram = '''1、uengine相关软件包(基于anbox开发)
|
||||
2、Python3
|
||||
3、tkinter(tkinter.tk、ttkthemes 和 tkinter.ttk)
|
||||
4、aapt
|
||||
……'''
|
||||
|
||||
###########################
|
||||
# 加载配置
|
||||
###########################
|
||||
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/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"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json", json.dumps({})) # 创建配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindUninstallApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindUninstallApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/SaveApkIcon.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/SaveApkIcon.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
|
||||
###########################
|
||||
# 设置变量
|
||||
###########################
|
||||
findApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApkHistory.json")).values())
|
||||
fineUninstallApkHistory = list(json.loads(readtxt(get_home() + "/.config/uengine-runner/FindUninstallApkHistory.json")).values())
|
||||
|
||||
# add sub window
|
||||
#添加窗口开启关闭开关,防止重复开启
|
||||
windowflag = "close"
|
||||
|
||||
def showhelp():
|
||||
|
||||
#define window and frame and button label
|
||||
#
|
||||
global windowflag
|
||||
if windowflag == "close":
|
||||
helpwindow=tk.Toplevel()
|
||||
helpwindow.resizable(0, 0)
|
||||
helpwindow.title("帮助")
|
||||
|
||||
|
||||
# get screen width and height
|
||||
screen_width = helpwindow.winfo_screenwidth()
|
||||
screen_height = helpwindow.winfo_screenheight()
|
||||
# calculate position x and y coordinates 假设主窗口大小固定 570x236像素 ,设置窗口位置为屏幕中心。
|
||||
winwith=490
|
||||
winhigh=600
|
||||
x = (screen_width/2) - (winwith/2)
|
||||
y = (screen_height/2) - (winhigh/2)
|
||||
|
||||
helpwindow.geometry("490x650"+"+{:.0f}+{:.0f}".format(x, y))
|
||||
|
||||
style = ttkthemes.ThemedStyle(helpwindow)
|
||||
style.set_theme("breeze")
|
||||
|
||||
|
||||
|
||||
Frmroot=ttk.Frame(helpwindow)
|
||||
FrmMenu = ttk.Frame(Frmroot)
|
||||
FrmText = ttk.Frame(Frmroot)
|
||||
|
||||
LabFrmText=ttk.LabelFrame(FrmText,text="帮助",height=800,borderwidth=3)
|
||||
HelpStr = tk.StringVar()
|
||||
HelpStr.set(tips)
|
||||
LabText = ttk.Label(LabFrmText, textvariable=HelpStr,width=50)
|
||||
LabText.config(wraplength=350)
|
||||
|
||||
def on_closing():
|
||||
global windowflag
|
||||
windowflag = "close"
|
||||
print(windowflag)
|
||||
helpwindow.destroy()
|
||||
|
||||
|
||||
|
||||
# define button func
|
||||
def ChgLog():
|
||||
HelpStr.set(updateThingsString)
|
||||
def ChgAbout():
|
||||
HelpStr.set(about)
|
||||
def ChgDep():
|
||||
HelpStr.set(useProgram)
|
||||
def ChgCon():
|
||||
HelpStr.set(contribute)
|
||||
def ChgTips():
|
||||
HelpStr.set(tips)
|
||||
LabText.config(wraplength=350)
|
||||
|
||||
BtnReadme = ttk.Button(FrmMenu, text="使用说明",width=14,command=ChgTips)
|
||||
BtnLog = ttk.Button(FrmMenu, text="更新内容",width=14,command=ChgLog)
|
||||
BtnZujian = ttk.Button(FrmMenu, text="程序依赖的组件",width=14,command=ChgDep)
|
||||
BtnGongxian = ttk.Button(FrmMenu, text="有贡献的开发者",width=14,command=ChgCon)
|
||||
BtnAbout = ttk.Button(FrmMenu, text="关于",width=14,command=ChgAbout)
|
||||
|
||||
|
||||
#layout
|
||||
FrmMenu.grid(row=0,column=0,sticky=tk.NW)
|
||||
BtnReadme.grid(row=0,column=0,sticky=tk.NW,padx=3)
|
||||
BtnLog.grid(row=1,column=0,sticky=tk.NW,padx=3)
|
||||
BtnZujian.grid(row=2,column=0,sticky=tk.NW,padx=3)
|
||||
BtnGongxian.grid(row=3,column=0,sticky=tk.NW,padx=3)
|
||||
BtnAbout.grid(row=4,column=0,sticky=tk.NW,padx=3)
|
||||
|
||||
FrmText.grid(row=0,column=1,sticky=tk.NW)
|
||||
LabFrmText.grid(row=0,column=0,sticky=tk.NW,padx=3,pady=3)
|
||||
LabText.grid(row=0,column=0,sticky=tk.NW)
|
||||
|
||||
Frmroot.pack()
|
||||
windowflag = "open"
|
||||
print(windowflag)
|
||||
#helpwindow.mainloop()
|
||||
helpwindow.protocol("WM_DELETE_WINDOW", on_closing)
|
||||
|
||||
|
||||
###########################
|
||||
# 窗口创建
|
||||
###########################
|
||||
win = tk.Tk() # 创建窗口
|
||||
|
||||
# 设置窗口
|
||||
style = ttkthemes.ThemedStyle(win)
|
||||
style.set_theme("breeze")
|
||||
window = ttk.Frame(win)
|
||||
win.attributes('-alpha', 0.5)
|
||||
win.title(title)
|
||||
win.resizable(0, 0)
|
||||
win.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
|
||||
# get screen width and height
|
||||
screen_width = win.winfo_screenwidth()
|
||||
screen_height = win.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)
|
||||
|
||||
win.geometry(""+"+{:.0f}+{:.0f}".format(x, y))
|
||||
|
||||
# 创建控件
|
||||
FrmInstall = ttk.Frame(window)
|
||||
FrmUninstall = ttk.Frame(window)
|
||||
LabApkPath = ttk.Label(window, text="安装APK:")
|
||||
LabUninstallPath = ttk.Label(window, text="卸载APK:")
|
||||
ComboInstallPath = ttk.Combobox(window, width=50)
|
||||
ComboUninstallPath = ttk.Combobox(window, width=50)
|
||||
BtnFindApk = ttk.Button(FrmInstall, text="浏览", command=FindApk)
|
||||
BtnInstall = ttk.Button(FrmInstall, text="安装", command=Button3Install)
|
||||
BtnShowUengineApp = ttk.Button(window, text="打开 uengine 应用列表", command=Button5Click)
|
||||
BtnUninstallApkBrowser = ttk.Button(FrmUninstall, text="浏览", command=BtnFindUninstallApkClk)
|
||||
BtnUninstall = ttk.Button(FrmUninstall, text="卸载", command=ButtonClick8)
|
||||
Btngeticon = ttk.Button(window, text="保存图标", command=SaveIconToOtherPath)
|
||||
# 设置菜单栏
|
||||
menu = tk.Menu(window, background="white")
|
||||
|
||||
programmenu = 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="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) # 设置“退出程序”
|
||||
|
||||
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
|
||||
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
|
||||
|
||||
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
|
||||
help.add_command(label="帮助", command=showhelp) # 设置“关于这个程序”项
|
||||
|
||||
menu.configure(activebackground="dodgerblue")
|
||||
help.configure(activebackground="dodgerblue")
|
||||
uengine.configure(activebackground="dodgerblue")
|
||||
programmenu.configure(activebackground="dodgerblue")
|
||||
|
||||
# 设置控件
|
||||
ComboUninstallPath['value'] = fineUninstallApkHistory
|
||||
ComboInstallPath['value'] = findApkHistory
|
||||
# 显示控件
|
||||
win.config(menu=menu) # 显示菜单栏
|
||||
|
||||
|
||||
|
||||
LabApkPath.grid(row=1, column=0,sticky= tk.W,padx=3)
|
||||
ComboInstallPath.grid(row=2, column=0,padx=3)
|
||||
|
||||
|
||||
FrmInstall.grid(row=2, column=1,padx=3)
|
||||
BtnFindApk.grid(row=0, column=0)
|
||||
BtnInstall.grid(row=0, column=1)
|
||||
|
||||
LabUninstallPath.grid(row=3, column=0,sticky= tk.W,padx=3)
|
||||
ComboUninstallPath.grid(row=4, column=0,padx=3)
|
||||
|
||||
FrmUninstall.grid(row=4, column=1,padx=3)
|
||||
BtnUninstallApkBrowser.grid(row=0, column=0)
|
||||
BtnUninstall.grid(row=0, column=1)
|
||||
|
||||
BtnShowUengineApp.grid(row=5, column=0,sticky= tk.W,padx=3,pady=2)
|
||||
|
||||
Btngeticon.grid(row=3, column=1,sticky= tk.W,padx=3,pady=2)
|
||||
|
||||
window.pack()
|
||||
|
||||
win.mainloop()
|
||||
|
||||
16
uengine-install (1).desktop
Normal file
@@ -0,0 +1,16 @@
|
||||
[Desktop Entry]
|
||||
Categories=system;Utility;
|
||||
Encoding=UTF-8
|
||||
Exec=uengine-runner -ci %F
|
||||
GenericName=APK 安装(uengine)
|
||||
GenericName[zh_CN]=APK 安装(uengine)
|
||||
Icon=/opt/apps/uengine-runner/icon.png
|
||||
MimeType=application/apk;
|
||||
Name=APK 安装(uengine)
|
||||
Name[zh_CN]=APK 安装(uengine)
|
||||
NoDisplay=true
|
||||
OnlyShowIn=Unity;
|
||||
StartupNotify=false
|
||||
StartupWMClass=APK 安装(uengine)
|
||||
Terminal=false
|
||||
Type=Application
|
||||
299
uengine-runner
@@ -1,299 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# 使用系统默认的 python3 运行
|
||||
###########################################################################################
|
||||
# 作者:gfdgd xi
|
||||
# 版本:1.0.0
|
||||
# 更新时间:2021年
|
||||
# 感谢:
|
||||
# 基于 Python3 的 tkinter 构建
|
||||
###########################################################################################
|
||||
#################
|
||||
# 引入所需的库
|
||||
#################
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
import traceback
|
||||
import threading
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.messagebox as messagebox
|
||||
import tkinter.filedialog as filedialog
|
||||
import PIL.Image as Image
|
||||
import PIL.ImageTk as ImageTk
|
||||
|
||||
def KillAdbProgress():
|
||||
DisabledAndEnbled(True)
|
||||
Return = GetCommandReturn("killall adb")
|
||||
if Return is "":
|
||||
Return = "OK!"
|
||||
messagebox.showinfo(title="tips", message=Return)
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def Button1Click():
|
||||
if combobox2.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=ConnectPhoneIp).start()
|
||||
|
||||
def ConnectPhoneIp():
|
||||
global phoneIp
|
||||
messagebox.showinfo(title="tips", 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 FindApk():
|
||||
path = filedialog.askopenfilename(title="选择 Apk", filetypes=[("APK 文件", "*.apk"), ("所有文件", "*.*")], initialdir=json.loads(readtxt(get_home() + "/.config/uengine-runner/FindApk.json"))["path"])
|
||||
if not path is "":
|
||||
combobox1.set(path)
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": os.path.dirname(path)})) # 写入配置文件
|
||||
|
||||
def Button3Install():
|
||||
if combobox1.get() is "":
|
||||
messagebox.showerror(title="Tips", message="Don't input right things in ComboBox")
|
||||
return
|
||||
DisabledAndEnbled(True)
|
||||
threading.Thread(target=InstallApk, args=(combobox1.get(),)).start()
|
||||
|
||||
def InstallApk(path):
|
||||
global findApkHistory
|
||||
messagebox.showinfo(title="Tips", message=GetCommandReturn("adb install '{}'".format(path)))
|
||||
findApkHistory.append(combobox1.get())
|
||||
combobox1['value'] = findApkHistory
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
def DisabledAndEnbled(choose):
|
||||
userChoose = {True: tk.DISABLED, False: tk.NORMAL}
|
||||
a = userChoose[choose]
|
||||
combobox1.configure(state=a)
|
||||
combobox2.configure(state=a)
|
||||
button1.configure(state=a)
|
||||
button2.configure(state=a)
|
||||
button3.configure(state=a)
|
||||
button4.configure(state=a)
|
||||
button5.configure(state=a)
|
||||
|
||||
# 需引入 subprocess
|
||||
def GetCommandReturn(cmd):
|
||||
# cmd 是要获取输出的命令
|
||||
return subprocess.getoutput(cmd)
|
||||
|
||||
def Button5Click():
|
||||
threading.Thread(target=OpenUengineProgramList).start()
|
||||
|
||||
def OpenUengineProgramList():
|
||||
os.system("/usr/bin/uengine-launch.sh --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
||||
|
||||
# 显示“关于这个程序”窗口
|
||||
def about_this_program():
|
||||
global about
|
||||
global title
|
||||
global iconPath
|
||||
message = tk.Toplevel()
|
||||
message.title("关于 {}".format(title))
|
||||
message.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
img = ImageTk.PhotoImage(Image.open(iconPath))
|
||||
label1 = ttk.Label(message, image=img)
|
||||
label2 = ttk.Label(message, text=about)
|
||||
button1 = ttk.Button(message, text="确定", command=message.withdraw)
|
||||
label1.pack()
|
||||
label2.pack()
|
||||
button1.pack(side="bottom")
|
||||
message.mainloop()
|
||||
|
||||
# 显示“提示”窗口
|
||||
def helps():
|
||||
global tips
|
||||
messagebox.showinfo(title="提示", message=tips)
|
||||
|
||||
# 显示更新内容窗口
|
||||
def UpdateThings():
|
||||
messagebox.showinfo(title="更新内容", message=updateThings)
|
||||
|
||||
# 打开程序官网
|
||||
def OpenProgramURL():
|
||||
webbrowser.open_new_tab(programUrl)
|
||||
|
||||
# 重启本应用程序
|
||||
def ReStartProgram():
|
||||
python = sys.executable
|
||||
os.execl(python, python, * sys.argv)
|
||||
|
||||
def CleanProgramHistory():
|
||||
try:
|
||||
if messagebox.askokcancel(title="警告", message="删除后将无法恢复,你确定吗?\n删除后软件将会自动重启。"):
|
||||
shutil.rmtree(get_home() + "/.config/uengine-runner")
|
||||
ReStartProgram()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
|
||||
# 获取用户主目录
|
||||
def get_home():
|
||||
return os.path.expanduser('~')
|
||||
|
||||
def SendUengineAndroidListForDesktop():
|
||||
global desktop
|
||||
global desktopName
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/{}".format(get_desktop_path(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="桌面已经存在快捷方式,你确定要覆盖吗?"):
|
||||
return
|
||||
shutil.copy(desktop, get_desktop_path())
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 获取用户桌面目录
|
||||
def get_desktop_path():
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
def SendUengineAndroidListForLauncher():
|
||||
DisabledAndEnbled(True)
|
||||
try:
|
||||
if os.path.exists("{}/.local/share/applications/{}".format(get_home(), desktopName)):
|
||||
if not messagebox.askokcancel(title="提示", message="启动器已经存在快捷方式,你确定要覆盖吗?"):
|
||||
return
|
||||
if not os.path.exists("{}/.local/share/applications/".format(get_home())):
|
||||
os.makedirs("{}/.local/share/applications/".format(get_home()))
|
||||
shutil.copy(desktop, "{}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
os.system("chmod 755 {}/.local/share/applications/{}".format(get_home(), desktopName))
|
||||
messagebox.showinfo(title="提示", message="发送成功!")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
messagebox.showerror(title="错误", message=traceback.format_exc())
|
||||
DisabledAndEnbled(False)
|
||||
|
||||
# 数组转字典
|
||||
def ListToDictionary(list):
|
||||
dictionary = {}
|
||||
for i in range(len(list)):
|
||||
dictionary[i] = list[i]
|
||||
return dictionary
|
||||
|
||||
# 读取文本文档
|
||||
def readtxt(path):
|
||||
f = open(path, "r") # 设置文件对象
|
||||
str = f.read() # 获取内容
|
||||
f.close() # 关闭文本对象
|
||||
return str # 返回结果
|
||||
|
||||
# 写入文本文档
|
||||
def write_txt(path, things):
|
||||
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
|
||||
file.write(things) # 写入文本
|
||||
file.close() # 关闭文本对象
|
||||
|
||||
###########################
|
||||
# 程序信息
|
||||
###########################
|
||||
programUrl = "https://gitee.com/gfdgd-xi/uengine-runner"
|
||||
version = "1.0.0"
|
||||
goodRunSystem = "Linux"
|
||||
about = '''一个基于 Python3 的 tkinter 制作的 uengine APK 安装器
|
||||
版本:{}
|
||||
适用平台:{}
|
||||
tkinter 版本:{}
|
||||
程序官网:{}
|
||||
©2021-{} gfdgd xi'''.format(version, goodRunSystem, tk.TkVersion, programUrl, time.strftime("%Y"))
|
||||
tips = '''提示:
|
||||
1、None'''
|
||||
updateThingsString = ''''''
|
||||
title = "uengine 运行器 {}".format(version)
|
||||
updateTime = "2021年"
|
||||
updateThings = "{} 更新内容:\n{}\n更新时间:{}".format(version, updateThingsString, updateTime, time.strftime("%Y"))
|
||||
iconPath = "/opt/apps/uengine-runner/icon.png"
|
||||
desktop = "/opt/apps/uengine-runner/UengineAndroidProgramList.desktop"
|
||||
desktopName = "UengineAndroidProgramList.desktop"
|
||||
|
||||
###########################
|
||||
# 加载配置
|
||||
###########################
|
||||
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/FindApkHistory.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApkHistory.json", json.dumps({})) # 创建配置文件
|
||||
if not os.path.exists(get_home() + "/.config/uengine-runner/FindApk.json"): # 如果没有配置文件
|
||||
write_txt(get_home() + "/.config/uengine-runner/FindApk.json", json.dumps({"path": "~"})) # 写入(创建)一个配置文件
|
||||
|
||||
###########################
|
||||
# 设置变量
|
||||
###########################
|
||||
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())
|
||||
|
||||
###########################
|
||||
# 窗口创建
|
||||
###########################
|
||||
window = tk.Tk()
|
||||
window.title(title)
|
||||
window.iconphoto(False, tk.PhotoImage(file=iconPath))
|
||||
frame1 = ttk.Frame(window)
|
||||
frame2 = ttk.Frame(window)
|
||||
label1 = ttk.Label(window, text="要安装的 apk 路径:")
|
||||
label2 = ttk.Label(window, text="要连接的设备的 IP(默认 IP 为 192.168.250.2):")
|
||||
combobox1 = ttk.Combobox(window, width=100)
|
||||
combobox2 = ttk.Combobox(window, width=100)
|
||||
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="Kill Adb Progress", command=KillAdbProgress)
|
||||
button5 = ttk.Button(frame2, text="Open uengine Program List", command=Button5Click)
|
||||
menu = tk.Menu(window) # 设置菜单栏
|
||||
programmenu = tk.Menu(menu, tearoff=0) # 设置“程序”菜单栏
|
||||
menu.add_cascade(label="程序", menu=programmenu)
|
||||
programmenu.add_command(label="清空软件历史记录", command=CleanProgramHistory)
|
||||
programmenu.add_separator() # 设置分界线
|
||||
programmenu.add_command(label="退出程序", command=window.quit) # 设置“退出程序”项
|
||||
uengine = tk.Menu(menu, tearoff=0)
|
||||
menu.add_cascade(label="uengine", menu=uengine)
|
||||
uengine.add_command(label="发送 uengine 应用列表到桌面", command=SendUengineAndroidListForDesktop)
|
||||
uengine.add_command(label="发送 uengine 应用列表到启动器", command=SendUengineAndroidListForLauncher)
|
||||
help = tk.Menu(menu, tearoff=0) # 设置“帮助”菜单栏
|
||||
menu.add_cascade(label="帮助", menu=help)
|
||||
help.add_command(label="程序官网", command=OpenProgramURL) # 设置“程序官网”项
|
||||
help.add_separator()
|
||||
help.add_command(label="小提示", command=helps) # 设置“小提示”项
|
||||
help.add_command(label="更新内容", command=UpdateThings) # 设置“更新内容”项
|
||||
help.add_command(label="关于这个程序", command=about_this_program) # 设置“关于这个程序”项
|
||||
# 设置控件
|
||||
combobox2['value'] = phoneIp
|
||||
combobox1['value'] = findApkHistory
|
||||
#
|
||||
window.config(menu=menu) # 显示菜单栏
|
||||
label1.grid(row=2, column=0)
|
||||
label2.grid(row=0, column=0)
|
||||
combobox1.grid(row=2, column=1)
|
||||
combobox2.grid(row=0, column=1)
|
||||
button1.grid(column=0, row=0)
|
||||
button2.grid(row=2, column=2)
|
||||
button3.grid(row=0, column=0)
|
||||
button4.grid(column=1, row=0)
|
||||
button5.grid(row=0, column=1)
|
||||
frame1.grid(row=1, columnspa=3)
|
||||
frame2.grid(row=3, columnspa=3)
|
||||
window.mainloop()
|
||||
BIN
示例/HyperBowl.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
示例/小猿口算.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
示例/百度网盘.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
示例/百度翻译.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
示例/腾讯课堂.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |