]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Closes #13 (hopefully). I wasn't able to reproduce this issue on my machine. But...
[VimFx.git] / extension / bootstrap.coffee
1 "use strict"
2
3 { 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 baseURI = Services.io.newURI __SCRIPT_URI_SPEC__, null, null
11 getResourceURI = (path) -> Services.io.newURI path, null, baseURI
12
13 include = (src, scope = {}) ->
14 try
15 uri = getResourceURI "packages/#{ src }.js"
16 Services.scriptloader.loadSubScript uri.spec, scope
17 catch error
18 uri = getResourceURI src
19 Services.scriptloader.loadSubScript uri.spec, scope
20
21 return scope
22
23
24 modules = {}
25 require = (src) ->
26 if modules[src]
27 return modules[src]
28 else
29 scope =
30 require: require
31 include: include
32 exports: {}
33
34 include src, scope
35
36 return modules[src] = scope.exports;
37
38 global.include = include
39 global.require = require
40 global.getResourceURI = getResourceURI
41
42 # Include into global scope
43 include("includes/#{ name }.js", this) for name in [
44 'chrome',
45 'console',
46 'unload',
47 'window-utils',
48 ]
49
50 { loadCss } = require 'utils'
51 { addEventListeners } = require 'events'
52 { getPref
53 , installPrefObserver } = require 'prefs'
54 { setButtonInstallPosition
55 , addToolbarButton } = require 'button'
56
57 # Firefox will call this method on startup/enabling
58 startup = (data, reason) ->
59 if reason = ADDON_INSTALL
60 # Position the toolbar button right before the default Bookmarks button
61 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
62 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
63
64 loadCss 'style'
65 watchWindows addEventListeners, 'navigator:browser'
66 watchWindows addToolbarButton, 'navigator:browser'
67 installPrefObserver()
68
69 # Firefox will call this method on shutdown/disabling
70 shutdown = (data, reason) ->
71 # Don't bother to clean up if the browser is shutting down
72 if reason != APP_SHUTDOWN
73 unload()
Imprint / Impressum