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

@@ -1,17 +1,13 @@
const Lang = imports.lang;
const Main = imports.ui.main;
var ComponentManager = new Lang.Class({
Name: 'ComponentManager',
_init() {
var ComponentManager = class {
constructor() {
this._allComponents = {};
this._enabledComponents = [];
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
this._sessionUpdated();
},
}
_sessionUpdated() {
let newEnabledComponents = Main.sessionMode.components;
@@ -29,12 +25,12 @@ var ComponentManager = new Lang.Class({
});
this._enabledComponents = newEnabledComponents;
},
}
_importComponent(name) {
let module = imports.ui.components[name];
return module.Component;
},
}
_ensureComponent(name) {
let component = this._allComponents[name];
@@ -48,13 +44,13 @@ var ComponentManager = new Lang.Class({
component = new constructor();
this._allComponents[name] = component;
return component;
},
}
_enableComponent(name) {
let component = this._ensureComponent(name);
if (component)
component.enable();
},
}
_disableComponent(name) {
let component = this._allComponents[name];
@@ -62,4 +58,4 @@ var ComponentManager = new Lang.Class({
return;
component.disable();
}
});
};

View File

@@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
@@ -19,10 +18,8 @@ const SETTING_ENABLE_AUTOMOUNT = 'automount';
var AUTORUN_EXPIRE_TIMEOUT_SECS = 10;
var AutomountManager = new Lang.Class({
Name: 'AutomountManager',
_init() {
var AutomountManager = class {
constructor() {
this._settings = new Gio.Settings({ schema_id: SETTINGS_SCHEMA });
this._volumeQueue = [];
this._activeOperations = new Map();
@@ -34,7 +31,7 @@ var AutomountManager = new Lang.Class({
this._inhibited = false;
this._volumeMonitor = Gio.VolumeMonitor.get();
},
}
enable() {
this._volumeAddedId = this._volumeMonitor.connect('volume-added', this._onVolumeAdded.bind(this));
@@ -45,7 +42,7 @@ var AutomountManager = new Lang.Class({
this._mountAllId = Mainloop.idle_add(this._startupMountAll.bind(this));
GLib.Source.set_name_by_id(this._mountAllId, '[gnome-shell] this._startupMountAll');
},
}
disable() {
this._volumeMonitor.disconnect(this._volumeAddedId);
@@ -58,7 +55,7 @@ var AutomountManager = new Lang.Class({
Mainloop.source_remove(this._mountAllId);
this._mountAllId = 0;
}
},
}
_InhibitorsChanged(object, senderName, [inhibtor]) {
this._session.IsInhibitedRemote(GNOME_SESSION_AUTOMOUNT_INHIBIT,
@@ -67,7 +64,7 @@ var AutomountManager = new Lang.Class({
this._inhibited = result[0];
}
});
},
}
_startupMountAll() {
let volumes = this._volumeMonitor.get_volumes();
@@ -79,7 +76,7 @@ var AutomountManager = new Lang.Class({
this._mountAllId = 0;
return GLib.SOURCE_REMOVE;
},
}
_onDriveConnected() {
// if we're not in the current ConsoleKit session,
@@ -91,7 +88,7 @@ var AutomountManager = new Lang.Class({
player.play_from_theme('device-added-media',
_("External drive connected"),
null);
},
}
_onDriveDisconnected() {
// if we're not in the current ConsoleKit session,
@@ -103,7 +100,7 @@ var AutomountManager = new Lang.Class({
sound.play_from_theme('device-removed-media',
_("External drive disconnected"),
null);
},
}
_onDriveEjectButton(monitor, drive) {
// TODO: this code path is not tested, as the GVfs volume monitor
@@ -134,11 +131,11 @@ var AutomountManager = new Lang.Class({
}
});
}
},
}
_onVolumeAdded(monitor, volume) {
this._checkAndMountVolume(volume);
},
}
_checkAndMountVolume(volume, params) {
params = Params.parse(params, { checkSession: true,
@@ -178,7 +175,7 @@ var AutomountManager = new Lang.Class({
} else {
this._mountVolume(volume, null, params.allowAutorun);
}
},
}
_mountVolume(volume, operation, allowAutorun) {
if (allowAutorun)
@@ -189,7 +186,7 @@ var AutomountManager = new Lang.Class({
volume.mount(0, mountOp, null,
this._onVolumeMounted.bind(this));
},
}
_onVolumeMounted(volume, res) {
this._allowAutorunExpire(volume);
@@ -214,7 +211,7 @@ var AutomountManager = new Lang.Class({
this._closeOperation(volume);
}
}
},
}
_onVolumeRemoved(monitor, volume) {
if (volume._allowAutorunExpireId && volume._allowAutorunExpireId > 0) {
@@ -223,7 +220,7 @@ var AutomountManager = new Lang.Class({
}
this._volumeQueue =
this._volumeQueue.filter(element => (element != volume));
},
}
_reaskPassword(volume) {
let prevOperation = this._activeOperations.get(volume);
@@ -232,7 +229,7 @@ var AutomountManager = new Lang.Class({
new ShellMountOperation.ShellMountOperation(volume,
{ existingDialog: existingDialog });
this._mountVolume(volume, operation);
},
}
_closeOperation(volume) {
let operation = this._activeOperations.get(volume);
@@ -240,11 +237,11 @@ var AutomountManager = new Lang.Class({
return;
operation.close();
this._activeOperations.delete(volume);
},
}
_allowAutorun(volume) {
volume.allowAutorun = true;
},
}
_allowAutorunExpire(volume) {
let id = Mainloop.timeout_add_seconds(AUTORUN_EXPIRE_TIMEOUT_SECS, () => {
@@ -255,5 +252,5 @@ var AutomountManager = new Lang.Class({
volume._allowAutorunExpireId = id;
GLib.Source.set_name_by_id(id, '[gnome-shell] volume.allowAutorun');
}
});
};
var Component = AutomountManager;

View File

@@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const St = imports.gi.St;
@@ -84,13 +83,11 @@ function HotplugSniffer() {
'/org/gnome/Shell/HotplugSniffer');
}
var ContentTypeDiscoverer = new Lang.Class({
Name: 'ContentTypeDiscoverer',
_init(callback) {
var ContentTypeDiscoverer = class {
constructor(callback) {
this._callback = callback;
this._settings = new Gio.Settings({ schema_id: SETTINGS_SCHEMA });
},
}
guessContentTypes(mount) {
let autorunEnabled = !this._settings.get_boolean(SETTING_DISABLE_AUTORUN);
@@ -103,7 +100,7 @@ var ContentTypeDiscoverer = new Lang.Class({
} else {
this._emitCallback(mount, []);
}
},
}
_onContentTypeGuessed(mount, res) {
let contentTypes = [];
@@ -126,7 +123,7 @@ var ContentTypeDiscoverer = new Lang.Class({
this._emitCallback(mount, contentTypes);
});
}
},
}
_emitCallback(mount, contentTypes) {
if (!contentTypes)
@@ -150,27 +147,25 @@ var ContentTypeDiscoverer = new Lang.Class({
this._callback(mount, apps, contentTypes);
}
});
};
var AutorunManager = new Lang.Class({
Name: 'AutorunManager',
_init() {
var AutorunManager = class {
constructor() {
this._session = new GnomeSession.SessionManager();
this._volumeMonitor = Gio.VolumeMonitor.get();
this._dispatcher = new AutorunDispatcher(this);
},
}
enable() {
this._mountAddedId = this._volumeMonitor.connect('mount-added', this._onMountAdded.bind(this));
this._mountRemovedId = this._volumeMonitor.connect('mount-removed', this._onMountRemoved.bind(this));
},
}
disable() {
this._volumeMonitor.disconnect(this._mountAddedId);
this._volumeMonitor.disconnect(this._mountRemovedId);
},
}
_onMountAdded(monitor, mount) {
// don't do anything if our session is not the currently
@@ -182,21 +177,19 @@ var AutorunManager = new Lang.Class({
this._dispatcher.addMount(mount, apps, contentTypes);
});
discoverer.guessContentTypes(mount);
},
}
_onMountRemoved(monitor, mount) {
this._dispatcher.removeMount(mount);
}
});
};
var AutorunDispatcher = new Lang.Class({
Name: 'AutorunDispatcher',
_init(manager) {
var AutorunDispatcher = class {
constructor(manager) {
this._manager = manager;
this._sources = [];
this._settings = new Gio.Settings({ schema_id: SETTINGS_SCHEMA });
},
}
_getAutorunSettingForType(contentType) {
let runApp = this._settings.get_strv(SETTING_START_APP);
@@ -212,7 +205,7 @@ var AutorunDispatcher = new Lang.Class({
return AutorunSetting.FILES;
return AutorunSetting.ASK;
},
}
_getSourceForMount(mount) {
let filtered = this._sources.filter(source => (source.mount == mount));
@@ -224,7 +217,7 @@ var AutorunDispatcher = new Lang.Class({
return filtered[0];
return null;
},
}
_addSource(mount, apps) {
// if we already have a source showing for this
@@ -234,7 +227,7 @@ var AutorunDispatcher = new Lang.Class({
// add a new source
this._sources.push(new AutorunSource(this._manager, mount, apps));
},
}
addMount(mount, apps, contentTypes) {
// if autorun is disabled globally, return
@@ -272,7 +265,7 @@ var AutorunDispatcher = new Lang.Class({
// but we failed launching the default app or the default file manager
if (!success)
this._addSource(mount, apps);
},
}
removeMount(mount) {
let source = this._getSourceForMount(mount);
@@ -284,45 +277,39 @@ var AutorunDispatcher = new Lang.Class({
// destroy the notification source
source.destroy();
}
});
};
var AutorunSource = new Lang.Class({
Name: 'AutorunSource',
Extends: MessageTray.Source,
var AutorunSource = class extends MessageTray.Source {
constructor(manager, mount, apps) {
super(mount.get_name());
_init(manager, mount, apps) {
this._manager = manager;
this.mount = mount;
this.apps = apps;
this.parent(mount.get_name());
this._notification = new AutorunNotification(this._manager, this);
// add ourselves as a source, and popup the notification
Main.messageTray.add(this);
this.notify(this._notification);
},
}
getIcon() {
return this.mount.get_icon();
},
}
_createPolicy() {
return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
}
});
};
var AutorunNotification = new Lang.Class({
Name: 'AutorunNotification',
Extends: MessageTray.Notification,
_init(manager, source) {
this.parent(source, source.title);
var AutorunNotification = class extends MessageTray.Notification {
constructor(manager, source) {
super(source, source.title);
this._manager = manager;
this._mount = source.mount;
},
}
createBanner() {
let banner = new MessageTray.NotificationBanner(this);
@@ -335,7 +322,7 @@ var AutorunNotification = new Lang.Class({
});
return banner;
},
}
_buttonForApp(app) {
let box = new St.BoxLayout();
@@ -362,14 +349,14 @@ var AutorunNotification = new Lang.Class({
});
return button;
},
}
activate() {
this.parent();
super.activate();
let app = Gio.app_info_get_default_for_type('inode/directory', false);
startAppForMount(app, this._mount);
}
});
};
var Component = AutorunManager;

View File

@@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Clutter = imports.gi.Clutter;
const St = imports.gi.St;
@@ -18,12 +17,9 @@ const Tweener = imports.ui.tweener;
var WORK_SPINNER_ICON_SIZE = 16;
var KeyringDialog = new Lang.Class({
Name: 'KeyringDialog',
Extends: ModalDialog.ModalDialog,
_init() {
this.parent({ styleClass: 'prompt-dialog' });
var KeyringDialog = class extends ModalDialog.ModalDialog {
constructor() {
super({ styleClass: 'prompt-dialog' });
this.prompt = new Shell.KeyringPrompt();
this.prompt.connect('show-password', this._onShowPassword.bind(this));
@@ -61,7 +57,7 @@ var KeyringDialog = new Lang.Class({
this.prompt.bind_property('cancel-label', this._cancelButton, 'label', GObject.BindingFlags.SYNC_CREATE);
this.prompt.bind_property('continue-label', this._continueButton, 'label', GObject.BindingFlags.SYNC_CREATE);
},
}
_setWorking(working) {
if (!this._workSpinner)
@@ -71,7 +67,7 @@ var KeyringDialog = new Lang.Class({
this._workSpinner.play();
else
this._workSpinner.stop();
},
}
_buildControlTable() {
let layout = new Clutter.GridLayout({ orientation: Clutter.Orientation.VERTICAL });
@@ -162,7 +158,7 @@ var KeyringDialog = new Lang.Class({
this._controlTable = table;
this._content.messageBox.add(table, { x_fill: true, y_fill: true });
},
}
_updateSensitivity(sensitive) {
if (this._passwordEntry) {
@@ -178,7 +174,7 @@ var KeyringDialog = new Lang.Class({
this._continueButton.can_focus = sensitive;
this._continueButton.reactive = sensitive;
this._setWorking(!sensitive);
},
}
_ensureOpen() {
// NOTE: ModalDialog.open() is safe to call if the dialog is
@@ -196,65 +192,61 @@ var KeyringDialog = new Lang.Class({
' Dismissing prompt request');
this.prompt.cancel()
return false;
},
}
_onShowPassword(prompt) {
this._buildControlTable();
this._ensureOpen();
this._updateSensitivity(true);
this._passwordEntry.grab_key_focus();
},
}
_onShowConfirm(prompt) {
this._buildControlTable();
this._ensureOpen();
this._updateSensitivity(true);
this._continueButton.grab_key_focus();
},
}
_onHidePrompt(prompt) {
this.close();
},
}
_onPasswordActivate() {
if (this.prompt.confirm_visible)
this._confirmEntry.grab_key_focus();
else
this._onContinueButton();
},
}
_onConfirmActivate() {
this._onContinueButton();
},
}
_onContinueButton() {
this._updateSensitivity(false);
this.prompt.complete();
},
}
_onCancelButton() {
this.prompt.cancel();
},
});
}
};
var KeyringDummyDialog = new Lang.Class({
Name: 'KeyringDummyDialog',
_init() {
var KeyringDummyDialog = class {
constructor() {
this.prompt = new Shell.KeyringPrompt();
this.prompt.connect('show-password', this._cancelPrompt.bind(this));
this.prompt.connect('show-confirm', this._cancelPrompt.bind(this));
},
}
_cancelPrompt() {
this.prompt.cancel();
}
});
};
var KeyringPrompter = new Lang.Class({
Name: 'KeyringPrompter',
_init() {
var KeyringPrompter = class {
constructor() {
this._prompter = new Gcr.SystemPrompter();
this._prompter.connect('new-prompt', () => {
let dialog = this._enabled ? new KeyringDialog()
@@ -266,7 +258,7 @@ var KeyringPrompter = new Lang.Class({
this._registered = false;
this._enabled = false;
this._currentPrompt = null;
},
}
enable() {
if (!this._registered) {
@@ -276,7 +268,7 @@ var KeyringPrompter = new Lang.Class({
this._registered = true;
}
this._enabled = true;
},
}
disable() {
this._enabled = false;
@@ -285,6 +277,6 @@ var KeyringPrompter = new Lang.Class({
this._currentPrompt.cancel();
this._currentPrompt = null;
}
});
};
var Component = KeyringPrompter;

View File

@@ -4,7 +4,6 @@ const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
const NM = imports.gi.NM;
const Pango = imports.gi.Pango;
const Shell = imports.gi.Shell;
@@ -21,12 +20,9 @@ const ShellEntry = imports.ui.shellEntry;
const VPN_UI_GROUP = 'VPN Plugin UI';
var NetworkSecretDialog = new Lang.Class({
Name: 'NetworkSecretDialog',
Extends: ModalDialog.ModalDialog,
_init(agent, requestId, connection, settingName, hints, contentOverride) {
this.parent({ styleClass: 'prompt-dialog' });
var NetworkSecretDialog = class extends ModalDialog.ModalDialog {
constructor(agent, requestId, connection, settingName, hints, contentOverride) {
super({ styleClass: 'prompt-dialog' });
this._agent = agent;
this._requestId = requestId;
@@ -121,7 +117,7 @@ var NetworkSecretDialog = new Lang.Class({
this._okButton]);
this._updateOkButton();
},
}
_updateOkButton() {
let valid = true;
@@ -132,7 +128,7 @@ var NetworkSecretDialog = new Lang.Class({
this._okButton.button.reactive = valid;
this._okButton.button.can_focus = valid;
},
}
_onOk() {
let valid = true;
@@ -148,12 +144,12 @@ var NetworkSecretDialog = new Lang.Class({
this.close(global.get_current_time());
}
// do nothing if not valid
},
}
cancel() {
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.USER_CANCELED);
this.close(global.get_current_time());
},
}
_validateWpaPsk(secret) {
let value = secret.value;
@@ -169,7 +165,7 @@ var NetworkSecretDialog = new Lang.Class({
}
return (value.length >= 8 && value.length <= 63);
},
}
_validateStaticWep(secret) {
let value = secret.value;
@@ -194,7 +190,7 @@ var NetworkSecretDialog = new Lang.Class({
return false;
}
return true;
},
}
_getWirelessSecrets(secrets, wirelessSetting) {
let wirelessSecuritySetting = this._connection.get_setting_wireless_security();
@@ -231,7 +227,7 @@ var NetworkSecretDialog = new Lang.Class({
default:
log('Invalid wireless key management: ' + wirelessSecuritySetting.key_mgmt);
}
},
}
_get8021xSecrets(secrets) {
let ieee8021xSetting = this._connection.get_setting_802_1x();
@@ -274,7 +270,7 @@ var NetworkSecretDialog = new Lang.Class({
default:
log('Invalid EAP/IEEE802.1x method: ' + ieee8021xSetting.get_eap_method(0));
}
},
}
_getPPPoESecrets(secrets) {
let pppoeSetting = this._connection.get_setting_pppoe();
@@ -284,7 +280,7 @@ var NetworkSecretDialog = new Lang.Class({
value: pppoeSetting.service || '', password: false });
secrets.push({ label: _("Password: "), key: 'password',
value: pppoeSetting.password || '', password: true });
},
}
_getMobileSecrets(secrets, connectionType) {
let setting;
@@ -294,7 +290,7 @@ var NetworkSecretDialog = new Lang.Class({
setting = this._connection.get_setting_by_name(connectionType);
secrets.push({ label: _("Password: "), key: 'password',
value: setting.value || '', password: true });
},
}
_getContent() {
let connectionSetting = this._connection.get_setting_connection();
@@ -347,12 +343,10 @@ var NetworkSecretDialog = new Lang.Class({
return content;
}
});
};
var VPNRequestHandler = new Lang.Class({
Name: 'VPNRequestHandler',
_init(agent, requestId, authHelper, serviceType, connection, hints, flags) {
var VPNRequestHandler = class {
constructor(agent, requestId, authHelper, serviceType, connection, hints, flags) {
this._agent = agent;
this._requestId = requestId;
this._connection = connection;
@@ -412,7 +406,7 @@ var VPNRequestHandler = new Lang.Class({
this._agent.respond(requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
}
},
}
cancel(respond) {
if (respond)
@@ -428,7 +422,7 @@ var VPNRequestHandler = new Lang.Class({
}
this.destroy();
},
}
destroy() {
if (this._destroyed)
@@ -442,7 +436,7 @@ var VPNRequestHandler = new Lang.Class({
// Stdout is closed when we finish reading from it
this._destroyed = true;
},
}
_vpnChildFinished(pid, status, requestObj) {
this._childWatch = 0;
@@ -463,7 +457,7 @@ var VPNRequestHandler = new Lang.Class({
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
this.destroy();
},
}
_vpnChildProcessLineOldStyle(line) {
if (this._previousLine != undefined) {
@@ -481,7 +475,7 @@ var VPNRequestHandler = new Lang.Class({
} else {
this._previousLine = line;
}
},
}
_readStdoutOldStyle() {
this._dataStdout.read_line_async(GLib.PRIORITY_DEFAULT, null, (stream, result) => {
@@ -498,7 +492,7 @@ var VPNRequestHandler = new Lang.Class({
// try to read more!
this._readStdoutOldStyle();
});
},
}
_readStdoutNewStyle() {
this._dataStdout.fill_async(-1, GLib.PRIORITY_DEFAULT, null, (stream, result) => {
@@ -516,7 +510,7 @@ var VPNRequestHandler = new Lang.Class({
this._dataStdout.set_buffer_size(2 * this._dataStdout.get_buffer_size());
this._readStdoutNewStyle();
});
},
}
_showNewStyleDialog() {
let keyfile = new GLib.KeyFile();
@@ -580,7 +574,7 @@ var VPNRequestHandler = new Lang.Class({
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.CONFIRMED);
this.destroy();
}
},
}
_writeConnection() {
let vpnSetting = this._connection.get_setting_vpn();
@@ -601,14 +595,12 @@ var VPNRequestHandler = new Lang.Class({
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
this.destroy();
}
},
});
}
};
Signals.addSignalMethods(VPNRequestHandler.prototype);
var NetworkAgent = new Lang.Class({
Name: 'NetworkAgent',
_init() {
var NetworkAgent = class {
constructor() {
this._native = new Shell.NetworkAgent({ identifier: 'org.gnome.Shell.NetworkAgent',
capabilities: NM.SecretAgentCapabilities.VPN_HINTS,
auto_register: false
@@ -639,7 +631,7 @@ var NetworkAgent = new Lang.Class({
logError(e, 'error initializing the NetworkManager Agent');
}
});
},
}
enable() {
if (!this._native)
@@ -648,7 +640,7 @@ var NetworkAgent = new Lang.Class({
this._native.auto_register = true;
if (this._initialized && !this._native.registered)
this._native.register_async(null, null);
},
}
disable() {
let requestId;
@@ -671,7 +663,7 @@ var NetworkAgent = new Lang.Class({
this._native.auto_register = false;
if (this._initialized && this._native.registered)
this._native.unregister_async(null, null);
},
}
_showNotification(requestId, connection, settingName, hints, flags) {
let source = new MessageTray.Source(_("Network Manager"), 'network-transmit-receive');
@@ -731,14 +723,14 @@ var NetworkAgent = new Lang.Class({
Main.messageTray.add(source);
source.notify(notification);
},
}
_newRequest(agent, requestId, connection, settingName, hints, flags) {
if (!(flags & NM.SecretAgentGetSecretsFlags.USER_REQUESTED))
this._showNotification(requestId, connection, settingName, hints, flags);
else
this._handleRequest(requestId, connection, settingName, hints, flags);
},
}
_handleRequest(requestId, connection, settingName, hints, flags) {
if (settingName == 'vpn') {
@@ -752,7 +744,7 @@ var NetworkAgent = new Lang.Class({
});
this._dialogs[requestId] = dialog;
dialog.open(global.get_current_time());
},
}
_cancelRequest(agent, requestId) {
if (this._dialogs[requestId]) {
@@ -763,7 +755,7 @@ var NetworkAgent = new Lang.Class({
this._vpnRequests[requestId].cancel(false);
delete this._vpnRequests[requestId];
}
},
}
_vpnRequest(requestId, connection, hints, flags) {
let vpnSetting = connection.get_setting_vpn();
@@ -785,7 +777,7 @@ var NetworkAgent = new Lang.Class({
delete this._vpnRequests[requestId];
});
this._vpnRequests[requestId] = vpnRequest;
},
}
_buildVPNServiceCache() {
if (this._vpnCacheBuilt)
@@ -818,5 +810,5 @@ var NetworkAgent = new Lang.Class({
}
});
}
});
};
var Component = NetworkAgent;

View File

@@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Signals = imports.signals;
const Shell = imports.gi.Shell;
const AccountsService = imports.gi.AccountsService;
@@ -26,12 +25,9 @@ var DIALOG_ICON_SIZE = 48;
var WORK_SPINNER_ICON_SIZE = 16;
var AuthenticationDialog = new Lang.Class({
Name: 'AuthenticationDialog',
Extends: ModalDialog.ModalDialog,
_init(actionId, body, cookie, userNames) {
this.parent({ styleClass: 'prompt-dialog' });
var AuthenticationDialog = class extends ModalDialog.ModalDialog {
constructor(actionId, body, cookie, userNames) {
super({ styleClass: 'prompt-dialog' });
this.actionId = actionId;
this.message = body;
@@ -158,14 +154,14 @@ var AuthenticationDialog = new Lang.Class({
this._identityToAuth = Polkit.UnixUser.new_for_name(userName);
this._cookie = cookie;
},
}
_setWorking(working) {
if (working)
this._workSpinner.play();
else
this._workSpinner.stop();
},
}
performAuthentication() {
this._destroySession();
@@ -176,7 +172,7 @@ var AuthenticationDialog = new Lang.Class({
this._sessionShowErrorId = this._session.connect('show-error', this._onSessionShowError.bind(this));
this._sessionShowInfoId = this._session.connect('show-info', this._onSessionShowInfo.bind(this));
this._session.initiate();
},
}
_ensureOpen() {
// NOTE: ModalDialog.open() is safe to call if the dialog is
@@ -198,14 +194,14 @@ var AuthenticationDialog = new Lang.Class({
' cookie ' + this._cookie);
this._emitDone(true);
}
},
}
_emitDone(dismissed) {
if (!this._doneEmitted) {
this._doneEmitted = true;
this.emit('done', dismissed);
}
},
}
_updateSensitivity(sensitive) {
this._passwordEntry.reactive = sensitive;
@@ -214,7 +210,7 @@ var AuthenticationDialog = new Lang.Class({
this._okButton.can_focus = sensitive;
this._okButton.reactive = sensitive;
this._setWorking(!sensitive);
},
}
_onEntryActivate() {
let response = this._passwordEntry.get_text();
@@ -225,11 +221,11 @@ var AuthenticationDialog = new Lang.Class({
this._errorMessageLabel.hide();
this._infoMessageLabel.hide();
this._nullMessageLabel.show();
},
}
_onAuthenticateButtonPressed() {
this._onEntryActivate();
},
}
_onSessionCompleted(session, gainedAuthorization) {
if (this._completed || this._doneEmitted)
@@ -261,7 +257,7 @@ var AuthenticationDialog = new Lang.Class({
/* Try and authenticate again */
this.performAuthentication();
}
},
}
_onSessionRequest(session, request, echo_on) {
// Cheap localization trick
@@ -280,7 +276,7 @@ var AuthenticationDialog = new Lang.Class({
this._passwordEntry.grab_key_focus();
this._updateSensitivity(true);
this._ensureOpen();
},
}
_onSessionShowError(session, text) {
this._passwordEntry.set_text('');
@@ -289,7 +285,7 @@ var AuthenticationDialog = new Lang.Class({
this._infoMessageLabel.hide();
this._nullMessageLabel.hide();
this._ensureOpen();
},
}
_onSessionShowInfo(session, text) {
this._passwordEntry.set_text('');
@@ -298,7 +294,7 @@ var AuthenticationDialog = new Lang.Class({
this._errorMessageLabel.hide();
this._nullMessageLabel.hide();
this._ensureOpen();
},
}
_destroySession() {
if (this._session) {
@@ -312,20 +308,20 @@ var AuthenticationDialog = new Lang.Class({
this._session.disconnect(this._sessionShowInfoId);
this._session = null;
}
},
}
_onUserChanged() {
if (this._user.is_loaded && this._userAvatar) {
this._userAvatar.update();
this._userAvatar.actor.show();
}
},
}
cancel() {
this._wasDismissed = true;
this.close(global.get_current_time());
this._emitDone(true);
},
}
_onDialogClosed() {
if (this._sessionUpdatedId)
@@ -339,21 +335,19 @@ var AuthenticationDialog = new Lang.Class({
}
this._destroySession();
},
});
}
};
Signals.addSignalMethods(AuthenticationDialog.prototype);
var AuthenticationAgent = new Lang.Class({
Name: 'AuthenticationAgent',
_init() {
var AuthenticationAgent = class {
constructor() {
this._currentDialog = null;
this._handle = null;
this._native = new Shell.PolkitAuthenticationAgent();
this._native.connect('initiate', this._onInitiate.bind(this));
this._native.connect('cancel', this._onCancel.bind(this));
this._sessionUpdatedId = 0;
},
}
enable() {
try {
@@ -361,7 +355,7 @@ var AuthenticationAgent = new Lang.Class({
} catch(e) {
log('Failed to register AuthenticationAgent');
}
},
}
disable() {
try {
@@ -369,7 +363,7 @@ var AuthenticationAgent = new Lang.Class({
} catch(e) {
log('Failed to unregister AuthenticationAgent');
}
},
}
_onInitiate(nativeAgent, actionId, message, iconName, cookie, userNames) {
// Don't pop up a dialog while locked
@@ -397,15 +391,15 @@ var AuthenticationAgent = new Lang.Class({
this._currentDialog.connect('done', this._onDialogDone.bind(this));
this._currentDialog.performAuthentication();
},
}
_onCancel(nativeAgent) {
this._completeRequest(false);
},
}
_onDialogDone(dialog, dismissed) {
this._completeRequest(dismissed);
},
}
_completeRequest(dismissed) {
this._currentDialog.close();
@@ -416,7 +410,7 @@ var AuthenticationAgent = new Lang.Class({
this._sessionUpdatedId = 0;
this._native.complete(dismissed);
},
});
}
};
var Component = AuthenticationAgent;

View File

@@ -79,17 +79,15 @@ function makeMessageFromTplEvent(event) {
};
}
var TelepathyComponent = new Lang.Class({
Name: 'TelepathyComponent',
_init() {
var TelepathyComponent = class {
constructor() {
this._client = null;
if (!HAVE_TP)
return; // Telepathy isn't available
this._client = new TelepathyClient();
},
}
enable() {
if (!this._client)
@@ -103,7 +101,7 @@ var TelepathyComponent = new Lang.Class({
if (!this._client.account_manager.is_prepared(Tp.AccountManager.get_feature_quark_core()))
this._client.account_manager.prepare_async(null, null);
},
}
disable() {
if (!this._client)
@@ -111,7 +109,7 @@ var TelepathyComponent = new Lang.Class({
this._client.unregister();
}
});
};
var TelepathyClient = HAVE_TP ? new Lang.Class({
Name: 'TelepathyClient',
@@ -279,17 +277,14 @@ var TelepathyClient = HAVE_TP ? new Lang.Class({
},
}) : null;
var ChatSource = new Lang.Class({
Name: 'ChatSource',
Extends: MessageTray.Source,
var ChatSource = class extends MessageTray.Source {
constructor(account, conn, channel, contact, client) {
super(contact.get_alias());
_init(account, conn, channel, contact, client) {
this._account = account;
this._contact = contact;
this._client = client;
this.parent(contact.get_alias());
this.isChat = true;
this._pendingMessages = [];
@@ -313,7 +308,7 @@ var ChatSource = new Lang.Class({
Main.messageTray.add(this);
this._getLogMessages();
},
}
_ensureNotification() {
if (this._notification)
@@ -329,13 +324,13 @@ var ChatSource = new Lang.Class({
this._notification = null;
});
this.pushNotification(this._notification);
},
}
_createPolicy() {
if (this._account.protocol_name == 'irc')
return new MessageTray.NotificationApplicationPolicy('org.gnome.Polari');
return new MessageTray.NotificationApplicationPolicy('empathy');
},
}
createBanner() {
this._banner = new ChatNotificationBanner(this._notification);
@@ -348,7 +343,7 @@ var ChatSource = new Lang.Class({
});
return this._banner;
},
}
_updateAlias() {
let oldAlias = this.title;
@@ -360,7 +355,7 @@ var ChatSource = new Lang.Class({
this.setTitle(newAlias);
if (this._notification)
this._notification.appendAliasChange(oldAlias, newAlias);
},
}
getIcon() {
let file = this._contact.get_avatar_file();
@@ -369,7 +364,7 @@ var ChatSource = new Lang.Class({
} else {
return new Gio.ThemedIcon({ name: 'avatar-default' });
}
},
}
getSecondaryIcon() {
let iconName;
@@ -398,7 +393,7 @@ var ChatSource = new Lang.Class({
iconName = 'user-offline';
}
return new Gio.ThemedIcon({ name: iconName });
},
}
_updateAvatarIcon() {
this.iconUpdated();
@@ -406,7 +401,7 @@ var ChatSource = new Lang.Class({
this._notification.update(this._notification.title,
this._notification.bannerBodyText,
{ gicon: this.getIcon() });
},
}
open() {
Main.overview.hide();
@@ -431,7 +426,7 @@ var ChatSource = new Lang.Class({
cd.present_channel_async(this._channel, global.get_current_time(), null);
}
},
}
_getLogMessages() {
let logManager = Tpl.LogManager.dup_singleton();
@@ -440,7 +435,7 @@ var ChatSource = new Lang.Class({
logManager.get_filtered_events_async(this._account, entity,
Tpl.EventTypeMask.TEXT, SCROLLBACK_HISTORY_LINES,
null, this._displayPendingMessages.bind(this));
},
}
_displayPendingMessages(logManager, result) {
let [success, events] = logManager.get_filtered_events_finish(result);
@@ -493,7 +488,7 @@ var ChatSource = new Lang.Class({
if (pendingMessages.length > 0)
this.notify();
},
}
destroy(reason) {
if (this._client.is_handling_channel(this._channel)) {
@@ -527,25 +522,25 @@ var ChatSource = new Lang.Class({
this._contact.disconnect(this._notifyAvatarId);
this._contact.disconnect(this._presenceChangedId);
this.parent(reason);
},
super.destroy(reason);
}
_channelClosed() {
this.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
},
}
/* All messages are new messages for Telepathy sources */
get count() {
return this._pendingMessages.length;
},
}
get unseenCount() {
return this.count;
},
}
get countVisible() {
return this.count > 0;
},
}
_messageReceived(channel, message) {
if (message.get_message_type() == Tp.ChannelTextMessageType.DELIVERY_REPORT)
@@ -565,7 +560,7 @@ var ChatSource = new Lang.Class({
this._notifyTimeoutId = Mainloop.timeout_add(500,
this._notifyTimeout.bind(this));
GLib.Source.set_name_by_id(this._notifyTimeoutId, '[gnome-shell] this._notifyTimeout');
},
}
_notifyTimeout() {
if (this._pendingMessages.length != 0)
@@ -574,7 +569,7 @@ var ChatSource = new Lang.Class({
this._notifyTimeoutId = 0;
return GLib.SOURCE_REMOVE;
},
}
// This is called for both messages we send from
// our client and other clients as well.
@@ -582,11 +577,11 @@ var ChatSource = new Lang.Class({
this._ensureNotification();
message = makeMessageFromTpMessage(message, NotificationDirection.SENT);
this._notification.appendMessage(message);
},
}
notify() {
this.parent(this._notification);
},
super.notify(this._notification);
}
respond(text) {
let type;
@@ -601,7 +596,7 @@ var ChatSource = new Lang.Class({
this._channel.send_message_async(msg, 0, (src, result) => {
this._channel.send_message_finish(result);
});
},
}
setChatState(state) {
// We don't want to send COMPOSING every time a letter is typed into
@@ -614,14 +609,14 @@ var ChatSource = new Lang.Class({
this._chatState = state;
this._channel.set_chat_state_async(state, null);
}
},
}
_presenceChanged(contact, presence, status, message) {
if (this._notification)
this._notification.update(this._notification.title,
this._notification.bannerBodyText,
{ secondaryGIcon: this.getSecondaryIcon() });
},
}
_pendingRemoved(channel, message) {
let idx = this._pendingMessages.indexOf(message);
@@ -634,35 +629,32 @@ var ChatSource = new Lang.Class({
if (this._pendingMessages.length == 0 &&
this._banner && !this._banner.expanded)
this._banner.hide();
},
}
_ackMessages() {
// Don't clear our messages here, tp-glib will send a
// 'pending-message-removed' for each one.
this._channel.ack_all_pending_messages_async(null);
}
});
};
var ChatNotification = new Lang.Class({
Name: 'ChatNotification',
Extends: MessageTray.Notification,
_init(source) {
this.parent(source, source.title, null,
{ secondaryGIcon: source.getSecondaryIcon() });
var ChatNotification = class extends MessageTray.Notification {
constructor(source) {
super(source, source.title, null,
{ secondaryGIcon: source.getSecondaryIcon() });
this.setUrgency(MessageTray.Urgency.HIGH);
this.setResident(true);
this.messages = [];
this._timestampTimeoutId = 0;
},
}
destroy(reason) {
if (this._timestampTimeoutId)
Mainloop.source_remove(this._timestampTimeoutId);
this._timestampTimeoutId = 0;
this.parent(reason);
},
super.destroy(reason);
}
/**
* appendMessage:
@@ -700,7 +692,7 @@ var ChatNotification = new Lang.Class({
styles: styles,
timestamp: message.timestamp,
noTimestamp: noTimestamp });
},
}
_filterMessages() {
if (this.messages.length < 1)
@@ -725,7 +717,7 @@ var ChatNotification = new Lang.Class({
for (let i = 0; i < expired.length; i++)
this.emit('message-removed', expired[i]);
}
},
}
/**
* _append:
@@ -773,7 +765,7 @@ var ChatNotification = new Lang.Class({
}
this._filterMessages();
},
}
appendTimestamp() {
this._timestampTimeoutId = 0;
@@ -784,7 +776,7 @@ var ChatNotification = new Lang.Class({
this._filterMessages();
return GLib.SOURCE_REMOVE;
},
}
appendAliasChange(oldAlias, newAlias) {
oldAlias = GLib.markup_escape_text(oldAlias, -1);
@@ -800,7 +792,7 @@ var ChatNotification = new Lang.Class({
this._filterMessages();
}
});
};
var ChatLineBox = new Lang.Class({
Name: 'ChatLineBox',
@@ -812,12 +804,9 @@ var ChatLineBox = new Lang.Class({
}
});
var ChatNotificationBanner = new Lang.Class({
Name: 'ChatNotificationBanner',
Extends: MessageTray.NotificationBanner,
_init(notification) {
this.parent(notification);
var ChatNotificationBanner = class extends MessageTray.NotificationBanner {
constructor(notification) {
super(notification);
this._responseEntry = new St.Entry({ style_class: 'chat-response',
x_expand: true,
@@ -880,14 +869,14 @@ var ChatNotificationBanner = new Lang.Class({
for (let i = this.notification.messages.length - 1; i >= 0; i--)
this._addMessage(this.notification.messages[i]);
},
}
_onDestroy() {
this.parent();
super._onDestroy();
this.notification.disconnect(this._messageAddedId);
this.notification.disconnect(this._messageRemovedId);
this.notification.disconnect(this._timestampChangedId);
},
}
scrollTo(side) {
let adjustment = this._scrollArea.vscroll.adjustment;
@@ -895,11 +884,11 @@ var ChatNotificationBanner = new Lang.Class({
adjustment.value = adjustment.lower;
else if (side == St.Side.BOTTOM)
adjustment.value = adjustment.upper;
},
}
hide() {
this.emit('done-displaying');
},
}
_addMessage(message) {
let highlighter = new MessageList.URLHighlighter(message.body, true, true);
@@ -921,7 +910,7 @@ var ChatNotificationBanner = new Lang.Class({
this._messageActors.set(message, lineBox);
this._updateTimestamp(message);
},
}
_updateTimestamp(message) {
let actor = this._messageActors.get(message);
@@ -942,7 +931,7 @@ var ChatNotificationBanner = new Lang.Class({
actor.add_actor(timeLabel);
}
},
}
_onEntryActivated() {
let text = this._responseEntry.get_text();
@@ -955,7 +944,7 @@ var ChatNotificationBanner = new Lang.Class({
// see Source._messageSent
this._responseEntry.set_text('');
this.notification.source.respond(text);
},
}
_composingStopTimeout() {
this._composingTimeoutId = 0;
@@ -963,7 +952,7 @@ var ChatNotificationBanner = new Lang.Class({
this.notification.source.setChatState(Tp.ChannelChatState.PAUSED);
return GLib.SOURCE_REMOVE;
},
}
_onEntryChanged() {
let text = this._responseEntry.get_text();
@@ -990,6 +979,6 @@ var ChatNotificationBanner = new Lang.Class({
this.notification.source.setChatState(Tp.ChannelChatState.ACTIVE);
}
}
});
};
var Component = TelepathyComponent;