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 # To be loaded in a bit
18 # Load and cache package
20 if packages[name] is undefined
21 scope = { console, require, exports: {} }
23 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
24 loader.loadSubScript(path, scope)
25 packages[name] = scope.exports
27 dump("Failed to load #{ name }: #{ error }\n")
32 # Load up console that is defined above
33 { console } = require 'console'
37 for path, scope in packages
38 for name, value in scope
42 # Firefox will call this method on startup/enabling
43 global.startup = (data, reason) ->
44 # Requires for startup/install
45 { loadCss } = require 'utils'
46 { addEventListeners } = require 'events'
48 , initPrefValues } = require 'prefs'
49 { setButtonInstallPosition
50 , addToolbarButton } = require 'button'
51 options = require 'options'
52 { watchWindows } = require 'window-utils'
53 { unload } = require 'unload'
55 if reason == ADDON_INSTALL
56 # Position the toolbar button right before the default Bookmarks button
57 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
58 setButtonInstallPosition('nav-bar', 'bookmarks-menu-button-container')
60 # Write default preference values on install
67 watchWindows(addEventListeners, 'navigator:browser')
68 watchWindows(addToolbarButton, 'navigator:browser')
72 # Firefox will call this method on shutdown/disabling
73 global.shutdown = (data, reason) ->
74 # Don't bother to clean up if the browser is shutting down
75 if reason != APP_SHUTDOWN
76 { unload } = require 'unload'
79 global.install = (data, reason) ->
81 global.uninstall = (data, reason) ->