Published on

Flameshot troubleshooting

Authors
  • avatar
    Name
    ttyS3
    Twitter

使用 GNOME 自定义快捷键无法调起 flameshot gui

这个解决办法主要来自 https://github.com/flatpak/xdg-desktop-portal/issues/1070#issuecomment-1762884545

注意, 这里比较奇怪的是,直接在 GNOME 自定义 key binding 里面的 command 写上 /usr/bin/env QT_QPA_PLATFORM=wayland flameshot gui 是不会工作的.

必须通过 shell 脚本执行。暂时不知道原因。

sudo tee /usr/local/bin/flameshot-gui-workaround > /dev/null <<'EOF'
#!/bin/bash
# workaround thanks to https://github.com/flatpak/xdg-desktop-portal/issues/1070#issuecomment-1762884545
env QT_QPA_PLATFORM=wayland flameshot gui

EOF

sudo chmod a+x /usr/local/bin/flameshot-gui-workaround

然后我们把原来配置的 GNOME 自定义 shortcut 的 command 从 flameshot gui 换成 /usr/local/bin/flameshot-gui-workaround :

flameshot-shortcut-2023-10-20_01-15.png

点击 "Take Screenshot" 无法显示截图界面

如果观察系统日志,会发现类似:

xdg-desktop-por[848788]: Failed to show access dialog: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Only the focused app is allowed to show a system access dialog

解决办法是:

https://github.com/flameshot-org/flameshot/issues/2868#issuecomment-1312470098

Hi guys, I was going to add my 2 cents on how it doesn't work for me, but then I experimented a bit more and it started working.

OS: Fedora 37, Wayland, Gnome 43, Flameshot: 12.1.0 installed using dnf, xdg-desktop-portal-1.15.0-1.fc37

What I did to make it work:

Run flameshot Open flameshot's settings window(I also maximized the window to lower the chances of loosing focus of that window - probably not needed) Take a screenshot using flameshot - I clicked the tray icon that came from a gnome extension Permissions question should appear - grant it It should now work fine without asking for permissions next time you take a screenshot The same can be done for flameshot run from the terminal, or triggered by a keyboard shortcut. You need to run flameshot in the terminal instead of using gnome launcher, and repeat the above steps. In this case I don't know if it's the flameshot settings window that needs to be actively focused to trigger the permissions prompt. But it's one of those.

In summary, I can now run flameshot from the tray icon, from terminal, from the ALT+F2(gnome's run command tool) and it takes screenshots without asking for permissions.

点击 "Take Screenshot" 直接被拒绝

与前面说的 "GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Only the focused app is allowed to show a system access dialog" 错误不同, 这次是直接被拒绝。 出现这种情况,基本上是因为,在第一次弹出权限确认窗口的时候,你没有选择(直接按esc也相当于回答了no), 或者选择了 no, 后面就会直接拒绝了。

日志信息:

org.flameshot.Flameshot.desktop[887167]: flameshot: error: Unable to capture screen

这种情况下,我们已经没办法再让这个允许权限的窗口弹出来显示了。

好在万能的 github 用户也给出了解决办法: https://github.com/flameshot-org/flameshot/issues/2868#issuecomment-1384310540

先 dump 一下当前的配置:

import dbus
import json

bus = dbus.SessionBus()
perm = bus.get_object('org.freedesktop.impl.portal.PermissionStore', '/org/freedesktop/impl/portal/PermissionStore')
perm_iface = dbus.Interface(perm, dbus_interface='org.freedesktop.impl.portal.PermissionStore')

perm_iface.Lookup("screenshot", "screenshot")
print(json.dumps(perm_iface.Lookup("screenshot", "screenshot"), indent=4))

正常情况下,dump 成 json 后的结果应该类似:

[
    {
        "": [
            "yes"
        ],
        "kitty": [
            "yes"
        ],
        "org.flameshot.Flameshot": [
            "yes"
        ]
    },
    0
]

这里主要是检查是否存在 org.flameshot.Flameshot 并且值应该为 ["yes"].

比如这种情况就是之前拒绝过的情况(值为 no):

>>> perm_iface.Lookup("screenshot", "screenshot")
(dbus.Dictionary({dbus.String(''): dbus.Array([dbus.String('yes')], signature=dbus.Signature('s')), dbus.String('org.flameshot.Flameshot'): dbus.Array([dbus.String('no')], signature=dbus.Signature('s'))}, signature=dbus.Signature('sas')), dbus.Byte(0, variant_level=1))

我们把它 set 回去成 yes:

perm_iface.Set("screenshot", dbus.Boolean(True), "screenshot", {"":["yes"], "org.flameshot.Flameshot": ["yes"]}, dbus.Byte(0x0))

>>> perm_iface.Lookup("screenshot", "screenshot")
(dbus.Dictionary({dbus.String(''): dbus.Array([dbus.String('yes')], signature=dbus.Signature('s')), dbus.String('org.flameshot.Flameshot'): dbus.Array([dbus.String('yes')], signature=dbus.Signature('s'))}, signature=dbus.Signature('sas')), dbus.Byte(0, variant_level=1))

"保存到文件" 无反应

不知道什么时候开始 flameshot 保存到文件的功能不工作了。也没报错。

今天抽空看了下。

找到了这个 issue https://github.com/flameshot-org/flameshot/issues/207

给了我灵感。

cat ~/.config/flameshot/flameshot.ini
[General]
checkForUpdates=false
contrastOpacity=188
showStartupLaunchMessage=false

发现配置就这几行。 但是明明 GUI 配置界面显示了保存路径是 /home/ttys3/Pictures/Screenshots 啊?

重新进入 general 配置,发现有一个 Prefered save file extension 没有值, 于是随手选了一个 avif 格式, 然后再看文件配置,发现已经有保存路径的配置了:

saveAsFileExtension=avif
savePath=/home/ttys3/Pictures/Screenshots
savePathFixed=true

然后再测试保存到文件的功能,也 OK 了. 看来就是 saveAsFileExtension 为空导致文本配置并没有保存成功。问题是它没取到 savePath 居然不报错。

2023-09-28_02-19-flameshot-config-save-path-and-save-extension.avif.png

refs

Taking screenshots with Java under Wayland https://adangel.org/2022/02/06/java-screenshot/

https://flameshot.org/docs/guide/wayland-help/#i-am-asked-to-share-my-screen-every-time

https://github.com/flameshot-org/flameshot/issues/2868#issuecomment-1384310540

https://github.com/flameshot-org/flameshot/issues/3326

https://github.com/flatpak/xdg-desktop-portal/issues/1070#issuecomment-1771302632

flameshot 官方文档里的 troubleshooting 也是不错的参考

https://flameshot.org/docs/guide/troubleshooting/

https://flameshot.org/docs/guide/troubleshooting/#flameshot-icon-is-visible-in-tray-area-but-when-i-click-on-it-nothing-happens

First try the using the command flameshot gui in terminal. This does exactly what clicking on the tray icon does. (make sure can you see Flameshot icon in the tray area)

If the above step didn't work:

Open 3 terminals

Kill Flameshot if it is already open using pkill flameshot

In the first terminal run dbus-monitor --session sender=org.flameshot.Flameshot

In the second terminal run flameshot

In the third terminal run flameshot gui