]> 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 # Load and cache package
16 require = (name) ->
17 if packages[name] is undefined
18 scope =
19 require: require
20 exports: {}
21 try
22 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
23 loader.loadSubScript(path, scope)
24 packages[name] = scope.exports
25 catch error
26 dump("Failed to load #{ name }: #{ error }\n")
27
28 return packages[name]
29
30 # Unload all packages
31 release = ->
32 for path, scope in packages
33 for name, value in scope
34 scope[name] = null
35 packages = {}
36
37 # Firefox will call this method on startup/enabling
38 global.startup = (data, reason) ->
39 # Requires for startup/install
40 { loadCss } = require 'utils'
41 { addEventListeners } = require 'events'
42 { getPref
43 , initPrefValues } = require 'prefs'
44 { setButtonInstallPosition
45 , addToolbarButton } = require 'button'
46 { watchWindows } = require 'window-utils'
47 { unload } = require 'unload'
48
49 if reason == ADDON_INSTALL
50 # Position the toolbar button right before the default Bookmarks button
51 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
52 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
53
54 # Write default preference values on install
55 initPrefValues()
56
57 loadCss('style')
58
59 watchWindows(addEventListeners, 'navigator:browser')
60 watchWindows(addToolbarButton, 'navigator:browser')
61
62 unload(release)
63
64 # Firefox will call this method on shutdown/disabling
65 global.shutdown = (data, reason) ->
66 # Don't bother to clean up if the browser is shutting down
67 if reason != APP_SHUTDOWN
68 { unload } = require 'unload'
69 unload()
70
71 global.install = (data, reason) ->
72
73 global.uninstall = (data, reason) ->
Imprint / Impressum