!6 解决更新时需要关闭所有python应用的问题
此前程序更新时需要关闭所有python应用。我的这次改动原理是将每个进程的pid记录下来,更新时将其统一关闭。 主要代码在updatekiller.py文件中,其他文件的改动是为了适配这个文件,用于记录pid。此外,mainwindow.py还适配了更新时的操作。 目前的pid文件位于/tmp/uengine-runner.pid。 手动运行(程序运行后手动执行updatekiller.py)测试通过。由于没有发布更新,我无法进行完整测试。 我修改了部分文案,包括: 更新临时脚本的输出提示(第1138行) 更新按钮(第1103行) Makefile文件(用于将updatekiller.py添加到安装包中) 可能有些小地方没有考虑到。 (我用的编辑器是IDLE,可能和你的不一样。它会在每个文件末尾自动加上换行符,而且无法删除。)
This commit is contained in:
commit
b459ee6db0
3
Makefile
3
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
|
||||
|
|
|
@ -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 安装安装包
|
||||
|
|
|
@ -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_())
|
||||
sys.exit(app.exec_())
|
||||
|
|
|
@ -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)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -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())
|
||||
sys.exit(main())
|
||||
|
|
|
@ -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)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -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"))
|
||||
sys.exit(os.system("sudo rm -rf /data/uengine"))
|
||||
|
|
|
@ -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()
|
||||
window.mainloop()
|
||||
|
|
|
@ -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()
|
||||
showhelp()
|
||||
|
|
|
@ -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_())
|
||||
sys.exit(app.exec_())
|
||||
|
|
|
@ -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)
|
||||
sys.exit(2)
|
||||
|
|
|
@ -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)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -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可以在行末输出换行符,而且可以省去类型转换
|
Loading…
Reference in New Issue