📝 Add some comments
This commit is contained in:
+7
-9
@@ -136,23 +136,21 @@ class Extension {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose a random effect.
|
// Create a list of all currently enabled effects.
|
||||||
const enabledEffects = [];
|
const enabledEffects = ALL_EFFECTS.filter(Effect => {
|
||||||
ALL_EFFECTS.forEach(Effect => {
|
const prefix = Effect.getSettingsPrefix();
|
||||||
const [minMajor, minMinor] = Effect.getMinShellVersion();
|
return this._settings.get_boolean(`${prefix}-close-effect`);
|
||||||
const prefix = Effect.getSettingsPrefix();
|
|
||||||
if (utils.shellVersionIsAtLeast(minMajor, minMinor) &&
|
|
||||||
this._settings.get_boolean(`${prefix}-close-effect`)) {
|
|
||||||
enabledEffects.push(Effect);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Nothing is enabled...
|
||||||
if (enabledEffects.length == 0) {
|
if (enabledEffects.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose a random effect.
|
||||||
const Effect = enabledEffects[Math.floor(Math.random() * enabledEffects.length)];
|
const Effect = enabledEffects[Math.floor(Math.random() * enabledEffects.length)];
|
||||||
|
|
||||||
|
// The effect usually will choose to override the present transitions on the actor.
|
||||||
Effect.tweakTransitions(actor, this._settings);
|
Effect.tweakTransitions(actor, this._settings);
|
||||||
|
|
||||||
// Add a cool shader to our window actor!
|
// Add a cool shader to our window actor!
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ const ALL_EFFECTS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// For now, the preferences dialog of this extension is very simple. In the future, if //
|
// The preferences dialog is organized in pages, each of which is loaded from a //
|
||||||
// we might consider to improve its layout... //
|
// separate ui file. There's one page with general options, all other paged are loaded //
|
||||||
|
// from the respective effects. //
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var PreferencesDialog = class PreferencesDialog {
|
var PreferencesDialog = class PreferencesDialog {
|
||||||
@@ -43,20 +44,25 @@ var PreferencesDialog = class PreferencesDialog {
|
|||||||
// Store a reference to the settings object.
|
// Store a reference to the settings object.
|
||||||
this._settings = ExtensionUtils.getSettings();
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
// Load the user interface file.
|
// Load the general user interface files.
|
||||||
this._builder = new Gtk.Builder();
|
{
|
||||||
this._builder.add_from_resource(`/ui/common/main-menu.ui`);
|
const dir = utils.isGTK4() ? 'gtk4' : 'gtk3';
|
||||||
this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/prefs.ui`);
|
|
||||||
this._builder.add_from_resource(
|
this._builder = new Gtk.Builder();
|
||||||
`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/generalPage.ui`);
|
this._builder.add_from_resource(`/ui/common/main-menu.ui`);
|
||||||
|
this._builder.add_from_resource(`/ui/${dir}/prefs.ui`);
|
||||||
|
this._builder.add_from_resource(`/ui/${dir}/generalPage.ui`);
|
||||||
|
}
|
||||||
|
|
||||||
// Bind general options properties.
|
// Bind general options properties.
|
||||||
this.bindSwitch('destroy-dialogs');
|
this.bindSwitch('destroy-dialogs');
|
||||||
|
|
||||||
|
// Add the General Options page to the main stack.
|
||||||
const stack = this._builder.get_object('main-stack');
|
const stack = this._builder.get_object('main-stack');
|
||||||
stack.add_titled(
|
stack.add_titled(
|
||||||
this._builder.get_object('general-prefs'), 'general', 'General Options');
|
this._builder.get_object('general-prefs'), 'general', 'General Options');
|
||||||
|
|
||||||
|
// Add all other effect pages.
|
||||||
ALL_EFFECTS.forEach(Effect => {
|
ALL_EFFECTS.forEach(Effect => {
|
||||||
const [minMajor, minMinor] = Effect.getMinShellVersion();
|
const [minMajor, minMinor] = Effect.getMinShellVersion();
|
||||||
if (utils.shellVersionIsAtLeast(minMajor, minMinor)) {
|
if (utils.shellVersionIsAtLeast(minMajor, minMinor)) {
|
||||||
@@ -102,22 +108,22 @@ var PreferencesDialog = class PreferencesDialog {
|
|||||||
|
|
||||||
// Populate the close-effects drop-down menu.
|
// Populate the close-effects drop-down menu.
|
||||||
{
|
{
|
||||||
|
const menu = this._builder.get_object('close-effect-menu');
|
||||||
const group = Gio.SimpleActionGroup.new();
|
const group = Gio.SimpleActionGroup.new();
|
||||||
window.insert_action_group('close-effects', group);
|
window.insert_action_group('close-effects', group);
|
||||||
|
|
||||||
const menu = this._builder.get_object('close-effect-menu');
|
|
||||||
|
|
||||||
ALL_EFFECTS.forEach(Effect => {
|
ALL_EFFECTS.forEach(Effect => {
|
||||||
const [minMajor, minMinor] = Effect.getMinShellVersion();
|
const [minMajor, minMinor] = Effect.getMinShellVersion();
|
||||||
if (utils.shellVersionIsAtLeast(minMajor, minMinor)) {
|
if (utils.shellVersionIsAtLeast(minMajor, minMinor)) {
|
||||||
const prefix = Effect.getSettingsPrefix();
|
const prefix = Effect.getSettingsPrefix();
|
||||||
const label = Effect.getLabel();
|
const label = Effect.getLabel();
|
||||||
|
const actionName = prefix + '-close-effect';
|
||||||
|
const fullName = 'close-effects.' + actionName;
|
||||||
|
|
||||||
const action = this._settings.create_action(`${prefix}-close-effect`);
|
const action = this._settings.create_action(actionName);
|
||||||
group.add_action(action);
|
group.add_action(action);
|
||||||
|
|
||||||
menu.append_item(
|
menu.append_item(Gio.MenuItem.new(label, fullName));
|
||||||
Gio.MenuItem.new(label, `close-effects.${prefix}-close-effect`));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user