Use ESLint and reformat code

This commit is contained in:
Romain
2020-08-01 07:31:53 +00:00
parent 35c6b8fa33
commit 728ae6ef40
77 changed files with 4129 additions and 3302 deletions
+64 -64
View File
@@ -30,89 +30,89 @@ const _ = Gettext.gettext;
var BackgroundsPreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Backgrounds');
const description = _('You can set different backgrounds for day and night.');
const content = new SettingsList();
const label = _('Backgrounds');
const description = _('You can set different backgrounds for day and night.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Switch backgrounds'), new BackgroundsEnabledControl()));
content.add_row(new SettingsListRow(_('Switch backgrounds'), new BackgroundsEnabledControl()));
const day_background_row = new SettingsListRow(_('Day background'), new TimeBackgroundControl('day'));
settings.bind(
'backgrounds-enabled',
day_background_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(day_background_row);
const dayBackgroundRow = new SettingsListRow(_('Day background'), new TimeBackgroundControl('day'));
settings.bind(
'backgrounds-enabled',
dayBackgroundRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayBackgroundRow);
const night_background_row = new SettingsListRow(_('Night background'), new TimeBackgroundControl('night'));
settings.bind(
'backgrounds-enabled',
night_background_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(night_background_row);
const nightBackgroundRow = new SettingsListRow(_('Night background'), new TimeBackgroundControl('night'));
settings.bind(
'backgrounds-enabled',
nightBackgroundRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(nightBackgroundRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class BackgroundsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('backgrounds-enabled')
});
settings.bind(
'backgrounds-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('backgrounds-enabled'),
});
settings.bind(
'backgrounds-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class TimeBackgroundControl {
constructor(time) {
const settings = compat.get_extension_settings();
constructor(time) {
const settings = compat.getExtensionSettings();
const filter = new Gtk.FileFilter();
filter.add_mime_type('image/jpeg');
filter.add_mime_type('image/png');
filter.add_mime_type('image/tiff');
const filter = new Gtk.FileFilter();
filter.add_mime_type('image/jpeg');
filter.add_mime_type('image/png');
filter.add_mime_type('image/tiff');
const preview = new Gtk.Image({
pixel_size: 256
});
const preview = new Gtk.Image({
pixel_size: 256,
});
const button = new Gtk.FileChooserButton({
title: _('Select your background image'),
action: Gtk.FileChooserAction.OPEN,
filter: filter,
preview_widget: preview,
use_preview_label: false
});
button.set_uri(settings.get_string(`background-${time}`));
button.connect('update-preview', () => {
const file = button.get_preview_filename();
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
preview.set_from_pixbuf(pixbuf);
});
button.connect('file-set', () => settings.set_string(`background-${time}`, button.get_uri()));
settings.connect(`changed::background-${time}`, () => button.set_uri(settings.get_string(`background-${time}`)));
const button = new Gtk.FileChooserButton({
title: _('Select your background image'),
action: Gtk.FileChooserAction.OPEN,
filter,
preview_widget: preview,
use_preview_label: false,
});
button.set_uri(settings.get_string(`background-${time}`));
button.connect('update-preview', () => {
const file = button.get_preview_filename();
const pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, 256, 256);
preview.set_from_pixbuf(pixbuf);
});
button.connect('file-set', () => settings.set_string(`background-${time}`, button.get_uri()));
settings.connect(`changed::background-${time}`, () => button.set_uri(settings.get_string(`background-${time}`)));
return button;
}
return button;
}
}
+56 -56
View File
@@ -30,77 +30,77 @@ const _ = Gettext.gettext;
var CommandsPreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Commands');
const description = _('You can set custom commands that will be run when the time of the day changes.');
const content = new SettingsList();
const label = _('Commands');
const description = _('You can set custom commands that will be run when the time of the day changes.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Use custom commands'), new CommandsEnabledControl()));
content.add_row(new SettingsListRow(_('Use custom commands'), new CommandsEnabledControl()));
const day_command_row = new SettingsListRow(_('Sunrise'), new SuntimeCommandControl('sunrise'));
settings.bind(
'commands-enabled',
day_command_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(day_command_row);
const dayCommandRow = new SettingsListRow(_('Sunrise'), new SuntimeCommandControl('sunrise'));
settings.bind(
'commands-enabled',
dayCommandRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayCommandRow);
const night_command_row = new SettingsListRow(_('Sunset'), new SuntimeCommandControl('sunset'));
settings.bind(
'commands-enabled',
night_command_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(night_command_row);
const nightCommandRow = new SettingsListRow(_('Sunset'), new SuntimeCommandControl('sunset'));
settings.bind(
'commands-enabled',
nightCommandRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(nightCommandRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class CommandsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('commands-enabled')
});
settings.bind(
'commands-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('commands-enabled'),
});
settings.bind(
'commands-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class SuntimeCommandControl {
constructor(suntime) {
const message = new Map([
['sunrise', _('Hello sunshine!')],
['sunset', _('Hello moonshine!')]
]);
const settings = compat.get_extension_settings();
const entry = new Gtk.Entry({
width_request: 300,
placeholder_text: _(`notify-send "${message.get(suntime)}"`)
});
settings.bind(
`command-${suntime}`,
entry,
'text',
Gio.SettingsBindFlags.DEFAULT
);
return entry;
}
constructor(suntime) {
const message = new Map([
['sunrise', _('Hello sunshine!')],
['sunset', _('Hello moonshine!')],
]);
const settings = compat.getExtensionSettings();
const entry = new Gtk.Entry({
width_request: 300,
placeholder_text: _(`notify-send "${message.get(suntime)}"`),
});
settings.bind(
`command-${suntime}`,
entry,
'text',
Gio.SettingsBindFlags.DEFAULT
);
return entry;
}
}
+52 -52
View File
@@ -23,7 +23,7 @@ const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_cursor_themes } = Me.imports.utils;
const { getInstalledCursorThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
@@ -31,72 +31,72 @@ const _ = Gettext.gettext;
var CursorThemePreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Cursor theme');
const description = _('You can set different cursor themes for day and night.');
const content = new SettingsList();
const label = _('Cursor theme');
const description = _('You can set different cursor themes for day and night.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Switch cursor variants'), new CursorVariantsEnabledControl()));
content.add_row(new SettingsListRow(_('Switch cursor variants'), new CursorVariantsEnabledControl()));
const day_variant_row = new SettingsListRow(_('Day variant'), new TimeCursorVariantControl('day'));
settings.bind(
'cursor-variants-enabled',
day_variant_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(day_variant_row);
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeCursorVariantControl('day'));
settings.bind(
'cursor-variants-enabled',
dayVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayVariantRow);
const night_variant_row = new SettingsListRow(_('Night variant'), new TimeCursorVariantControl('night'));
settings.bind(
'cursor-variants-enabled',
night_variant_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(night_variant_row);
const nightVariantRow = new SettingsListRow(_('Night variant'), new TimeCursorVariantControl('night'));
settings.bind(
'cursor-variants-enabled',
nightVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(nightVariantRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class CursorVariantsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('cursor-variants-enabled')
});
settings.bind(
'cursor-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('cursor-variants-enabled'),
});
settings.bind(
'cursor-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class TimeCursorVariantControl {
constructor(time) {
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_cursor_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`cursor-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
constructor(time) {
const settings = compat.getExtensionSettings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(getInstalledCursorThemes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`cursor-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
}
+69 -69
View File
@@ -23,7 +23,7 @@ const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_gtk_themes } = Me.imports.utils;
const { getInstalledGtkThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
@@ -31,96 +31,96 @@ const _ = Gettext.gettext;
var GtkThemePreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('GTK theme');
const description = _('The extension will try to automatically detect the day and night variants of your GTK theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
const content = new SettingsList();
const label = _('GTK theme');
const description = _('The extension will try to automatically detect the day and night variants of your GTK theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Switch GTK variants'), new GtkVariantsEnabledControl()));
content.add_row(new SettingsListRow(_('Switch GTK variants'), new GtkVariantsEnabledControl()));
const manual_variants_row = new SettingsListRow(_('Manual variants'), new ManualGtkVariantsControl());
settings.bind(
'gtk-variants-enabled',
manual_variants_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manual_variants_row);
const manualVariantsRow = new SettingsListRow(_('Manual variants'), new ManualGtkVariantsControl());
settings.bind(
'gtk-variants-enabled',
manualVariantsRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manualVariantsRow);
const day_variant_row = new SettingsListRow(_('Day variant'), new TimeGtkVariantControl('day'));
const update_day_variant_row_sensitivity = () => day_variant_row.set_sensitive(!!(settings.get_boolean('gtk-variants-enabled') && settings.get_boolean('manual-gtk-variants')));
settings.connect('changed::gtk-variants-enabled', update_day_variant_row_sensitivity);
settings.connect('changed::manual-gtk-variants', update_day_variant_row_sensitivity)
update_day_variant_row_sensitivity();
content.add_row(day_variant_row);
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeGtkVariantControl('day'));
const updateDayVariantRowSensitivity = () => dayVariantRow.set_sensitive(!!(settings.get_boolean('gtk-variants-enabled') && settings.get_boolean('manual-gtk-variants')));
settings.connect('changed::gtk-variants-enabled', updateDayVariantRowSensitivity);
settings.connect('changed::manual-gtk-variants', updateDayVariantRowSensitivity);
updateDayVariantRowSensitivity();
content.add_row(dayVariantRow);
const night_variant_row = new SettingsListRow(_('Night variant'), new TimeGtkVariantControl('night'));
const update_night_variant_row_sensitivity = () => night_variant_row.set_sensitive(!!(settings.get_boolean('gtk-variants-enabled') && settings.get_boolean('manual-gtk-variants')));
settings.connect('changed::gtk-variants-enabled', update_night_variant_row_sensitivity);
settings.connect('changed::manual-gtk-variants', update_night_variant_row_sensitivity)
update_night_variant_row_sensitivity();
content.add_row(night_variant_row);
const nightVariantRow = new SettingsListRow(_('Night variant'), new TimeGtkVariantControl('night'));
const updateNightVariantRowSensitivity = () => nightVariantRow.set_sensitive(!!(settings.get_boolean('gtk-variants-enabled') && settings.get_boolean('manual-gtk-variants')));
settings.connect('changed::gtk-variants-enabled', updateNightVariantRowSensitivity);
settings.connect('changed::manual-gtk-variants', updateNightVariantRowSensitivity);
updateNightVariantRowSensitivity();
content.add_row(nightVariantRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class GtkVariantsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('gtk-variants-enabled')
});
settings.bind(
'gtk-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('gtk-variants-enabled'),
});
settings.bind(
'gtk-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class ManualGtkVariantsControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
settings.bind(
'manual-gtk-variants',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: false,
});
settings.bind(
'manual-gtk-variants',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class TimeGtkVariantControl {
constructor(time) {
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_gtk_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`gtk-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
constructor(time) {
const settings = compat.getExtensionSettings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(getInstalledGtkThemes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`gtk-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
}
+52 -52
View File
@@ -23,7 +23,7 @@ const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_icon_themes } = Me.imports.utils;
const { getInstalledIconThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
@@ -31,72 +31,72 @@ const _ = Gettext.gettext;
var IconThemePreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Icon theme');
const description = _('You can set different icon themes for day and night.');
const content = new SettingsList();
const label = _('Icon theme');
const description = _('You can set different icon themes for day and night.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Switch icon variants'), new IconVariantsEnabledControl()));
content.add_row(new SettingsListRow(_('Switch icon variants'), new IconVariantsEnabledControl()));
const day_variant_row = new SettingsListRow(_('Day variant'), new TimeIconVariantControl('day'));
settings.bind(
'icon-variants-enabled',
day_variant_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(day_variant_row);
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeIconVariantControl('day'));
settings.bind(
'icon-variants-enabled',
dayVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayVariantRow);
const night_variant_row = new SettingsListRow(_('Night variant'), new TimeIconVariantControl('night'));
settings.bind(
'icon-variants-enabled',
night_variant_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(night_variant_row);
const nightVariantRow = new SettingsListRow(_('Night variant'), new TimeIconVariantControl('night'));
settings.bind(
'icon-variants-enabled',
nightVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(nightVariantRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class IconVariantsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('icon-variants-enabled')
});
settings.bind(
'icon-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('icon-variants-enabled'),
});
settings.bind(
'icon-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class TimeIconVariantControl {
constructor(time) {
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_icon_themes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`icon-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
constructor(time) {
const settings = compat.getExtensionSettings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(getInstalledIconThemes()).sort();
themes.forEach(theme => combo.append(theme, theme));
settings.bind(
`icon-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
}
+223 -226
View File
@@ -30,280 +30,277 @@ const _ = Gettext.gettext;
var SchedulePreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Schedule');
const description = _('The extension will try to use Night Light or Location Services to automatically set your current sunrise and sunset times if they are enabled.\n\nIf you prefer, you can manually choose a time source.');
const content = new SettingsList();
const label = _('Schedule');
const description = _('The extension will try to use Night Light or Location Services to automatically set your current sunrise and sunset times if they are enabled.\n\nIf you prefer, you can manually choose a time source.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Automatic time source'), new ManualTimeSourceControl()));
content.add_row(new SettingsListRow(_('Automatic time source'), new ManualTimeSourceControl()));
const time_source_row = new SettingsListRow(_('Time source'), new TimeSourceControl());
settings.bind(
'manual-time-source',
time_source_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(time_source_row);
const timeSourceRow = new SettingsListRow(_('Time source'), new TimeSourceControl());
settings.bind(
'manual-time-source',
timeSourceRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(timeSourceRow);
const ondemand_shortcut_row = new SettingsListRow(_('On-demand shortcut'), new KeyBindingControl());
const update_ondemand_shortcut_row_sensitivity = () => ondemand_shortcut_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'ondemand'));
settings.connect('changed::manual-time-source', () => update_ondemand_shortcut_row_sensitivity());
settings.connect('changed::time-source', () => update_ondemand_shortcut_row_sensitivity());
update_ondemand_shortcut_row_sensitivity();
content.add_row(ondemand_shortcut_row);
const ondemandShortcutRow = new SettingsListRow(_('On-demand shortcut'), new KeyBindingControl());
const updateOndemandShortcutRowSensitivity = () => ondemandShortcutRow.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'ondemand'));
settings.connect('changed::manual-time-source', () => updateOndemandShortcutRowSensitivity());
settings.connect('changed::time-source', () => updateOndemandShortcutRowSensitivity());
updateOndemandShortcutRowSensitivity();
content.add_row(ondemandShortcutRow);
const sunrise_row = new SettingsListRow(_('Sunrise'), new SuntimeControl('sunrise'));
const update_sunrise_row_sensitivity = () => sunrise_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule'));
settings.connect('changed::manual-time-source', () => update_sunrise_row_sensitivity());
settings.connect('changed::time-source', () => update_sunrise_row_sensitivity());
update_sunrise_row_sensitivity();
content.add_row(sunrise_row);
const sunriseRow = new SettingsListRow(_('Sunrise'), new SuntimeControl('sunrise'));
const updateSunriseRowSensitivity = () => sunriseRow.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule'));
settings.connect('changed::manual-time-source', () => updateSunriseRowSensitivity());
settings.connect('changed::time-source', () => updateSunriseRowSensitivity());
updateSunriseRowSensitivity();
content.add_row(sunriseRow);
const sunset_row = new SettingsListRow(_('Sunset'), new SuntimeControl('sunset'));
const update_sunset_row_sensitivity = () => sunset_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule'));
settings.connect('changed::manual-time-source', () => update_sunset_row_sensitivity());
settings.connect('changed::time-source', () => update_sunset_row_sensitivity());
update_sunset_row_sensitivity();
content.add_row(sunset_row);
const sunsetRow = new SettingsListRow(_('Sunset'), new SuntimeControl('sunset'));
const updateSunsetRowSensitivity = () => sunsetRow.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule'));
settings.connect('changed::manual-time-source', () => updateSunsetRowSensitivity());
settings.connect('changed::time-source', () => updateSunsetRowSensitivity());
updateSunsetRowSensitivity();
content.add_row(sunsetRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class ManualTimeSourceControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
settings.bind(
'manual-time-source',
toggle,
'active',
Gio.SettingsBindFlags.INVERT_BOOLEAN
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: false,
});
settings.bind(
'manual-time-source',
toggle,
'active',
Gio.SettingsBindFlags.INVERT_BOOLEAN
);
return toggle;
}
}
class TimeSourceControl {
constructor() {
const settings = compat.get_extension_settings();
const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
constructor() {
const settings = compat.getExtensionSettings();
const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' });
const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' });
const box = new Gtk.Box({
spacing: 8,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false
});
const box = new Gtk.Box({
spacing: 8,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false,
});
const nightlight_radio = new Gtk.RadioButton({
label: _('Night Light'),
active: (settings.get_string('time-source') === 'nightlight')
});
nightlight_radio.connect('toggled', () => {
if ( nightlight_radio.get_active() ) {
settings.set_string('time-source', 'nightlight')
}
});
colorSettings.bind(
'night-light-enabled',
nightlight_radio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(nightlight_radio, false, false, 0);
const nightlightRadio = new Gtk.RadioButton({
label: _('Night Light'),
active: settings.get_string('time-source') === 'nightlight',
});
nightlightRadio.connect('toggled', () => {
if (nightlightRadio.get_active())
settings.set_string('time-source', 'nightlight');
});
colorSettings.bind(
'night-light-enabled',
nightlightRadio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(nightlightRadio, false, false, 0);
const location_radio = new Gtk.RadioButton({
label: _('Location Services'),
group: nightlight_radio,
active: (settings.get_string('time-source') === 'location')
});
location_radio.connect('toggled', () => {
if ( location_radio.get_active() ) {
settings.set_string('time-source', 'location')
}
});
locationSettings.bind(
'enabled',
location_radio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(location_radio, false, false, 0);
const locationRadio = new Gtk.RadioButton({
label: _('Location Services'),
group: nightlightRadio,
active: settings.get_string('time-source') === 'location',
});
locationRadio.connect('toggled', () => {
if (locationRadio.get_active())
settings.set_string('time-source', 'location');
});
locationSettings.bind(
'enabled',
locationRadio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(locationRadio, false, false, 0);
const schedule_radio = new Gtk.RadioButton({
label: _('Manual schedule'),
group: nightlight_radio,
active: (settings.get_string('time-source') === 'schedule')
});
schedule_radio.connect('toggled', () => {
if ( schedule_radio.get_active() ) {
settings.set_string('time-source', 'schedule')
}
});
settings.bind(
'manual-time-source',
schedule_radio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(schedule_radio, false, false, 0);
const scheduleRadio = new Gtk.RadioButton({
label: _('Manual schedule'),
group: nightlightRadio,
active: settings.get_string('time-source') === 'schedule',
});
scheduleRadio.connect('toggled', () => {
if (scheduleRadio.get_active())
settings.set_string('time-source', 'schedule');
});
settings.bind(
'manual-time-source',
scheduleRadio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(scheduleRadio, false, false, 0);
const ondemand_radio = new Gtk.RadioButton({
label: _('On-demand'),
group: nightlight_radio,
active: (settings.get_string('time-source') === 'ondemand')
});
ondemand_radio.connect('toggled', () => {
settings.set_string('time-source', 'ondemand')
});
settings.bind(
'manual-time-source',
ondemand_radio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(ondemand_radio, false, false, 0);
const ondemandRadio = new Gtk.RadioButton({
label: _('On-demand'),
group: nightlightRadio,
active: settings.get_string('time-source') === 'ondemand',
});
ondemandRadio.connect('toggled', () => {
settings.set_string('time-source', 'ondemand');
});
settings.bind(
'manual-time-source',
ondemandRadio,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
box.pack_start(ondemandRadio, false, false, 0);
return box;
}
return box;
}
}
class KeyBindingControl {
constructor() {
const settings = compat.get_extension_settings();
const KEYBINDING_KEY = 'nightthemeswitcher-ondemand-keybinding';
const COLUMN_KEY = 0;
const COLUMN_MODS = 1;
constructor() {
const settings = compat.getExtensionSettings();
const KEYBINDING_KEY = 'nightthemeswitcher-ondemand-keybinding';
const COLUMN_KEY = 0;
const COLUMN_MODS = 1;
const list_store = new Gtk.ListStore();
list_store.set_column_types([GObject.TYPE_INT, GObject.TYPE_INT]);
const tree_view = new Gtk.TreeView({model: list_store});
tree_view.set_headers_visible(false);
const listStore = new Gtk.ListStore();
listStore.set_column_types([GObject.TYPE_INT, GObject.TYPE_INT]);
const treeView = new Gtk.TreeView({ model: listStore });
treeView.set_headers_visible(false);
const renderer = new Gtk.CellRendererAccel({ editable: true});
const column = new Gtk.TreeViewColumn();
const iter = list_store.append();
const renderer = new Gtk.CellRendererAccel({ editable: true });
const column = new Gtk.TreeViewColumn();
const iter = listStore.append();
const update_shortcut_row = (accel) => {
const [key, mods] = accel ? Gtk.accelerator_parse(accel) : [0, 0];
list_store.set(iter, [COLUMN_KEY, COLUMN_MODS], [key, mods]);
};
const updateShortcutRow = accel => {
const [key, mods] = accel ? Gtk.accelerator_parse(accel) : [0, 0];
listStore.set(iter, [COLUMN_KEY, COLUMN_MODS], [key, mods]);
};
renderer.connect('accel-edited', (renderer, path, key, mods) => {
const accel = Gtk.accelerator_name(key, mods);
update_shortcut_row(accel);
settings.set_strv(KEYBINDING_KEY, [accel]);
});
renderer.connect('accel-edited', (_renderer, _path, key, mods) => {
const accel = Gtk.accelerator_name(key, mods);
updateShortcutRow(accel);
settings.set_strv(KEYBINDING_KEY, [accel]);
});
renderer.connect('accel-cleared', () => {
update_shortcut_row(null);
settings.set_strv(KEYBINDING_KEY, []);
});
renderer.connect('accel-cleared', () => {
updateShortcutRow(null);
settings.set_strv(KEYBINDING_KEY, []);
});
settings.connect(`changed::${KEYBINDING_KEY}`, () => {
update_shortcut_row(settings.get_strv(KEYBINDING_KEY)[0]);
});
settings.connect(`changed::${KEYBINDING_KEY}`, () => {
updateShortcutRow(settings.get_strv(KEYBINDING_KEY)[0]);
});
column.pack_start(renderer, true);
column.add_attribute(renderer, 'accel-key', COLUMN_KEY);
column.add_attribute(renderer, 'accel-mods', COLUMN_MODS);
column.pack_start(renderer, true);
column.add_attribute(renderer, 'accel-key', COLUMN_KEY);
column.add_attribute(renderer, 'accel-mods', COLUMN_MODS);
tree_view.append_column(column);
update_shortcut_row(settings.get_strv(KEYBINDING_KEY)[0]);
treeView.append_column(column);
updateShortcutRow(settings.get_strv(KEYBINDING_KEY)[0]);
return tree_view;
}
return treeView;
}
}
class SuntimeControl {
constructor(suntime) {
const settings = compat.get_extension_settings();
const box = new Gtk.Box({
spacing: 8,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false
});
constructor(suntime) {
const settings = compat.getExtensionSettings();
const box = new Gtk.Box({
spacing: 8,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false,
});
const time = settings.get_double(`schedule-${suntime}`);
const hours = Math.trunc(time);
const minutes = Math.round((time - hours) * 60);
const time = settings.get_double(`schedule-${suntime}`);
const hours = Math.trunc(time);
const minutes = Math.round((time - hours) * 60);
const hours_spin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
value: hours,
lower: 0,
upper: 23,
step_increment: 1,
page_increment: 0,
page_size: 0
}),
value: hours,
numeric: true,
wrap: true,
orientation: Gtk.Orientation.VERTICAL
});
hours_spin.connect('output', () => {
const text = hours_spin.adjustment.value.toString().padStart(2, '0');
hours_spin.set_text(text);
return true;
});
hours_spin.connect('value-changed', () => {
const old_time = settings.get_double(`schedule-${suntime}`);
const old_hour = Math.trunc(old_time);
const minutes = old_time - old_hour;
const new_time = hours_spin.value + minutes;
settings.set_double(`schedule-${suntime}`, new_time);
});
const hoursSpin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
value: hours,
lower: 0,
upper: 23,
step_increment: 1,
page_increment: 0,
page_size: 0,
}),
value: hours,
numeric: true,
wrap: true,
orientation: Gtk.Orientation.VERTICAL,
});
hoursSpin.connect('output', () => {
const text = hoursSpin.adjustment.value.toString().padStart(2, '0');
hoursSpin.set_text(text);
return true;
});
hoursSpin.connect('value-changed', () => {
const oldTime = settings.get_double(`schedule-${suntime}`);
const oldHour = Math.trunc(oldTime);
const newMinutes = oldTime - oldHour;
const newTime = hoursSpin.value + newMinutes;
settings.set_double(`schedule-${suntime}`, newTime);
});
const separator = new Gtk.Label({ label: ':' });
const separator = new Gtk.Label({ label: ':' });
const minutes_spin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
value: minutes,
lower: 0,
upper: 59,
step_increment: 1,
page_increment: 0,
page_size: 0
}),
value: minutes,
numeric: true,
wrap: true,
orientation: Gtk.Orientation.VERTICAL
});
minutes_spin.connect('output', () => {
const text = minutes_spin.adjustment.value.toString().padStart(2, '0');
minutes_spin.set_text(text);
return true;
});
minutes_spin.connect('value-changed', () => {
const hour = Math.trunc(settings.get_double(`schedule-${suntime}`));
const minutes = minutes_spin.value / 60;
const new_time = hour + minutes;
settings.set_double(`schedule-${suntime}`, new_time);
});
const minutesSpin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
value: minutes,
lower: 0,
upper: 59,
step_increment: 1,
page_increment: 0,
page_size: 0,
}),
value: minutes,
numeric: true,
wrap: true,
orientation: Gtk.Orientation.VERTICAL,
});
minutesSpin.connect('output', () => {
const text = minutesSpin.adjustment.value.toString().padStart(2, '0');
minutesSpin.set_text(text);
return true;
});
minutesSpin.connect('value-changed', () => {
const hour = Math.trunc(settings.get_double(`schedule-${suntime}`));
const newMinutes = minutesSpin.value / 60;
const newTime = hour + newMinutes;
settings.set_double(`schedule-${suntime}`, newTime);
});
box.pack_start(hours_spin, false, false, 0);
box.pack_start(separator, false, false, 0);
box.pack_start(minutes_spin, false, false, 0);
return box;
}
box.pack_start(hoursSpin, false, false, 0);
box.pack_start(separator, false, false, 0);
box.pack_start(minutesSpin, false, false, 0);
return box;
}
}
+69 -69
View File
@@ -23,7 +23,7 @@ const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { get_installed_shell_themes } = Me.imports.utils;
const { getInstalledShellThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
@@ -31,96 +31,96 @@ const _ = Gettext.gettext;
var ShellThemePreferences = class {
constructor() {
const settings = compat.get_extension_settings();
constructor() {
const settings = compat.getExtensionSettings();
const label = _('Shell theme');
const description = _('The extension will try to automatically detect the day and night variants of your GNOME Shell theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
const content = new SettingsList();
const label = _('Shell theme');
const description = _('The extension will try to automatically detect the day and night variants of your GNOME Shell theme.\n\nIf the theme you use isn\'t supported, please <a href="https://gitlab.com/rmnvgr/nightthemeswitcher-gnome-shell-extension/-/issues">submit a request</a>. You can also manually set variants.');
const content = new SettingsList();
content.add_row(new SettingsListRow(_('Switch Shell variants'), new ShellVariantsEnabledControl()));
content.add_row(new SettingsListRow(_('Switch Shell variants'), new ShellVariantsEnabledControl()));
const manual_variants_row = new SettingsListRow(_('Manual variants'), new ManualShellVariantsControl());
settings.bind(
'shell-variants-enabled',
manual_variants_row,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manual_variants_row);
const manualVariantsRow = new SettingsListRow(_('Manual variants'), new ManualShellVariantsControl());
settings.bind(
'shell-variants-enabled',
manualVariantsRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manualVariantsRow);
const day_variant_row = new SettingsListRow(_('Day variant'), new TimeShellVariantControl('day'));
const update_day_variant_row_sensitivity = () => day_variant_row.set_sensitive(!!(settings.get_boolean('shell-variants-enabled') && settings.get_boolean('manual-shell-variants')));
settings.connect('changed::shell-variants-enabled', update_day_variant_row_sensitivity);
settings.connect('changed::manual-shell-variants', update_day_variant_row_sensitivity)
update_day_variant_row_sensitivity();
content.add_row(day_variant_row);
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeShellVariantControl('day'));
const updateDayVariantRowSensitivity = () => dayVariantRow.set_sensitive(!!(settings.get_boolean('shell-variants-enabled') && settings.get_boolean('manual-shell-variants')));
settings.connect('changed::shell-variants-enabled', updateDayVariantRowSensitivity);
settings.connect('changed::manual-shell-variants', updateDayVariantRowSensitivity);
updateDayVariantRowSensitivity();
content.add_row(dayVariantRow);
const night_variant_row = new SettingsListRow(_('Night variant'), new TimeShellVariantControl('night'));
const update_night_variant_row_sensitivity = () => night_variant_row.set_sensitive(!!(settings.get_boolean('shell-variants-enabled') && settings.get_boolean('manual-shell-variants')));
settings.connect('changed::shell-variants-enabled', update_night_variant_row_sensitivity);
settings.connect('changed::manual-shell-variants', update_night_variant_row_sensitivity)
update_night_variant_row_sensitivity();
content.add_row(night_variant_row);
const nightVariantRow = new SettingsListRow(_('Night variant'), new TimeShellVariantControl('night'));
const updateNightVariantRowSensitivity = () => nightVariantRow.set_sensitive(!!(settings.get_boolean('shell-variants-enabled') && settings.get_boolean('manual-shell-variants')));
settings.connect('changed::shell-variants-enabled', updateNightVariantRowSensitivity);
settings.connect('changed::manual-shell-variants', updateNightVariantRowSensitivity);
updateNightVariantRowSensitivity();
content.add_row(nightVariantRow);
return new SettingsPage(label, description, content);
}
return new SettingsPage(label, description, content);
}
}
};
class ShellVariantsEnabledControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('shell-variants-enabled')
});
settings.bind(
'shell-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: settings.get_boolean('shell-variants-enabled'),
});
settings.bind(
'shell-variants-enabled',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class ManualShellVariantsControl {
constructor() {
const settings = compat.get_extension_settings();
const toggle = new Gtk.Switch({
active: false
});
settings.bind(
'manual-shell-variants',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
constructor() {
const settings = compat.getExtensionSettings();
const toggle = new Gtk.Switch({
active: false,
});
settings.bind(
'manual-shell-variants',
toggle,
'active',
Gio.SettingsBindFlags.DEFAULT
);
return toggle;
}
}
class TimeShellVariantControl {
constructor(time) {
const settings = compat.get_extension_settings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(get_installed_shell_themes()).sort();
themes.forEach(theme => combo.append(theme, (theme === '' ? _('Default') : theme)));
settings.bind(
`shell-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
constructor(time) {
const settings = compat.getExtensionSettings();
const combo = new Gtk.ComboBoxText();
const themes = Array.from(getInstalledShellThemes()).sort();
themes.forEach(theme => combo.append(theme, theme === '' ? _('Default') : theme));
settings.bind(
`shell-variant-${time}`,
combo,
'active-id',
Gio.SettingsBindFlags.DEFAULT
);
return combo;
}
}
+68 -68
View File
@@ -21,89 +21,89 @@ const { Gtk } = imports.gi;
var SettingsPage = class {
constructor(label, description, content_widget) {
this.label = new Gtk.Label({
label: label
});
constructor(label, description, contentWidget) {
this.label = new Gtk.Label({
label,
});
this.page = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 30,
margin_top: 30,
margin_end: 36,
margin_start: 36,
margin_bottom: 36,
valign: Gtk.Align.START,
halign: Gtk.Align.CENTER
});
this.page = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 30,
margin_top: 30,
margin_end: 36,
margin_start: 36,
margin_bottom: 36,
valign: Gtk.Align.START,
halign: Gtk.Align.CENTER,
});
const description_widget = new Gtk.Label({
label: description,
use_markup: true,
width_request: 600,
max_width_chars: 60,
wrap: true,
justify: Gtk.Justification.LEFT,
halign: Gtk.Align.START
});
this.page.pack_start(description_widget, false, false, 0);
const descriptionWidget = new Gtk.Label({
label: description,
use_markup: true,
width_request: 600,
max_width_chars: 60,
wrap: true,
justify: Gtk.Justification.LEFT,
halign: Gtk.Align.START,
});
this.page.pack_start(descriptionWidget, false, false, 0);
this.page.pack_start(content_widget, false, false, 0);
}
this.page.pack_start(contentWidget, false, false, 0);
}
}
};
var SettingsList = class {
constructor() {
const frame = new Gtk.Frame({
can_focus: false
});
constructor() {
const frame = new Gtk.Frame({
can_focus: false,
});
const list = new Gtk.ListBox({
border_width: 0,
margin: 0,
can_focus: false,
selection_mode: Gtk.SelectionMode.NONE
});
frame.add(list);
const list = new Gtk.ListBox({
border_width: 0,
margin: 0,
can_focus: false,
selection_mode: Gtk.SelectionMode.NONE,
});
frame.add(list);
frame.add_row = (widget) => {
if ( list.get_children().length > 0 ) {
const separator = new Gtk.Separator({
orientation: Gtk.Orientation.VERTICAL,
can_focus: false
});
list.add(separator);
}
list.add(widget);
}
frame.add_row = widget => {
if (list.get_children().length > 0) {
const separator = new Gtk.Separator({
orientation: Gtk.Orientation.VERTICAL,
can_focus: false,
});
list.add(separator);
}
list.add(widget);
};
return frame;
}
return frame;
}
}
};
var SettingsListRow = class {
constructor(label, widget) {
const row = new Gtk.Box({
margin: 16,
spacing: 30,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false
});
constructor(label, widget) {
const row = new Gtk.Box({
margin: 16,
spacing: 30,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false,
});
const label_widget = new Gtk.Label({
label: label,
halign: Gtk.Align.START
});
row.pack_start(label_widget, true, true, 0);
const labelWidget = new Gtk.Label({
label,
halign: Gtk.Align.START,
});
row.pack_start(labelWidget, true, true, 0);
widget.set_halign(Gtk.Align.END);
row.pack_start(widget, false, false, 0);
widget.set_halign(Gtk.Align.END);
row.pack_start(widget, false, false, 0);
return row;
}
return row;
}
}
};