3 { classes: Cc, interfaces: Ci, utils: Cu } = Components
5 Cu.import('resource://gre/modules/Services.jsm')
7 # Populate the global namespace with console, require, and include
9 loader = Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader)
10 baseURI = Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)
12 # Loaded packages cache
15 # Load and cache package
17 if packages[name] is undefined
22 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
23 loader.loadSubScript(path, scope)
24 packages[name] = scope.exports
26 dump("Failed to load #{ name }: #{ error }\n")
32 for path, scope in packages
33 for name, value in scope
37 # Firefox will call this method on startup/enabling
38 global.startup = (data, reason) ->
39 # Requires for startup/install
40 { loadCss } = require 'utils'
41 { addEventListeners } = require 'events'
43 , initPrefValues } = require 'prefs'
44 { setButtonInstallPosition
45 , addToolbarButton } = require 'button'
46 { watchWindows } = require 'window-utils'
47 { unload } = require 'unload'
49 if reason == ADDON_INSTALL
50 # Position the toolbar button right before the default Bookmarks button
51 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
52 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
54 # Write default preference values on install
59 watchWindows(addEventListeners, 'navigator:browser')
60 watchWindows(addToolbarButton, 'navigator:browser')
64 # Firefox will call this method on shutdown/disabling
65 global.shutdown = (data, reason) ->
66 # Don't bother to clean up if the browser is shutting down
67 if reason != APP_SHUTDOWN
68 { unload } = require 'unload'
71 global.install = (data, reason) ->
73 global.uninstall = (data, reason) ->