gsconnect-preferences 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env -S gjs -m
  2. // SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect
  3. //
  4. // SPDX-License-Identifier: GPL-2.0-or-later
  5. // -*- mode: js; -*-
  6. import Gdk from 'gi://Gdk?version=3.0';
  7. import 'gi://GdkPixbuf?version=2.0';
  8. import Gio from 'gi://Gio?version=2.0';
  9. import GLib from 'gi://GLib?version=2.0';
  10. import GObject from 'gi://GObject?version=2.0';
  11. import Gtk from 'gi://Gtk?version=3.0';
  12. import system from 'system';
  13. import './preferences/init.js';
  14. import {Window} from './preferences/service.js';
  15. import Config from './config.js';
  16. import('gi://GioUnix?version=2.0').catch(() => {}); // Set version for optional dependency
  17. /**
  18. * Class representing the GSConnect service daemon.
  19. */
  20. const Preferences = GObject.registerClass({
  21. GTypeName: 'GSConnectPreferences',
  22. Implements: [Gio.ActionGroup],
  23. }, class Preferences extends Gtk.Application {
  24. _init() {
  25. super._init({
  26. application_id: 'org.gnome.Shell.Extensions.GSConnect.Preferences',
  27. resource_base_path: '/org/gnome/Shell/Extensions/GSConnect',
  28. });
  29. GLib.set_prgname('gsconnect-preferences');
  30. GLib.set_application_name(_('GSConnect Preferences'));
  31. }
  32. vfunc_activate() {
  33. if (this._window === undefined) {
  34. this._window = new Window({
  35. application: this,
  36. });
  37. }
  38. this._window.present();
  39. }
  40. vfunc_startup() {
  41. super.vfunc_startup();
  42. // Init some resources
  43. const provider = new Gtk.CssProvider();
  44. provider.load_from_resource(`${Config.APP_PATH}/application.css`);
  45. Gtk.StyleContext.add_provider_for_screen(
  46. Gdk.Screen.get_default(),
  47. provider,
  48. Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
  49. );
  50. const actions = [
  51. ['refresh', null],
  52. ['connect', GLib.VariantType.new('s')],
  53. ];
  54. for (const [name, type] of actions) {
  55. const action = new Gio.SimpleAction({
  56. name: name,
  57. parameter_type: type,
  58. });
  59. this.add_action(action);
  60. }
  61. }
  62. vfunc_activate_action(action_name, parameter) {
  63. try {
  64. const paramArray = [];
  65. if (parameter instanceof GLib.Variant)
  66. paramArray[0] = parameter;
  67. this.get_dbus_connection().call(
  68. 'org.gnome.Shell.Extensions.GSConnect',
  69. '/org/gnome/Shell/Extensions/GSConnect',
  70. 'org.freedesktop.Application',
  71. 'ActivateAction',
  72. GLib.Variant.new('(sava{sv})', [action_name, paramArray, {}]),
  73. null,
  74. Gio.DBusCallFlags.NONE,
  75. -1,
  76. null,
  77. null
  78. );
  79. } catch (e) {
  80. logError(e);
  81. }
  82. }
  83. });
  84. await (new Preferences()).runAsync([system.programInvocationName].concat(ARGV));