about.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict'
  2. import GLib from 'gi://GLib';
  3. import Adw from 'gi://Adw';
  4. import GObject from 'gi://GObject';
  5. import Gio from 'gi://Gio';
  6. import Gtk from 'gi://Gtk';
  7. import Gdk from 'gi://Gdk';
  8. // Links
  9. const URLS = {
  10. readme: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/',
  11. bug_report: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/-/issues',
  12. license: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/-/blob/main/LICENSE',
  13. translate: 'https://hosted.weblate.org/engage/thinkpad-battery-threshold/',
  14. };
  15. export const About = GObject.registerClass({
  16. GTypeName: 'AboutPrefs',
  17. Template: GLib.Uri.resolve_relative(import.meta.url, '../ui/about.ui',GLib.UriFlags.NONE),
  18. InternalChildren: [
  19. 'app_icon_image',
  20. 'app_name_label',
  21. 'version_label',
  22. 'open_readme',
  23. 'open_bug_report',
  24. 'open_license',
  25. 'open_translate',
  26. ]
  27. }, class About extends Adw.PreferencesPage {
  28. constructor(window) {
  29. super({});
  30. this._app_icon_image.gicon = Gio.icon_new_for_string(`${GLib.Uri.resolve_relative(import.meta.url, '../icons/threshold-active.svg',GLib.UriFlags.NONE)}`);
  31. this._app_name_label.label = window._metadata.name;
  32. this._version_label.label = window._metadata.version ? window._metadata.version.toString() : "0";
  33. // Setup actions
  34. const actionGroup = new Gio.SimpleActionGroup();
  35. window.insert_action_group('prefs', actionGroup);
  36. // A list of actions with their associated link
  37. const actions = [
  38. {
  39. name: 'open-bug-report',
  40. link: URLS.bug_report
  41. },
  42. {
  43. name: 'open-readme',
  44. link: URLS.readme
  45. },
  46. {
  47. name: 'open-license',
  48. link: URLS.license
  49. },
  50. {
  51. name: 'open-translate',
  52. link: URLS.translate
  53. },
  54. ];
  55. actions.forEach(action => {
  56. let act = new Gio.SimpleAction({ name: action.name });
  57. act.connect(
  58. 'activate',
  59. _ => Gtk.show_uri(window, action.link, Gdk.CURRENT_TIME)
  60. );
  61. actionGroup.add_action(act);
  62. });
  63. // Set tooltips
  64. this._open_readme.tooltip_text = URLS.readme;
  65. this._open_license.tooltip_text = URLS.license;
  66. this._open_bug_report.tooltip_text = URLS.bug_report;
  67. this._open_translate.tooltip_text = URLS.translate;
  68. }
  69. });