Workbench icon indicating copy to clipboard operation
Workbench copied to clipboard

Allow using actions in the external preview

Open sonnyp opened this issue 3 years ago • 3 comments

When using Vala, the code and preview runs in a separate process.

So far, we were unable to use actions there so we had to disable/downgrade demos for Vala. See

  • https://github.com/sonnyp/Workbench/pull/101/commits/2df37308f602f93ae2d2a7a73da369922a45a362
  • https://github.com/sonnyp/Workbench/pull/101/commits/145f37cd6e1277019692de0358886d5976259da4

This ticket is about enabling the usage of actions in library entries when using Vala.

See the previous description below and comments for an analysis of the issue.

Since then, the architecture changed a little bit and the external process isn't a GApplication anymore. Instead Workench and the external process communicate via a direct dbus connection instead of via the session bus.

See https://github.com/sonnyp/Workbench/pull/184/files#diff-24cdf4b8c7c2fbd1c6b43e8b7bcc877d14cae496dd01e82eb212b6d5b4c68d59

Please note that Flatpak apps cannot have multiple dbus targets. https://github.com/flatpak/flatpak/issues/1902

Todo

  • [ ] Permit usage of GActions in Vala examples
  • [ ] Upgrade Vala examples to use GActions like the js ones
    • [ ] Toasts
    • [ ] Notifications

sonnyp avatar Jun 04 '22 13:06 sonnyp

Some ideas:

  • Proxy/relay all dbus stuff somehow through the Workbench process
  • custom WorkbenchApplication object, that delegates stuff over dbus to the workbench ui. Also stuff like application.quit() could be handled safely then. (by @lw64 )
  • Start the vala/previewer process outside the sandbox (probably no)
  • Do not use actions at all in Workbench demos (probably no)

sonnyp avatar Jun 11 '22 10:06 sonnyp

Doing some investigation.

Both applications are registered

image

but when running the Vala desktop notification demo:

#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {
  var application = workbench.application as GLib.Application;

  // this is required now for some reason?
  application.register(null);

  var notification = new Notification ("Lunch is ready");
  notification.set_body (
    "Today we have pancakes and salad, and fruit and cake for dessert"
  );
  notification.set_default_action ("app.notification-reply");
  notification.add_button ("Accept", "app.notification-accept");
  notification.add_button ("Decline", "app.notification-decline");

  var icon = new ThemedIcon ("object-rotate-right-symbolic");
  notification.set_icon (icon);

  var simple_button = workbench.builder.get_object ("button_simple") as Gtk.Button;
  simple_button.clicked.connect (() => {
    application.send_notification ("lunch-is-ready", notification);
  });

  var action_reply = new SimpleAction ("notification-reply", null);
  action_reply.activate.connect (() => {
    stdout.printf ("Reply");
  });
  application.add_action (action_reply);

  var action_accept = new SimpleAction ("notification-accept", null);
  action_accept.activate.connect (() => {
    stdout.printf ("Accept");
  });
  application.add_action (action_accept);

  var action_decline = new SimpleAction ("notification-decline", null);
  action_decline.activate.connect (() => {
    stdout.printf ("Decline");
  });

  application.add_action (action_decline);
}

the notification shows but clicking on an action Accept or Decline appears to communicate with /re/sonny/Workbench instead of /re/sonny/Workbench/vala_previewer.

image

sonnyp avatar Nov 26 '22 15:11 sonnyp

Actions are registered properly on /re/sonny/Workbench/vala_preview

Screenshot from 2022-11-26 16-18-52

sonnyp avatar Nov 26 '22 15:11 sonnyp