diff --git a/spark-dwine-helper/build.sh b/spark-dwine-helper/build.sh index 61c8b9b..e65a3cb 100755 --- a/spark-dwine-helper/build.sh +++ b/spark-dwine-helper/build.sh @@ -26,6 +26,7 @@ Architecture: all Maintainer: shenmo Installed-Size: $SIZE Depends: zenity, p7zip-legacy (>= 16.02+dfsg-8+Mejituu-2024022216) | p7zip-full (<< 16.02+transitional.1), fonts-noto-cjk, transhell, python3, wmctrl +Recommends: python3-pyqt5 Section: utils Priority: extra Multi-Arch: foreign @@ -83,7 +84,7 @@ Architecture: all Maintainer: shenmo Installed-Size: $SIZE Depends: zenity, p7zip-legacy (>= 16.02+dfsg-8+Mejituu-2024022216) | p7zip-full (<< 16.02+transitional.1), fonts-noto-cjk, transhell, python3 -Recommends: wmctrl +Recommends: wmctrl,python3-pyqt5 Section: utils Priority: extra Provides: spark-dwine-helper(=$version) diff --git a/spark-dwine-helper/s-wine-helper/opt/deepinwine/tools/spark-wine-banner b/spark-dwine-helper/s-wine-helper/opt/deepinwine/tools/spark-wine-banner index bfa8e31..7175323 100755 --- a/spark-dwine-helper/s-wine-helper/opt/deepinwine/tools/spark-wine-banner +++ b/spark-dwine-helper/s-wine-helper/opt/deepinwine/tools/spark-wine-banner @@ -1,4 +1,17 @@ #!/bin/bash + +##### 若有pybanner则尝试启动 +if [ -e /opt/durapps/spark-dwine-helper/pybanner/pybanner.py ];then +echo "Protocol upgrade: Trying to activate python banner..." +python3 /opt/durapps/spark-dwine-helper/pybanner/pybanner.py +if [ "$?" = "0" ];then +exit +else +echo "Failed to activate. Fallback to normal zenity." +fi +fi + + if [ ! -z "$WAYLAND_DISPLAY" ]; then echo "Wayland detected. Do not check wmclass" zenity --progress --title="星火Windows应用兼容助手" --text="正在为您启动以下应用:$WINE_APP_NAME" --pulsate --width=400 --auto-close --no-cancel --timeout=3 @@ -41,4 +54,4 @@ while true; do done } - check_wmclass | zenity --progress --title="星火Windows应用兼容助手" --text="正在为您启动以下应用:$WINE_APP_NAME" --pulsate --width=400 --auto-close --no-cancel --timeout=10 + check_wmclass | zenity --progress --title="星火Windows应用兼容助手" --text="正在为您启动以下应用:$WINE_APP_NAME" --pulsate --width=400 --auto-close --no-cancel --timeout=20 diff --git a/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/fallback.png b/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/fallback.png new file mode 100755 index 0000000..5284ebe Binary files /dev/null and b/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/fallback.png differ diff --git a/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/pybanner.py b/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/pybanner.py new file mode 100644 index 0000000..5c0f461 --- /dev/null +++ b/spark-dwine-helper/s-wine-helper/opt/durapps/spark-dwine-helper/pybanner/pybanner.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +import os +import sys +import time +import subprocess +import threading +from PyQt5.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtWidgets import * + + + + +def check_window(): + # 使用 wmctrl 命令列出所有窗口,并使用 grep 过滤出特定的 WMCLASS + windows = subprocess.getoutput(f'wmctrl -lx | grep "{target_wmclass}"') + # 如果窗口存在,则关闭提示 + if windows.replace("\n", "").replace(" ", "") != "": + # 提取窗口ID + window_id = windows.replace(" ", " ").split(" ")[0] + + print(f"Window with WMCLASS '{target_wmclass}' found") + return 1 +# else: +# print(f"Window with WMCLASS '{target_wmclass}' not found.") + + +def check_wmclass(): + if timeout: + time.sleep(timeout) + window.close() + return + # 循环检测窗口是否存在的函数 + # 每隔一段时间检测一次窗口是否存在 + showtimeout = 20 # 为防止因为应用无法打开而无法正常关闭窗口,于是设置 time out + while True: + if check_window(): + break + # 等待一段时间后再次检测 + time.sleep(1) + AppInfoShowerRefresh() + showtimeout -= 1 + if showtimeout <= 0: + break + window.close() + + +timeout = 0 +if os.getenv("WAYLAND_DISPLAY"): + timeout = 3 + +if os.system("which wmctrl"): + print("No wmctrl installed. Do not check wmclass") + timeout = 3 + +target_wmclass = os.getenv("WINE_WMCLASS") + +def GetRecommendWindowSize(window: QMainWindow): + # 计算屏幕分辨率 + screen = QGuiApplication.primaryScreen() + width = screen.geometry().width() + height = screen.geometry().height() + # 如果为竖状屏幕 + if width < height: + temp = height + height = width + width = temp + return [int(width / 4), window.geometry().height()] + +def SetWindowSize(window: QMainWindow): + # 计算比例 + size = GetRecommendWindowSize(window) + window.resize(size[0], size[1]) + +def MoveCenter(window: QMainWindow): + # 计算屏幕分辨率 + screen = QGuiApplication.primaryScreen() + width = screen.geometry().width() + height = screen.geometry().height() + print(window.geometry().height()) + # 计算窗口坐标 + window.move(int(width / 2 - window.geometry().width() / 2), + int(height / 2.8 - window.geometry().height() / 2) + ) + +def AppInfoShowerRefresh(): + global appInfoShowerTime + appInfoShower.setText(f"

星火Windows应用兼容助手

正在为您启动以下应用:{os.getenv('WINE_APP_NAME')} {'.' * (appInfoShowerTime % 3 + 1)}

") + + appInfoShowerTime += 1 + +programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string + +app = QApplication(sys.argv) +# 构建窗口 +window = QMainWindow() +widget = QWidget() +layout = QGridLayout() + +appInfoShower = QLabel() +appInfoShowerTime = 0 +AppInfoShowerRefresh() + +# GXDE 彩蛋 +if os.path.exists("/usr/share/gxde-resources/spark-dwine-helper.png"): + backgroundImgPath = "/usr/share/gxde-resources/spark-dwine-helper.png" +########## +if os.path.exists("/opt/durapps/spark-dwine-helper/pybanner/fallback.png"): + backgroundImgPath = "/opt/durapps/spark-dwine-helper/pybanner/fallback.png" +if os.path.exists(f"{programPath}/banner.png"): + backgroundImgPath = f"{programPath}/banner.png" +window.setWindowTitle("星火Windows应用兼容助手") +layout.addWidget(QLabel(f""), 1, 0) +layout.addWidget(appInfoShower, 2, 0) +layout.addWidget(QLabel(f"
由 Wine 运行器驱动"), 4, 0) +widget.setLayout(layout) +window.setCentralWidget(widget) +window.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint) +MoveCenter(window) +SetWindowSize(window) +window.show() + + +layout.addWidget(QLabel(f"

"), 0, 0) +threading.Thread(target=check_wmclass).start() +MoveCenter(window) +app.exec_()