2019-01-31 09:07:06 -05:00
/* exported main */
2019-08-21 13:36:42 -04:00
imports . gi . versions . Gdk = '3.0' ;
imports . gi . versions . Gtk = '3.0' ;
2012-01-18 21:21:56 -05:00
const Gettext = imports . gettext ;
2019-02-08 22:21:36 -05:00
const { Gdk , GLib , Gio , GObject , Gtk , Pango } = imports . gi ;
2012-05-04 17:23:08 -04:00
const Format = imports . format ;
2012-01-18 21:21:56 -05:00
const _ = Gettext . gettext ;
const ExtensionUtils = imports . misc . extensionUtils ;
2018-09-05 20:55:20 -04:00
const { loadInterfaceXML } = imports . misc . fileUtils ;
2012-01-18 21:21:56 -05:00
2018-11-01 08:55:17 -04:00
const { ExtensionState } = ExtensionUtils ;
2018-09-05 20:55:20 -04:00
const GnomeShellIface = loadInterfaceXML ( 'org.gnome.Shell.Extensions' ) ;
2012-01-18 21:21:56 -05:00
const GnomeShellProxy = Gio . DBusProxy . makeProxyWrapper ( GnomeShellIface ) ;
function stripPrefix ( string , prefix ) {
if ( string . slice ( 0 , prefix . length ) == prefix )
return string . slice ( prefix . length ) ;
return string ;
}
2019-10-28 14:35:33 -04:00
var Application = GObject . registerClass (
class Application extends Gtk . Application {
2019-05-28 17:22:37 -04:00
_init ( ) {
2012-01-18 21:21:56 -05:00
GLib . set _prgname ( 'gnome-shell-extension-prefs' ) ;
2019-05-28 17:22:37 -04:00
super . _init ( {
2012-01-18 21:21:56 -05:00
application _id : 'org.gnome.shell.ExtensionPrefs' ,
2019-08-20 17:43:54 -04:00
flags : Gio . ApplicationFlags . HANDLES _COMMAND _LINE ,
2012-01-18 21:21:56 -05:00
} ) ;
2019-11-29 20:48:18 -05:00
}
get shellProxy ( ) {
return this . _shellProxy ;
}
vfunc _activate ( ) {
this . _window . present ( ) ;
}
vfunc _startup ( ) {
super . vfunc _startup ( ) ;
this . _shellProxy = new GnomeShellProxy ( Gio . DBus . session , 'org.gnome.Shell' , '/org/gnome/Shell' ) ;
this . _window = new ExtensionsWindow ( { application : this } ) ;
}
vfunc _command _line ( commandLine ) {
let args = commandLine . get _arguments ( ) ;
if ( args . length ) {
let uuid = args [ 0 ] ;
// Strip off "extension:///" prefix which fakes a URI, if it exists
uuid = stripPrefix ( uuid , 'extension:///' ) ;
this . _window . openPrefs ( uuid ) ;
} else {
this . activate ( ) ;
}
return 0 ;
}
} ) ;
2019-11-29 20:48:18 -05:00
var ExtensionsWindow = GObject . registerClass ( {
GTypeName : 'ExtensionsWindow' ,
Template : 'resource:///org/gnome/shell/ui/extensions-window.ui' ,
InternalChildren : [
'extensionsList' ,
'killSwitch' ,
2020-01-29 19:28:02 -05:00
'mainBox' ,
2019-11-29 20:48:18 -05:00
'mainStack' ,
2020-01-29 19:28:02 -05:00
'scrolledWindow' ,
2019-11-29 20:48:18 -05:00
] ,
} , class ExtensionsWindow extends Gtk . ApplicationWindow {
2019-11-29 20:48:18 -05:00
_init ( params ) {
super . _init ( params ) ;
2012-01-18 21:21:56 -05:00
2013-02-28 08:50:56 -05:00
this . _startupUuid = null ;
2014-05-26 19:36:41 -04:00
this . _loaded = false ;
2019-11-29 20:48:18 -05:00
this . _prefsDialog = null ;
2020-01-29 19:28:02 -05:00
this . _mainBox . set _focus _vadjustment ( this . _scrolledWindow . vadjustment ) ;
2019-11-29 20:48:18 -05:00
this . _settings = new Gio . Settings ( { schema _id : 'org.gnome.shell' } ) ;
this . _settings . bind ( 'disable-user-extensions' ,
this . _killSwitch , 'active' ,
Gio . SettingsBindFlags . DEFAULT | Gio . SettingsBindFlags . INVERT _BOOLEAN ) ;
2019-11-29 20:48:18 -05:00
this . _extensionsList . set _sort _func ( this . _sortList . bind ( this ) ) ;
this . _extensionsList . set _header _func ( this . _updateHeader . bind ( this ) ) ;
2019-11-29 20:48:18 -05:00
this . _shellProxy . connectSignal ( 'ExtensionStateChanged' ,
this . _onExtensionStateChanged . bind ( this ) ) ;
this . _scanExtensions ( ) ;
2018-11-01 08:55:17 -04:00
}
2019-11-29 20:48:18 -05:00
get _shellProxy ( ) {
return this . application . shellProxy ;
}
openPrefs ( uuid ) {
if ( ! this . _loaded )
this . _startupUuid = uuid ;
else if ( ! this . _showPrefs ( uuid ) )
this . present ( ) ;
2017-10-30 21:19:44 -04:00
}
2012-01-18 21:21:56 -05:00
2018-11-01 08:50:30 -04:00
_showPrefs ( uuid ) {
2019-11-29 20:48:18 -05:00
if ( this . _prefsDialog )
return false ;
2019-11-29 20:48:18 -05:00
let row = this . _extensionsList . get _children ( ) . find ( c => {
2018-11-01 08:50:30 -04:00
return c . uuid === uuid && c . hasPrefs ;
} ) ;
2012-01-18 21:21:56 -05:00
2018-11-01 08:50:30 -04:00
if ( ! row )
2012-01-18 21:21:56 -05:00
return false ;
let widget ;
try {
2018-11-01 08:50:30 -04:00
widget = row . prefsModule . buildPrefsWidget ( ) ;
2012-01-18 21:21:56 -05:00
} catch ( e ) {
2018-11-01 08:50:30 -04:00
widget = this . _buildErrorUI ( row , e ) ;
2012-01-18 21:21:56 -05:00
}
2019-11-29 20:48:18 -05:00
this . _prefsDialog = new Gtk . Window ( {
application : this . application ,
default _width : 600 ,
default _height : 400 ,
modal : this . visible ,
2019-08-20 17:43:54 -04:00
type _hint : Gdk . WindowTypeHint . DIALOG ,
2019-11-29 20:48:18 -05:00
window _position : Gtk . WindowPosition . CENTER ,
2018-11-01 08:50:30 -04:00
} ) ;
2019-11-29 20:48:18 -05:00
this . _prefsDialog . set _titlebar ( new Gtk . HeaderBar ( {
2018-11-01 08:50:30 -04:00
show _close _button : true ,
title : row . name ,
2019-08-20 17:43:54 -04:00
visible : true ,
2018-11-01 08:50:30 -04:00
} ) ) ;
2014-05-26 19:36:41 -04:00
2019-11-29 20:48:18 -05:00
if ( this . visible )
this . _prefsDialog . transient _for = this ;
this . _prefsDialog . connect ( 'destroy' , ( ) => {
this . _prefsDialog = null ;
if ( ! this . visible )
this . destroy ( ) ;
} ) ;
2014-05-26 19:36:41 -04:00
2019-11-29 20:48:18 -05:00
this . _prefsDialog . add ( widget ) ;
this . _prefsDialog . show ( ) ;
2019-07-20 18:07:00 -04:00
return true ;
2017-10-30 21:19:44 -04:00
}
2012-01-18 21:21:56 -05:00
2018-11-01 08:50:30 -04:00
_buildErrorUI ( row , exc ) {
2018-08-05 22:15:12 -04:00
let scroll = new Gtk . ScrolledWindow ( {
hscrollbar _policy : Gtk . PolicyType . NEVER ,
2019-08-20 17:43:54 -04:00
propagate _natural _height : true ,
2018-08-05 22:15:12 -04:00
} ) ;
let box = new Gtk . Box ( {
orientation : Gtk . Orientation . VERTICAL ,
spacing : 12 ,
margin : 100 ,
2019-08-20 17:43:54 -04:00
margin _bottom : 60 ,
2018-08-05 22:15:12 -04:00
} ) ;
scroll . add ( box ) ;
2012-01-18 21:21:56 -05:00
let label = new Gtk . Label ( {
2019-02-01 14:11:39 -05:00
label : '<span size="x-large">%s</span>' . format ( _ ( "Something’ s gone wrong" ) ) ,
2019-08-20 17:43:54 -04:00
use _markup : true ,
2018-08-05 22:15:12 -04:00
} ) ;
label . get _style _context ( ) . add _class ( Gtk . STYLE _CLASS _DIM _LABEL ) ;
box . add ( label ) ;
label = new Gtk . Label ( {
label : _ ( "We’ re very sorry, but there’ s been a problem: the settings for this extension can’ t be displayed. We recommend that you report the issue to the extension authors." ) ,
justify : Gtk . Justification . CENTER ,
2019-08-20 17:43:54 -04:00
wrap : true ,
2012-01-18 21:21:56 -05:00
} ) ;
box . add ( label ) ;
2018-08-05 22:15:12 -04:00
let expander = new Expander ( {
label : _ ( "Technical Details" ) ,
2019-08-20 17:43:54 -04:00
margin _top : 12 ,
2018-08-05 22:15:12 -04:00
} ) ;
box . add ( expander ) ;
2012-01-18 21:21:56 -05:00
2018-08-05 22:15:12 -04:00
let errortext = ` ${ exc } \n \n Stack trace: \n ${
// Indent stack trace.
exc . stack . split ( '\n' ) . map ( line => ` ${ line } ` ) . join ( '\n' )
} ` ;
2012-01-18 21:21:56 -05:00
let buffer = new Gtk . TextBuffer ( { text : errortext } ) ;
2018-08-05 22:15:12 -04:00
let textview = new Gtk . TextView ( {
2019-08-19 15:06:04 -04:00
buffer ,
2018-08-05 22:15:12 -04:00
wrap _mode : Gtk . WrapMode . WORD ,
monospace : true ,
editable : false ,
top _margin : 12 ,
bottom _margin : 12 ,
left _margin : 12 ,
2019-08-20 17:43:54 -04:00
right _margin : 12 ,
2018-08-05 22:15:12 -04:00
} ) ;
let toolbar = new Gtk . Toolbar ( ) ;
let provider = new Gtk . CssProvider ( ) ;
provider . load _from _data ( ` * {
border : 0 solid @ borders ;
border - top - width : 1 px ;
} ` );
toolbar . get _style _context ( ) . add _provider (
provider ,
Gtk . STYLE _PROVIDER _PRIORITY _APPLICATION
) ;
let copyButton = new Gtk . ToolButton ( {
icon _name : 'edit-copy-symbolic' ,
2019-08-20 17:43:54 -04:00
tooltip _text : _ ( "Copy Error" ) ,
2018-08-05 22:15:12 -04:00
} ) ;
toolbar . add ( copyButton ) ;
copyButton . connect ( 'clicked' , w => {
let clipboard = Gtk . Clipboard . get _default ( w . get _display ( ) ) ;
2019-02-12 09:16:08 -05:00
// markdown for pasting in gitlab issues
let lines = [
2018-11-01 08:50:30 -04:00
` The settings of extension ${ row . uuid } had an error: ` ,
2019-10-29 09:01:07 -04:00
'```' , // '`' (xgettext throws up on odd number of backticks)
2019-02-12 09:16:08 -05:00
` ${ exc } ` ,
2019-10-29 09:01:07 -04:00
'```' , // '`'
2019-02-12 09:16:08 -05:00
'' ,
'Stack trace:' ,
2019-10-29 09:01:07 -04:00
'```' , // '`'
2019-02-12 09:16:08 -05:00
exc . stack . replace ( /\n$/ , '' ) , // stack without trailing newline
2019-10-29 09:01:07 -04:00
'```' , // '`'
2019-08-20 17:43:54 -04:00
'' ,
2019-02-12 09:16:08 -05:00
] ;
clipboard . set _text ( lines . join ( '\n' ) , - 1 ) ;
2018-08-05 22:15:12 -04:00
} ) ;
2012-01-18 21:21:56 -05:00
2018-08-05 22:15:12 -04:00
let spacing = new Gtk . SeparatorToolItem ( { draw : false } ) ;
toolbar . add ( spacing ) ;
toolbar . child _set _property ( spacing , "expand" , true ) ;
let urlButton = new Gtk . ToolButton ( {
label : _ ( "Homepage" ) ,
tooltip _text : _ ( "Visit extension homepage" ) ,
no _show _all : true ,
2019-08-20 17:43:54 -04:00
visible : row . url != null ,
2018-08-05 22:15:12 -04:00
} ) ;
toolbar . add ( urlButton ) ;
urlButton . connect ( 'clicked' , w => {
let context = w . get _display ( ) . get _app _launch _context ( ) ;
2018-11-01 08:50:30 -04:00
Gio . AppInfo . launch _default _for _uri ( row . url , context ) ;
2018-08-05 22:15:12 -04:00
} ) ;
let expandedBox = new Gtk . Box ( {
2019-08-20 17:43:54 -04:00
orientation : Gtk . Orientation . VERTICAL ,
2018-08-05 22:15:12 -04:00
} ) ;
expandedBox . add ( textview ) ;
expandedBox . add ( toolbar ) ;
expander . add ( expandedBox ) ;
scroll . show _all ( ) ;
return scroll ;
2017-10-30 21:19:44 -04:00
}
2012-01-18 21:21:56 -05:00
2017-10-30 20:03:21 -04:00
_sortList ( row1 , row2 ) {
2018-11-01 08:50:30 -04:00
return row1 . name . localeCompare ( row2 . name ) ;
2017-10-30 21:19:44 -04:00
}
2014-05-22 22:49:37 -04:00
2017-10-30 20:03:21 -04:00
_updateHeader ( row , before ) {
2014-05-22 22:49:37 -04:00
if ( ! before || row . get _header ( ) )
return ;
let sep = new Gtk . Separator ( { orientation : Gtk . Orientation . HORIZONTAL } ) ;
row . set _header ( sep ) ;
2017-10-30 21:19:44 -04:00
}
2014-05-22 22:49:37 -04:00
2018-11-01 08:55:17 -04:00
_findExtensionRow ( uuid ) {
2019-11-29 20:48:18 -05:00
return this . _extensionsList . get _children ( ) . find ( c => c . uuid === uuid ) ;
2018-11-01 08:55:17 -04:00
}
_onExtensionStateChanged ( proxy , senderName , [ uuid , newState ] ) {
2019-11-30 00:01:44 -05:00
let extension = ExtensionUtils . deserializeExtension ( newState ) ;
2018-11-01 08:55:17 -04:00
let row = this . _findExtensionRow ( uuid ) ;
2019-11-30 00:01:44 -05:00
2018-11-01 08:55:17 -04:00
if ( row ) {
2019-11-30 00:01:44 -05:00
if ( extension . state === ExtensionState . UNINSTALLED )
2018-11-01 08:55:17 -04:00
row . destroy ( ) ;
return ; // we only deal with new and deleted extensions here
}
2019-11-30 00:01:44 -05:00
this . _addExtensionRow ( extension ) ;
2018-11-01 08:55:17 -04:00
}
2017-10-30 20:03:21 -04:00
_scanExtensions ( ) {
2018-11-01 08:55:17 -04:00
this . _shellProxy . ListExtensionsRemote ( ( [ extensionsMap ] , e ) => {
if ( e ) {
if ( e instanceof Gio . DBusError ) {
log ( ` Failed to connect to shell proxy: ${ e } ` ) ;
this . _mainStack . visible _child _name = 'noshell' ;
2019-08-19 20:51:42 -04:00
} else {
2018-11-01 08:55:17 -04:00
throw e ;
2019-08-19 20:51:42 -04:00
}
2018-11-01 08:55:17 -04:00
return ;
}
for ( let uuid in extensionsMap ) {
let extension = ExtensionUtils . deserializeExtension ( extensionsMap [ uuid ] ) ;
this . _addExtensionRow ( extension ) ;
}
this . _extensionsLoaded ( ) ;
} ) ;
2017-10-30 21:19:44 -04:00
}
2012-01-18 21:21:56 -05:00
2018-11-01 08:55:17 -04:00
_addExtensionRow ( extension ) {
2018-11-01 08:50:30 -04:00
let row = new ExtensionRow ( extension ) ;
2014-05-22 22:49:37 -04:00
2017-10-30 20:38:18 -04:00
row . prefsButton . connect ( 'clicked' , ( ) => {
2018-11-01 08:50:30 -04:00
this . _showPrefs ( row . uuid ) ;
2017-10-30 20:38:18 -04:00
} ) ;
2014-05-22 22:49:37 -04:00
row . show _all ( ) ;
2019-11-29 20:48:18 -05:00
this . _extensionsList . add ( row ) ;
2017-10-30 21:19:44 -04:00
}
2012-06-04 17:14:18 -04:00
2017-10-30 20:03:21 -04:00
_extensionsLoaded ( ) {
2019-11-29 20:48:18 -05:00
if ( this . _extensionsList . get _children ( ) . length > 0 )
this . _mainStack . visible _child _name = 'main' ;
2018-08-05 20:31:18 -04:00
else
this . _mainStack . visible _child _name = 'placeholder' ;
2018-11-01 08:50:30 -04:00
if ( this . _startupUuid )
this . _showPrefs ( this . _startupUuid ) ;
2013-02-28 08:50:56 -05:00
this . _startupUuid = null ;
2014-05-26 19:36:41 -04:00
this . _loaded = true ;
2017-10-30 21:19:44 -04:00
}
2019-05-28 17:22:37 -04:00
} ) ;
2012-01-18 21:21:56 -05:00
2018-08-05 22:15:12 -04:00
var Expander = GObject . registerClass ( {
Properties : {
'label' : GObject . ParamSpec . string (
'label' , 'label' , 'label' ,
GObject . ParamFlags . READWRITE ,
null
2019-08-20 17:43:54 -04:00
) ,
} ,
2018-08-05 22:15:12 -04:00
} , class Expander extends Gtk . Box {
_init ( params = { } ) {
this . _labelText = null ;
super . _init ( Object . assign ( params , {
orientation : Gtk . Orientation . VERTICAL ,
2019-08-20 17:43:54 -04:00
spacing : 0 ,
2018-08-05 22:15:12 -04:00
} ) ) ;
this . _frame = new Gtk . Frame ( {
shadow _type : Gtk . ShadowType . IN ,
2019-08-20 17:43:54 -04:00
hexpand : true ,
2018-08-05 22:15:12 -04:00
} ) ;
let eventBox = new Gtk . EventBox ( ) ;
this . _frame . add ( eventBox ) ;
let hbox = new Gtk . Box ( {
spacing : 6 ,
2019-08-20 17:43:54 -04:00
margin : 12 ,
2018-08-05 22:15:12 -04:00
} ) ;
eventBox . add ( hbox ) ;
this . _arrow = new Gtk . Image ( {
2019-08-20 17:43:54 -04:00
icon _name : 'pan-end-symbolic' ,
2018-08-05 22:15:12 -04:00
} ) ;
hbox . add ( this . _arrow ) ;
this . _label = new Gtk . Label ( { label : this . _labelText } ) ;
hbox . add ( this . _label ) ;
this . _revealer = new Gtk . Revealer ( ) ;
this . _childBin = new Gtk . Frame ( {
2019-08-20 17:43:54 -04:00
shadow _type : Gtk . ShadowType . IN ,
2018-08-05 22:15:12 -04:00
} ) ;
this . _revealer . add ( this . _childBin ) ;
// Directly chain up to parent for internal children
super . add ( this . _frame ) ;
super . add ( this . _revealer ) ;
let provider = new Gtk . CssProvider ( ) ;
provider . load _from _data ( '* { border-top-width: 0; }' ) ;
this . _childBin . get _style _context ( ) . add _provider (
provider ,
Gtk . STYLE _PROVIDER _PRIORITY _APPLICATION
) ;
this . _gesture = new Gtk . GestureMultiPress ( {
widget : this . _frame ,
button : 0 ,
2019-08-20 17:43:54 -04:00
exclusive : true ,
2018-08-05 22:15:12 -04:00
} ) ;
this . _gesture . connect ( 'released' , ( gesture , nPress ) => {
if ( nPress == 1 )
this . _revealer . reveal _child = ! this . _revealer . reveal _child ;
} ) ;
this . _revealer . connect ( 'notify::reveal-child' , ( ) => {
if ( this . _revealer . reveal _child )
this . _arrow . icon _name = 'pan-down-symbolic' ;
else
this . _arrow . icon _name = 'pan-end-symbolic' ;
} ) ;
}
get label ( ) {
return this . _labelText ;
}
set label ( text ) {
if ( this . _labelText == text )
return ;
if ( this . _label )
this . _label . label = text ;
this . _labelText = text ;
this . notify ( 'label' ) ;
}
add ( child ) {
// set expanded child
this . _childBin . get _children ( ) . forEach ( c => {
this . _childBin . remove ( c ) ;
} ) ;
if ( child )
this . _childBin . add ( child ) ;
}
} ) ;
2017-10-30 21:23:39 -04:00
var DescriptionLabel = GObject . registerClass (
class DescriptionLabel extends Gtk . Label {
2017-10-30 20:03:21 -04:00
vfunc _get _preferred _height _for _width ( width ) {
2015-12-14 18:37:47 -05:00
// Hack: Request the maximum height allowed by the line limit
if ( this . lines > 0 )
2017-10-30 21:23:39 -04:00
return super . vfunc _get _preferred _height _for _width ( 0 ) ;
return super . vfunc _get _preferred _height _for _width ( width ) ;
2015-12-14 18:37:47 -05:00
}
} ) ;
2017-10-30 21:23:39 -04:00
var ExtensionRow = GObject . registerClass (
class ExtensionRow extends Gtk . ListBoxRow {
2018-11-01 08:50:30 -04:00
_init ( extension ) {
2017-10-30 21:23:39 -04:00
super . _init ( ) ;
2014-05-22 22:49:37 -04:00
2018-11-01 08:55:17 -04:00
this . _app = Gio . Application . get _default ( ) ;
2018-11-01 08:50:30 -04:00
this . _extension = extension ;
this . _prefsModule = null ;
2014-05-22 22:49:37 -04:00
2019-09-09 11:06:55 -04:00
this . connect ( 'destroy' , this . _onDestroy . bind ( this ) ) ;
this . _buildUI ( ) ;
2018-11-01 08:55:17 -04:00
this . _extensionStateChangedId = this . _app . shellProxy . connectSignal (
'ExtensionStateChanged' , ( p , sender , [ uuid , newState ] ) => {
if ( this . uuid !== uuid )
return ;
this . _extension = ExtensionUtils . deserializeExtension ( newState ) ;
2019-08-19 15:38:51 -04:00
let state = this . _extension . state == ExtensionState . ENABLED ;
2019-09-09 11:08:53 -04:00
2019-10-30 13:11:56 -04:00
this . _switch . block _signal _handler ( this . _notifyActiveId ) ;
2018-11-01 08:55:17 -04:00
this . _switch . state = state ;
2019-10-30 13:11:56 -04:00
this . _switch . unblock _signal _handler ( this . _notifyActiveId ) ;
2019-09-09 11:08:53 -04:00
2018-11-01 08:55:17 -04:00
this . _switch . sensitive = this . _canToggle ( ) ;
2017-10-30 20:38:18 -04:00
} ) ;
2017-10-30 21:23:39 -04:00
}
2014-05-22 22:49:37 -04:00
2018-11-01 08:50:30 -04:00
get uuid ( ) {
return this . _extension . uuid ;
}
get name ( ) {
return this . _extension . metadata . name ;
}
get hasPrefs ( ) {
return this . _extension . hasPrefs ;
}
2014-05-22 22:49:37 -04:00
2018-11-01 08:50:30 -04:00
get url ( ) {
return this . _extension . metadata . url ;
}
2018-11-01 08:55:17 -04:00
_onDestroy ( ) {
if ( ! this . _app . shellProxy )
return ;
if ( this . _extensionStateChangedId )
this . _app . shellProxy . disconnectSignal ( this . _extensionStateChangedId ) ;
this . _extensionStateChangedId = 0 ;
}
2018-11-01 08:50:30 -04:00
_buildUI ( ) {
2014-05-22 22:49:37 -04:00
let hbox = new Gtk . Box ( { orientation : Gtk . Orientation . HORIZONTAL ,
2015-12-14 18:37:47 -05:00
hexpand : true , margin _end : 24 , spacing : 24 ,
margin : 12 } ) ;
2014-05-22 22:49:37 -04:00
this . add ( hbox ) ;
let vbox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL ,
spacing : 6 , hexpand : true } ) ;
hbox . add ( vbox ) ;
2018-11-01 08:50:30 -04:00
let name = GLib . markup _escape _text ( this . name , - 1 ) ;
2014-05-22 22:49:37 -04:00
let label = new Gtk . Label ( { label : '<b>' + name + '</b>' ,
use _markup : true ,
halign : Gtk . Align . START } ) ;
vbox . add ( label ) ;
2018-11-01 08:50:30 -04:00
let desc = this . _extension . metadata . description . split ( '\n' ) [ 0 ] ;
2015-12-14 18:37:47 -05:00
label = new DescriptionLabel ( { label : desc , wrap : true , lines : 2 ,
ellipsize : Pango . EllipsizeMode . END ,
2019-11-30 01:27:48 -05:00
max _width _chars : 60 ,
2015-12-14 18:37:47 -05:00
xalign : 0 , yalign : 0 } ) ;
2014-05-22 22:49:37 -04:00
vbox . add ( label ) ;
let button = new Gtk . Button ( { valign : Gtk . Align . CENTER ,
2018-11-01 08:50:30 -04:00
visible : this . hasPrefs ,
2014-05-22 22:49:37 -04:00
no _show _all : true } ) ;
2019-04-05 12:24:09 -04:00
button . set _image ( new Gtk . Image ( { icon _name : 'emblem-system-symbolic' ,
icon _size : Gtk . IconSize . BUTTON ,
visible : true } ) ) ;
2016-03-03 18:48:02 -05:00
button . get _style _context ( ) . add _class ( 'circular' ) ;
2014-05-22 22:49:37 -04:00
hbox . add ( button ) ;
this . prefsButton = button ;
2014-05-26 17:40:26 -04:00
2018-11-01 08:55:17 -04:00
this . _switch = new Gtk . Switch ( {
valign : Gtk . Align . CENTER ,
sensitive : this . _canToggle ( ) ,
2019-08-20 17:43:54 -04:00
state : this . _extension . state === ExtensionState . ENABLED ,
2018-11-01 08:55:17 -04:00
} ) ;
2019-09-09 11:08:53 -04:00
this . _notifyActiveId = this . _switch . connect ( 'notify::active' , ( ) => {
2017-10-30 20:38:18 -04:00
if ( this . _switch . active )
2018-11-01 08:55:17 -04:00
this . _app . shellProxy . EnableExtensionRemote ( this . uuid ) ;
2017-10-30 20:38:18 -04:00
else
2018-11-01 08:55:17 -04:00
this . _app . shellProxy . DisableExtensionRemote ( this . uuid ) ;
2017-10-30 20:38:18 -04:00
} ) ;
this . _switch . connect ( 'state-set' , ( ) => true ) ;
2014-05-26 17:40:26 -04:00
hbox . add ( this . _switch ) ;
2017-10-30 21:23:39 -04:00
}
2014-05-26 17:40:26 -04:00
2018-11-01 08:55:17 -04:00
_canToggle ( ) {
return this . _extension . canChange ;
2014-05-22 22:49:37 -04:00
}
2018-11-01 08:50:30 -04:00
get prefsModule ( ) {
2019-11-30 13:15:14 -05:00
// give extension prefs access to their own extension object
ExtensionUtils . getCurrentExtension = ( ) => this . _extension ;
2018-11-01 08:50:30 -04:00
if ( ! this . _prefsModule ) {
ExtensionUtils . installImporter ( this . _extension ) ;
this . _prefsModule = this . _extension . imports . prefs ;
this . _prefsModule . init ( this . _extension . metadata ) ;
}
return this . _prefsModule ;
}
2014-05-22 22:49:37 -04:00
} ) ;
2012-01-18 21:21:56 -05:00
function initEnvironment ( ) {
// Monkey-patch in a "global" object that fakes some Shell utilities
// that ExtensionUtils depends on.
window . global = {
2019-02-12 06:24:30 -05:00
log ( ... args ) {
print ( args . join ( ', ' ) ) ;
2012-01-18 21:21:56 -05:00
} ,
2017-10-30 20:03:21 -04:00
logError ( s ) {
2019-01-29 19:18:24 -05:00
log ( ` ERROR: ${ s } ` ) ;
2012-01-18 21:21:56 -05:00
} ,
2019-08-20 17:43:54 -04:00
userdatadir : GLib . build _filenamev ( [ GLib . get _user _data _dir ( ) , 'gnome-shell' ] ) ,
2012-01-18 21:21:56 -05:00
} ;
String . prototype . format = Format . format ;
}
function main ( argv ) {
initEnvironment ( ) ;
2019-05-28 17:22:37 -04:00
new Application ( ) . run ( argv ) ;
2012-01-18 21:21:56 -05:00
}