gnome-shell-extension-tool: Add a reload option

This might be a good fit for extension developers: With
this option one doesn't need to restart the whole Shell
in order to see their changes in effect.

https://bugzilla.gnome.org/show_bug.cgi?id=772593
This commit is contained in:
Jonh Wendell 2016-10-08 15:23:45 -03:00
parent f5bd86fa11
commit 2812afed22

View File

@ -17,7 +17,7 @@ except ImportError:
print('The Python simplejson module is required') print('The Python simplejson module is required')
sys.exit(1) sys.exit(1)
from gi.repository import Gio from gi.repository import Gio, GLib
SAMPLE_EXTENSION_FILES = { SAMPLE_EXTENSION_FILES = {
"extension.js": """ "extension.js": """
@ -172,6 +172,30 @@ def disable_extension(uuid):
settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions) settings.set_strv(ENABLED_EXTENSIONS_KEY, extensions)
print("%r is now disabled." % (uuid,), file=sys.stderr) print("%r is now disabled." % (uuid,), file=sys.stderr)
def reload_extension(uuid):
settings = Gio.Settings(schema='org.gnome.shell')
extensions = settings.get_strv(ENABLED_EXTENSIONS_KEY)
if uuid not in extensions:
print("%r is not enabled or installed." % (uuid,), file=sys.stderr)
sys.exit(1)
proxy = Gio.DBusProxy.new_sync(Gio.bus_get_sync(Gio.BusType.SESSION, None),
Gio.DBusProxyFlags.NONE,
None,
'org.gnome.Shell',
'/org/gnome/Shell',
'org.gnome.Shell.Extensions',
None)
proxy.call_sync('ReloadExtension',
GLib.Variant('(s)', (uuid,)),
Gio.DBusCallFlags.NONE,
-1,
None)
print("%r reloaded." % (uuid,), file=sys.stderr)
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option("-d", "--disable-extension", dest="disable", parser.add_option("-d", "--disable-extension", dest="disable",
@ -180,6 +204,8 @@ def main():
help="Enable a GNOME Shell extension") help="Enable a GNOME Shell extension")
parser.add_option("-c", "--create-extension", dest="create", action="store_true", parser.add_option("-c", "--create-extension", dest="create", action="store_true",
help="Create a new GNOME Shell extension") help="Create a new GNOME Shell extension")
parser.add_option("-r", "--reload-extension", dest="reload",
help="Reload a GNOME Shell extension")
options, args = parser.parse_args() options, args = parser.parse_args()
if args: if args:
@ -195,6 +221,9 @@ def main():
elif options.create: elif options.create:
create_extension() create_extension()
elif options.reload:
reload_extension(options.reload)
else: else:
parser.print_usage() parser.print_usage()
sys.exit(1) sys.exit(1)