cleanup: Port non-GObject classes to JS6 classes
ES6 finally adds standard class syntax to the language, so we can replace our custom Lang.Class framework with the new syntax. Any classes that inherit from GObject will need special treatment, so limit the port to regular javascript classes for now. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:

committed by
Georges Basile Stavracas Neto

parent
99ce3deeb0
commit
bacfdbbb03
@ -2,7 +2,6 @@
|
||||
|
||||
const GLib = imports.gi.GLib;
|
||||
const Gio = imports.gi.Gio;
|
||||
const Lang = imports.lang;
|
||||
const Mainloop = imports.mainloop;
|
||||
const St = imports.gi.St;
|
||||
const Signals = imports.signals;
|
||||
@ -14,10 +13,8 @@ var ANIMATED_ICON_UPDATE_TIMEOUT = 16;
|
||||
var SPINNER_ANIMATION_TIME = 0.3;
|
||||
var SPINNER_ANIMATION_DELAY = 1.0;
|
||||
|
||||
var Animation = new Lang.Class({
|
||||
Name: 'Animation',
|
||||
|
||||
_init(file, width, height, speed) {
|
||||
var Animation = class {
|
||||
constructor(file, width, height, speed) {
|
||||
this.actor = new St.Bin();
|
||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
||||
this._speed = speed;
|
||||
@ -31,7 +28,7 @@ var Animation = new Lang.Class({
|
||||
this._animations = St.TextureCache.get_default().load_sliced_image (file, width, height, scaleFactor,
|
||||
this._animationsLoaded.bind(this));
|
||||
this.actor.set_child(this._animations);
|
||||
},
|
||||
}
|
||||
|
||||
play() {
|
||||
if (this._isLoaded && this._timeoutId == 0) {
|
||||
@ -43,7 +40,7 @@ var Animation = new Lang.Class({
|
||||
}
|
||||
|
||||
this._isPlaying = true;
|
||||
},
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this._timeoutId > 0) {
|
||||
@ -52,7 +49,7 @@ var Animation = new Lang.Class({
|
||||
}
|
||||
|
||||
this._isPlaying = false;
|
||||
},
|
||||
}
|
||||
|
||||
_showFrame(frame) {
|
||||
let oldFrameActor = this._animations.get_child_at_index(this._frame);
|
||||
@ -64,56 +61,50 @@ var Animation = new Lang.Class({
|
||||
let newFrameActor = this._animations.get_child_at_index(this._frame);
|
||||
if (newFrameActor)
|
||||
newFrameActor.show();
|
||||
},
|
||||
}
|
||||
|
||||
_update() {
|
||||
this._showFrame(this._frame + 1);
|
||||
return GLib.SOURCE_CONTINUE;
|
||||
},
|
||||
}
|
||||
|
||||
_animationsLoaded() {
|
||||
this._isLoaded = this._animations.get_n_children() > 0;
|
||||
|
||||
if (this._isPlaying)
|
||||
this.play();
|
||||
},
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
this.stop();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var AnimatedIcon = new Lang.Class({
|
||||
Name: 'AnimatedIcon',
|
||||
Extends: Animation,
|
||||
|
||||
_init(file, size) {
|
||||
this.parent(file, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
|
||||
var AnimatedIcon = class extends Animation {
|
||||
constructor(file, size) {
|
||||
super(file, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var Spinner = new Lang.Class({
|
||||
Name: 'Spinner',
|
||||
Extends: AnimatedIcon,
|
||||
|
||||
_init(size, animate=false) {
|
||||
var Spinner = class extends AnimatedIcon {
|
||||
constructor(size, animate=false) {
|
||||
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/process-working.svg');
|
||||
this.parent(file, size);
|
||||
super(file, size);
|
||||
|
||||
this.actor.opacity = 0;
|
||||
this._animate = animate;
|
||||
},
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
this._animate = false;
|
||||
this.parent();
|
||||
},
|
||||
super._onDestroy();
|
||||
}
|
||||
|
||||
play() {
|
||||
Tweener.removeTweens(this.actor);
|
||||
|
||||
if (this._animate) {
|
||||
this.parent();
|
||||
super.play();
|
||||
Tweener.addTween(this.actor, {
|
||||
opacity: 255,
|
||||
delay: SPINNER_ANIMATION_DELAY,
|
||||
@ -122,9 +113,9 @@ var Spinner = new Lang.Class({
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 255;
|
||||
this.parent();
|
||||
super.play();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
stop() {
|
||||
Tweener.removeTweens(this.actor);
|
||||
@ -140,7 +131,7 @@ var Spinner = new Lang.Class({
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 0;
|
||||
this.parent();
|
||||
super.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user