[gnome] Update extensions

This commit is contained in:
2024-10-31 10:19:02 -04:00
parent 851ec4a772
commit 6d1e6d1132
238 changed files with 8705 additions and 4185 deletions

View File

@ -1,21 +1,41 @@
import { ColorEffect } from '../effects/color_effect.js';
import { NoiseEffect } from '../effects/noise_effect.js';
import { get_supported_effects } from '../effects/effects.js';
/// An object to manage effects (by not destroying them all the time)
export const EffectsManager = class EffectsManager {
constructor(connections) {
this.connections = connections;
this.used = [];
this.color_effects = [];
this.noise_effects = [];
this.SUPPORTED_EFFECTS = get_supported_effects();
Object.keys(this.SUPPORTED_EFFECTS).forEach(effect_name => {
// init the arrays containing each unused effect
this[effect_name + '_effects'] = [];
// init the functions for each effect
this['new_' + effect_name + '_effect'] = function (params) {
let effect;
if (this[effect_name + '_effects'].length > 0) {
effect = this[effect_name + '_effects'].splice(0, 1)[0];
effect.set({
...this.SUPPORTED_EFFECTS[effect_name].class.default_params, ...params
});
} else
effect = new this.SUPPORTED_EFFECTS[effect_name].class({
...this.SUPPORTED_EFFECTS[effect_name].class.default_params, ...params
});
this.used.push(effect);
this.connect_to_destroy(effect);
return effect;
};
});
}
connect_to_destroy(effect) {
effect.old_actor = effect.get_actor();
if (effect.old_actor)
effect.old_actor_id = effect.old_actor.connect('destroy', _ => {
this.remove(effect);
this.remove(effect, true);
});
this.connections.connect(effect, 'notify::actor', _ => {
@ -24,42 +44,22 @@ export const EffectsManager = class EffectsManager {
if (effect.old_actor && actor != effect.old_actor)
effect.old_actor.disconnect(effect.old_actor_id);
if (actor) {
if (actor && actor != effect.old_actor) {
effect.old_actor_id = actor.connect('destroy', _ => {
this.remove(effect);
this.remove(effect, true);
});
}
});
}
new_color_effect(params, settings) {
let effect;
if (this.color_effects.length > 0) {
effect = this.color_effects.splice(0, 1)[0];
effect.set(params);
} else
effect = new ColorEffect(params, settings);
this.used.push(effect);
this.connect_to_destroy(effect);
return effect;
}
new_noise_effect(params, settings) {
let effect;
if (this.noise_effects.length > 0) {
effect = this.noise_effects.splice(0, 1)[0];
effect.set(params);
} else
effect = new NoiseEffect(params, settings);
this.used.push(effect);
this.connect_to_destroy(effect);
return effect;
}
remove(effect) {
effect.get_actor()?.remove_effect(effect);
// IMPORTANT: do never call this in a mutable `this.used.forEach`
remove(effect, actor_already_destroyed = false) {
if (!actor_already_destroyed)
try {
effect.get_actor()?.remove_effect(effect);
} catch (e) {
this._warn(`could not remove the effect, continuing: ${e}`);
}
if (effect.old_actor)
effect.old_actor.disconnect(effect.old_actor_id);
delete effect.old_actor;
@ -69,21 +69,22 @@ export const EffectsManager = class EffectsManager {
if (index >= 0) {
this.used.splice(index, 1);
if (effect instanceof ColorEffect)
this.color_effects.push(effect);
else if (effect instanceof NoiseEffect)
this.noise_effects.push(effect);
Object.keys(this.SUPPORTED_EFFECTS).forEach(effect_name => {
if (effect instanceof this.SUPPORTED_EFFECTS[effect_name].class)
this[effect_name + '_effects'].push(effect);
});
}
}
destroy_all() {
this.used.forEach(effect => { this.remove(effect); });
[
this.used,
this.color_effects,
this.noise_effects
].forEach(array => {
array.splice(0, array.length);
const immutable_used_list = [...this.used];
immutable_used_list.forEach(effect => this.remove(effect));
Object.keys(this.SUPPORTED_EFFECTS).forEach(effect_name => {
this[effect_name + '_effects'].splice(0, this[effect_name + '_effects'].length);
});
}
_warn(str) {
console.warn(`[Blur my Shell > effects mng] ${str}`);
}
};