k-kirill / anki-libunity

3 stars 1 forks source link

Launcher dots #8

Open kitzberger opened 2 years ago

kitzberger commented 2 years ago

Hi @k-kirill,

I guess I need some support to get the dots on the launcher icon to work. You've mentioned in your README this:

If your Anki's desktop file is not named net.ankiweb.Anki.desktop, then please change the application name in the add-on's config.

Where would I find that file? I've just pinned the anki icon to the launcher by right-clicking and then "add to favorites". Did that create that desktop file? Where? ;-)

k-kirill commented 2 years ago

To see the Anki app name in GNOME:

  1. Start Anki
  2. Press Alt+F2
  3. Type "lg" and press Enter
  4. Switch to the Windows tab
  5. See the app: line for Anki

To change app name in the add-on:

  1. Start Anki
  2. Open Tools > Add-ons
  3. Select the "anki_libnotify" add-on
  4. Click the Config button
  5. Change the app name to the one from the app: line but without the .desktop extension
kitzberger commented 2 years ago

@k-kirill, wow, thanks a lot for the walk thru ;-)

Found it: image

So I set the app_name to anki-ppd_anki but still no dots ;-(

k-kirill commented 2 years ago

Did you restart Anki after the change? Do you use the Dash to Dock extension?

kitzberger commented 2 years ago

Yeah, did a restart after changing the plugins config.

I'm on Ubuntu 22.04 which is coming with Ubuntu Dock 71. According to its description that's a modified version of Dash to Dock.

k-kirill commented 2 years ago

What's the number of cards to study you get in Anki Browser for the is:new or is:due search?

kitzberger commented 2 years ago

That's 38.

The notification popups are working btw.!

k-kirill commented 2 years ago

Do you see that badge in the dock for some other applications like Telegram?

k-kirill commented 2 years ago

Can you please post the output of this command after starting Anki?

dbus-monitor "type='signal',interface='com.canonical.Unity.LauncherEntry'"
kitzberger commented 2 years ago
signal time=1665834899.935455 sender=org.freedesktop.DBus -> destination=:1.2486 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.2486"
signal time=1665834899.935483 sender=org.freedesktop.DBus -> destination=:1.2486 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.2486"
k-kirill commented 2 years ago

Sorry, I meant the following: run the dbus-monitror command first in terminal and then start Anki and then you should see the output in terminal like this

signal time=1665834743.205162 sender=:1.163 -> destination=(null destination) serial=23 path=/; interface=com.canonical.Unity.LauncherEntry; member=Update
   string "application://net.ankiweb.Anki.desktop"
   array [
      dict entry(
         string "count"
         variant             int64 20
      )
      dict entry(
         string "count-visible"
         variant             boolean true
      )
      dict entry(
         string "progress"
         variant             double 0
      )
      dict entry(
         string "progress-visible"
         variant             boolean true
      )
kitzberger commented 2 years ago

Ah, then it's this here:

   string "application://anki-ppd_anki.desktop"
   array [
      dict entry(
         string "count"
         variant             int64 38
      )
      dict entry(
         string "count-visible"
         variant             boolean true
      )
      dict entry(
         string "progress"
         variant             double 0.530864
      )
      dict entry(
         string "progress-visible"
         variant             boolean true
      )
   ]

I don't have telegram installed.

kitzberger commented 2 years ago

I was able to add a progress bar and the count badge to the app icon via this snippet here: https://wiki.ubuntu.com/Unity/LauncherAPI#Python_Example

image

I've adjusted the script to this here:

from gi.repository import Unity, Gio, GObject, Dbusmenu

loop = GObject.MainLoop()

# Pretend to be evolution for the sake of the example 
launcher = Unity.LauncherEntry.get_for_desktop_id ("anki-ppd_anki.desktop")

# Show a count of 124 on the icon
launcher.set_property("count", 124)
launcher.set_property("count_visible", True)

# Set progress to 42% done 
launcher.set_property("progress", 0.42)
launcher.set_property("progress_visible", True)

# We also want a quicklist 
ql = Dbusmenu.Menuitem.new ()
item1 = Dbusmenu.Menuitem.new ()
item1.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 1")
item1.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
item2 = Dbusmenu.Menuitem.new ()
item2.property_set (Dbusmenu.MENUITEM_PROP_LABEL, "Item 2")
item2.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
ql.child_append (item1)
ql.child_append (item2)
launcher.set_property("quicklist", ql) 

def update_urgency():
    if launcher.get_property("urgent"):
        print("Removing urgent flag")
        launcher.set_property("urgent", False)
    else:
        print("setting urgent flag")
        launcher.set_property("urgent", True)
    return True

GObject.timeout_add_seconds(5, update_urgency)

loop.run()
k-kirill commented 2 years ago

Nice, but the add-on uses low level DBus API. Can you please temporarily replace Ubuntu Dock with Dash to Dock to test with it?

kitzberger commented 2 years ago

Can you please temporarily replace Ubuntu Dock with Dash to Dock to test with it?

I already did that, it's working with both ;-)

This is the same script with Ubtuntu Dock:

image

k-kirill commented 2 years ago

And Anki add-on does not work with both :( Maybe it's some snap issue like misconfigured dbus interface (for example, no access to the com.canonical.Unity.LauncherEntry interface). I use flatpak version of Anki and do not have any snaps to troubleshoot it :(

k-kirill commented 2 years ago

Can you please try this solution? https://forum.snapcraft.io/t/using-com-canonical-unity-launcherentry-dbus-interface/22004 Change the 16th line of __init__.py of the add-on (Tools > Add-ons > select the add-on > View Files) to the following:

     path = "/com/canonical/unity/launcherentry/1"
kitzberger commented 2 years ago

Here's the output, still no badges on the launcher icon though ;-(

signal time=1665843183.792471 sender=:1.2802 -> destination=(null destination) serial=9 path=/com/canonical/unity/launcherentry/1; interface=com.canonical.Unity.LauncherEntry; member=Update
   string "application://anki-ppd_anki.desktop"
   array [
      dict entry(
         string "count"
         variant             int64 46
      )
      dict entry(
         string "count-visible"
         variant             boolean true
      )
      dict entry(
         string "progress"
         variant             double 0.483146
      )
      dict entry(
         string "progress-visible"
         variant             boolean true
      )
   ]
k-kirill commented 2 years ago

It seems like the unity7 plugin is missing in https://github.com/ppd/anki-ppd/blob/master/snap/snapcraft.yaml Looking at https://snapcraft.io/docs/interface-management, something like that should be able to enable it:

$ sudo snap connect anki-ppd:unity7 :unity7

Please note I have never used snaps as I use openSUSE Tumbleweed

kitzberger commented 2 years ago

Hm, it seems that this connection could only be made if the snapcraft.yaml would've specified that "plug".

$ sudo snap connect anki-ppd:unity7 :unity7
Error: snap "anki-ppd" has no plug named "unity7"

Damn.

k-kirill commented 2 years ago

Okay, let's wait for ppd/anki-ppd#5