flathub / eu.betterbird.Betterbird

https://flathub.org/apps/details/eu.betterbird.Betterbird
6 stars 0 forks source link

Makes firefox light instead of opening config dir #146

Open moritztim opened 5 months ago

moritztim commented 5 months ago

Originally posted in https://github.com/Betterbird/thunderbird-patches/issues/263:

Steps:

  1. Click on the three horizontal lines in the top bar
  2. Click on Help Screenshot
  3. Click on Troubleshooting Information Screenshot
  4. Spam click Open Directory under "Profile Directory"

Firefox goes into light mode, even if dark mode is explicitly selected. It seems to reset itself as soon as it's somehow reloaded, as you can see in the video

This happens on arch with the GNOME shell with the combination of pacman firefox and:

@Betterbird:

Sorry, but certainly not a Betterbird "the application" issue. Looks like some weird interaction of packages/processes(???) on Linux. You can file FlatPak issue at the BB FlatPak repo: flathub/eu.betterbird.Betterbird

Betterbird commented 5 months ago

A per https://github.com/Betterbird/thunderbird-patches/issues/263#issuecomment-1923653024 it doesn't happen with FlatPak TB, so maybe looking at the differences could shed some light on this.

When you say that it doesn't happen with TB FlatPak, that's using a different profile, right? And AUR BB, that's also using a different profile?

This is just totally weird. Why would pressing a button in app 1 (which should launch a file browser to the directory, and it does in my test) interfere with the display on app 2? I assume you don't have FF configured as file browser?

We had a very weird issue where BB opens links in FF instead of the configured browser app Chrome. We weren't able to work out what causes that, but when people switched BB to the TB profile, it worked correctly.

All I'm saying is that there may be a gremlin hiding in the BB FlatPak profile.

moritztim commented 5 months ago

When you say that it doesn't happen with TB FlatPak, that's using a different profile, right? And AUR BB, that's also using a different profile?

Yes. I did it with a fresh install with all of them, except on Betterbird FlatPak, where I used my personal profile.

I assume you don't have FF configured as file browser?

No.

I also want to note that some other apps have trouble opening my file browser, including FlatPak Thunderbird, since it's not the default FlatPak one but from the AUR.

Betterbird commented 5 months ago

I'm getting confused: "other apps have trouble opening my file browser, including FlatPak Thunderbird". You said that TB FlatPak didn't show the issue. Well, maybe it doesn't show the issue with making FF light, but launching the file browser also doesn't work.

That's the connection between BB FlatPak and FF?

moritztim commented 5 months ago

Well, maybe it doesn't show the issue with making FF light, but launching the file browser also doesn't work.

Exactly. I just wanted to clarify that the issue of the file browser not opening is separate and most likely external.

Betterbird commented 5 months ago

So, just browsing https://github.com/flathub/eu.betterbird.Betterbird/blob/master/README.md, I found a reference to https://bugzilla.mozilla.org/show_bug.cgi?id=1625111 in the "unresolved issues" section.

I'd also suggest to grant BB/TB access to your home directory as described just above the "unresolved issues" section.

Betterbird commented 5 months ago

Just for the record, here is the code that opens the profile directory in TB/BB and FF, it's identical:

https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/toolkit/content/aboutSupport.js#1874-1886 https://searchfox.org/comm-central/rev/26ea08f1bdac796acae793e32203ccf3e35843e5/mail/components/about-support/content/aboutSupport.js#1571-1583

The reveal() function is here: https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/xpcom/io/nsIFile.idl#506-514

Then on Windows: https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/xpcom/io/nsLocalFileWin.cpp#3296-3320 https://searchfox.org/mozilla-central/source/xpcom/io/nsLocalFileWin.cpp#126-183

and on Linux and Mac: https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/xpcom/io/nsLocalFileUnix.cpp#2207-2241 continuing on Linux at: https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/toolkit/system/gnome/nsGIOService.cpp#817-835 The RevealFileViaDBusWithProxy() function it right above, it then calls RevealDirectory(): https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/toolkit/system/gnome/nsGIOService.cpp#720-734 At the end it calls LaunchPath() and LaunchPathImpl(): https://searchfox.org/mozilla-central/rev/34ba7989ae53b9112d543ce39d350b79dc2a16b4/toolkit/system/gnome/nsGIOService.cpp#669-704

