UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Refresh icon view in App Drawer in real time

    Scheduled Pinned Locked Moved Support
    12 Posts 4 Posters 1.2k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • hankschwieH Offline
        hankschwie
        last edited by hankschwie

        Hi!

        We wrote a small script and a desktop file to toogle Anbox via

        anbox-tool enable|disable
        

        see [https://wiki.ubuntuusers.de/Ubuntu_Touch/Anbox/#Automatisches-Umschalten-per-Icon] .

        because Anbox is using energy, even when not in use. It works fine.

        Now I thought it would be nice to change the icon (like using a green one when Anbox is enabled, and a red one when it is disabled). I tried to use cp within the script to copy a new icon to home/phablet/.local/share/applications/ . That works, but it looks like the icons are cached somewhere, and are only refreshed after unity8 is restarted, or the whole device.

        Would it be possible to change that in real time, so I could see just by the colour of the icon if Anbox is enabled or not?

        1 Reply Last reply Reply Quote 4
        • hankschwieH Offline
          hankschwie
          last edited by hankschwie

          Hi!

          I was able to solve this. I noticed that anbox apps are displayed immediately after installation, as soon as the desktop file is placed in /home/phablet/.local/share/applications . So I tried to work with two desktop files which are moved back and forth between /home/phablet/.local/share/applications and /home/phablet/Downloads . The anboxtoggle.sh shovels those back and forth with each disable/enable run instead of the icons - they stay in place.

          anboxtoogle.sh looks like this:

          #!/bin/bash
          anboxtool=($(anbox-tool status)) 
          atenabled=${anboxtool[5]}
          
          if [ "$atenabled" == "YES" ]; then
                anbox-tool disable
          	mv /home/phablet/Downloads/anboxtoggleRED.desktop /home/phablet/.local/share/applications/anboxtoggleRED.desktop
          	mv /home/phablet/.local/share/applications/anboxtoggleGREEN.desktop /home/phablet/Downloads/anboxtoggleGREEN.desktop 
          else
                anbox-tool enable
          	mv /home/phablet/Downloads/anboxtoggleGREEN.desktop /home/phablet/.local/share/applications/anboxtoggleGREEN.desktop
          	mv /home/phablet/.local/share/applications/anboxtoggleRED.desktop /home/phablet/Downloads/anboxtoggleRED.desktop 
          fi
          

          The desktop file anboxtoggleGREEN.desktop:

          [Desktop Entry]
          Name=Anboxtoggle
          Type=Application
          Terminal=false
          Icon=/home/phablet/.local/share/applications/anbox-green.png
          Categories=Utility
          Comment=Switch between anbox enabled and disabled
          X-Ubuntu-Touch=true
          Exec=/home/phablet/.local/share/applications/anboxtoggle.sh 
          

          For anboxtoggleRED.desktop you just need to change the icon name in the Icon line to anbox-red.png. You need two different icon pictures, called anbox-red.png and anbox-green.png, as well (just grab some from the net, and change the colours with gimp or a similar program, if neccessary).
          Make the other files executable, and put the two icon files and one of the desktop files in /home/phablet/.local/share/applications/, the other desktop file in /home/phablet/Downloads/. (If Anbox currently is runnig, put anboxRed.desktop in .../applications, if not anboxtoggleGREEN.desktop.)

          Now there should be just one icon in the app drawer, indicating if anbox is enabled or not, changing is colour with every call.

          Have fun!

          1 Reply Last reply Reply Quote 3
          • C Offline
            chrisse
            last edited by

            Hi,
            Everything works fine, thanks!

            1 Reply Last reply Reply Quote 0
            • hankschwieH Offline
              hankschwie
              last edited by hankschwie

              Hmmmm.... Don't know why, but the icons vanished from /home/phablet/.local/share/applications/ after a restart of Unity8. I put them back in, but renamed them to match the desktop files, so they now are called anboxtoggleGREEN.png and anboxtoggleRED.png; changed that in the desktop files, too. Hope this will work permanently,

              1 Reply Last reply Reply Quote 0
              • C Offline
                chrisse
                last edited by

                You're right, I just restarted Unity8 and they vanished.
                Tell me if your solution works before I transfer them again.
                Otherwise, I will transfer them to Downloads and copy them to ../applications everytime I restart Unity8 (not often)...

                hankschwieH 1 Reply Last reply Reply Quote 0
                • hankschwieH Offline
                  hankschwie @chrisse
                  last edited by

                  @chrisse

                  Well, the icons survived a couple of unity8 restarts, and two device restarts, so it looks like the name was important... For all anbox apps the names for the desktop files and their icons are identical except for the ending, so I thought that could do the trick.

                  1 Reply Last reply Reply Quote 1
                  • C Offline
                    chrisse
                    last edited by

                    Two Unity8 restarts and it still works! Thanks!

                    LakotaubpL 1 Reply Last reply Reply Quote 0
                    • LakotaubpL Offline
                      Lakotaubp @chrisse
                      last edited by

                      @chrisse Two Lomiri restarts 😉

                      1 Reply Last reply Reply Quote 2
                      • TobsEndT Offline
                        TobsEnd
                        last edited by TobsEnd

                        Hi,
                        I tried to use the script, but it couldn't get it to work. I can see the red icon in the drawer but nothing happens when I push the button. Do I have to activate something so that the script can run properly?
                        Do I need to make script executable with root rights?

                        Pixel 2XL rc

                        hankschwieH 1 Reply Last reply Reply Quote 0
                        • hankschwieH Offline
                          hankschwie @TobsEnd
                          last edited by

                          @TobsEnd
                          Yes, you need to make the script executable. It will run without r/w rights later on.

                          TobsEndT 1 Reply Last reply Reply Quote 0
                          • TobsEndT Offline
                            TobsEnd @hankschwie
                            last edited by TobsEnd

                            @hankschwie I do i have to use chmod +x or ```
                            sudo chmod +x

                            Pixel 2XL rc

                            hankschwieH 1 Reply Last reply Reply Quote 0
                            • hankschwieH Offline
                              hankschwie @TobsEnd
                              last edited by hankschwie

                              @TobsEnd
                              Sorry, I didn't use chmod, but used a nautilus function to set it executable

                              ls -la in the directory tells me:

                              rwxr-xr-x 1 heinrich heinrich 631 Mär 15 19:30 anboxtoggle.sh
                              for the skript, so I guess you would have to use the sudo version.

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post