pop-os / launcher

Modular IPC-based desktop launcher service
Mozilla Public License 2.0
219 stars 42 forks source link

Continuous updates of plugin data #188

Closed friedow closed 1 year ago

friedow commented 1 year ago

Currently plugins are invoked on input changes (when the user types in new stuff). This enables plugins to react to stuff happening in the frontend. However, sometimes data from plugins changes even if the user does not do anything.

Take this plugin, which displays the current time as an example:

plugin.ron
(
    name: "Clock",
    description: "Shows the current time",
    bin: (path: "clock.nu"),
    icon: Name("utilities-terminal"),
)
clock.nu
#!/usr/bin/env nu
print $'{ "Append": { "id": 0, "name": "Time: (date now)", "description": ""  } }'

Currently there is no way to update the time from the plugin proactively. I would however love to do something like this:

clock.nu
#!/usr/bin/env nu
while true {
  print 'Clear'
  print $'{ "Append": { "id": 0, "name": "Time: (date now)", "description": ""  } }'
  sleep 1sec
}

This could enable a bunch of new plugins especially for displaying data. Imagine plugins like:

PS: These are my thought on pop-launcher combined with onagre. Please correct me if any of my assumptions are wrong.

friedow commented 1 year ago

Turns out: the protocol, pop-launcher as well as onagre do support updating data from the plugin side continuously. My implementation of this was just flawed! For everyone wondering, here is a working implementation of the clock plugin:

clock.nu
#!/usr/bin/env nu
while true {
  let currentTime = (date now | date format '%H:%M')
  print '"Clear"' # double quotes inside single quotes to send a string to the json ipc ;) 
  print $'{ "Append": { "id": 0, "name": "($currentTime)", "description": "Current Time"  } }'
  print '"Finished"'
  sleep 1sec
}

To System76 and all maintainers of this project: Thanks for open sourcing this and doing an awesome job on this project :heart:!