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
26 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
27 loader.loadSubScript(path, scope)
28 packages[name] = scope.exports
30 dump("Failed to load #{ name }: #{ error }\n")
34 # Load up console that is defined above
35 { console } = require 'console'
39 for path, scope in packages
40 for name, value in scope
44 # Firefox will call this method on startup/enabling
45 global.startup = (data, reason) ->
46 # Requires for startup/install
47 { loadCss } = require 'utils'
48 { addEventListeners } = require 'events'
50 , initPrefValues } = require 'prefs'
51 { setButtonInstallPosition
52 , addToolbarButton } = require 'button'
53 { watchWindows } = require 'window-utils'
54 { unload } = require 'unload'
56 if reason == ADDON_INSTALL
57 # Position the toolbar button right before the default Bookmarks button
58 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
59 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
61 # Write default preference values on install
66 watchWindows(addEventListeners, 'navigator:browser')
67 watchWindows(addToolbarButton, 'navigator:browser')
71 # Firefox will call this method on shutdown/disabling
72 global.shutdown = (data, reason) ->
73 # Don't bother to clean up if the browser is shutting down
74 if reason != APP_SHUTDOWN
75 { unload } = require 'unload'
78 global.install = (data, reason) ->
80 global.uninstall = (data, reason) ->