]> 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 =
22 console: console
23 require: require
24 exports: {}
25 try
26 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
27 loader.loadSubScript(path, scope)
28 packages[name] = scope.exports
29 catch error
30 dump("Failed to load #{ name }: #{ error }\n")
31
32 return packages[name]
33
34 # Load up console that is defined above
35 { console } = require 'console'
36
37 # Unload all packages
38 release = ->
39 for path, scope in packages
40 for name, value in scope
41 scope[name] = null
42 packages = {}
43
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'
49 { getPref
50 , initPrefValues } = require 'prefs'
51 { setButtonInstallPosition
52 , addToolbarButton } = require 'button'
53 { watchWindows } = require 'window-utils'
54 { unload } = require 'unload'
55
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'
60
61 # Write default preference values on install
62 initPrefValues()
63
64 loadCss('style')
65
66 watchWindows(addEventListeners, 'navigator:browser')
67 watchWindows(addToolbarButton, 'navigator:browser')
68
69 unload(release)
70
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'
76 unload()
77
78 global.install = (data, reason) ->
79
80 global.uninstall = (data, reason) ->
Imprint / Impressum