2012-05-16 18:26:44 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported SessionMode, listModes */
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-11-28 15:14:21 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2012-09-01 08:42:53 -04:00
|
|
|
const Signals = imports.signals;
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-11-29 12:20:43 -05:00
|
|
|
const FileUtils = imports.misc.fileUtils;
|
2012-05-16 18:26:44 -04:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
|
2014-02-11 17:20:15 -05:00
|
|
|
const Config = imports.misc.config;
|
|
|
|
|
2012-09-03 21:26:37 -04:00
|
|
|
const DEFAULT_MODE = 'restrictive';
|
2012-05-16 18:26:44 -04:00
|
|
|
|
|
|
|
const _modes = {
|
2012-09-03 21:26:37 -04:00
|
|
|
'restrictive': {
|
2012-11-29 14:42:38 -05:00
|
|
|
parentMode: null,
|
2013-02-04 22:13:44 -05:00
|
|
|
stylesheetName: 'gnome-shell.css',
|
2020-03-03 04:05:54 -05:00
|
|
|
themeResourceName: 'gnome-shell-theme.gresource',
|
2012-09-03 21:23:22 -04:00
|
|
|
hasOverview: false,
|
|
|
|
showCalendarEvents: false,
|
2021-04-05 13:36:29 -04:00
|
|
|
showWelcomeDialog: false,
|
2012-09-03 21:23:22 -04:00
|
|
|
allowSettings: false,
|
|
|
|
allowExtensions: false,
|
2013-07-17 21:22:54 -04:00
|
|
|
allowScreencast: false,
|
2012-11-29 10:09:21 -05:00
|
|
|
enabledExtensions: [],
|
2012-09-03 21:23:22 -04:00
|
|
|
hasRunDialog: false,
|
|
|
|
hasWorkspaces: false,
|
|
|
|
hasWindows: false,
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: false,
|
2017-06-03 18:37:36 -04:00
|
|
|
hasWmMenus: false,
|
2012-09-03 21:26:37 -04:00
|
|
|
isLocked: false,
|
2012-09-04 13:28:19 -04:00
|
|
|
isGreeter: false,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: false,
|
2012-09-04 13:28:19 -04:00
|
|
|
unlockDialog: null,
|
2012-09-03 21:23:22 -04:00
|
|
|
components: [],
|
2012-09-03 21:26:37 -04:00
|
|
|
panel: {
|
|
|
|
left: [],
|
|
|
|
center: [],
|
2019-08-20 17:43:54 -04:00
|
|
|
right: [],
|
2012-09-03 21:26:37 -04:00
|
|
|
},
|
2019-08-20 17:43:54 -04:00
|
|
|
panelStyle: null,
|
2012-09-03 21:26:37 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
'gdm': {
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
isGreeter: true,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
unlockDialog: imports.gdm.loginDialog.LoginDialog,
|
2021-06-10 17:12:27 -04:00
|
|
|
components: Config.HAVE_NETWORKMANAGER
|
|
|
|
? ['networkAgent', 'polkitAgent']
|
|
|
|
: ['polkitAgent'],
|
2012-09-03 21:23:22 -04:00
|
|
|
panel: {
|
2013-03-22 20:29:23 -04:00
|
|
|
left: [],
|
2012-09-03 21:23:22 -04:00
|
|
|
center: ['dateMenu'],
|
2019-08-20 17:43:54 -04:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
2012-09-21 16:19:27 -04:00
|
|
|
},
|
2019-08-20 17:43:54 -04:00
|
|
|
panelStyle: 'login-screen',
|
2012-09-03 21:23:22 -04:00
|
|
|
},
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2012-08-26 10:53:08 -04:00
|
|
|
'unlock-dialog': {
|
|
|
|
isLocked: true,
|
|
|
|
unlockDialog: undefined,
|
2012-09-20 02:53:20 -04:00
|
|
|
components: ['polkitAgent', 'telepathyClient'],
|
2012-08-26 10:53:08 -04:00
|
|
|
panel: {
|
2013-05-22 14:46:47 -04:00
|
|
|
left: [],
|
2012-08-26 10:53:08 -04:00
|
|
|
center: [],
|
2019-08-20 17:43:54 -04:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
2012-08-26 10:53:08 -04:00
|
|
|
},
|
2019-08-20 17:43:54 -04:00
|
|
|
panelStyle: 'unlock-screen',
|
2012-08-26 10:53:08 -04:00
|
|
|
},
|
|
|
|
|
2012-09-03 21:23:22 -04:00
|
|
|
'user': {
|
|
|
|
hasOverview: true,
|
2021-12-03 14:04:05 -05:00
|
|
|
showCalendarEvents: false,
|
2021-04-05 13:36:29 -04:00
|
|
|
showWelcomeDialog: true,
|
2012-09-03 21:23:22 -04:00
|
|
|
allowSettings: true,
|
|
|
|
allowExtensions: true,
|
2013-07-17 21:22:54 -04:00
|
|
|
allowScreencast: true,
|
2012-09-03 21:23:22 -04:00
|
|
|
hasRunDialog: true,
|
|
|
|
hasWorkspaces: true,
|
|
|
|
hasWindows: true,
|
2017-06-03 18:37:36 -04:00
|
|
|
hasWmMenus: true,
|
2012-08-26 10:53:08 -04:00
|
|
|
hasNotifications: true,
|
2012-09-04 13:28:19 -04:00
|
|
|
isLocked: false,
|
2012-09-06 07:21:12 -04:00
|
|
|
isPrimary: true,
|
2012-08-26 10:53:08 -04:00
|
|
|
unlockDialog: imports.ui.unlockDialog.UnlockDialog,
|
2019-08-19 15:33:15 -04:00
|
|
|
components: Config.HAVE_NETWORKMANAGER
|
|
|
|
? ['networkAgent', 'polkitAgent', 'telepathyClient',
|
|
|
|
'keyring', 'autorunManager', 'automountManager']
|
|
|
|
: ['polkitAgent', 'telepathyClient',
|
|
|
|
'keyring', 'autorunManager', 'automountManager'],
|
2014-02-11 17:20:15 -05:00
|
|
|
|
2012-09-03 21:23:22 -04:00
|
|
|
panel: {
|
|
|
|
left: ['activities', 'appMenu'],
|
|
|
|
center: ['dateMenu'],
|
2019-08-20 17:43:54 -04:00
|
|
|
right: ['dwellClick', 'a11y', 'keyboard', 'aggregateMenu'],
|
|
|
|
},
|
|
|
|
},
|
2012-05-16 18:26:44 -04:00
|
|
|
};
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
function _loadMode(file, info) {
|
2012-11-29 12:20:43 -05:00
|
|
|
let name = info.get_name();
|
|
|
|
let suffix = name.indexOf('.json');
|
|
|
|
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
|
|
|
|
2019-06-29 19:05:27 -04:00
|
|
|
if (Object.prototype.hasOwnProperty.call(_modes, modeName))
|
2012-11-29 12:20:43 -05:00
|
|
|
return;
|
|
|
|
|
2019-01-31 09:08:00 -05:00
|
|
|
let fileContent, success_, newMode;
|
2012-11-28 15:14:21 -05:00
|
|
|
try {
|
2019-01-31 09:08:00 -05:00
|
|
|
[success_, fileContent] = file.load_contents(null);
|
2021-08-12 10:38:57 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
newMode = JSON.parse(decoder.decode(fileContent));
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2012-11-28 15:14:21 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
_modes[modeName] = {};
|
2020-08-04 04:39:29 -04:00
|
|
|
const excludedProps = ['unlockDialog'];
|
2013-12-06 15:25:15 -05:00
|
|
|
for (let prop in _modes[DEFAULT_MODE]) {
|
2012-11-29 12:20:43 -05:00
|
|
|
if (newMode[prop] !== undefined &&
|
2020-08-04 04:39:29 -04:00
|
|
|
!excludedProps.includes(prop))
|
2013-12-06 15:25:15 -05:00
|
|
|
_modes[modeName][prop] = newMode[prop];
|
2012-11-28 15:14:21 -05:00
|
|
|
}
|
2013-11-04 10:07:44 -05:00
|
|
|
_modes[modeName]['isPrimary'] = true;
|
|
|
|
}
|
|
|
|
|
2013-12-06 15:28:23 -05:00
|
|
|
function _loadModes() {
|
2013-11-04 10:07:44 -05:00
|
|
|
FileUtils.collectFromDatadirs('modes', false, _loadMode);
|
2012-11-28 15:14:21 -05:00
|
|
|
}
|
|
|
|
|
2012-05-17 21:52:57 -04:00
|
|
|
function listModes() {
|
2013-12-06 15:28:23 -05:00
|
|
|
_loadModes();
|
2019-08-19 14:50:33 -04:00
|
|
|
let loop = new GLib.MainLoop(null, false);
|
|
|
|
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2013-12-06 15:28:23 -05:00
|
|
|
let names = Object.getOwnPropertyNames(_modes);
|
2019-08-19 20:51:42 -04:00
|
|
|
for (let i = 0; i < names.length; i++) {
|
2012-11-29 12:20:43 -05:00
|
|
|
if (_modes[names[i]].isPrimary)
|
|
|
|
print(names[i]);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2019-08-19 14:50:33 -04:00
|
|
|
loop.quit();
|
2012-11-29 12:20:43 -05:00
|
|
|
});
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] listModes');
|
2019-08-19 14:50:33 -04:00
|
|
|
loop.run();
|
2012-05-17 21:52:57 -04:00
|
|
|
}
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var SessionMode = class {
|
|
|
|
constructor() {
|
2013-12-06 15:31:46 -05:00
|
|
|
_loadModes();
|
2019-08-19 15:38:51 -04:00
|
|
|
let isPrimary = _modes[global.session_mode] &&
|
|
|
|
_modes[global.session_mode].isPrimary;
|
2013-11-04 10:07:44 -05:00
|
|
|
let mode = isPrimary ? global.session_mode : 'user';
|
|
|
|
this._modeStack = [mode];
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
pushMode(mode) {
|
2012-09-01 08:42:53 -04:00
|
|
|
this._modeStack.push(mode);
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popMode(mode) {
|
2012-09-01 08:42:53 -04:00
|
|
|
if (this.currentMode != mode || this._modeStack.length === 1)
|
|
|
|
throw new Error("Invalid SessionMode.popMode");
|
|
|
|
this._modeStack.pop();
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-01 08:42:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
switchMode(to) {
|
2012-08-26 10:53:08 -04:00
|
|
|
if (this.currentMode == to)
|
|
|
|
return;
|
|
|
|
this._modeStack[this._modeStack.length - 1] = to;
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-26 10:53:08 -04:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
get currentMode() {
|
|
|
|
return this._modeStack[this._modeStack.length - 1];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-05-16 18:26:44 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2013-11-04 10:07:44 -05:00
|
|
|
let params = _modes[this.currentMode];
|
2012-11-29 14:42:38 -05:00
|
|
|
let defaults;
|
2019-08-19 20:51:42 -04:00
|
|
|
if (params.parentMode) {
|
2013-11-04 10:07:44 -05:00
|
|
|
defaults = Params.parse(_modes[params.parentMode],
|
|
|
|
_modes[DEFAULT_MODE]);
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2013-11-04 10:07:44 -05:00
|
|
|
defaults = _modes[DEFAULT_MODE];
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2012-11-29 14:42:38 -05:00
|
|
|
params = Params.parse(params, defaults);
|
2012-05-17 09:50:51 -04:00
|
|
|
|
2012-09-04 13:28:19 -04: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 09:50:51 -04:00
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
this.emit('updated');
|
2012-09-04 13:28:19 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-09-01 08:42:53 -04:00
|
|
|
Signals.addSignalMethods(SessionMode.prototype);
|