]> git.gir.st - VimFx.git/blob - extension/lib/config.coffee
Change license to MIT
[VimFx.git] / extension / lib / config.coffee
1 # This file loads the user config file: config.js and frame.js.
2
3 createConfigAPI = require('./api')
4 messageManager = require('./message-manager')
5 utils = require('./utils')
6
7 {OS} = Components.utils.import('resource://gre/modules/osfile.jsm', {})
8
9 load = (vimfx, options = null, callback = ->) ->
10 configDir = vimfx.options.config_file_directory
11
12 unless configDir
13 callback(null)
14 return
15
16 scope = {vimfx: createConfigAPI(vimfx, options)}
17
18 # Calling `vimfx.createKeyTrees()` after each `vimfx.set()` that modifies a
19 # shortcut is absolutely redundant and may make Firefox start slower. Do it
20 # once instead.
21 vimfx.skipCreateKeyTrees = true
22 error = loadFile(configDir, 'config.js', scope)
23 vimfx.skipCreateKeyTrees = false
24 vimfx.createKeyTrees()
25
26 if error
27 callback(false)
28 return
29
30 messageManager.send('loadConfig', null, callback)
31
32 loadFile = (dir, file, scope) ->
33 expandedDir = utils.expandPath(dir)
34 uri = OS.Path.toFileURI(OS.Path.join(expandedDir, file))
35 try
36 Services.scriptloader.loadSubScriptWithOptions(uri, {
37 target: Object.assign({
38 __dirname: OS.Path.toFileURI(expandedDir)
39 }, scope)
40 charset: 'UTF-8'
41 ignoreCache: true
42 })
43 return null
44 catch error
45 console.error("VimFx: Error loading #{file}", uri, error)
46 return error
47
48 module.exports = {
49 load
50 loadFile
51 }
Imprint / Impressum