diff --git a/Makefile b/Makefile index 07d90d0..16c1596 100755 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ build: cp -rv builer.svg new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv api new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv Help new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ - cp -rv Download.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ + cp -rv Download.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ + cp -rv updatekiller.py new-deb-build/opt/apps/com.gitee.uengine.runner.spark/files/ cp -rv pkexec/* new-deb-build/usr/share/polkit-1/actions python3 RemovePycacheFile.py cp -rv new-deb-build /tmp/uengine-runner-builder diff --git a/mainwindow.py b/mainwindow.py index eb93586..09dfcb7 100755 --- a/mainwindow.py +++ b/mainwindow.py @@ -26,6 +26,7 @@ import traceback import threading import webbrowser import subprocess +import updatekiller map = True import matplotlib import matplotlib.figure @@ -1099,7 +1100,7 @@ class UpdateWindow(): updateWidgetLayout = QtWidgets.QGridLayout() versionLabel = QtWidgets.QLabel(f"当前版本:{version}\n最新版本:未知\n更新内容:") updateText = QtWidgets.QTextBrowser() - ok = QtWidgets.QPushButton("更新(更新过程中会关闭所有Python应用,包括这个应用)") + ok = QtWidgets.QPushButton("更新(更新过程中会关闭这个应用的所有进程)") ok.clicked.connect(UpdateWindow.Update) cancel = QtWidgets.QPushButton("取消") cancel.clicked.connect(UpdateWindow.update.close) @@ -1134,8 +1135,8 @@ class UpdateWindow(): write_txt("/tmp/uengine-runner/update.sh", f"""#!/bin/bash echo 删除多余的安装包 rm -rfv /tmp/uengine-runner/update/* -echo 关闭“UEngine 运行器”以及其它“Python 应用” -killall python3 +echo 关闭“UEngine 运行器” +python3 {programPath}/updatekiller.py echo 下载安装包 wget -P /tmp/uengine-runner/update {UpdateWindow.data["Url"][0]} echo 安装安装包 diff --git a/uengine-apk-builder b/uengine-apk-builder index ee1b48e..ad6389f 100755 --- a/uengine-apk-builder +++ b/uengine-apk-builder @@ -18,6 +18,7 @@ import random import zipfile import traceback import subprocess +import updatekiller import PyQt5.QtGui as QtGui import PyQt5.QtCore as QtCore import PyQt5.QtWidgets as QtWidgets @@ -490,4 +491,4 @@ try: except: print("无参数") window.show() -sys.exit(app.exec_()) \ No newline at end of file +sys.exit(app.exec_()) diff --git a/uengine-app-install b/uengine-app-install index 120467c..5984cb2 100755 --- a/uengine-app-install +++ b/uengine-app-install @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) sys.exit(os.system("sudo /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(sys.argv[1]))) print("命令参数错误") -sys.exit(1) \ No newline at end of file +sys.exit(1) diff --git a/uengine-app-setting.py b/uengine-app-setting.py index 2fca036..0993ca1 100755 --- a/uengine-app-setting.py +++ b/uengine-app-setting.py @@ -2,6 +2,7 @@ from modulefinder import packagePathMap import sys import ttkthemes +import updatekiller import tkinter as tk import tkinter.ttk as ttk @@ -31,4 +32,4 @@ def main(): return 0 if __name__ == "__main__": - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/uengine-app-uninstall b/uengine-app-uninstall index 452bfc9..6e63022 100755 --- a/uengine-app-uninstall +++ b/uengine-app-uninstall @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) sys.exit(os.system("sudo /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(sys.argv[1]))) print("命令参数错误") -sys.exit(1) \ No newline at end of file +sys.exit(1) diff --git a/uengine-clean b/uengine-clean index 98543e0..8c3a509 100755 --- a/uengine-clean +++ b/uengine-clean @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import updatekiller if len(sys.argv) > 1: if sys.argv[1] == "--help": print("帮助:") @@ -8,4 +9,4 @@ if len(sys.argv) > 1: sys.exit(0) print("参数错误") sys.exit(1) -sys.exit(os.system("sudo rm -rf /data/uengine")) \ No newline at end of file +sys.exit(os.system("sudo rm -rf /data/uengine")) diff --git a/uengine-keyboard b/uengine-keyboard index eaf54a7..9cb4d80 100755 --- a/uengine-keyboard +++ b/uengine-keyboard @@ -14,6 +14,7 @@ import traceback import ttkthemes import pyautogui import threading +import updatekiller import tkinter as tk import tkinter.ttk as ttk import tkinter.messagebox as messagebox @@ -238,4 +239,4 @@ keys.start() threading.Thread(target=ShowTips).start() pyautogui.FAILSAFE = False threading.Thread(target=RestartProgramTimer).start() -window.mainloop() \ No newline at end of file +window.mainloop() diff --git a/uengine-runner-about b/uengine-runner-about index ea82964..70208f7 100755 --- a/uengine-runner-about +++ b/uengine-runner-about @@ -16,6 +16,7 @@ import time import json import ttkthemes import subprocess +import updatekiller import tkinter as tk import tkinter.ttk as ttk @@ -167,4 +168,4 @@ def showhelp(): print(windowflag) helpwindow.mainloop() #helpwindow.protocol("WM_DELETE_WINDOW", on_closing) -showhelp() \ No newline at end of file +showhelp() diff --git a/uengine-runner-update-bug b/uengine-runner-update-bug index 143fa2c..544d66c 100755 --- a/uengine-runner-update-bug +++ b/uengine-runner-update-bug @@ -6,6 +6,7 @@ import base64 import requests import traceback import webbrowser +import updatekiller import urllib.parse as parse import PyQt5.QtGui as QtGui import PyQt5.QtWidgets as QtWidgets @@ -108,4 +109,4 @@ window.setCentralWidget(widget) window.setWindowTitle(f"UEngine 运行器 {version} 问题/建议反馈") window.setWindowIcon(QtGui.QIcon(iconPath)) window.show() -sys.exit(app.exec_()) \ No newline at end of file +sys.exit(app.exec_()) diff --git a/uengine-useadb b/uengine-useadb index 85fe2be..e0eaf6b 100755 --- a/uengine-useadb +++ b/uengine-useadb @@ -6,6 +6,7 @@ import os import sys import traceback +import updatekiller import PyQt5.QtWidgets as QtWidgets ######################## # @@ -69,4 +70,4 @@ try: except: traceback.print_exc() QtWidgets.QMessageBox.information(None, "错误", traceback.format_exc()) - sys.exit(2) \ No newline at end of file + sys.exit(2) diff --git a/uengine-window-size-setting.py b/uengine-window-size-setting.py index 28e8136..4178d1d 100755 --- a/uengine-window-size-setting.py +++ b/uengine-window-size-setting.py @@ -3,6 +3,7 @@ import os import sys import shutil import traceback +import updatekiller def Add(): try: @@ -41,4 +42,4 @@ if __name__ == "__main__": Del() sys.exit(0) print("参数错误!") - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/updatekiller.py b/updatekiller.py new file mode 100755 index 0000000..962aee4 --- /dev/null +++ b/updatekiller.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +import sys +import os +import atexit + +PIDFILE = '/tmp/uengine-runner.pid' + +#程序结束时清理pid +@atexit.register +def remove_pid(): + with open(PIDFILE) as pidfile: + pidlst = pidfile.readlines() + pidlst.remove(str(PID)+'\n') + with open(PIDFILE,'w') as pidfile: + pidfile.writelines(pidlst) + +#更新时结束进程 +def main(): + for i in open(PIDFILE): + try: + os.kill(int(i),15) + except ProcessLookupError: + pass + os.remove(PIDFILE) + +#当该程序被直接执行时,执行结束进程操作。如果是导入的形式,则只是记录pid +if __name__ == '__main__': + sys.exit(main()) +else: + #获取进程pid,用于更新时结束进程 + PID = os.getpid() + with open(PIDFILE,'a') as pidfile: + print(PID,file=pidfile) #使用print可以在行末输出换行符,而且可以省去类型转换