You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下YAD托盘图标在GNOME终端/启动应用崩溃,VS Code终端正常

Ubuntu 22.04下YAD通知图标脚本在GNOME终端/启动应用中触发Gtk关键错误

我在Ubuntu 22.04(Jammy Jellyfish)系统上编写了一段创建YAD通知图标的Bash脚本,该脚本在Visual Studio Code内置终端中运行正常,但在GNOME终端执行./yad-debug.sh或设置为启动应用时,会触发Gtk关键错误。

脚本代码

#!/bin/bash

# Stop on error (always a good practice)
set -e

# Create a FIFO file, used to manage the I/O redirection from the shell
PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
export PIPE

# Attach a file descriptor to the file
exec 3<> $PIPE

# Add a handler to manage process shutdown
function on_exit() {
    # Send command to YAD through pipe
    echo "quit" >&3
    rm -f $PIPE
}
trap on_exit EXIT

# Create the notification icon
yad --notification                  \
    --listen                        \
    --image="/path/to/icon" <&3 &

while true; do
    sleep 60
done

触发的错误信息

(yad:29692): Gtk-CRITICAL **: 15:21:14.013: gtk_widget_get_scale_factor: assertion 'GTK_IS_WIDGET (widget)' failed

尝试的解决动作

我尝试匹配Visual Studio Code的环境变量,但问题未解决,脚本已指定使用/bin/bash。以下是VS Code与GNOME终端的环境变量差异diff:

