]> git.gir.st - VimFx.git/blob - extension/lib/main.coffee
Merge pull request #553 from akhodakivskiy/non-multi-process-event-quirks
[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 # This file pulls in all the different parts of VimFx, initializes them, and
22 # stiches them together.
23
24 createAPI = require('./api')
25 button = require('./button')
26 defaults = require('./defaults')
27 UIEventManager = require('./events')
28 messageManager = require('./message-manager')
29 modes = require('./modes')
30 options = require('./options')
31 parsePref = require('./parse-prefs')
32 prefs = require('./prefs')
33 utils = require('./utils')
34 VimFx = require('./vimfx')
35 test = try require('../test/index')
36
37 Cu.import('resource://gre/modules/AddonManager.jsm')
38
39 module.exports = (data, reason) ->
40 parsedOptions = {}
41 for pref of defaults.all_options
42 parsedOptions[pref] = parsePref(pref)
43 vimfx = new VimFx(modes, parsedOptions)
44 vimfx.id = data.id
45 vimfx.version = data.version
46 AddonManager.getAddonByID(vimfx.id, (info) -> vimfx.info = info)
47
48 # Setup the public API.
49 apiUrl = "#{ data.resourceURI.spec }lib/public.js"
50 { setAPI } = Cu.import(apiUrl, {})
51 setAPI(createAPI(vimfx))
52 module.onShutdown(-> Cu.unload(apiUrl))
53 prefs.set('apiUrl', apiUrl)
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 value = parsePref(pref)
64 vimfx.options[pref] = value
65 )
66
67 button.injectButton(vimfx)
68
69 test?(vimfx)
70
71 windows = new WeakSet()
72 messageManager.listen('tabCreated', (data, { target }) ->
73 # Frame script are run in more places than we need. Tell those not to do
74 # anything.
75 return false unless target.getAttribute('messagemanagergroup') == 'browsers'
76
77 window = target.ownerGlobal
78 vimfx.addVim(target)
79
80 unless windows.has(window)
81 windows.add(window)
82 eventManager = new UIEventManager(vimfx, window)
83 eventManager.addListeners(vimfx, window)
84
85 return [__SCRIPT_URI_SPEC__, MULTI_PROCESS_ENABLED]
86 )
87
88 messageManager.load('bootstrap')
Imprint / Impressum