2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-09-23 18:30:05 +00:00
|
|
|
|
2011-06-28 02:21:02 +00:00
|
|
|
const Lang = imports.lang;
|
2011-08-16 12:19:59 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
2009-09-23 18:30:05 +00:00
|
|
|
|
2011-06-30 00:09:00 +00:00
|
|
|
const Config = imports.misc.config;
|
2011-06-23 02:03:04 +00:00
|
|
|
const ExtensionSystem = imports.ui.extensionSystem;
|
2009-09-23 18:30:05 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2011-08-16 12:19:59 +00:00
|
|
|
const GnomeShellIface = <interface name="org.gnome.Shell">
|
|
|
|
<method name="Eval">
|
|
|
|
<arg type="s" direction="in" name="script" />
|
|
|
|
<arg type="b" direction="out" name="success" />
|
|
|
|
<arg type="s" direction="out" name="result" />
|
|
|
|
</method>
|
|
|
|
<method name="ListExtensions">
|
|
|
|
<arg type="a{sa{sv}}" direction="out" name="extensions" />
|
|
|
|
</method>
|
|
|
|
<method name="GetExtensionInfo">
|
|
|
|
<arg type="s" direction="in" name="extension" />
|
|
|
|
<arg type="a{sv}" direction="out" name="info" />
|
|
|
|
</method>
|
|
|
|
<method name="GetExtensionErrors">
|
|
|
|
<arg type="s" direction="in" name="extension" />
|
|
|
|
<arg type="as" direction="out" name="errors" />
|
|
|
|
</method>
|
|
|
|
<method name="ScreenshotArea">
|
|
|
|
<arg type="i" direction="in" name="x"/>
|
|
|
|
<arg type="i" direction="in" name="y"/>
|
|
|
|
<arg type="i" direction="in" name="width"/>
|
|
|
|
<arg type="i" direction="in" name="height"/>
|
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="ScreenshotWindow">
|
|
|
|
<arg type="b" direction="in" name="include_frame"/>
|
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="Screenshot">
|
|
|
|
<arg type="s" direction="in" name="filename"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<method name="EnableExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
</method>
|
|
|
|
<method name="DisableExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
</method>
|
|
|
|
<method name="InstallRemoteExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
<arg type="s" direction="in" name="version"/>
|
|
|
|
</method>
|
|
|
|
<method name="UninstallExtension">
|
|
|
|
<arg type="s" direction="in" name="uuid"/>
|
|
|
|
<arg type="b" direction="out" name="success"/>
|
|
|
|
</method>
|
|
|
|
<property name="OverviewActive" type="b" access="readwrite" />
|
|
|
|
<property name="ApiVersion" type="i" access="read" />
|
|
|
|
<property name="ShellVersion" type="s" access="read" />
|
|
|
|
<signal name="ExtensionStatusChanged">
|
|
|
|
<arg type="s" name="uuid"/>
|
|
|
|
<arg type="i" name="state"/>
|
|
|
|
<arg type="s" name="error"/>
|
|
|
|
</signal>
|
|
|
|
</interface>;
|
2009-09-23 18:30:05 +00:00
|
|
|
|
|
|
|
function GnomeShell() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
GnomeShell.prototype = {
|
|
|
|
_init: function() {
|
2011-08-16 12:19:59 +00:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell');
|
2011-06-28 02:21:02 +00:00
|
|
|
ExtensionSystem.connect('extension-state-changed',
|
|
|
|
Lang.bind(this, this._extensionStateChanged));
|
2009-09-23 18:30:05 +00: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) {
|
2011-10-27 21:41:06 +00:00
|
|
|
if (!global.settings.get_boolean('development-tools'))
|
|
|
|
return [false, null];
|
|
|
|
|
2009-09-23 18:30:05 +00:00
|
|
|
let returnValue;
|
|
|
|
let success;
|
|
|
|
try {
|
|
|
|
returnValue = JSON.stringify(eval(code));
|
2009-11-12 23:17:58 +00:00
|
|
|
// A hack; DBus doesn't have null/undefined
|
|
|
|
if (returnValue == undefined)
|
2010-05-13 19:46:04 +00:00
|
|
|
returnValue = '';
|
2009-09-23 18:30:05 +00:00
|
|
|
success = true;
|
|
|
|
} catch (e) {
|
|
|
|
returnValue = JSON.stringify(e);
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return [success, returnValue];
|
|
|
|
},
|
|
|
|
|
2011-08-24 14:06:13 +00: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-23 02:03:04 +00:00
|
|
|
ListExtensions: function() {
|
2011-11-15 21:37:57 +00:00
|
|
|
let out = {};
|
2011-08-16 12:19:59 +00:00
|
|
|
for (let uuid in ExtensionSystem.extensionMeta) {
|
|
|
|
let dbusObj = this.GetExtensionInfo(uuid);
|
|
|
|
out[uuid] = dbusObj;
|
|
|
|
}
|
|
|
|
return out;
|
2011-06-23 02:03:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
GetExtensionInfo: function(uuid) {
|
2011-08-16 12:19:59 +00:00
|
|
|
let meta = ExtensionSystem.extensionMeta[uuid] || {};
|
2011-11-15 21:37:57 +00:00
|
|
|
let out = {};
|
2011-08-16 12:19:59 +00:00
|
|
|
for (let key in meta) {
|
|
|
|
let val = meta[key];
|
|
|
|
let type;
|
|
|
|
switch (typeof val) {
|
|
|
|
case 'string':
|
|
|
|
type = 's';
|
|
|
|
break;
|
|
|
|
case 'number':
|
|
|
|
type = 'd';
|
|
|
|
break;
|
2011-11-15 21:46:17 +00:00
|
|
|
default:
|
|
|
|
continue;
|
2011-08-16 12:19:59 +00:00
|
|
|
}
|
|
|
|
out[key] = GLib.Variant.new(type, val);
|
|
|
|
}
|
|
|
|
return out;
|
2011-06-23 02:03:04 +00:00
|
|
|
},
|
|
|
|
|
2011-06-23 01:41:30 +00:00
|
|
|
GetExtensionErrors: function(uuid) {
|
|
|
|
return ExtensionSystem.errors[uuid] || [];
|
|
|
|
},
|
|
|
|
|
2011-06-23 01:56:24 +00: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 18:16:03 +00:00
|
|
|
InstallRemoteExtension: function(uuid, version_tag) {
|
|
|
|
ExtensionSystem.installExtensionFromUUID(uuid, version_tag);
|
2011-08-24 17:08:34 +00:00
|
|
|
},
|
|
|
|
|
2011-09-10 21:10:50 +00:00
|
|
|
UninstallExtension: function(uuid) {
|
|
|
|
return ExtensionSystem.uninstallExtensionFromUUID(uuid);
|
|
|
|
},
|
|
|
|
|
2009-09-23 18:30:05 +00:00
|
|
|
get OverviewActive() {
|
|
|
|
return Main.overview.visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
set OverviewActive(visible) {
|
|
|
|
if (visible)
|
|
|
|
Main.overview.show();
|
|
|
|
else
|
|
|
|
Main.overview.hide();
|
2011-06-30 00:09:00 +00:00
|
|
|
},
|
|
|
|
|
2011-09-12 18:16:03 +00:00
|
|
|
ApiVersion: ExtensionSystem.API_VERSION,
|
2011-06-30 00:09:00 +00:00
|
|
|
|
2011-06-28 02:21:02 +00:00
|
|
|
ShellVersion: Config.PACKAGE_VERSION,
|
|
|
|
|
|
|
|
_extensionStateChanged: function(_, newState) {
|
2011-11-12 02:45:44 +00:00
|
|
|
this._dbusImpl.emit_signal('ExtensionStatusChanged',
|
|
|
|
GLib.Variant.new('(sis)', [newState.uuid, newState.state, newState.error]));
|
2011-06-28 02:21:02 +00:00
|
|
|
}
|
2009-09-23 18:30:05 +00:00
|
|
|
};
|