]> git.gir.st - VimFx.git/blob - extension/lib/main.coffee
Lay the foundation for using multi-process Firefox
[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 messageManager = require('./message-manager')
26 modes = require('./modes')
27 options = require('./options')
28 parsePref = require('./parse-prefs')
29 prefs = require('./prefs')
30 utils = require('./utils')
31 VimFx = require('./vimfx')
32 test = try require('../test/index')
33
34 Cu.import('resource://gre/modules/AddonManager.jsm')
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 AddonManager.getAddonByID(vimfx.id, (info) -> vimfx.info = info)
44
45 # Setup the public API.
46 apiUrl = "#{ data.resourceURI.spec }lib/public.js"
47 { setAPI } = Cu.import(apiUrl, {})
48 setAPI(createAPI(vimfx))
49 module.onShutdown(-> Cu.unload(apiUrl))
50 prefs.set('apiUrl', apiUrl)
51
52 vimfx.windows = new WeakSet()
53
54 test?(vimfx)
55
56 utils.loadCss('style')
57
58 options.observe(vimfx)
59
60 prefs.observe('', (pref) ->
61 if pref.startsWith('mode.') or pref.startsWith('custom.')
62 vimfx.createKeyTrees()
63 else if pref of defaults.all_options
64 vimfx.options[pref] = parsePref(pref)
65 )
66
67 messageManager.listen(null, 'tabCreated', ({ target }) ->
68 return false unless target.getAttribute('messagemanagergroup') == 'browsers'
69
70 window = target.ownerGlobal
71 unless vimfx.windows.has(window)
72 vimfx.windows.add(window)
73 button.injectButton(vimfx, window)
74 addEventListeners(vimfx, window)
75
76 return __SCRIPT_URI_SPEC__
77 )
78 messageManager.load(null, 'bootstrap')
Imprint / Impressum