]> git.gir.st - VimFx.git/blob - extension/lib/config.coffee
Add partial support for the wasavi extension
[VimFx.git] / extension / lib / config.coffee
1 ###
2 # Copyright Simon Lydell 2016.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 # This file loads the user config file: config.js and frame.js.
21
22 createConfigAPI = require('./api')
23 messageManager = require('./message-manager')
24
25 load = (vimfx, callback = ->) ->
26 configDir = vimfx.options.config_file_directory
27
28 unless configDir
29 callback(null)
30 return
31
32 scope = {vimfx: createConfigAPI(vimfx)}
33
34 # Calling `vimfx.createKeyTrees()` after each `vimfx.set()` that modifies a
35 # shortcut is absolutely redundant and may make Firefox start slower. Do it
36 # once instead.
37 vimfx.skipCreateKeyTrees = true
38 error = loadFile(configDir, 'config.js', scope)
39 vimfx.skipCreateKeyTrees = false
40 vimfx.createKeyTrees()
41
42 if error
43 callback(false)
44 return
45
46 messageManager.send('loadConfig', configDir, callback)
47
48 loadFile = (dir, file, scope) ->
49 uri = "#{dir}/#{file}"
50 try
51 Services.scriptloader.loadSubScriptWithOptions(uri, {
52 target: scope
53 charset: 'UTF-8'
54 ignoreCache: true
55 })
56 return null
57 catch error
58 console.error("VimFx: Error loading #{file}", uri, error)
59 return error
60
61 module.exports = {
62 load
63 loadFile
64 }
Imprint / Impressum