3 { utils: Cu } = Components
5 Cu.import "resource://gre/modules/Services.jsm"
6 Cu.import "resource://gre/modules/AddonManager.jsm"
8 # Populate the global namespace with console, require, and include
10 baseURI = Services.io.newURI __SCRIPT_URI_SPEC__, null, null
11 getResourceURI = (path) -> Services.io.newURI path, null, baseURI
13 include = (src, scope = {}) ->
15 uri = getResourceURI "packages/#{ src }.js"
16 Services.scriptloader.loadSubScript uri.spec, scope
18 uri = getResourceURI src
19 Services.scriptloader.loadSubScript uri.spec, scope
36 return modules[src] = scope.exports;
38 global.include = include
39 global.require = require
40 global.getResourceURI = getResourceURI
42 # Include into global scope
43 include("includes/#{ name }.js", global) for name in [
50 # Init localization `underscore` method
51 { l10n } = require 'l10n'
52 global._ = l10n "vimfx.properties"
54 { loadCss } = require 'utils'
55 { addEventListeners } = require 'events'
57 , installPrefObserver } = require 'prefs'
58 { setButtonInstallPosition
59 , addToolbarButton } = require 'button'
61 # Firefox will call this method on startup/enabling
62 global.startup = (data, reason) ->
65 if reason = ADDON_INSTALL
66 # Position the toolbar button right before the default Bookmarks button
67 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
68 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
71 watchWindows addEventListeners, 'navigator:browser'
72 watchWindows addToolbarButton, 'navigator:browser'
75 # Firefox will call this method on shutdown/disabling
76 global.shutdown = (data, reason) ->
77 # Don't bother to clean up if the browser is shutting down
78 if reason != APP_SHUTDOWN