And, much to our surprise, that calls g_app_info_launch_default_for_uri() which is a GTK function, documented here: https://docs.gtk.org/gio/iface.AppInfo.html Utility function that launches the default application registered to handle the specified uri.

So if Firefox "moves" when you click the button, I hate to say it, FF must the the default application for "launching" directories.

Since we have the entire call stack here, it would actually be interesting to see why https://bugzilla.mozilla.org/show_bug.cgi?id=1625111 exists. Does TB/BB/FF try to launch an incorrect directory? That's hard to believe since there as so much code that relies on getting the profile directory.

Betterbird commented 5 months ago

For someone who can build a debug FlatPak of either FF or TB/BB, it should be easy to see which directory is launched and why it doesn't work. You might want to post a comment to https://bugzilla.mozilla.org/show_bug.cgi?id=1625111 to make them aware of our previous comment.

Betterbird commented 5 months ago

Paste console.log(Services.dirsvc.get("ProfD", Ci.nsIFile).path) into the console (Ctrl+Shift+J). What do you get?

mfschumann commented 5 months ago

For someone who can build a debug FlatPak of either FF or TB/BB, it should be easy to see which directory is launched and why it doesn't work.

I debugged into LaunchPath() in the BB flatpak and found that the directory to be launched is always a subdirectory of ~/.thunderbird.

When clicking the button to open the directory, BB passes the directory path to the default app for opening directories on the host (a file browser typically). As this app is running outside of the BB flatpak sandbox, it can access directories only via their path on the host.

When BB has been granted access to the home directory, ~/.thunderbird inside the sandbox is ~/.thunderbird on the host, so the directory opens in the file browser successfully when clicking the button.

When BB has not been granted access to the home directory (the default), the profile still resides in ~/.thunderbird inside the sandbox, but this directory is mapped to ~/.var/app/eu.betterbird.Betterbird/.thunderbird on the host. As the file browser is still launched with a directory under ~/.thunderbird, it cannot find it and silently fails. In order to make this scenario work, one would have to translate ~/.thunderbird inside the sandbox to the proper path on the host before passing it into LaunchPath().

mfschumann commented 5 months ago

As for the initially reported issue: I can reproduce that firefox (flatpak) turns from dark mode to light mode when I click the button for opening the profile directory in BB (flatpak) more than once. That test was done with a fresh BB profile on Fedora 39 Silverblue with Gnome.

Btw, I get the same behavior when clicking the button in firefox itself (on the about:profiles page) or in flatpak Thunderbird.

It's quite unexpected to see two sandboxed apps interact like this.

Betterbird commented 5 months ago

Thanks Martin. What does console.log(Services.dirsvc.get("ProfD", Ci.nsIFile).path) in the console give? I wouldn't have thought that reveals the path that's ultimately passed to LauchPath() (so no further debugging necessary).

Firefox going "light" isn't some sort of intended "activation alert"? Something like GetAttention()? https://searchfox.org/mozilla-central/rev/8efb21298a627f403d9a9aa2d77254c1b021b18d/widget/gtk/nsWindow.cpp#3669 https://searchfox.org/mozilla-central/rev/8efb21298a627f403d9a9aa2d77254c1b021b18d/widget/gtk/nsWindow.cpp#7399

mfschumann commented 5 months ago

What does console.log(Services.dirsvc.get("ProfD", Ci.nsIFile).path) in the console give?

It returns the profile path in ~/.thunderbird in both scenarios (access / no access to home directory), just as what went into LaunchPath() in my debugging session.

Firefox going "light" isn't some sort of intended "activation alert"? Something like GetAttention()?

I doubt it. It exactly looks like switching the Gnome shell from dark to light theme. And I haven't seen firefox turn light like this on any occasion before. Where is the "nsWindow::GetAttention" log message supposed to show up? I watched the console in firefox while triggering the issue, but there was nothing.

