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:
Florian Müllner
2017-10-31 02:19:44 +01:00
committed by Georges Basile Stavracas Neto
parent 99ce3deeb0
commit bacfdbbb03
102 changed files with 3454 additions and 4183 deletions

View File

@ -60,10 +60,8 @@ var MANUAL_FADE_TIME = 0.3;
var BACKGROUND_FADE_TIME = 1.0;
var CURTAIN_SLIDE_TIME = 0.3;
var Clock = new Lang.Class({
Name: 'ScreenShieldClock',
_init() {
var Clock = class {
constructor() {
this.actor = new St.BoxLayout({ style_class: 'screen-shield-clock',
vertical: true });
@ -77,7 +75,7 @@ var Clock = new Lang.Class({
this._wallClock.connect('notify::clock', this._updateClock.bind(this));
this._updateClock();
},
}
_updateClock() {
this._time.text = this._wallClock.clock;
@ -87,18 +85,16 @@ var Clock = new Lang.Class({
long format */
let dateFormat = Shell.util_translate_time_string(N_("%A, %B %d"));
this._date.text = date.toLocaleFormat(dateFormat);
},
}
destroy() {
this.actor.destroy();
this._wallClock.run_dispose();
}
});
};
var NotificationsBox = new Lang.Class({
Name: 'NotificationsBox',
_init() {
var NotificationsBox = class {
constructor() {
this.actor = new St.BoxLayout({ vertical: true,
name: 'screenShieldNotifications',
style_class: 'screen-shield-notifications-container' });
@ -118,7 +114,7 @@ var NotificationsBox = new Lang.Class({
this._updateVisibility();
this._sourceAddedId = Main.messageTray.connect('source-added', this._sourceAdded.bind(this));
},
}
destroy() {
if (this._sourceAddedId) {
@ -132,21 +128,21 @@ var NotificationsBox = new Lang.Class({
}
this.actor.destroy();
},
}
_updateVisibility() {
this._notificationBox.visible =
this._notificationBox.get_children().some(a => a.visible);
this.actor.visible = this._notificationBox.visible;
},
}
_makeNotificationCountText(count, isChat) {
if (isChat)
return ngettext("%d new message", "%d new messages", count).format(count);
else
return ngettext("%d new notification", "%d new notifications", count).format(count);
},
}
_makeNotificationSource(source, box) {
let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
@ -166,7 +162,7 @@ var NotificationsBox = new Lang.Class({
box.visible = count != 0;
return [title, countLabel];
},
}
_makeNotificationDetailedSource(source, box) {
let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
@ -204,7 +200,7 @@ var NotificationsBox = new Lang.Class({
box.visible = visible;
return [title, null];
},
}
_showSource(source, obj, box) {
if (obj.detailed) {
@ -214,7 +210,7 @@ var NotificationsBox = new Lang.Class({
}
box.visible = obj.visible && (source.unseenCount > 0);
},
}
_sourceAdded(tray, source, initial) {
let obj = {
@ -276,11 +272,11 @@ var NotificationsBox = new Lang.Class({
if (obj.sourceBox.visible)
this.emit('wake-up-screen');
}
},
}
_titleChanged(source, obj) {
obj.titleLabel.text = source.title;
},
}
_countChanged(source, obj) {
if (obj.detailed) {
@ -300,7 +296,7 @@ var NotificationsBox = new Lang.Class({
this._updateVisibility();
if (obj.sourceBox.visible)
this.emit('wake-up-screen');
},
}
_visibleChanged(source, obj) {
if (obj.visible == source.policy.showInLockScreen)
@ -312,7 +308,7 @@ var NotificationsBox = new Lang.Class({
this._updateVisibility();
if (obj.sourceBox.visible)
this.emit('wake-up-screen');
},
}
_detailedChanged(source, obj) {
if (obj.detailed == source.policy.detailsInLockScreen)
@ -323,12 +319,12 @@ var NotificationsBox = new Lang.Class({
obj.sourceBox.destroy_all_children();
obj.titleLabel = obj.countLabel = null;
this._showSource(source, obj, obj.sourceBox);
},
}
_onSourceDestroy(source, obj) {
this._removeSource(source, obj);
this._updateVisibility();
},
}
_removeSource(source, obj) {
obj.sourceBox.destroy();
@ -340,8 +336,8 @@ var NotificationsBox = new Lang.Class({
source.policy.disconnect(obj.policyChangedId);
this._sources.delete(source);
},
});
}
};
Signals.addSignalMethods(NotificationsBox.prototype);
var Arrow = new Lang.Class({
@ -430,10 +426,8 @@ function clamp(value, min, max) {
* This will ensure that the screen blanks at the right time when it fades out.
* https://bugzilla.gnome.org/show_bug.cgi?id=668703 explains the dependency.
*/
var ScreenShield = new Lang.Class({
Name: 'ScreenShield',
_init() {
var ScreenShield = class {
constructor() {
this.actor = Main.layoutManager.screenShieldGroup;
this._lockScreenState = MessageTray.State.HIDDEN;
@ -573,7 +567,7 @@ var ScreenShield = new Lang.Class({
this._cursorTracker = Meta.CursorTracker.get_for_display(global.display);
this._syncInhibitor();
},
}
_setActive(active) {
let prevIsActive = this._isActive;
@ -586,7 +580,7 @@ var ScreenShield = new Lang.Class({
this._loginSession.SetLockedHintRemote(active);
this._syncInhibitor();
},
}
_createBackground(monitorIndex) {
let monitor = Main.layoutManager.monitors[monitorIndex];
@ -604,7 +598,7 @@ var ScreenShield = new Lang.Class({
this._bgManagers.push(bgManager);
this._backgroundGroup.add_child(widget);
},
}
_updateBackgrounds() {
for (let i = 0; i < this._bgManagers.length; i++)
@ -615,7 +609,7 @@ var ScreenShield = new Lang.Class({
for (let i = 0; i < Main.layoutManager.monitors.length; i++)
this._createBackground(i);
},
}
_liftShield(onPrimary, velocity) {
if (this._isLocked) {
@ -624,7 +618,7 @@ var ScreenShield = new Lang.Class({
} else {
this.deactivate(true /* animate */);
}
},
}
_maybeCancelDialog() {
if (!this._dialog)
@ -639,7 +633,7 @@ var ScreenShield = new Lang.Class({
} else {
this._dialog = null;
}
},
}
_becomeModal() {
if (this._isModal)
@ -654,7 +648,7 @@ var ScreenShield = new Lang.Class({
this._isModal = Main.pushModal(this.actor, { options: Meta.ModalOptions.POINTER_ALREADY_GRABBED,
actionMode: Shell.ActionMode.LOCK_SCREEN });
return this._isModal;
},
}
_onLockScreenKeyPress(actor, event) {
let symbol = event.get_key_symbol();
@ -684,7 +678,7 @@ var ScreenShield = new Lang.Class({
this._liftShield(true, 0);
return Clutter.EVENT_STOP;
},
}
_onLockScreenScroll(actor, event) {
if (this._lockScreenState != MessageTray.State.SHOWN)
@ -704,7 +698,7 @@ var ScreenShield = new Lang.Class({
}
return Clutter.EVENT_STOP;
},
}
_syncInhibitor() {
let lockEnabled = this._settings.get_boolean(LOCK_ENABLED_KEY);
@ -723,7 +717,7 @@ var ScreenShield = new Lang.Class({
this._inhibitor.close(null);
this._inhibitor = null;
}
},
}
_prepareForSleep(loginManager, aboutToSuspend) {
if (aboutToSuspend) {
@ -732,7 +726,7 @@ var ScreenShield = new Lang.Class({
} else {
this._wakeUpScreen();
}
},
}
_animateArrows() {
let arrows = this._arrowContainer.get_children();
@ -754,7 +748,7 @@ var ScreenShield = new Lang.Class({
}
return GLib.SOURCE_CONTINUE;
},
}
_onDragBegin() {
Tweener.removeTweens(this._lockScreenGroup);
@ -764,7 +758,7 @@ var ScreenShield = new Lang.Class({
this._ensureUnlockDialog(false, false);
return true;
},
}
_onDragMotion() {
let [origX, origY] = this._dragAction.get_press_coords(0);
@ -776,7 +770,7 @@ var ScreenShield = new Lang.Class({
this._lockScreenGroup.y = newY;
return true;
},
}
_onDragEnd(action, actor, eventX, eventY, modifiers) {
if (this._lockScreenState != MessageTray.State.HIDING)
@ -804,7 +798,7 @@ var ScreenShield = new Lang.Class({
this._maybeCancelDialog();
}
},
}
_onStatusChanged(status) {
if (status != GnomeSession.PresenceStatus.IDLE)
@ -855,7 +849,7 @@ var ScreenShield = new Lang.Class({
}
this._activateFade(this._longLightbox, STANDARD_FADE_TIME);
},
}
_activateFade(lightbox, time) {
Main.uiGroup.set_child_above_sibling(lightbox.actor, null);
@ -863,7 +857,7 @@ var ScreenShield = new Lang.Class({
if (this._becameActiveId == 0)
this._becameActiveId = this.idleMonitor.add_user_active_watch(this._onUserBecameActive.bind(this));
},
}
_onUserBecameActive() {
// This function gets called here when the user becomes active
@ -893,15 +887,15 @@ var ScreenShield = new Lang.Class({
} else {
this.deactivate(false);
}
},
}
_onLongLightboxShown() {
this.activate(false);
},
}
_onShortLightboxShown() {
this._completeLockScreenShown();
},
}
showDialog() {
if (!this._becomeModal()) {
@ -915,7 +909,7 @@ var ScreenShield = new Lang.Class({
this._isLocked = true;
if (this._ensureUnlockDialog(true, true))
this._hideLockScreen(false, 0);
},
}
_hideLockScreenComplete() {
if (Main.sessionMode.currentMode == 'lock-screen')
@ -928,7 +922,7 @@ var ScreenShield = new Lang.Class({
this._dialog.actor.grab_key_focus();
this._dialog.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
}
},
}
_hideLockScreen(animate, velocity) {
if (this._lockScreenState == MessageTray.State.HIDDEN)
@ -961,7 +955,7 @@ var ScreenShield = new Lang.Class({
}
this._cursorTracker.set_pointer_visible(true);
},
}
_ensureUnlockDialog(onPrimary, allowCancel) {
if (!this._dialog) {
@ -989,12 +983,12 @@ var ScreenShield = new Lang.Class({
this._dialog.allowCancel = allowCancel;
return true;
},
}
_onUnlockFailed() {
this._resetLockScreen({ animateLockScreen: true,
fadeToBlack: false });
},
}
_resetLockScreen(params) {
// Don't reset the lock screen unless it is completely hidden
@ -1036,7 +1030,7 @@ var ScreenShield = new Lang.Class({
if (Main.sessionMode.currentMode != 'lock-screen')
Main.sessionMode.pushMode('lock-screen');
},
}
_startArrowAnimation() {
this._arrowActiveWatchId = 0;
@ -1050,7 +1044,7 @@ var ScreenShield = new Lang.Class({
if (!this._arrowWatchId)
this._arrowWatchId = this.idleMonitor.add_idle_watch(ARROW_IDLE_TIME,
this._pauseArrowAnimation.bind(this));
},
}
_pauseArrowAnimation() {
if (this._arrowAnimationId) {
@ -1060,7 +1054,7 @@ var ScreenShield = new Lang.Class({
if (!this._arrowActiveWatchId)
this._arrowActiveWatchId = this.idleMonitor.add_user_active_watch(this._startArrowAnimation.bind(this));
},
}
_stopArrowAnimation() {
if (this._arrowAnimationId) {
@ -1075,7 +1069,7 @@ var ScreenShield = new Lang.Class({
this.idleMonitor.remove_watch(this._arrowWatchId);
this._arrowWatchId = 0;
}
},
}
_checkArrowAnimation() {
let idleTime = this.idleMonitor.get_idletime();
@ -1084,7 +1078,7 @@ var ScreenShield = new Lang.Class({
this._startArrowAnimation();
else
this._pauseArrowAnimation();
},
}
_lockScreenShown(params) {
if (this._dialog && !this._isGreeter) {
@ -1122,12 +1116,12 @@ var ScreenShield = new Lang.Class({
this._completeLockScreenShown();
}
},
}
_completeLockScreenShown() {
this._setActive(true);
this.emit('lock-screen-shown');
},
}
// Some of the actors in the lock screen are heavy in
// resources, so we only create them when needed
@ -1154,12 +1148,12 @@ var ScreenShield = new Lang.Class({
expand: true });
this._hasLockScreen = true;
},
}
_wakeUpScreen() {
this._onUserBecameActive();
this.emit('wake-up-screen');
},
}
_clearLockScreen() {
this._clock.destroy();
@ -1176,26 +1170,26 @@ var ScreenShield = new Lang.Class({
this._lockScreenContentsBox.destroy();
this._hasLockScreen = false;
},
}
get locked() {
return this._isLocked;
},
}
get active() {
return this._isActive;
},
}
get activationTime() {
return this._activationTime;
},
}
deactivate(animate) {
if (this._dialog)
this._dialog.finish(() => { this._continueDeactivate(animate); });
else
this._continueDeactivate(animate);
},
}
_continueDeactivate(animate) {
this._hideLockScreen(animate, 0);
@ -1237,7 +1231,7 @@ var ScreenShield = new Lang.Class({
onComplete: this._completeDeactivate.bind(this),
onCompleteScope: this
});
},
}
_completeDeactivate() {
if (this._dialog) {
@ -1264,7 +1258,7 @@ var ScreenShield = new Lang.Class({
this._isLocked = false;
this.emit('locked-changed');
global.set_runtime_state(LOCKED_STATE_STR, null);
},
}
activate(animate) {
if (this._activationTime == 0)
@ -1296,7 +1290,7 @@ var ScreenShield = new Lang.Class({
// blank during the animation.
// This is not a problem for the idle fade case, because we
// activate without animation in that case.
},
}
lock(animate) {
if (this._lockSettings.get_boolean(DISABLE_LOCK_KEY)) {
@ -1328,7 +1322,7 @@ var ScreenShield = new Lang.Class({
this.activate(animate);
this.emit('locked-changed');
},
}
// If the previous shell crashed, and gnome-session restarted us, then re-lock
lockIfWasLocked() {
@ -1341,5 +1335,5 @@ var ScreenShield = new Lang.Class({
this.lock(false);
});
}
});
};
Signals.addSignalMethods(ScreenShield.prototype);