[gnome] Update extensions for v46
This commit is contained in:
@ -0,0 +1,55 @@
|
||||
'use strict'
|
||||
|
||||
import GLib from 'gi://GLib';
|
||||
import Adw from 'gi://Adw';
|
||||
import GObject from 'gi://GObject';
|
||||
import Gio from 'gi://Gio';
|
||||
import Gtk from 'gi://Gtk';
|
||||
import Gdk from 'gi://Gdk';
|
||||
|
||||
export const About = GObject.registerClass({
|
||||
GTypeName: 'AboutPrefs',
|
||||
Template: GLib.Uri.resolve_relative(import.meta.url, '../ui/about.ui',GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
'app_icon_image',
|
||||
'app_name_label',
|
||||
'version_label',
|
||||
]
|
||||
}, class About extends Adw.PreferencesPage {
|
||||
constructor(window) {
|
||||
super({});
|
||||
|
||||
this._app_icon_image.gicon = Gio.icon_new_for_string(`${GLib.Uri.resolve_relative(import.meta.url, '../icons/threshold-active.svg',GLib.UriFlags.NONE)}`);
|
||||
this._app_name_label.label = window._metadata.name;
|
||||
this._version_label.label = window._metadata.version.toString();
|
||||
|
||||
// setup menu actions
|
||||
const actionGroup = new Gio.SimpleActionGroup();
|
||||
window.insert_action_group('prefs', actionGroup);
|
||||
|
||||
// a list of actions with their associated link
|
||||
const actions = [
|
||||
{
|
||||
name: 'open-bug-report',
|
||||
link: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/-/issues'
|
||||
},
|
||||
{
|
||||
name: 'open-readme',
|
||||
link: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/'
|
||||
},
|
||||
{
|
||||
name: 'open-license',
|
||||
link: 'https://gitlab.com/marcosdalvarez/thinkpad-battery-threshold-extension/-/blob/main/LICENSE'
|
||||
},
|
||||
];
|
||||
|
||||
actions.forEach(action => {
|
||||
let act = new Gio.SimpleAction({ name: action.name });
|
||||
act.connect(
|
||||
'activate',
|
||||
_ => Gtk.show_uri(window, action.link, Gdk.CURRENT_TIME)
|
||||
);
|
||||
actionGroup.add_action(act);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,75 @@
|
||||
'use strict'
|
||||
|
||||
import GLib from 'gi://GLib';
|
||||
import Adw from 'gi://Adw';
|
||||
import GObject from 'gi://GObject';
|
||||
import Gio from 'gi://Gio';
|
||||
|
||||
import * as Utils from './utils.js';
|
||||
|
||||
export const General = GObject.registerClass({
|
||||
GTypeName: 'GeneralPrefs',
|
||||
Template: GLib.Uri.resolve_relative(import.meta.url, '../ui/general.ui',GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
'indicator_mode',
|
||||
'color_mode',
|
||||
'show_values',
|
||||
'show_notifications',
|
||||
'reset_all',
|
||||
'reset_dialog',
|
||||
],
|
||||
}, class General extends Adw.PreferencesPage {
|
||||
constructor(window) {
|
||||
super({});
|
||||
|
||||
Utils.bindAdwComboRow(this._indicator_mode, window._settings, 'indicator-mode');
|
||||
window._settings.bind(
|
||||
'color-mode',
|
||||
this._color_mode,
|
||||
'active',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
window._settings.bind(
|
||||
'show-current-values',
|
||||
this._show_values,
|
||||
'active',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
window._settings.bind(
|
||||
'show-notifications',
|
||||
this._show_notifications,
|
||||
'active',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
|
||||
this._reset_dialog.connect('response', (obj, response, data) => {
|
||||
if (response === 'reset') {
|
||||
this._resetSettings(window._settings);
|
||||
window._driver.enableAll();
|
||||
}
|
||||
});
|
||||
|
||||
this._reset_all.connect('clicked', () => {
|
||||
this._reset_dialog.transientFor = this.root;
|
||||
this._reset_dialog.present();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all (recursively) settings values to default
|
||||
*
|
||||
* @param {Gio.Settings} settings Settings to reset
|
||||
*/
|
||||
_resetSettings(settings) {
|
||||
const keys = settings.settings_schema.list_keys();
|
||||
keys.forEach(key => {
|
||||
settings.reset(key);
|
||||
});
|
||||
|
||||
const childrens = settings.settings_schema.list_children();
|
||||
childrens.forEach(children => {
|
||||
const childrenSettings = settings.get_child(children);
|
||||
this._resetSettings(childrenSettings);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,119 @@
|
||||
'use strict'
|
||||
|
||||
import GLib from 'gi://GLib';
|
||||
import Adw from 'gi://Adw';
|
||||
import GObject from 'gi://GObject';
|
||||
import Gio from 'gi://Gio';
|
||||
|
||||
export const Thinkpad = GObject.registerClass({
|
||||
GTypeName: 'ThinkpadPrefs',
|
||||
Template: GLib.Uri.resolve_relative(import.meta.url, '../ui/thinkpad.ui',GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
'start_bat0',
|
||||
'end_bat0',
|
||||
'start_bat1',
|
||||
'end_bat1',
|
||||
'reset',
|
||||
'apply_bat0',
|
||||
'apply_bat1',
|
||||
'reset_thresholds_dialog'
|
||||
],
|
||||
}, class Thinkpad extends Adw.PreferencesPage {
|
||||
constructor(window) {
|
||||
super({});
|
||||
|
||||
window._settings.bind(
|
||||
'start-bat0',
|
||||
this._start_bat0,
|
||||
'value',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
window._settings.bind(
|
||||
'end-bat0',
|
||||
this._end_bat0,
|
||||
'value',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
window._settings.bind(
|
||||
'start-bat1',
|
||||
this._start_bat1,
|
||||
'value',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
window._settings.bind(
|
||||
'end-bat1',
|
||||
this._end_bat1,
|
||||
'value',
|
||||
Gio.SettingsBindFlags.DEFAULT
|
||||
);
|
||||
|
||||
window._settings.connect('changed::start-bat0', () => {
|
||||
if (this._start_bat0.value >= this._end_bat0.value) {
|
||||
this._end_bat0.value = this._start_bat0.value + 1;
|
||||
}
|
||||
});
|
||||
window._settings.connect('changed::end-bat0', () => {
|
||||
if (this._start_bat0.value >= this._end_bat0.value) {
|
||||
this._start_bat0.value = this._end_bat0.value - 1;
|
||||
}
|
||||
});
|
||||
window._settings.connect('changed::start-bat1', () => {
|
||||
if (this._start_bat1.value >= this._end_bat1.value) {
|
||||
this._end_bat1.value = this._start_bat1.value + 1;
|
||||
}
|
||||
});
|
||||
window._settings.connect('changed::end-bat1', () => {
|
||||
if (this._start_bat1.value >= this._end_bat1.value) {
|
||||
this._start_bat1.value = this._end_bat1.value - 1;
|
||||
}
|
||||
});
|
||||
|
||||
const bat0 = window._driver.batteries.find(battery => battery.name === 'BAT0');
|
||||
const bat1 = window._driver.batteries.find(battery => battery.name === 'BAT1');
|
||||
|
||||
this._apply_bat0.connect('clicked', () => {
|
||||
bat0.enable();
|
||||
});
|
||||
this._apply_bat1.connect('clicked', () => {
|
||||
bat1.enable();
|
||||
});
|
||||
|
||||
this._apply_bat0.visible = bat0.isAvailable;
|
||||
bat0.connect('notify::is-available', () => {
|
||||
this._apply_bat0.visible = bat0.isAvailable;
|
||||
});
|
||||
this._apply_bat0.sensitive = bat0.pendingChanges;
|
||||
bat0.connect('notify::pending-changes', () => {
|
||||
this._apply_bat0.sensitive = bat0.pendingChanges;
|
||||
});
|
||||
|
||||
this._apply_bat1.visible = bat1.isAvailable;
|
||||
bat1.connect('notify::is-available', () => {
|
||||
this._apply_bat1.visible = bat1.isAvailable;
|
||||
});
|
||||
this._apply_bat1.sensitive = bat1.pendingChanges;
|
||||
bat1.connect('notify::pending-changes', () => {
|
||||
this._apply_bat1.sensitive = bat1.pendingChanges;
|
||||
});
|
||||
|
||||
this._reset_thresholds_dialog.connect('response', (obj, response, data) => {
|
||||
if (response === 'reset') {
|
||||
const keys = [
|
||||
'start-bat0',
|
||||
'end-bat0',
|
||||
'start-bat1',
|
||||
'end-bat1'
|
||||
];
|
||||
keys.forEach(key => {
|
||||
window._settings.reset(key);
|
||||
});
|
||||
window._driver.enableAll();
|
||||
}
|
||||
});
|
||||
|
||||
this._reset.connect('clicked', () => {
|
||||
this._reset_thresholds_dialog.transientFor = this.root;
|
||||
this._reset_thresholds_dialog.present();
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Bind AdwComboRow item
|
||||
*
|
||||
* @param {Adw.comboRow} comboRow Adw combo row item
|
||||
* @param {Gio.Settings} settings Settings object
|
||||
* @param {string} key Key name
|
||||
*/
|
||||
export function bindAdwComboRow(comboRow, settings, key) {
|
||||
comboRow.selected = settings.get_enum(key);
|
||||
settings.connect(
|
||||
`changed::${key}`, () => {
|
||||
comboRow.selected = settings.get_enum(key);
|
||||
}
|
||||
);
|
||||
comboRow.connect('notify::selected', () => {
|
||||
settings.set_enum(key, comboRow.selected);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user