]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Merge branch 'develop' into huffman
[VimFx.git] / extension / bootstrap.coffee
1 'use strict'
2
3 { classes: Cc, interfaces: Ci, utils: Cu } = Components
4
5 Cu.import('resource://gre/modules/Services.jsm')
6
7 # Populate the global namespace with console, require, and include
8 do (global = this) ->
9 loader = Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader)
10 baseURI = Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)
11
12 # Loaded packages cache
13 packages = {}
14
15 # To be loaded in a bit
16 console = null
17
18 # Load and cache package
19 require = (name) ->
20 if packages[name] is undefined
21 scope = { console, require, exports: {} }
22 try
23 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
24 loader.loadSubScript(path, scope)
25 packages[name] = scope.exports
26 catch error
27 dump("Failed to load #{ name }: #{ error }\n")
28 dump(error.stack)
29
30 return packages[name]
31
32 # Load up console that is defined above
33 { console } = require 'console'
34
35 # Unload all packages
36 release = ->
37 for path, scope in packages
38 for name, value in scope
39 scope[name] = null
40 packages = {}
41
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'
47 { getPref
48 , initPrefValues } = require 'prefs'
49 { setButtonInstallPosition
50 , addToolbarButton } = require 'button'
51 { watchWindows } = require 'window-utils'
52 { unload } = require 'unload'
53
54 if reason == ADDON_INSTALL
55 # Position the toolbar button right before the default Bookmarks button
56 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
57 setButtonInstallPosition('nav-bar', 'bookmarks-menu-button-container')
58
59 # Write default preference values on install
60 initPrefValues()
61
62 loadCss('style')
63
64 watchWindows(addEventListeners, 'navigator:browser')
65 watchWindows(addToolbarButton, 'navigator:browser')
66
67 unload(release)
68
69 # Firefox will call this method on shutdown/disabling
70 global.shutdown = (data, reason) ->
71 # Don't bother to clean up if the browser is shutting down
72 if reason != APP_SHUTDOWN
73 { unload } = require 'unload'
74 unload()
75
76 global.install = (data, reason) ->
77
78 global.uninstall = (data, reason) ->
Imprint / Impressum