~comcloudway/melon

7be67f223d008e8b77b1ae1c8e583777fb805ee4 — Jakob Meier a month ago fbb652c
Fix playlist deletion error

Caused by the notification system still notifying the playlist view, as
it did not unsubscribe from the notifications

The register callback now returns a shorthand function to unsubscribe
from the call.
As long as the screen can only be opened once, this can be called
multiple times.
3 files changed, 11 insertions(+), 1 deletions(-)

M melon/models/callbacks.py
M melon/playlist/__init__.py
M melon/widgets/feeditem.py
M melon/models/callbacks.py => melon/models/callbacks.py +1 -0
@@ 34,6 34,7 @@ def register_callback(target: str, callback_id: str, function):
    if not target in callbacks:
        return
    callbacks[target][callback_id] = function
    return lambda: unregister_callback(target, callback_id)


def unregister_callback(target: str, callback_id: str):

M melon/playlist/__init__.py => melon/playlist/__init__.py +9 -1
@@ 37,10 37,16 @@ class LocalPlaylistScreen(Adw.NavigationPage):

        self.playlist_id = playlist_id
        # register update listener
        register_callback("playlists_changed", "playlist-view", self.do_update)
        self.unregister = register_callback(
            "playlists_changed", "playlist-view", self.do_update
        )
        self.connect("hidden", self.on_close)
        # draw frame
        self.do_update()

    def on_close(self, k):
        self.unregister()

    def do_update(self):
        # load playlist data
        self.playlist = get_local_playlist(self.playlist_id)


@@ 320,6 326,8 @@ class LocalPlaylistScreen(Adw.NavigationPage):
        self.dlt_diag.show()

    def delete(self):
        # make sure that this widget does not receive an update notification
        self.unregister()
        # go home and delete afterwards
        # so that the reload/callback doesn't trigger
        self.activate_action("win.home", None)

M melon/widgets/feeditem.py => melon/widgets/feeditem.py +1 -0
@@ 18,6 18,7 @@ from melon.utils import pass_me, many
# [url]: texture
preview_cache = {}


class AdaptiveFeedItem(Adw.ActionRow):
    """
    FeedItem with automatic adjustment to resource type