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