With the release of Ubuntu 11.04, the Unity shell rather unexpectedly took the place of the default shell. The appearance of Unity in Ubuntu Netbook Edition, despite the slow speed of work, was quite reasonable: it allowed the effective use of small screens of netbooks, thanks to, for example, a vertical panel for switching between running programs. Why did it become necessary to transfer Unity to desktops? It would be possible to answer this question now. However, such an incomplete, without ready-made examples, a subjective response would hardly satisfy the user, who at the moment had to face the inconvenience of the transition. Therefore, we will talk about how to improve, and not about how and why to survive.unityfox - chrome ---- content ------ main.xul - chrome.manifest - install.rdf
<? xml version = "1.0" ?>
<RDF xmlns = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns: em = "http://www.mozilla.org/2004/em-rdf#" >
<Description about = "urn: mozilla: install-manifest" >
<em: id > unityfox@mozilla.org </ em: id >
<em: version > 0.1.3 </ em: version >
<em: type > 2 </ em: type >
<em: targetApplication >
<Description >
<em: id > {ec8030f7-c20a-464f-9b0e-13a3a9e97384} </ em: id >
<em: minVersion > 4.0 </ em: minVersion >
<em: maxVersion > 6.0a1 </ em: maxVersion >
</ Description >
</ em: targetApplication >
<em: name > unityfox </ em: name >
<em: description > Integration with the Ubuntu Unity panel </ em: description >
<em: creator > Lockal </ em: creator >
</ Description >
</ Rdf >
This tells the browser to download our main.xul file along with the browser.xul browser interface.content unityfox chrome / content / overlay chrome: //browser/content/browser.xul chrome: //unityfox/content/main.xul
<? xml version = "1.0"?>
<overlay id = "unityfox"
xmlns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type = "text / javascript" >
// In Firefox extensions, it is customary to be careful about the global area in xul
if ( "undefined" == typeof ( unityProgress ) ) {
var unityProgress = {
setup : function ( ) {
// Load the ctypes module to access the system libraries
Components. utils . import ( "resource: //gre/modules/ctypes.jsm" ) ;
// Execute libunity.so.4 loading
// We do not need the extension to generate errors in the absence of libunity
try {
this . libunity = ctypes. open ( "libunity.so.4" ) ;
} catch ( err ) { return ; }
// Describe the necessary functions libunity
this . getEntry = this . libunity . declare ( "unity_launcher_entry_get_for_desktop_id" ,
ctypes. default_abi ,
ctypes. voidptr_t ,
ctypes. char . ptr ) ;
this . setProgress = this . libunity . declare ( "unity_launcher_entry_set_progress" ,
ctypes. default_abi ,
ctypes. void_t ,
ctypes. voidptr_t ,
ctypes. double ) ;
this . setVisibilityP = this . libunity . declare ( "unity_launcher_entry_set_progress_visible" ,
ctypes. default_abi ,
ctypes. void_t ,
ctypes. voidptr_t ,
ctypes. int ) ;
this . setVisibilityN = this . libunity . declare ( "unity_launcher_entry_set_count_visible" ,
ctypes. default_abi ,
ctypes. void_t ,
ctypes. voidptr_t ,
ctypes. int ) ;
this . setCount = this . libunity . declare ( "unity_launcher_entry_set_count" ,
ctypes. default_abi ,
ctypes. void_t ,
ctypes. voidptr_t ,
ctypes. long ) ;
// all main functions of libunity library work with UnityLauncherEntry *
this . entry = this . getEntry ( "firefox.desktop" ) ;
this . Cc = Components. classes ;
this . Ci = Components. interfaces ;
this . IDLM = this . Ci . nsIDownloadManager ;
// The panel will be updated using the download-manager service
// Interfaces of all embedded services are described at https://developer.mozilla.org
this . dlMgr = this . Cc [ "@ mozilla.org / download-manager; 1" ] . getService ( this . IDLM ) ;
this . dlMgr . addListener ( this ) ;
} ,
// The update function is called on each event from download-manager
update : function ( ) {
var total = 0 , cur = 0 , count = 0 ;
var dls = this . dlMgr . activeDownloads ;
while ( dls. hasMoreElements ( ) ) {
var dl = dls. getNext ( ) . QueryInterface ( this . Ci . NsIDownload ) ;
// Skip inactive downloads and downloads, the end time of which is unknown
if ( dl. state ! = this . IDLM . DOWNLOAD_DOWNLOADING || dl. percentComplete == - 1 )
continue ;
// Consider the total size, the loaded size and the number of downloads
total + = dl. size ;
cur + = dl. amountTransferred ;
count ++;
}
if ( total == 0 ) {
// If there are no downloads, hide the counter and the bar on the panel
this . setVisibilityP ( this . entry , 0 ) ;
this . setVisibilityN ( this . entry , 0 ) ;
} else {
// Show the download progress (from 0 to 1) and the number of downloads
this . setProgress ( this . entry , cur / total ) ;
this . setCount ( this . entry , count ) ;
this . setVisibilityP ( this . entry , 1 ) ;
this . setVisibilityN ( this . entry , 1 ) ;
}
} ,
// This object is nsIDownloadProgressListener in combination.
// nsIDownloadManager will send messages to the functions described below.
onDownloadStateChange : function ( ) { this . update ( ) } ,
onStateChange : function ( ) { this . update ( ) } ,
onProgressChange : function ( ) { this . update ( ) } ,
onSecurityChange : function ( ) { this . update ( ) }
} ;
}
// Finally, initialize unityProgress via the so-called. anonymous namespace
( function ( ) { this . setup ( ) ; } ) . apply ( unityProgress ) ;
</ script>
</ overlay>
Source: https://habr.com/ru/post/118678/
All Articles