]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Merge branch 'develop' into better-hintmarkers
[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 Cu.import('resource://gre/modules/devtools/Console.jsm')
7
8 do (global = this) ->
9 baseURI = Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)
10
11 # Loaded packages cache.
12 packages = {}
13
14 # Load and cache package.
15 require = (name) ->
16 unless packages[name]?
17 scope = {require, exports: packages[name] = {}}
18 try
19 path = Services.io.newURI("packages/#{ name }.js", null, baseURI).spec
20 Services.scriptloader.loadSubScript(path, scope)
21 catch error
22 dump("Failed to load #{ name }: #{ error }\n")
23 dump(error.stack)
24
25 return packages[name]
26
27 # Unload all packages.
28 release = ->
29 for path, scope in packages
30 for name, value in scope
31 scope[name] = null
32 packages = {}
33
34 global.startup = (data, reason) ->
35 { loadCss } = require 'utils'
36 { addEventListeners
37 , vimBucket } = require 'events'
38 { getPref
39 , setDefaultPrefs } = require 'prefs'
40 { setButtonInstallPosition
41 , addToolbarButton } = require 'button'
42 options = require 'options'
43 { watchWindows } = require 'window-utils'
44 { unloader } = require 'unloader'
45
46 setDefaultPrefs()
47
48 if reason == ADDON_INSTALL
49 # Position the toolbar button right before the default Bookmarks button.
50 # If Bookmarks button is hidden the VimFx button will be appended to the
51 # toolbar.
52 setButtonInstallPosition('nav-bar', 'bookmarks-menu-button-container')
53
54 loadCss('style')
55
56 options.observe()
57
58 watchWindows(addEventListeners, 'navigator:browser')
59 watchWindows(addToolbarButton.bind(undefined, vimBucket),
60 'navigator:browser')
61
62 unloader.add(release)
63
64 global.shutdown = (data, reason) ->
65 # Don't bother to clean up if the browser is shutting down.
66 unless reason == APP_SHUTDOWN
67 { unloader } = require 'unloader'
68 unloader.unload()
69
70 global.install = (data, reason) ->
71
72 global.uninstall = (data, reason) ->
Imprint / Impressum