]> git.gir.st - VimFx.git/blob - extension/bootstrap.coffee
Merge branch 'release-0.4'
[VimFx.git] / extension / bootstrap.coffee
1 "use strict"
2
3 { utils: Cu, classes: Cc, interfaces: Ci } = 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 loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
14
15 include = (src, scope = {}) ->
16 try
17 uri = getResourceURI src
18 loader.loadSubScript uri.spec, scope
19 catch error
20 dump "Failed to load #{ src }: #{ error }\n"
21
22 return scope
23
24
25 modules = {}
26 require = (src) ->
27 if modules[src]
28 return modules[src]
29 else
30 scope =
31 require: require
32 include: include
33 exports: {}
34
35 include "packages/#{ src }.js", scope
36
37 return modules[src] = scope.exports;
38
39 global.include = include
40 global.require = require
41 global.getResourceURI = getResourceURI
42
43 # Include into global scope
44 include("includes/#{ name }.js", global) for name in [
45 'chrome',
46 'console',
47 'unload',
48 ]
49
50 # Init localization `underscore` method
51 global._ = require('l10n').l10n "vimfx.properties"
52
53 # Requires for startup/install
54 { loadCss } = require 'utils'
55 { addEventListeners } = require 'events'
56 { getPref
57 , installPrefObserver
58 , transferPrefs } = require 'prefs'
59 { setButtonInstallPosition
60 , addToolbarButton } = require 'button'
61 wu = require 'window-utils'
62
63 # Firefox will call this method on startup/enabling
64 global.startup = (data, reason) ->
65
66 if reason == ADDON_INSTALL
67 # Position the toolbar button right before the default Bookmarks button
68 # If Bookmarks button is hidden - then VimFx button will be appended to the toolbar
69 setButtonInstallPosition 'nav-bar', 'bookmarks-menu-button-container'
70 else if reason == ADDON_UPGRADE
71 if data["version"] > "0.3.3"
72 transferPrefs "extension.VimFx.", "extensions.VimFx."
73
74 loadCss 'style'
75 wu.watchWindows addEventListeners, 'navigator:browser'
76 wu.watchWindows addToolbarButton, 'navigator:browser'
77 installPrefObserver()
78
79 # Firefox will call this method on shutdown/disabling
80 global.shutdown = (data, reason) ->
81 # Don't bother to clean up if the browser is shutting down
82 if reason != APP_SHUTDOWN
83 unload()
84
85 global.install = (data, reason) ->
86
87 global.uninstall = (data, reason) ->
88
Imprint / Impressum