]> git.gir.st - VimFx.git/blob - extension/lib/main.coffee
Add a link to the documentation in the Add-ons Manager
[VimFx.git] / extension / lib / main.coffee
1 ###
2 # Copyright Anton Khodakivskiy 2012, 2013, 2014.
3 # Copyright Simon Lydell 2013, 2014.
4 #
5 # This file is part of VimFx.
6 #
7 # VimFx is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # VimFx is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
19 ###
20
21 createAPI = require('./api')
22 button = require('./button')
23 defaults = require('./defaults')
24 { addEventListeners } = require('./events')
25 modes = require('./modes')
26 options = require('./options')
27 parsePref = require('./parse-prefs')
28 prefs = require('./prefs')
29 utils = require('./utils')
30 VimFx = require('./vimfx')
31 { watchWindows } = require('./window-utils')
32 test = try require('../test/index')
33
34 { utils: Cu } = Components
35
36 Cu.import('resource://gre/modules/AddonManager.jsm')
37
38 module.exports = (data, reason) ->
39 parsedOptions = {}
40 for pref of defaults.all_options
41 parsedOptions[pref] = parsePref(pref)
42 vimfx = new VimFx(modes, parsedOptions)
43 vimfx.id = data.id
44 vimfx.version = data.version
45 AddonManager.getAddonByID(vimfx.id, (info) -> vimfx.info = info)
46
47 # Setup the public API. The URL is encoded (which means that there will be
48 # only ASCII characters) so that the pref can be read using a simple
49 # `Services.prefs.getCharPref()` (which only supports ASCII characters).
50 api_url = encodeURI("#{ data.resourceURI.spec }lib/public.js")
51 { setAPI } = Cu.import(api_url, {})
52 setAPI(createAPI(vimfx))
53 module.onShutdown(-> Cu.unload(api_url))
54 prefs.set('api_url', api_url)
55
56 test?(vimfx)
57
58 utils.loadCss('style')
59
60 options.observe(vimfx)
61
62 prefs.observe('', (pref) ->
63 if pref.startsWith('mode.') or pref.startsWith('custom.')
64 vimfx.createKeyTrees()
65 else if pref of defaults.all_options
66 vimfx.options[pref] = parsePref(pref)
67 )
68
69 watchWindows(button.injectButton.bind(null, vimfx), 'navigator:browser')
70 watchWindows(addEventListeners.bind(null, vimfx), 'navigator:browser')
Imprint / Impressum