Betterbird commented 5 months ago

It's here: https://searchfox.org/mozilla-central/rev/8efb21298a627f403d9a9aa2d77254c1b021b18d/widget/gtk/nsAppShell.cpp#50

So:

export MOZ_LOG="Widget:5,timestamp"
export MOZ_LOG_FILE="/where/ever/you/want"

Then start in the same shell.

It exactly looks like switching the Gnome shell from dark to light theme.

And is the change permanent?

mfschumann commented 5 months ago

Thanks. I set MOZ_LOG and MOZ_LOG_FILE as suggested before running firefox, but no log file was created.

And is the change permanent?

I have not seen firefox return to dark mode on its own, only after restarting it. I have not waited longer than ~15 minutes though.

Another observation is that there is some communication on the session bus when clicking the button. Interestingly, the communication differs between the first click (that does not change the firefox theme) and the second click that changes firefox from dark to light mode.

Betterbird's log of the session bus communication (flatpak run --log-session-bus eu.betterbird.Betterbird):

------------------------------------------ click #1 -----------------------------------------------
C29: -> org.freedesktop.DBus call org.freedesktop.DBus.AddMatch at /org/freedesktop/DBus
C30: -> org.freedesktop.DBus call org.freedesktop.DBus.AddMatch at /org/freedesktop/DBus
C31: -> org.freedesktop.DBus call org.freedesktop.DBus.StartServiceByName at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return from C29
B-1: <- org.freedesktop.DBus return from C30
B-1: <- org.freedesktop.DBus return from C31
C32: -> org.freedesktop.DBus call org.freedesktop.DBus.GetNameOwner at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return from C32
C33: -> :1.253 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
B186: <- :1.253 return from C33
C34: -> :1.253 call org.freedesktop.portal.OpenURI.OpenFile at /org/freedesktop/portal/desktop
B187: <- :1.253 return from C34
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
------------------------------------------ click #2 -----------------------------------------------
C35: -> org.freedesktop.portal.Desktop call org.freedesktop.portal.OpenURI.OpenFile at /org/freedesktop/portal/desktop
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
C25: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
B150: <- :1.262 return from C25
B151: <- :1.262 return from C35
C36: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
C37: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
C38: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.NoReply from C36
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.NoReply from C38
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.NoReply from C37
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus

Firefox' log of the session bus communication (flatpak run --log-session-bus org.mozilla.firefox):

------------------------------------------ click #1 -----------------------------------------------
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
------------------------------------------ click #2 -----------------------------------------------
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
C60: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
C61: -> org.freedesktop.DBus call org.freedesktop.DBus.StartServiceByName at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return from C61
C62: -> org.freedesktop.DBus call org.freedesktop.DBus.GetNameOwner at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return from C62
C63: -> :1.262 call org.freedesktop.DBus.Properties.GetAll at /org/freedesktop/portal/desktop
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.NoReply from C60
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.NoReply from C63
B-1: <- org.freedesktop.DBus signal org.freedesktop.DBus.NameOwnerChanged at /org/freedesktop/DBus
C64: -> :1.262 call org.freedesktop.portal.Settings.Read at /org/freedesktop/portal/desktop
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.ServiceUnknown from C64
C65: -> :1.262 call org.freedesktop.portal.Settings.Read at /org/freedesktop/portal/desktop
B-1: <- org.freedesktop.DBus return error org.freedesktop.DBus.Error.ServiceUnknown from C65

It seems that Betterbird tries to open the profile directory using a org.freedesktop.portal.OpenURI.OpenFile call. Maybe the response or one of the subsequent calls is handled by firefox by mistake? I could imagine that something like this happens because FF and BB share the code for DBus handling. But I am not an expert with DBus or this type of logs, so I am not sure if this is possible at all or if there is some mechanism that ensures responses can only reach the original sender.

I played around a bit with session bus talk permissions hoping I could prevent BB and FF to talk to each other, but was not successful. Even with all talk permissions removed the issue still occurred.

moritztim commented 5 months ago

Wow there's a can of worms. If you need any more info from me, feel free to ping.