🔧 Port to ESM

This commit is contained in:
Simon Schneegans
2023-08-07 12:57:38 +02:00
parent 505289376e
commit d1cddb129d
5 changed files with 131 additions and 159 deletions
+4 -58
View File
@@ -17,10 +17,6 @@
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
const _ = imports.gettext.domain('burn-my-windows').gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
//////////////////////////////////////////////////////////////////////////////////////////
// Burn-My-Windows allows applying different sets of effect settings under specific //
// circumstances. These settings are called "effect profiles". The ProfileManager //
@@ -33,7 +29,9 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
export class ProfileManager {
// ------------------------------------------------------------------------- constructor
constructor() {
constructor(metadata) {
this._metadata = metadata;
this._makeProfilesDir();
this.reloadProfiles();
}
@@ -150,58 +148,6 @@ export class ProfileManager {
return priority;
}
// Profiles are named according to their configuration. This method returns a localized
// string describing the settings of the profile.
getProfileName(settings) {
let items = [];
// If an app is configured, use it as first component for the profile's name.
const app = settings.get_string('profile-app');
if (app != '') {
items.push(app);
}
// Now add components to the name for each non-default profile option. Make sure that
// these are the same strings as used in the UI files!
const addComponent = (settingsKey, options) => {
const option = settings.get_int(settingsKey);
if (option > 0) {
items.push(options[option - 1]);
}
};
// clang-format off
addComponent('profile-animation-type', [_('Opening Windows'),
_('Closing Windows')]);
addComponent('profile-window-type', [_('Normal Windows'),
_('Dialog Windows')]);
addComponent('profile-color-scheme', [_('Default Color Scheme'),
_('Dark Color Scheme')]);
addComponent('profile-power-mode', [_('On Battery'),
_('Plugged In')]);
addComponent('profile-power-profile', [_('Power-Saver Mode'),
_('Balanced Mode'),
_('Performance Mode'),
_('Power Saver or Balanced'),
_('Balanced or Performance')]);
// clang-format on
// If the profile is a high-priority profile, also add this..
if (settings.get_boolean('profile-high-priority')) {
items.push(_('High Priority'));
}
let name = '';
if (items.length == 0) {
name = _('Standard Profile');
} else {
name = items.join(' · ');
}
return name;
}
// ----------------------------------------------------------------------- private stuff
// Creates the directory ~/.config/burn-my-windows/profiles if it does not yet exist.
@@ -220,7 +166,7 @@ export class ProfileManager {
// 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');
const schemaDir = this._metadata.dir.get_child('schemas');
let source;
if (schemaDir.query_exists(null)) {
source = Gio.SettingsSchemaSource.new_from_directory(
+2 -2
View File
@@ -18,8 +18,8 @@
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
const Main = imports.ui.main;
const LookingGlass = imports.ui.lookingGlass;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as LookingGlass from 'resource:///org/gnome/shell/ui/lookingGlass.js';
import {getStringResource} from './utils.js';
+3 -5
View File
@@ -33,12 +33,9 @@ function toNumericVersion(x) {
return x;
}
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Config = imports.misc.config;
const [GS_MAJOR, GS_MINOR] = Config.PACKAGE_VERSION.split('.').map(toNumericVersion);
const _ = imports.gettext.domain('burn-my-windows').gettext;
// This method can be used to write a message to GNOME Shell's log. This is enhances
// the standard log() functionality by prepending the extension's name and the location
// where the message was logged. As the extensions name is part of the location, you
@@ -54,9 +51,10 @@ export function debug(message) {
// Find the index of the extension directory (e.g. particles@schneegans.github.com) in
// the stack entry. We do not want to print the entire absolute file path.
const extensionRoot = stack[0].indexOf(Me.metadata.uuid);
// const extensionRoot = stack[0].indexOf(Extension.uuid);
log('[' + stack[0].slice(extensionRoot) + '] ' + message);
log('[' + stack[0] + '] ' + message);
// log('[' + stack[0].slice(extensionRoot) + '] ' + message);
}
// This method simply returns true if we are currently using GTK4.