gsconnect-preferences 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env gjs
  2. // SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect
  3. //
  4. // SPDX-License-Identifier: GPL-2.0-or-later
  5. // -*- mode: js; -*-
  6. 'use strict';
  7. imports.gi.versions.Gdk = '3.0';
  8. imports.gi.versions.GdkPixbuf = '2.0';
  9. imports.gi.versions.Gio = '2.0';
  10. imports.gi.versions.GLib = '2.0';
  11. imports.gi.versions.GObject = '2.0';
  12. imports.gi.versions.Gtk = '3.0';
  13. const Gdk = imports.gi.Gdk;
  14. const Gio = imports.gi.Gio;
  15. const GLib = imports.gi.GLib;
  16. const GObject = imports.gi.GObject;
  17. const Gtk = imports.gi.Gtk;
  18. // Bootstrap
  19. function get_datadir() {
  20. let [, path] = /@([^:]+):\d+/.exec(new Error().stack.split('\n')[1]);
  21. const info = Gio.File.new_for_path(path)
  22. .query_info('standard::*', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
  23. path = info.get_is_symlink() ? info.get_symlink_target() : path;
  24. return Gio.File.new_for_path(path).get_parent().get_path();
  25. }
  26. imports.searchPath.unshift(get_datadir());
  27. imports.config.PACKAGE_DATADIR = imports.searchPath[0];
  28. // Bootstrap
  29. const {setup, setupGettext} = imports.utils.setup;
  30. setup(imports.config.PACKAGE_DATADIR);
  31. setupGettext();
  32. // Local Imports
  33. const Config = imports.config;
  34. const Settings = imports.preferences.service;
  35. /**
  36. * Class representing the GSConnect service daemon.
  37. */
  38. const Preferences = GObject.registerClass({
  39. GTypeName: 'GSConnectPreferences',
  40. Implements: [Gio.ActionGroup],
  41. }, class Preferences extends Gtk.Application {
  42. _init() {
  43. super._init({
  44. application_id: 'org.gnome.Shell.Extensions.GSConnect.Preferences',
  45. resource_base_path: '/org/gnome/Shell/Extensions/GSConnect',
  46. });
  47. GLib.set_prgname('gsconnect-preferences');
  48. GLib.set_application_name(_('GSConnect Preferences'));
  49. }
  50. vfunc_activate() {
  51. if (this._window === undefined) {
  52. this._window = new Settings.Window({
  53. application: this,
  54. });
  55. }
  56. this._window.present();
  57. }
  58. vfunc_startup() {
  59. super.vfunc_startup();
  60. // Init some resources
  61. let provider = new Gtk.CssProvider();
  62. provider.load_from_resource(`${Config.APP_PATH}/application.css`);
  63. Gtk.StyleContext.add_provider_for_screen(
  64. Gdk.Screen.get_default(),
  65. provider,
  66. Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
  67. );
  68. let actions = [
  69. ['refresh', null],
  70. ['connect', GLib.VariantType.new('s')],
  71. ];
  72. for (let [name, type] of actions) {
  73. let action = new Gio.SimpleAction({
  74. name: name,
  75. parameter_type: type,
  76. });
  77. this.add_action(action);
  78. }
  79. }
  80. vfunc_activate_action(action_name, parameter) {
  81. try {
  82. let paramArray = [];
  83. if (parameter instanceof GLib.Variant)
  84. paramArray[0] = parameter;
  85. this.get_dbus_connection().call(
  86. 'org.gnome.Shell.Extensions.GSConnect',
  87. '/org/gnome/Shell/Extensions/GSConnect',
  88. 'org.freedesktop.Application',
  89. 'ActivateAction',
  90. GLib.Variant.new('(sava{sv})', [action_name, paramArray, {}]),
  91. null,
  92. Gio.DBusCallFlags.NONE,
  93. -1,
  94. null,
  95. null
  96. );
  97. } catch (e) {
  98. logError(e);
  99. }
  100. }
  101. });
  102. (new Preferences()).run([imports.system.programInvocationName].concat(ARGV));