[Share Experiences] Deepin Wine6的kill.sh脚本探索——可清理残留进程的辅助脚本
Tofloor
poster avatar
神末shenmo
deepin
Spark-App
Q&A Team
2022-05-31 03:06
Author

https://shenmo7192.gitee.io/categories/spark-dwine-helper%E6%96%87%E6%A1%A3/

这里会放关于deepin-wine和辅助工具的文档

正文:

发布时间: 2022-05-30T18:26:37+08:00

对于QQ等退出会残留进程(没有窗口也没有托盘,还在后台跑)的流氓软件,deepin-wine也做了相应的调整,在启动时杀死,防止出错

位置:/opt/deepinwine/tools/kill.sh

行为:

  • 在没有任何参数时,杀死QQ进程
  • 接收到参数时,会寻找第一个参数对应的容器名(在一系列骚操作下,懒得分析了,管他的,好用就完了),找到进程,然后杀死
  • 如果存在第二个参数,如果第二个参数为block,会检测是不是正在残留进程(如果被标注的bottle不活跃(没有Window,也没有托盘)则认为是残留;如果发现这个bottle有Window或者托盘,则认为这是活跃中的应用,不是残留进程),则尝试杀死。

用例:在run_v4.sh中,如果发现应用容器为Deepin-WXWork",则执行CallWXWork(),代码片段如下

CallWXWork()
{
    if [ "autostart" == "$1" ]; then
        env WINEPREFIX="$WINEPREFIX" $WINE_CMD /opt/deepinwine/tools/startbottle.exe &
    else
        /opt/deepinwine/tools/kill.sh WXWork.exe block

        env WINEPREFIX="$WINEPREFIX" $WINE_CMD "c:\\Program Files\\WXWork\\WXWork.exe" &
    fi
}

如果是自动启动,则直接打开

如果不是,先杀死残留进程(如果有)再执行启动

以此原理,在spark_run_v4.sh中添加这样的case+Call启动,即可做到对星火wine应用的定制化启动,比如以后可以在星火的QQ启动脚本中添加此功能

Reply Favorite View the author
All Replies
deepin-superuser
deepin
2022-05-31 03:38
#1

TIM 退出时有进程残留,可以这个用搞吗?

Reply View the author
神末shenmo
deepin
Spark-App
Q&A Team
2022-05-31 04:36
#2
deepin-superuser

TIM 退出时有进程残留,可以这个用搞吗?

CallTIM()
{
    if [ ! -f "$WINEPREFIX/../.QQ_run" ]; then
        debug_log "first run time"
        $SHELL_DIR/add_hotkeys
        $SHELL_DIR/fontconfig
        # If the bottle not exists, run reg may cost lots of times
        # So create the bottle befor run reg
        env WINEPREFIX="$WINEPREFIX" $WINE_CMD uninstaller --list
        touch $WINEPREFIX/../.QQ_run
    fi

    CallProcess "$@"

    #disable Tencent MiniBrowser
    _DeleteRegistry "HKCU\\Software\\Tencent\\MiniBrowser"
}

官方的这里似乎没有这个逻辑,你可以手动杀一下试试

/opt/deepinwine/tools/kill.sh Deepin-TIM block

欢迎给spark_run_v4.sh提pr!打包应用时选择spark_run_v4.sh即可

Call段新增这个逻辑,然后在case $BOTTLENAME in这里写上容器名然后调用Call即可

在依赖中加入spark-dwine-helper即可使用spark_run_v4.sh

Reply View the author
神末shenmo
deepin
Spark-App
Q&A Team
2022-05-31 04:57
#3
deepin-superuser

TIM 退出时有进程残留,可以这个用搞吗?

等下,进程残留这个似乎会默认清理的

CallProcess()
{
    #get file full path
    path="$1"
    path=$(echo ${path/c:/${WINEPREFIX}/drive_c})
    path=$(echo ${path//\\/\/})

    #kill bloack process
    is_autostart $DEB_PACKAGE_NAME
    autostart=$?
    if [ $autostart -ne 0 ];then
        $SHELL_DIR/kill.sh "$BOTTLENAME" block
    fi

    #change current dir to excute path
    path=$(dirname "$path")
    cd "$path"
    pwd

    #Set default mime type
    if [ -n "$MIME_TYPE" ]; then
        xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE"
    fi

    debug_log_to_file "Starting process $* ..."

    env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$@" &

    #start autobottle
    if [ $autostart -eq 0 ];then
        $SHELL_DIR/autostart_wine.sh $DEB_PACKAGE_NAME
    fi
}

如果你没有用官方的TIM容器,应该是自动清理的

Reply View the author
xuqi
deepin testing team
2022-08-25 05:20
#4

kissing_heart

Reply View the author