🔧 Use more robust preview logic

This commit is contained in:
Simon Schneegans
2022-01-23 13:13:55 +01:00
parent 242625ee9f
commit 8475ae29ba
3 changed files with 36 additions and 31 deletions
+28 -9
View File
@@ -215,18 +215,37 @@ class Extension {
return;
}
// Create a list of all currently enabled effects.
const enabledEffects = ALL_EFFECTS.filter(Effect => {
return this._settings.get_boolean(`${Effect.getNick()}-close-effect`);
});
// Now we have to choose an effect.
this._effect = null;
// Nothing is enabled...
if (enabledEffects.length == 0) {
return;
// First we check if an effect is to be previewd.
const previewNick = this._settings.get_string('close-preview-effect');
if (previewNick != '') {
this._effect = ALL_EFFECTS.find(Effect => {
return Effect.getNick() == previewNick;
});
// Only preview the effect once.
this._settings.set_string('close-preview-effect', '');
} else {
// Else we choose a random effect from all enabled effects. Therefore, we first
// create a list of all currently enabled effects.
const enabled = ALL_EFFECTS.filter(Effect => {
return this._settings.get_boolean(`${Effect.getNick()}-close-effect`);
});
// And then choose a random effect.
if (enabled.length > 0) {
this._effect = enabled[Math.floor(Math.random() * enabled.length)];
}
}
// Choose a random effect.
this._effect = enabledEffects[Math.floor(Math.random() * enabledEffects.length)];
// If nothing was enabled, we have to do nothing :)
if (this._effect == null) {
return;
}
// The effect usually will choose to override the present transitions on the actor.
const transitionConfig = this._effect.getCloseTransition(actor, this._settings);
+2 -22
View File
@@ -297,18 +297,9 @@ var PreferencesDialog = class PreferencesDialog {
// Open the preview window once the preview button is clicked.
this._button.connect('clicked', () => {
// Create a list of all currently enabled effects.
const enabledEffects = ALL_EFFECTS.filter(Effect => {
return dialog.getSettings().get_boolean(`${Effect.getNick()}-close-effect`);
});
// Disable all enabled effects temporarily.
enabledEffects.forEach(Effect => {
dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, false);
});
// Enable the to-be-previewed effect.
dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, true);
// Set the to-be-previewed effect.
dialog.getSettings().set_string('close-preview-effect', Effect.getNick());
// Create the preview-window.
const window = new Gtk.Window({
@@ -344,17 +335,6 @@ var PreferencesDialog = class PreferencesDialog {
}
window.show();
// Restore settings when the window gets closed.
window.connect('unrealize', () => {
// Disable the to-be-previewed effect again.
dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, false);
// Enable all previously enabled effects again.
enabledEffects.forEach(Effect => {
dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, true);
});
});
});
}
});
@@ -13,6 +13,12 @@
<description>Set to true to burn dialogs as well.</description>
</key>
<key name="close-preview-effect" type="s">
<default>""</default>
<summary>Close Preview Effect</summary>
<description>The effect with this nick will be used for the next window-close animation.</description>
</key>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Fire Options -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->