sessionMode: Make loading of external modes asynchronous
Blocking IO on startup is bad m'kay ... https://bugzilla.gnome.org/show_bug.cgi?id=689304
This commit is contained in:
parent
6b40c3974d
commit
92083eaf76
@ -3,8 +3,10 @@
|
|||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
const GLib = imports.gi.GLib;
|
const GLib = imports.gi.GLib;
|
||||||
const Lang = imports.lang;
|
const Lang = imports.lang;
|
||||||
|
const Mainloop = imports.mainloop;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
|
const FileUtils = imports.misc.fileUtils;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const Params = imports.misc.params;
|
const Params = imports.misc.params;
|
||||||
|
|
||||||
@ -106,68 +108,48 @@ const _modes = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function _getModes() {
|
function _getModes(modesLoadedCallback) {
|
||||||
let modes = _modes;
|
FileUtils.collectFromDatadirsAsync('modes',
|
||||||
let dataDirs = GLib.get_system_data_dirs();
|
{ processFile: _loadMode,
|
||||||
for (let i = 0; i < dataDirs.length; i++) {
|
loadedCallback: modesLoadedCallback,
|
||||||
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', 'modes']);
|
data: _modes });
|
||||||
let dir = Gio.file_new_for_path(path);
|
|
||||||
|
|
||||||
try {
|
|
||||||
dir.query_info('standard:type', Gio.FileQueryInfoFlags.NONE, null);
|
|
||||||
} catch (e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_getModesFromDir(dir, modes);
|
|
||||||
}
|
|
||||||
return modes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getModesFromDir(dir, modes) {
|
function _loadMode(file, info, loadedData) {
|
||||||
let fileEnum;
|
let name = info.get_name();
|
||||||
|
let suffix = name.indexOf('.json');
|
||||||
|
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
||||||
|
|
||||||
|
if (loadedData.hasOwnProperty(modeName))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let fileContent, success, tag, newMode;
|
||||||
try {
|
try {
|
||||||
fileEnum = dir.enumerate_children('standard::*',
|
[success, fileContent, tag] = file.load_contents(null);
|
||||||
Gio.FileQueryInfoFlags.NONE, null);
|
newMode = JSON.parse(fileContent);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let info;
|
loadedData[modeName] = {};
|
||||||
while ((info = fileEnum.next_file(null)) != null) {
|
let propBlacklist = ['unlockDialog'];
|
||||||
let name = info.get_name();
|
for (let prop in loadedData[DEFAULT_MODE]) {
|
||||||
let suffix = name.indexOf('.json');
|
if (newMode[prop] !== undefined &&
|
||||||
let modeName = suffix == -1 ? name : name.slice(name, suffix);
|
propBlacklist.indexOf(prop) == -1)
|
||||||
|
loadedData[modeName][prop]= newMode[prop];
|
||||||
if (modes.hasOwnProperty(modeName))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
let file = dir.get_child(name);
|
|
||||||
let fileContent, success, tag, newMode;
|
|
||||||
try {
|
|
||||||
[success, fileContent, tag] = file.load_contents(null);
|
|
||||||
newMode = JSON.parse(fileContent);
|
|
||||||
} catch(e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
modes[modeName] = {};
|
|
||||||
let propBlacklist = ['unlockDialog'];
|
|
||||||
for (let prop in modes[DEFAULT_MODE]) {
|
|
||||||
if (newMode[prop] !== undefined &&
|
|
||||||
propBlacklist.indexOf(prop) == -1)
|
|
||||||
modes[modeName][prop]= newMode[prop];
|
|
||||||
}
|
|
||||||
modes[modeName]['isPrimary'] = true;
|
|
||||||
}
|
}
|
||||||
fileEnum.close(null);
|
loadedData[modeName]['isPrimary'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function listModes() {
|
function listModes() {
|
||||||
let modes = Object.getOwnPropertyNames(_getModes());
|
_getModes(function(modes) {
|
||||||
for (let i = 0; i < modes.length; i++)
|
let names = Object.getOwnPropertyNames(modes);
|
||||||
if (_modes[modes[i]].isPrimary)
|
for (let i = 0; i < names.length; i++)
|
||||||
print(modes[i]);
|
if (_modes[names[i]].isPrimary)
|
||||||
|
print(names[i]);
|
||||||
|
Mainloop.quit('listModes');
|
||||||
|
});
|
||||||
|
Mainloop.run('listModes');
|
||||||
}
|
}
|
||||||
|
|
||||||
const SessionMode = new Lang.Class({
|
const SessionMode = new Lang.Class({
|
||||||
@ -175,11 +157,18 @@ const SessionMode = new Lang.Class({
|
|||||||
|
|
||||||
_init: function() {
|
_init: function() {
|
||||||
global.connect('notify::session-mode', Lang.bind(this, this._sync));
|
global.connect('notify::session-mode', Lang.bind(this, this._sync));
|
||||||
this._modes = _getModes();
|
this._modes = _modes;
|
||||||
let mode = this._modes[global.session_mode].isPrimary ? global.session_mode
|
this._modeStack = [DEFAULT_MODE];
|
||||||
: 'user';
|
|
||||||
this._modeStack = [mode];
|
|
||||||
this._sync();
|
this._sync();
|
||||||
|
|
||||||
|
_getModes(Lang.bind(this, function(modes) {
|
||||||
|
this._modes = modes;
|
||||||
|
let primary = modes[global.session_mode] &&
|
||||||
|
modes[global.session_mode].isPrimary;
|
||||||
|
let mode = primary ? global.session_mode : 'user';
|
||||||
|
this._modeStack = [mode];
|
||||||
|
this._sync();
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
pushMode: function(mode) {
|
pushMode: function(mode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user