]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Reorganized code, removed memory leaks
[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/AddonManager.jsm')
7
8 # Populate the global namespace with console, require, and include
9 do (global = this) ->
10 loader = Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader)
11 baseURI = Services.io.newURI(__SCRIPT_URI_SPEC__, null, null)
12
13 include = (src, scope) ->
14 try
15 path = Services.io.newURI(src, null, baseURI).spec
16 loader.loadSubScript(path, scope)
17 catch error
18 dump("Failed to load #{ src }: #{ error }\n")
19
20 return scope
21
22
23 modules = {}
24 require = (src) ->
25 if modules[src]
26 return modules[src]
27 else
28 scope =
29 require: require
30 exports: {}
31
32 include("packages/#{ src }.js", scope)
33
34 return modules[src] = scope.exports
35
36 release = ->
37 for path, scope in modules
38 for name, value in scope
39 scope[name] = null
40 modules = {}
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 } = require 'prefs'
48 { setButtonInstallPosition
49 , addToolbarButton } = require 'button'
50 { watchWindows } = require 'window-utils'
51 { unload } = require 'unload'
52
53 if reason == ADDON_INSTALL
54 # Position the toolbar button right before the default Bookmarks button
55 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
56 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
57
58 loadCss('style')
59
60 watchWindows(addEventListeners, 'navigator:browser')
61 watchWindows(addToolbarButton, 'navigator:browser')
62
63 unload(release)
64
65 # Firefox will call this method on shutdown/disabling
66 global.shutdown = (data, reason) ->
67 # Don't bother to clean up if the browser is shutting down
68 if reason != APP_SHUTDOWN
69 { unload } = require 'unload'
70 unload()
71
72 global.install = (data, reason) ->
73
74 global.uninstall = (data, reason) ->
Imprint / Impressum