2012-05-16 22:26:44 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported SessionMode, listModes */
|
2012-05-16 22:26:44 +00:00
|
|
|
|
2012-11-28 20:14:21 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
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,
|
2017-06-03 22:37:36 +00:00
|
|
|
hasWmMenus: 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: [],
|
2019-08-20 21:43:54 +00:00
|
|
|
right: [],
|
2012-09-04 01:26:37 +00:00
|
|
|
},
|
2019-08-20 21:43:54 +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'],
|
2019-08-20 21:43:54 +00:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
2012-09-21 20:19:27 +00:00
|
|
|
},
|
2019-08-20 21:43:54 +00:00
|
|
|
panelStyle: 'login-screen',
|
2012-09-04 01:23:22 +00:00
|
|
|
},
|
2012-05-16 22:26:44 +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: [],
|
2019-08-20 21:43:54 +00:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
2012-08-26 14:53:08 +00:00
|
|
|
},
|
2019-08-20 21:43:54 +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,
|
2017-06-03 22:37:36 +00:00
|
|
|
hasWmMenus: 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,
|
2019-08-19 19:33:15 +00:00
|
|
|
components: Config.HAVE_NETWORKMANAGER
|
|
|
|
? ['networkAgent', 'polkitAgent', 'telepathyClient',
|
|
|
|
'keyring', 'autorunManager', 'automountManager']
|
|
|
|
: ['polkitAgent', 'telepathyClient',
|
|
|
|
'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'],
|
2019-08-20 21:43:54 +00:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
|
|
|
},
|
|
|
|
},
|
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);
|
|
|
|
|
2019-06-29 23:05:27 +00:00
|
|
|
if (Object.prototype.hasOwnProperty.call(_modes, modeName))
|
2012-11-29 17:20:43 +00:00
|
|
|
return;
|
|
|
|
|
2019-01-31 14:08:00 +00:00
|
|
|
let fileContent, success_, newMode;
|
2012-11-28 20:14:21 +00:00
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
[success_, fileContent] = 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);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2012-11-28 20:14:21 +00:00
|
|
|
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 &&
|
2018-07-14 20:56:22 +00:00
|
|
|
!propBlacklist.includes(prop))
|
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();
|
2019-08-19 18:50:33 +00:00
|
|
|
let loop = new GLib.MainLoop(null, false);
|
|
|
|
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2013-12-06 20:28:23 +00:00
|
|
|
let names = Object.getOwnPropertyNames(_modes);
|
2019-08-20 00:51:42 +00:00
|
|
|
for (let i = 0; i < names.length; i++) {
|
2012-11-29 17:20:43 +00:00
|
|
|
if (_modes[names[i]].isPrimary)
|
|
|
|
print(names[i]);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2019-08-19 18:50:33 +00:00
|
|
|
loop.quit();
|
2012-11-29 17:20:43 +00:00
|
|
|
});
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] listModes');
|
2019-08-19 18:50:33 +00:00
|
|
|
loop.run();
|
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();
|
2019-08-19 19:38:51 +00:00
|
|
|
let isPrimary = _modes[global.session_mode] &&
|
|
|
|
_modes[global.session_mode].isPrimary;
|
2013-11-04 15:07:44 +00:00
|
|
|
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;
|
2019-08-20 00:51:42 +00:00
|
|
|
if (params.parentMode) {
|
2013-11-04 15:07:44 +00:00
|
|
|
defaults = Params.parse(_modes[params.parentMode],
|
|
|
|
_modes[DEFAULT_MODE]);
|
2019-08-20 00:51:42 +00:00
|
|
|
} else {
|
2013-11-04 15:07:44 +00:00
|
|
|
defaults = _modes[DEFAULT_MODE];
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
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);
|