Build preferences from UI file

This commit is contained in:
Romain
2020-08-03 20:11:47 +00:00
parent 7440cec8ff
commit e477be9ae6
14 changed files with 3485 additions and 1518 deletions
-118
View File
@@ -1,118 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { GdkPixbuf, Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var BackgroundsPreferences = class {
constructor() {
const settings = compat.getExtensionSettings();
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()));
const dayBackgroundRow = new SettingsListRow(_('Day background'), new TimeBackgroundControl('day'));
settings.bind(
'backgrounds-enabled',
dayBackgroundRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayBackgroundRow);
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);
}
};
class BackgroundsEnabledControl {
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.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 preview = new Gtk.Image({
pixel_size: 256,
});
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;
}
}
-106
View File
@@ -1,106 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var CommandsPreferences = class {
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();
content.add_row(new SettingsListRow(_('Use custom commands'), new CommandsEnabledControl()));
const dayCommandRow = new SettingsListRow(_('Sunrise'), new SuntimeCommandControl('sunrise'));
settings.bind(
'commands-enabled',
dayCommandRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayCommandRow);
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);
}
};
class CommandsEnabledControl {
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.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;
}
}
-102
View File
@@ -1,102 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { GdkPixbuf, Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { getInstalledCursorThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var CursorThemePreferences = class {
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();
content.add_row(new SettingsListRow(_('Switch cursor variants'), new CursorVariantsEnabledControl()));
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeCursorVariantControl('day'));
settings.bind(
'cursor-variants-enabled',
dayVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayVariantRow);
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);
}
};
class CursorVariantsEnabledControl {
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.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;
}
}
-126
View File
@@ -1,126 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { getInstalledGtkThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var GtkThemePreferences = class {
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();
content.add_row(new SettingsListRow(_('Switch GTK variants'), new GtkVariantsEnabledControl()));
const manualVariantsRow = new SettingsListRow(_('Manual variants'), new ManualGtkVariantsControl());
settings.bind(
'gtk-variants-enabled',
manualVariantsRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manualVariantsRow);
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 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);
}
};
class GtkVariantsEnabledControl {
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.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.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;
}
}
-102
View File
@@ -1,102 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { GdkPixbuf, Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { getInstalledIconThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var IconThemePreferences = class {
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();
content.add_row(new SettingsListRow(_('Switch icon variants'), new IconVariantsEnabledControl()));
const dayVariantRow = new SettingsListRow(_('Day variant'), new TimeIconVariantControl('day'));
settings.bind(
'icon-variants-enabled',
dayVariantRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(dayVariantRow);
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);
}
};
class IconVariantsEnabledControl {
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.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;
}
}
-306
View File
@@ -1,306 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gio, GObject, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var SchedulePreferences = class {
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();
content.add_row(new SettingsListRow(_('Automatic time source'), new ManualTimeSourceControl()));
const timeSourceRow = new SettingsListRow(_('Time source'), new TimeSourceControl());
settings.bind(
'manual-time-source',
timeSourceRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(timeSourceRow);
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 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 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);
}
};
class ManualTimeSourceControl {
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.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 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 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 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 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;
}
}
class KeyBindingControl {
constructor() {
const settings = compat.getExtensionSettings();
const KEYBINDING_KEY = 'nightthemeswitcher-ondemand-keybinding';
const COLUMN_KEY = 0;
const COLUMN_MODS = 1;
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 = listStore.append();
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);
updateShortcutRow(accel);
settings.set_strv(KEYBINDING_KEY, [accel]);
});
renderer.connect('accel-cleared', () => {
updateShortcutRow(null);
settings.set_strv(KEYBINDING_KEY, []);
});
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);
treeView.append_column(column);
updateShortcutRow(settings.get_strv(KEYBINDING_KEY)[0]);
return treeView;
}
}
class SuntimeControl {
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 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 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(hoursSpin, false, false, 0);
box.pack_start(separator, false, false, 0);
box.pack_start(minutesSpin, false, false, 0);
return box;
}
}
-126
View File
@@ -1,126 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gio, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const compat = Me.imports.compat;
const { SettingsPage, SettingsList, SettingsListRow } = Me.imports.preferences.bases;
const { getInstalledShellThemes } = Me.imports.utils;
const Gettext = imports.gettext.domain(Me.metadata.uuid);
const _ = Gettext.gettext;
var ShellThemePreferences = class {
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();
content.add_row(new SettingsListRow(_('Switch Shell variants'), new ShellVariantsEnabledControl()));
const manualVariantsRow = new SettingsListRow(_('Manual variants'), new ManualShellVariantsControl());
settings.bind(
'shell-variants-enabled',
manualVariantsRow,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
content.add_row(manualVariantsRow);
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 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);
}
};
class ShellVariantsEnabledControl {
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.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.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;
}
}
-109
View File
@@ -1,109 +0,0 @@
/*
Night Theme Switcher Gnome Shell extension
Copyright (C) 2020 Romain Vigier
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http s ://www.gnu.org/licenses/>.
*/
const { Gtk } = imports.gi;
var SettingsPage = class {
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,
});
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(contentWidget, false, false, 0);
}
};
var SettingsList = class {
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);
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;
}
};
var SettingsListRow = class {
constructor(label, widget) {
const row = new Gtk.Box({
margin: 16,
spacing: 30,
orientation: Gtk.Orientation.HORIZONTAL,
can_focus: false,
});
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);
return row;
}
};