Bug 446739 - Cannot update launcher property of Task Manager from JS scripting api
Summary: Cannot update launcher property of Task Manager from JS scripting api
Status: CONFIRMED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Task Manager and Icons-Only Task Manager widgets (show other bugs)
Version: 5.23.4
Platform: Arch Linux Linux
: NOR minor
Target Milestone: 1.0
Assignee: Eike Hein
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-09 17:03 UTC by solonovamax
Modified: 2021-12-09 19:01 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description solonovamax 2021-12-09 17:03:25 UTC
Note: this was written in markdown because I'm used to it, and it helps add clarity to some parts. Here is a link to a github gist, which contains an exact copy of this post: https://gist.github.com/solonovamax/2d3ba510c6b113051ea7d74ced79e91b

## Summary

When updating the `launcher` property of the icons only task manager (`org.kde.plasma.icontasks`/`org.kde.plasma.taskmanager`) via the javascript scripting api, it will not be updated visually. Usually, it will just remove all pinned items, but sometimes it won't update at all. It can also sometimes produce a white and unusable shortcut.


## Steps to Reproduce
1. Make sure the icons only task manager is enabled and added on your system:
2. Open the desktop shell scripting api and add the following code:
   ```js
   function forEachWidgetInContainmentList(containmentList, callback) {
       for (var containmentIndex = 0; containmentIndex < containmentList.length; containmentIndex++) {
           var containment = containmentList[containmentIndex];
   
           var widgets = containment.widgets();
           for (var widgetIndex = 0; widgetIndex < widgets.length; widgetIndex++) {
               var widget = widgets[widgetIndex];
               callback(widget, containment);
           }
       }
   }
   
   function forEachWidget(callback) {
       forEachWidgetInContainmentList(desktops(), callback);
       forEachWidgetInContainmentList(panels(), callback);
   }
   
   function forEachWidgetByType(type, callback) {
       forEachWidget(function(widget, containment) {
           if (widget.type == type) {
               callback(widget, containment);
           }
       });
   }
   
   function setWidgetProperty(args) {
       forEachWidgetByType(args.widgetType, (widget) => {
           widget.currentConfigGroup = [args.configGroup]

           //--- Begin Debug
           let oldValue = widget.readConfig(args.configKey)
           print(`${widget.type} (id: ${widget.id}):`)
           print(`\t[${args.configGroup}] ${args.configKey}: ${oldValue} => ${args.configValue}\n`)
           print(`did update: ${oldValue != args.configValue}\n`)
           //--- End Debug

          if (oldValue != args.configValue)
               widget.writeConfig(args.configKey, args.configValue)

          widget.reloadConfig() // Doesn't properly reoload ?

           print(`config: ${widget.readConfig(args.configKey)}\n`)

           desktops().forEach((desktop) => { // Maybe this will reload it?
               desktop.reloadConfig() // nope...
           })
       })
   }
   
   setWidgetProperty({
       widgetType: "org.kde.plasma.icontasks",
       configGroup: "General",
       configKey: "launchers",
       configValue: "applications:systemsettings.desktop,applications:org.kde.discover.desktop,preferred://filemanager,preferred://browser",
       // Also I'm getting unclear results when requestion a working configuration, so this might work? Though, it doesn't.
       // configValue: "applications:systemsettings.desktop\\,applications:org.kde.discover.desktop\\,preferred://filemanager\\,preferred://browser"
   })
   ```
   
   Note: the above code was copied from the [scripting api docs](https://develop.kde.org/docs/plasma/scripting/examples/#changing-a-config-value-for-each-instance-of-a-specific-widget), with some minor modifications.
3. Make sure `configValue` is set to something different from what is currently in `~/.config/plasma-org.kde.plasma.desktop-appletsrc`.
4. Run code

## Observed Result

The task manager is not updated.


## Expected Result
The items displayed in the task manager should be updated updated upon updating that property.

## OS/Software Versions

| Software               | Version                                  |
|------------------------|------------------------------------------|
| Operating System       | Arch Linux                               |
| KDE Plasma Version     | 5.23.4                                   |
| KDE Frameworks Version | 5.88.0                                   |
| Qt Version             | 5.15.2                                   |
| Kernel Version         | 5.15.5-zen1-1-zen (64-bit)               |
| Graphics Platform      | X11                                      |
| Processors             | 8 × Intel® Core™ i7-3740QM CPU @ 2.70GHz |
| Memory                 | 7.7 GiB of RAM                           |
| Graphics Processor     | Quadro K1000M/PCIe/SSE2                  |

## Additiona Information

Currently, this issue can be worked around by restarting plasmashell (with `plasmashell --replace >/dev/null 2>&1 &`)