Flatpak support?

Issue #49 resolved
Guilherme created an issue

Hey there! Is there any plans to have a flatpak build?

Thanks!

Comments (6)

  1. Eloy García Almadén repo owner

    Hi Guilherme!

    First of all, thank you very much for your interest in WallpaperDownloader 🙂

    The application is now packed as a snap package, PPA and it is published in AUR too. Of course, I have always had in mind to create a flatpak but I didn’t have enough time to start to investigate how can I do it. I don’t know if it is easy or difficult and it would be great if someone with more experience with this things could help me with this task.

    So I take this opportunity to appeal to the community. If someone is interested in helping me with this task, it would be great!!!

  2. Guilherme reporter

    No worries! I thank you for WallpaperDownloader, it’s really great. 😁

    I’ve been trying to get my Flatpak build of WallpaperDownloader to run, but I’m afraid it won’t work as expected unless some code changes happen. Granted, I’m not experienced with neither Flatpak and Java, but right off the bat I got a java.lang.NullPointerException when trying to run your official wallpaperdownloader.jar build:

    $ flatpak-builder --run build-dir es.estoes.wallpaperDownloader.yaml es.estoes.wallpaperDownloader.sh
    log4j:WARN File option not set for appender [logfile].
    log4j:WARN Are you using FileAppender instead of ConsoleAppender?
    [16:51:22] INFO  WDConfigManager:76 - Checking configuration...
    [16:51:22] INFO  WDConfigManager:77 - Checking application's directory
    [16:51:22] INFO  PreferencesManager:49 - Creating PreferenceManager instance for the first time...
    [16:51:22] INFO  PreferencesManager:65 - Setting user's configuration file path to /home/gui/.wallpaperdownloader/config.txt
    [16:51:22] INFO  WDConfigManager:89 - There is no configuration file. Creating a new one. Please wait...
    [16:51:22] INFO  WDConfigManager:96 - Checking downloads directory...
    [16:51:22] INFO  WDConfigManager:117 - Downloads folder doesn't exist. Creating...
    [16:51:22] INFO  WDConfigManager:122 - Downloads directory -> /home/gui/.wallpaperdownloader/downloads
    [16:51:22] INFO  WDConfigManager:127 - User configuration file doesn't exist. Creating...
    [16:51:22] INFO  WDConfigManager:311 - Checking blacklist directory...
    [16:51:22] INFO  WDConfigManager:316 - Blacklist directory doesn't exist. Creating...
    [16:51:22] INFO  WDConfigManager:326 - Retrieving operating system... Linux
    [16:51:22] INFO  WDConfigManager:348 - Operating System detected: Linux
    [16:51:22] INFO  WallpaperChanger:72 - Instanciating wallpaper changer...
    [16:51:22] INFO  LinuxWallpaperChanger:54 - Checking XDG_CURRENT_DESKTOP environment variable. Value = KDE
    [16:51:22] INFO  LinuxWallpaperChanger:97 - Desktop environment detected: KDE
    [16:51:22] ERROR LinuxWallpaperChanger:466 - Error checking KDE Plasma version: Cannot run program "plasmashell": error=2, No such file or directory
    [16:51:22] ERROR LinuxWallpaperChanger:466 - Error checking KDE Plasma version: Cannot run program "plasmashell": error=2, No such file or directory
    [16:51:22] ERROR LinuxWallpaperChanger:466 - Error checking KDE Plasma version: Cannot run program "plasmashell": error=2, No such file or directory
    [16:51:22] ERROR LinuxWallpaperChanger:466 - Error checking KDE Plasma version: Cannot run program "plasmashell": error=2, No such file or directory
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at es.estoes.wallpaperDownloader.window.WallpaperDownloader.initializeGUI(WallpaperDownloader.java:3338)
            at es.estoes.wallpaperDownloader.window.WallpaperDownloader.initialize(WallpaperDownloader.java:1594)
            at es.estoes.wallpaperDownloader.window.WallpaperDownloader.<init>(WallpaperDownloader.java:325)
            at es.estoes.wallpaperDownloader.window.WallpaperDownloader$1.run(WallpaperDownloader.java:283)
            at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
            at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
            at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
            at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
            at java.base/java.security.AccessController.doPrivileged(Native Method)
            at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
            at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
            at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
            at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
            at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
            at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
            at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
            at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    

    The errors about a missing binary for plasmashell are to be expected, since Flatpak blocks access to most directories in /. In my limited understanding of Flatpaks, making exec() calls work, would require white-listing basically most directories in / (due to libraries and config files residing there too). But, in my opinion, that would defeat the purpose of having a sand-boxed program in the first place, right? One solution to that, would be replacing most Runtime.exec() calls by DBus signals (major desktop environments support them anyway). Perhaps an easier solution would be using one of these workarounds? I’m not sure...

    Anyway, going back to the java.lang.NullPointerException bug I was talking about, I believe it happens because a value is only assigned to btnNextWallpaper inside this block of code, but this Flatpak build never gets inside that block of code, since isWallpaperChangeable() currently returns false. Unfortunately though, even after fixing that, I still got a few other java.lang.NullPointerException errors, which are also related to the previous one.

    As I mentioned before, Java isn’t exactly my thing, but I’ve decided to create a flatpak branch in my fork of WallpaperDownloader, in a attempt to fix some of those issues.

    The first commit I’ve put there, is to deal with events being added to uninitialized buttons (I apologize it looks messy, something went wrong with my editor and it messed up the indentation. But what I did was put the buttons logic inside a big if(isWallpaperChangeable()) { ... } code block, in order to avoid events being assigned to them when the wallpaper-changing functionality is not available:

    https://bitbucket.org/guihkx/wallpaperdownloader/commits/4605634e8601bb794f95b2c2279211600a7d3050

    In this second commit, I just commented out the code that was checking for internet connectivity prior to downloading wallpapers. That is necessary too, because it relies on the ping binary, which is not available. I know this is not optimal, at all, but I just added it to test if WallpaperDownloader would at least be able to download something. And, fortunately it was: 🎉

    On a side note, are you aware that you can restrict network access of any Flatpak program you have installed? So, I decided to do that just to see how WallpaperDownloader would behave:

    flatpak override --user --unshare=network es.estoes.wallpaperDownloader
    

    I must say the result was not very pleasing 😅 It got stuck in an infinite loop trying to download wallpapers over and over again, hahah. Anyway, here is the god-awful commit:

    https://bitbucket.org/guihkx/wallpaperdownloader/commits/dfa3c3d4be26e7325fef0791bb642e21b4d6055f

    Finally, I’ve put together instructions on how to build and run a Flatpak build of WallpaperDownloader. Currently, the instructions are only for Arch Linux (sorry!), but apart from installing flatpak and flatpak-builder, the instructions should work pretty much in any other distro:

    https://bitbucket.org/guihkx/wallpaperdownloader/commits/branch/flatpak

    By the way, and this is very important, please don’t feel pressured to implement anything of what I said, or even add support for Flatpak at all. I imagine how cumbersome it’d be to implement fixes just for a Flatpak build, so don’t even worry. I’m mostly doing it just for learning anyway. I’ve been using WallpaperDownloader for some time on Arch Linux and it works just fine for me.

    Thanks a lot!

  3. Eloy García Almadén repo owner

    Oh my god! You are doing a very impressive job with this stuff!! THANK YOU very much.

    I need time to process all this information. I’ve seen your fork and the instructions you have published so I’ll take a look at them in order to test the package. When I created the snap package, I had to modify the code as well, so if changes needed for flatpak support are not very complicated, I can do them. I think it is very interesting to have WallpaperDownloader packaged in flatpak too.

    And talking about D-Bus, I can try to include this java library and test it. One of the main problems with the snap in KDE is that the changer is not working because I’m relying on a script that needs to be executed (and as you said before, the isolation of these type of packages avoids the execution of additional scripts). Maybe using D-Bus I can fix this issue.

    My email address is eloy.garcia.pca@gmail.com. If you send me an email we can be in touch and talk about the process.

    And again, thank you very much for your time and work!

  4. Eloy García Almadén repo owner

    No, thank you again to you Guilherme for all the work you have done!!!

    This is amazing. Community is amazing. FOSS is amazing! 🙂

  5. Log in to comment