198d197
< _=
284,315d282
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< {
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
< }
521d487
< BASH_COMMAND='set > ~/Documents/vscode.env'
526d491
< BASH_REMATCH=()
543,557d507
<     builtin eval "terms=( $(trap -p "${1:-DEBUG}") )";;
<     builtin local -a terms;
<     builtin local LC_ALL=C str="${1}" i byte token out='';
<     builtin printf '\e]633;A\a'
<     builtin printf '\e]633;B\a'
<     builtin printf '\e]633;C\a';
<         builtin printf '\e]633;D\a';
<         builtin printf '\e]633;D;%s\a' "$__vsc_status";;
<     builtin printf '\e]633;E;%s;%s\a' "$(__vsc_escape_value "${__vsc_current_command}")" $__vsc_nonce
<     builtin printf '\e]633;F\a'
<     builtin printf '\e]633;G\a'
<     builtin printf '\e]633;P;Cwd=%s\a' "$(__vsc_escape_value "$PWD")"
<     builtin printf '%s' "${terms[2]:-}"
<     builtin printf '%s\n' "${out}"
<         byte="${str:$i:1}";;
602d551
< CHROME_DESKTOP=code-url-handler.desktop
605c554
< COLUMNS=138
---
> COLUMNS=80
838,839d786
<     do
<     do
896,897d842
<     done;
<     done;
947,948d891
<             else
<         else
971,973d913
<         else
<     else
<     else
1042d981
<         eval "${cmd:-}";;
1118d1056
<             fi;
1155,1159d1092
<         fi;
<         fi;
<         fi;
<         fi;
<     fi
1182,1184d1114
<     fi
<     fi;
<     fi;
1254d1183
<     for cmd in "${__vsc_original_prompt_command[@]}";
1262d1190
<     for ((i=0; i < "${#str}"; ++i ))
1299d1226
< GDK_BACKEND=x11
1311,1312d1237
< GIO_LAUNCHED_DESKTOP_FILE_PID=9235
< GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/code.desktop
1314d1238
< GIT_ASKPASS=/usr/share/code/resources/app/extensions/git/dist/askpass.sh
1341,1342d1264
< GJS_DEBUG_OUTPUT=stderr
< GJS_DEBUG_TOPICS='JS ERROR;JS LOG'
1345a1268,1269
> GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/5de6f03d_baec_4b5b_90c9_0e17b9fa9894
> GNOME_TERMINAL_SERVICE=:1.810
1358a1283
> _=/home/simon/.cargo/env
1393d1317
<     if [[ ! "$BASH_COMMAND" =~ ^__vsc_prompt* ]]; then
1396,1397d1319
<             if [ "$byte" = ";" ]; then
<         if [ "$byte" = "\\" ]; then
1459,1464d1380
<     if [ "$__vsc_current_command" = "" ]; then
<         if [[ "$__vsc_custom_PS1" == "" || "$__vsc_custom_PS1" != "$PS1" ]]; then
<         if [[ "$__vsc_custom_PS2" == "" || "$__vsc_custom_PS2" != "$PS2" ]]; then
<         if [ "$__vsc_history_verify" = "1" ]; then
<     if [ "$__vsc_in_command_execution" = "0" ]; then
<     if [ "$__vsc_in_command_execution" = "1" ]; then
1575d1490
< IM_CONFIG_CHECK_ENV=1
1594d1508
< INVOCATION_ID=da802a91e49b408ea31998f9b2c352a8
1602d1515
< JOURNAL_STREAM=8:31235
1638c1551
< LINES=15
---
> LINES=24
1824d1736
< MANAGERPID=1657
1875d1786
< ORIGINAL_XDG_CURRENT_DESKTOP=ubuntu:GNOME
1877d1787
<         out+="$token";;
1898c1808
< PATH=/home/simon/.local/bin:/home/simon/.cargo/bin:/home/simon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
---
> PATH=/home/simon/.cargo/bin:/home/simon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
1907c1817
< PPID=9800
---
> PPID=62895
1948,1949d1857
< PROMPT_COMMAND=__vsc_prompt_cmd
< PS1=$'\\[\E]633;A\a\\]\\[\e]0;\\u@\\h: \\w\\a\\]${debian_chroot:+($debian_chroot)}\\[\033[01;32m\\]\\u@\\h\\[\033[00m\\]:\\[\033[01;34m\\]\\w\\[\033[00m\\]\\$ \\[\E]633;B\a\\]'
1952c1860
<             PS1="$__vsc_custom_PS1";;
---
> PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
1955,1956c1863
< PS2=$'\\[\E]633;F\a\\]&gt; \\[\E]633;G\a\\]'
<             PS2="$__vsc_custom_PS2";;
---
> PS2='&gt; '
1962c1869
< PWD='/home/simon/Zoho WorkDrive (Kriele)/My Folders/coding/bash'
---
> PWD=/home/simon
2014d1920
<     return "$1"
2113c2019
< SYSTEMD_EXEC_PID=1884
---
> SYSTEMD_EXEC_PID=2040
2121,2122d2026
< TERM_PROGRAM_VERSION=1.83.1
< TERM_PROGRAM=vscode
2133,2135d2036
<             token="\\\\";
<                 token="$byte";
<                 token="\\x3b";
2192,2245c2093
< __vsc_command_complete ()
<     __vsc_command_complete "$__vsc_status";;
<     __vsc_command_output_start
< __vsc_command_output_start ()
< __vsc_continuation_end ()
< __vsc_continuation_start ()
<         __vsc_current_command="";
<     __vsc_current_command="";
<             __vsc_current_command=$BASH_COMMAND;
<             __vsc_current_command="$(builtin history 1 | sed 's/ *[0-9]* *//')";
< __vsc_current_command='set > ~/Documents/vscode.env'
< __vsc_custom_PS1=$'\\[\E]633;A\a\\]\\[\e]0;\\u@\\h: \\w\\a\\]${debian_chroot:+($debian_chroot)}\\[\033[01;32m\\]\\u@\\h\\[\033[00m\\]:\\[\033[01;34m\\]\\w\\[\033[00m\\]\\$ \\[\E]633;B\a\\]'
<             __vsc_custom_PS1="\[$(__vsc_prompt_start)\]$__vsc_original_PS1\[$(__vsc_prompt_end)\]";
< __vsc_custom_PS2=$'\\[\E]633;F\a\\]&gt; \\[\E]633;G\a\\]'
<             __vsc_custom_PS2="\[$(__vsc_continuation_start)\]$__vsc_original_PS2\[$(__vsc_continuation_end)\]";
< __vsc_dbg_trap=
< __vsc_escape_value ()
< __vsc_get_trap ()
< __vsc_history_verify=0
<         __vsc_in_command_execution="0";
<         __vsc_in_command_execution="1";
< __vsc_in_command_execution=1
<     __vsc_initialized=1;
< __vsc_initialized=1
< __vsc_nonce=f9d9fe6a-77d1-48c1-9ea1-40770118ec5c
< VSCODE_GIT_ASKPASS_EXTRA_ARGS=--ms-enable-electron-run-as-node
< VSCODE_GIT_ASKPASS_MAIN=/usr/share/code/resources/app/extensions/git/dist/askpass-main.js
< VSCODE_GIT_ASKPASS_NODE=/usr/share/code/code
< VSCODE_GIT_IPC_HANDLE=/run/user/1000/vscode-git-b4e1450751.sock
< VSCODE_SHELL_INTEGRATION=1
< __vsc_original_prompt_command=
<             __vsc_original_PS1=$PS1;
< __vsc_original_PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
< __vsc_original_PS2='&gt; '
<             __vsc_original_PS2=$PS2;
<     __vsc_precmd
<     __vsc_precmd
< __vsc_precmd ()
<         __vsc_preexec;
< __vsc_preexec ()
< __vsc_preexec_only ()
< __vsc_prompt_cmd ()
< __vsc_prompt_cmd_original ()
< __vsc_prompt_end ()
< __vsc_prompt_start ()
< __vsc_restore_exit_code ()
<     __vsc_restore_exit_code "${__vsc_status}";;
<     __vsc_status="$?";
<     __vsc_status="$?";
< __vsc_status=0
<     __vsc_update_cwd
< __vsc_update_cwd ()
<     __vsc_update_prompt
< __vsc_update_prompt ()
---
> VTE_VERSION=6800
2283c2131
< XDG_CURRENT_DESKTOP=Unity
---
> XDG_CURRENT_DESKTOP=ubuntu:GNOME

内容的提问来源于stack exchange,提问作者dot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 15:24:49