🔧 Profile configuration start working
This commit is contained in:
+2
-120
@@ -14,8 +14,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {Gtk, Gio, GLib} = imports.gi;
|
||||
const ByteArray = imports.byteArray;
|
||||
const {Gtk, Gio} = imports.gi;
|
||||
const ByteArray = imports.byteArray;
|
||||
|
||||
// libadwaita is available starting with GNOME Shell 42.
|
||||
let Adw = null;
|
||||
@@ -110,121 +110,3 @@ function getStringResource(path) {
|
||||
const data = Gio.resources_lookup_data(path, 0);
|
||||
return ByteArray.toString(ByteArray.fromGBytes(data));
|
||||
}
|
||||
|
||||
function createProfile() {
|
||||
const path =
|
||||
GLib.get_user_config_dir() + `/burn-my-windows/profiles/${GLib.get_real_time()}.conf`;
|
||||
const file = Gio.File.new_for_path(path);
|
||||
|
||||
if (!file.get_parent().query_exists(null)) {
|
||||
file.get_parent().make_directory_with_parents(null);
|
||||
}
|
||||
|
||||
file.create(Gio.FileCreateFlags.NONE, null);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
function deleteProfile(profilePath) {
|
||||
const profileDir = GLib.get_user_config_dir() + `/burn-my-windows/profiles`;
|
||||
const file = Gio.File.new_for_path(profilePath);
|
||||
if (file.has_prefix(Gio.File.new_for_path(profileDir)) && file.query_exists(null)) {
|
||||
file.delete(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function listProfiles() {
|
||||
|
||||
const profileDir =
|
||||
Gio.File.new_for_path(GLib.get_user_config_dir() + '/burn-my-windows/profiles');
|
||||
|
||||
if (!profileDir.query_exists(null)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const files =
|
||||
profileDir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
|
||||
|
||||
let profiles = [];
|
||||
|
||||
while (true) {
|
||||
const presetInfo = files.next_file(null);
|
||||
|
||||
if (presetInfo == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (presetInfo.get_file_type() == Gio.FileType.REGULAR) {
|
||||
const suffixPos = presetInfo.get_display_name().indexOf('.conf');
|
||||
if (suffixPos > 0) {
|
||||
profiles.push(profileDir.get_child(presetInfo.get_name()).get_path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return profiles.sort();
|
||||
}
|
||||
|
||||
// Based on
|
||||
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/misc/extensionUtils.js#L213
|
||||
function getProfileSettings(profilePath) {
|
||||
|
||||
// Expect USER extensions to have a schemas/ subfolder, otherwise assume a
|
||||
// SYSTEM extension that has been installed in the same prefix as the shell
|
||||
const schemaDir = Me.dir.get_child('schemas');
|
||||
let source;
|
||||
if (schemaDir.query_exists(null)) {
|
||||
source = Gio.SettingsSchemaSource.new_from_directory(
|
||||
schemaDir.get_path(), Gio.SettingsSchemaSource.get_default(), false);
|
||||
} else {
|
||||
source = Gio.SettingsSchemaSource.get_default();
|
||||
}
|
||||
|
||||
const schema =
|
||||
source.lookup('org.gnome.shell.extensions.burn-my-windows-profile', true);
|
||||
|
||||
const backend =
|
||||
Gio.keyfile_settings_backend_new(profilePath, '/org/gnome/shell/extensions/', null);
|
||||
|
||||
return new Gio.Settings({settings_schema: schema, backend: backend});
|
||||
}
|
||||
|
||||
function getProfileName(profilePath) {
|
||||
let items = [];
|
||||
const settings = getProfileSettings(profilePath);
|
||||
|
||||
const addItems = (settingsKey, options) => {
|
||||
const option = settings.get_int(settingsKey);
|
||||
if (option > 0) {
|
||||
items.push(options[option - 1]);
|
||||
}
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
addItems('profile-animation-type', [_('Opening Windows'),
|
||||
_('Closing Windows')]);
|
||||
addItems('profile-window-type', [_('Normal Windows'),
|
||||
_('Dialog Windows')]);
|
||||
addItems('profile-desktop-style', [_('Bright Mode'),
|
||||
_('Dark Mode')]);
|
||||
addItems('profile-power-mode', [_('On Battery'),
|
||||
_('Plugged In')]);
|
||||
addItems('profile-power-profile', [_('Power-Saver Mode'),
|
||||
_('Balanced Mode'),
|
||||
_('Performance Mode'),
|
||||
_('Power Saver or Balanced'),
|
||||
_('Balanced or Performance')]);
|
||||
// clang-format on
|
||||
|
||||
let label = '';
|
||||
|
||||
if (items.length == 0) {
|
||||
label = _('Default Profile');
|
||||
} else {
|
||||
label = items.join(' · ');
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
Reference in New Issue
Block a user