2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-23 14:30:05 -04:00
|
|
|
|
|
|
|
const DBus = imports.dbus;
|
2011-06-27 22:21:02 -04:00
|
|
|
const Lang = imports.lang;
|
2009-09-23 14:30:05 -04:00
|
|
|
|
2011-06-29 20:09:00 -04:00
|
|
|
const Config = imports.misc.config;
|
2011-06-22 22:03:04 -04:00
|
|
|
const ExtensionSystem = imports.ui.extensionSystem;
|
2009-09-23 14:30:05 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const GnomeShellIface = {
|
2010-05-13 15:46:04 -04:00
|
|
|
name: 'org.gnome.Shell',
|
|
|
|
methods: [{ name: 'Eval',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: 'bs'
|
2011-06-22 22:03:04 -04:00
|
|
|
},
|
|
|
|
{ name: 'ListExtensions',
|
|
|
|
inSignature: '',
|
|
|
|
outSignature: 'a{sa{sv}}'
|
|
|
|
},
|
|
|
|
{ name: 'GetExtensionInfo',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: 'a{sv}'
|
|
|
|
},
|
2011-06-22 21:41:30 -04:00
|
|
|
{ name: 'GetExtensionErrors',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: 'as'
|
2011-08-24 10:06:13 -04:00
|
|
|
},
|
|
|
|
{ name: 'ScreenshotArea',
|
|
|
|
inSignature: 'iiiis',
|
|
|
|
outSignature: 'b'
|
|
|
|
},
|
|
|
|
{ name: 'ScreenshotWindow',
|
|
|
|
inSignature: 'bs',
|
|
|
|
outSignature: 'b'
|
|
|
|
},
|
|
|
|
{ name: 'Screenshot',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: 'b'
|
2011-06-22 21:56:24 -04:00
|
|
|
},
|
|
|
|
{ name: 'EnableExtension',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: ''
|
|
|
|
},
|
|
|
|
{ name: 'DisableExtension',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: ''
|
2011-08-24 13:08:34 -04:00
|
|
|
},
|
|
|
|
{ name: 'InstallRemoteExtension',
|
2011-09-12 14:16:03 -04:00
|
|
|
inSignature: 'ss',
|
2011-08-24 13:08:34 -04:00
|
|
|
outSignature: ''
|
2011-09-10 17:10:50 -04:00
|
|
|
},
|
|
|
|
{ name: 'UninstallExtension',
|
|
|
|
inSignature: 's',
|
|
|
|
outSignature: 'b'
|
2011-06-22 21:41:30 -04:00
|
|
|
}
|
2009-09-23 14:30:05 -04:00
|
|
|
],
|
2011-06-27 22:21:02 -04:00
|
|
|
signals: [{ name: 'ExtensionStatusChanged',
|
|
|
|
inSignature: 'sis' }],
|
2010-05-13 15:46:04 -04:00
|
|
|
properties: [{ name: 'OverviewActive',
|
|
|
|
signature: 'b',
|
2011-06-29 20:09:00 -04:00
|
|
|
access: 'readwrite' },
|
|
|
|
{ name: 'ApiVersion',
|
|
|
|
signature: 'i',
|
|
|
|
access: 'read' },
|
|
|
|
{ name: 'ShellVersion',
|
|
|
|
signature: 's',
|
|
|
|
access: 'read' }]
|
2009-09-23 14:30:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
function GnomeShell() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
GnomeShell.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
DBus.session.exportObject('/org/gnome/Shell', this);
|
2011-06-27 22:21:02 -04:00
|
|
|
ExtensionSystem.connect('extension-state-changed',
|
|
|
|
Lang.bind(this, this._extensionStateChanged));
|
2009-09-23 14:30:05 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Eval:
|
|
|
|
* @code: A string containing JavaScript code
|
|
|
|
*
|
|
|
|
* This function executes arbitrary code in the main
|
|
|
|
* loop, and returns a boolean success and
|
|
|
|
* JSON representation of the object as a string.
|
|
|
|
*
|
|
|
|
* If evaluation completes without throwing an exception,
|
|
|
|
* then the return value will be [true, JSON.stringify(result)].
|
|
|
|
* If evaluation fails, then the return value will be
|
|
|
|
* [false, JSON.stringify(exception)];
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
Eval: function(code) {
|
|
|
|
let returnValue;
|
|
|
|
let success;
|
|
|
|
try {
|
|
|
|
returnValue = JSON.stringify(eval(code));
|
2009-11-12 18:17:58 -05:00
|
|
|
// A hack; DBus doesn't have null/undefined
|
|
|
|
if (returnValue == undefined)
|
2010-05-13 15:46:04 -04:00
|
|
|
returnValue = '';
|
2009-09-23 14:30:05 -04:00
|
|
|
success = true;
|
|
|
|
} catch (e) {
|
|
|
|
returnValue = JSON.stringify(e);
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return [success, returnValue];
|
|
|
|
},
|
|
|
|
|
2011-08-24 10:06:13 -04:00
|
|
|
/**
|
|
|
|
* ScreenshotArea:
|
|
|
|
* @x: The X coordinate of the area
|
|
|
|
* @y: The Y coordinate of the area
|
|
|
|
* @width: The width of the area
|
|
|
|
* @height: The height of the area
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
*
|
|
|
|
* Takes a screenshot of the passed in area and saves it
|
|
|
|
* in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ScreenshotAreaAsync : function (x, y, width, height, filename, callback) {
|
|
|
|
global.screenshot_area (x, y, width, height, filename, function (obj, result) { callback(result); });
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ScreenshotWindow:
|
|
|
|
* @include_frame: Whether to include the frame or not
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
*
|
|
|
|
* Takes a screenshot of the focused window (optionally omitting the frame)
|
|
|
|
* and saves it in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ScreenshotWindow : function (include_frame, filename) {
|
|
|
|
return global.screenshot_window (include_frame, filename);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Screenshot:
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
*
|
|
|
|
* Takes a screenshot of the whole screen and saves it
|
|
|
|
* in @filename as png image, it returns a boolean
|
|
|
|
* indicating whether the operation was successful or not.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ScreenshotAsync : function (filename, callback) {
|
|
|
|
global.screenshot(filename, function (obj, result) { callback(result); });
|
|
|
|
},
|
|
|
|
|
2011-06-22 22:03:04 -04:00
|
|
|
ListExtensions: function() {
|
|
|
|
return ExtensionSystem.extensionMeta;
|
|
|
|
},
|
|
|
|
|
|
|
|
GetExtensionInfo: function(uuid) {
|
|
|
|
return ExtensionSystem.extensionMeta[uuid] || {};
|
|
|
|
},
|
|
|
|
|
2011-06-22 21:41:30 -04:00
|
|
|
GetExtensionErrors: function(uuid) {
|
|
|
|
return ExtensionSystem.errors[uuid] || [];
|
|
|
|
},
|
|
|
|
|
2011-06-22 21:56:24 -04:00
|
|
|
EnableExtension: function(uuid) {
|
|
|
|
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
|
|
|
|
if (enabledExtensions.indexOf(uuid) == -1)
|
|
|
|
enabledExtensions.push(uuid);
|
|
|
|
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
},
|
|
|
|
|
|
|
|
DisableExtension: function(uuid) {
|
|
|
|
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
|
|
|
|
while (enabledExtensions.indexOf(uuid) != -1)
|
|
|
|
enabledExtensions.splice(enabledExtensions.indexOf(uuid), 1);
|
|
|
|
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
|
|
},
|
|
|
|
|
2011-09-12 14:16:03 -04:00
|
|
|
InstallRemoteExtension: function(uuid, version_tag) {
|
|
|
|
ExtensionSystem.installExtensionFromUUID(uuid, version_tag);
|
2011-08-24 13:08:34 -04:00
|
|
|
},
|
|
|
|
|
2011-09-10 17:10:50 -04:00
|
|
|
UninstallExtension: function(uuid) {
|
|
|
|
return ExtensionSystem.uninstallExtensionFromUUID(uuid);
|
|
|
|
},
|
|
|
|
|
2009-09-23 14:30:05 -04:00
|
|
|
get OverviewActive() {
|
|
|
|
return Main.overview.visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
set OverviewActive(visible) {
|
|
|
|
if (visible)
|
|
|
|
Main.overview.show();
|
|
|
|
else
|
|
|
|
Main.overview.hide();
|
2011-06-29 20:09:00 -04:00
|
|
|
},
|
|
|
|
|
2011-09-12 14:16:03 -04:00
|
|
|
ApiVersion: ExtensionSystem.API_VERSION,
|
2011-06-29 20:09:00 -04:00
|
|
|
|
2011-06-27 22:21:02 -04:00
|
|
|
ShellVersion: Config.PACKAGE_VERSION,
|
|
|
|
|
|
|
|
_extensionStateChanged: function(_, newState) {
|
|
|
|
DBus.session.emit_signal('/org/gnome/Shell',
|
|
|
|
'org.gnome.Shell',
|
|
|
|
'ExtensionStatusChanged', 'sis',
|
|
|
|
[newState.uuid, newState.state, newState.error]);
|
|
|
|
}
|
2009-09-23 14:30:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
DBus.conformExport(GnomeShell.prototype, GnomeShellIface);
|
|
|
|
|