ping.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect
  2. //
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. import Gio from 'gi://Gio';
  5. import GLib from 'gi://GLib';
  6. import GObject from 'gi://GObject';
  7. import Plugin from '../plugin.js';
  8. export const Metadata = {
  9. label: _('Ping'),
  10. description: _('Send and receive pings'),
  11. id: 'org.gnome.Shell.Extensions.GSConnect.Plugin.Ping',
  12. incomingCapabilities: ['kdeconnect.ping'],
  13. outgoingCapabilities: ['kdeconnect.ping'],
  14. actions: {
  15. ping: {
  16. label: _('Ping'),
  17. icon_name: 'dialog-information-symbolic',
  18. parameter_type: new GLib.VariantType('s'),
  19. incoming: [],
  20. outgoing: ['kdeconnect.ping'],
  21. },
  22. },
  23. };
  24. /**
  25. * Ping Plugin
  26. * https://github.com/KDE/kdeconnect-kde/tree/master/plugins/ping
  27. */
  28. const PingPlugin = GObject.registerClass({
  29. GTypeName: 'GSConnectPingPlugin',
  30. }, class PingPlugin extends Plugin {
  31. _init(device) {
  32. super._init(device, 'ping');
  33. }
  34. handlePacket(packet) {
  35. // Notification
  36. const notif = {
  37. title: this.device.name,
  38. body: _('Ping'),
  39. icon: new Gio.ThemedIcon({name: `${this.device.icon_name}`}),
  40. };
  41. if (packet.body.message) {
  42. // TRANSLATORS: An optional message accompanying a ping, rarely if ever used
  43. // eg. Ping: A message sent with ping
  44. notif.body = _('Ping: %s').format(packet.body.message);
  45. }
  46. this.device.showNotification(notif);
  47. }
  48. ping(message = '') {
  49. const packet = {
  50. type: 'kdeconnect.ping',
  51. body: {},
  52. };
  53. if (message.length)
  54. packet.body.message = message;
  55. this.device.sendPacket(packet);
  56. }
  57. });
  58. export default PingPlugin;