]> git.gir.st - VimFx.git/blob - extension/lib/main.coffee
Major refactor: Rework all UI and related improvements
[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 module.exports = (data, reason) ->
37 parsedOptions = {}
38 for pref of defaults.all_options
39 parsedOptions[pref] = parsePref(pref)
40 vimfx = new VimFx(modes, parsedOptions)
41 vimfx.id = data.id
42 vimfx.version = data.version
43
44 # Setup the public API. The URL is encoded (which means that there will be
45 # only ASCII characters) so that the pref can be read using a simple
46 # `Services.prefs.getCharPref()` (which only supports ASCII characters).
47 api_url = encodeURI("#{ data.resourceURI.spec }lib/public.js")
48 { setAPI } = Cu.import(api_url, {})
49 setAPI(createAPI(vimfx))
50 module.onShutdown(-> Cu.unload(api_url))
51 prefs.set('api_url', api_url)
52
53 test?(vimfx)
54
55 utils.loadCss('style')
56
57 options.observe(vimfx)
58
59 prefs.observe('', (pref) ->
60 if pref.startsWith('mode.') or pref.startsWith('custom.')
61 vimfx.createKeyTrees()
62 else if pref of defaults.all_options
63 vimfx.options[pref] = parsePref(pref)
64 )
65
66 watchWindows(button.injectButton.bind(null, vimfx), 'navigator:browser')
67 watchWindows(addEventListeners.bind(null, vimfx), 'navigator:browser')
Imprint / Impressum