2012-05-16 22:26:44 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2012-11-28 20:14:21 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-11-29 17:20:43 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2012-09-01 12:42:53 +00:00
|
|
|
const Signals = imports.signals;
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-11-29 17:20:43 +00:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-05-16 22:26:44 +00:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
|
2014-02-11 22:20:15 +00:00
|
|
|
const Config = imports.misc.config;
|
|
|
|
|
2012-09-04 01:26:37 +00:00
|
|
|
const DEFAULT_MODE = 'restrictive';
|
2012-05-16 22:26:44 +00:00
|
|
|
|
|
|
|
const _modes = {
|
2012-09-04 01:26:37 +00:00
|
|
|
'restrictive': {
|
2012-11-29 19:42:38 +00:00
|
|
|
parentMode: null,
|
2013-02-05 03:13:44 +00:00
|
|
|
stylesheetName: 'gnome-shell.css',
|
2012-09-04 01:23:22 +00:00
|
|
|
hasOverview: false,
|
|
|
|
showCalendarEvents: false,
|
|
|
|
allowSettings: false,
|
|
|
|
allowExtensions: false,
|
2013-07-18 01:22:54 +00:00
|
|
|
allowScreencast: false,
|
2012-11-29 15:09:21 +00:00
|
|
|
enabledExtensions: [],
|
2012-09-04 01:23:22 +00:00
|
|
|
hasRunDialog: false,
|
|
|
|
hasWorkspaces: false,
|
|
|
|
hasWindows: false,
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: false,
|
2012-09-04 01:26:37 +00:00
|
|
|
isLocked: false,
|
2012-09-04 17:28:19 +00:00
|
|
|
isGreeter: false,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: false,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: null,
|
2012-09-04 01:23:22 +00:00
|
|
|
components: [],
|
2012-09-04 01:26:37 +00:00
|
|
|
panel: {
|
|
|
|
left: [],
|
|
|
|
center: [],
|
|
|
|
right: []
|
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: null
|
2012-09-04 01:26:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'gdm': {
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
isGreeter: true,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: imports.gdm.loginDialog.LoginDialog,
|
2012-09-05 10:50:16 +00:00
|
|
|
components: ['polkitAgent'],
|
2012-09-04 01:23:22 +00:00
|
|
|
panel: {
|
2013-03-23 00:29:23 +00:00
|
|
|
left: [],
|
2012-09-04 01:23:22 +00:00
|
|
|
center: ['dateMenu'],
|
2017-10-13 14:17:46 +00:00
|
|
|
right: ['a11y', 'keyboard', 'aggregateMenu']
|
2012-09-21 20:19:27 +00:00
|
|
|
},
|
|
|
|
panelStyle: 'login-screen'
|
2012-09-04 01:23:22 +00:00
|
|
|
},
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
'lock-screen': {
|
2012-09-01 21:44:46 +00:00
|
|
|
isLocked: true,
|
2012-09-10 09:34:49 +00:00
|
|
|
isGreeter: undefined,
|
2012-09-04 17:28:19 +00:00
|
|
|
unlockDialog: undefined,
|
2012-09-20 06:53:20 +00:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-09-01 12:42:53 +00:00
|
|
|
panel: {
|
2013-05-22 18:46:47 +00:00
|
|
|
left: [],
|
2012-09-01 12:42:53 +00:00
|
|
|
center: [],
|
2013-06-06 21:27:32 +00:00
|
|
|
right: ['aggregateMenu']
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: 'lock-screen'
|
2012-09-01 12:42:53 +00:00
|
|
|
},
|
|
|
|
|
2012-08-26 14:53:08 +00:00
|
|
|
'unlock-dialog': {
|
|
|
|
isLocked: true,
|
|
|
|
unlockDialog: undefined,
|
2012-09-20 06:53:20 +00:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-08-26 14:53:08 +00:00
|
|
|
panel: {
|
2013-05-22 18:46:47 +00:00
|
|
|
left: [],
|
2012-08-26 14:53:08 +00:00
|
|
|
center: [],
|
2013-06-06 21:27:32 +00:00
|
|
|
right: ['a11y', 'keyboard', 'aggregateMenu']
|
2012-08-26 14:53:08 +00:00
|
|
|
},
|
2012-09-21 20:19:27 +00:00
|
|
|
panelStyle: 'unlock-screen'
|
2012-08-26 14:53:08 +00:00
|
|
|
},
|
|
|
|
|
2012-09-04 01:23:22 +00:00
|
|
|
'user': {
|
|
|
|
hasOverview: true,
|
|
|
|
showCalendarEvents: true,
|
|
|
|
allowSettings: true,
|
|
|
|
allowExtensions: true,
|
2013-07-18 01:22:54 +00:00
|
|
|
allowScreencast: true,
|
2012-09-04 01:23:22 +00:00
|
|
|
hasRunDialog: true,
|
|
|
|
hasWorkspaces: true,
|
|
|
|
hasWindows: true,
|
2012-08-26 14:53:08 +00:00
|
|
|
hasNotifications: true,
|
2012-09-04 17:28:19 +00:00
|
|
|
isLocked: false,
|
2012-09-06 11:21:12 +00:00
|
|
|
isPrimary: true,
|
2012-08-26 14:53:08 +00:00
|
|
|
unlockDialog: imports.ui.unlockDialog.UnlockDialog,
|
2014-02-11 22:20:15 +00:00
|
|
|
components: Config.HAVE_NETWORKMANAGER ?
|
|
|
|
['networkAgent', 'polkitAgent', 'telepathyClient',
|
|
|
|
'keyring', 'autorunManager', 'automountManager'] :
|
|
|
|
['polkitAgent', 'telepathyClient',
|
2013-07-18 01:22:54 +00:00
|
|
|
'keyring', 'autorunManager', 'automountManager'],
|
2014-02-11 22:20:15 +00:00
|
|
|
|
2012-09-04 01:23:22 +00:00
|
|
|
panel: {
|
|
|
|
left: ['activities', 'appMenu'],
|
|
|
|
center: ['dateMenu'],
|
2013-06-06 21:27:32 +00:00
|
|
|
right: ['a11y', 'keyboard', 'aggregateMenu']
|
2012-09-04 01:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-16 22:26:44 +00:00
|
|
|
};
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
function _loadMode(file, info) {
|
2012-11-29 17:20:43 +00:00
|
|
|
let name = info.get_name();
|
|
|
|
let suffix = name.indexOf('.json');
|
|
|
|
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
if (_modes.hasOwnProperty(modeName))
|
2012-11-29 17:20:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
let fileContent, success, tag, newMode;
|
2012-11-28 20:14:21 +00:00
|
|
|
try {
|
2012-11-29 17:20:43 +00:00
|
|
|
[success, fileContent, tag] = file.load_contents(null);
|
2018-07-30 12:35:27 +00:00
|
|
|
if (fileContent instanceof Uint8Array)
|
|
|
|
fileContent = imports.byteArray.toString(fileContent);
|
2012-11-29 17:20:43 +00:00
|
|
|
newMode = JSON.parse(fileContent);
|
2012-11-28 20:14:21 +00:00
|
|
|
} catch(e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-04 15:07:44 +00:00
|
|
|
_modes[modeName] = {};
|
2012-11-29 17:20:43 +00:00
|
|
|
let propBlacklist = ['unlockDialog'];
|
2013-12-06 20:25:15 +00:00
|
|
|
for (let prop in _modes[DEFAULT_MODE]) {
|
2012-11-29 17:20:43 +00:00
|
|
|
if (newMode[prop] !== undefined &&
|
|
|
|
propBlacklist.indexOf(prop) == -1)
|
2013-12-06 20:25:15 +00:00
|
|
|
_modes[modeName][prop] = newMode[prop];
|
2012-11-28 20:14:21 +00:00
|
|
|
}
|
2013-11-04 15:07:44 +00:00
|
|
|
_modes[modeName]['isPrimary'] = true;
|
|
|
|
}
|
|
|
|
|
2013-12-06 20:28:23 +00:00
|
|
|
function _loadModes() {
|
2013-11-04 15:07:44 +00:00
|
|
|
FileUtils.collectFromDatadirs('modes', false, _loadMode);
|
2012-11-28 20:14:21 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 01:52:57 +00:00
|
|
|
function listModes() {
|
2013-12-06 20:28:23 +00:00
|
|
|
_loadModes();
|
2017-10-31 00:38:18 +00:00
|
|
|
let id = Mainloop.idle_add(() => {
|
2013-12-06 20:28:23 +00:00
|
|
|
let names = Object.getOwnPropertyNames(_modes);
|
2012-11-29 17:20:43 +00:00
|
|
|
for (let i = 0; i < names.length; i++)
|
|
|
|
if (_modes[names[i]].isPrimary)
|
|
|
|
print(names[i]);
|
|
|
|
Mainloop.quit('listModes');
|
|
|
|
});
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] listModes');
|
2012-11-29 17:20:43 +00:00
|
|
|
Mainloop.run('listModes');
|
2012-05-18 01:52:57 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var SessionMode = class {
|
|
|
|
constructor() {
|
2013-12-06 20:31:46 +00:00
|
|
|
_loadModes();
|
2013-11-04 15:07:44 +00:00
|
|
|
let isPrimary = (_modes[global.session_mode] &&
|
|
|
|
_modes[global.session_mode].isPrimary);
|
|
|
|
let mode = isPrimary ? global.session_mode : 'user';
|
|
|
|
this._modeStack = [mode];
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
pushMode(mode) {
|
2012-09-01 12:42:53 +00:00
|
|
|
this._modeStack.push(mode);
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
popMode(mode) {
|
2012-09-01 12:42:53 +00:00
|
|
|
if (this.currentMode != mode || this._modeStack.length === 1)
|
|
|
|
throw new Error("Invalid SessionMode.popMode");
|
|
|
|
this._modeStack.pop();
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-01 12:42:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
switchMode(to) {
|
2012-08-26 14:53:08 +00:00
|
|
|
if (this.currentMode == to)
|
|
|
|
return;
|
|
|
|
this._modeStack[this._modeStack.length - 1] = to;
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-26 14:53:08 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
get currentMode() {
|
|
|
|
return this._modeStack[this._modeStack.length - 1];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2013-11-04 15:07:44 +00:00
|
|
|
let params = _modes[this.currentMode];
|
2012-11-29 19:42:38 +00:00
|
|
|
let defaults;
|
|
|
|
if (params.parentMode)
|
2013-11-04 15:07:44 +00:00
|
|
|
defaults = Params.parse(_modes[params.parentMode],
|
|
|
|
_modes[DEFAULT_MODE]);
|
2012-11-29 19:42:38 +00:00
|
|
|
else
|
2013-11-04 15:07:44 +00:00
|
|
|
defaults = _modes[DEFAULT_MODE];
|
2012-11-29 19:42:38 +00:00
|
|
|
params = Params.parse(params, defaults);
|
2012-05-17 13:50:51 +00:00
|
|
|
|
2012-09-04 17:28:19 +00:00
|
|
|
// A simplified version of Lang.copyProperties, handles
|
|
|
|
// undefined as a special case for "no change / inherit from previous mode"
|
|
|
|
for (let prop in params) {
|
|
|
|
if (params[prop] !== undefined)
|
|
|
|
this[prop] = params[prop];
|
|
|
|
}
|
2012-05-17 13:50:51 +00:00
|
|
|
|
2012-09-01 12:42:53 +00:00
|
|
|
this.emit('updated');
|
2012-09-04 17:28:19 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2012-09-01 12:42:53 +00:00
|
|
|
Signals.addSignalMethods(SessionMode.prototype);
|