( file: string, defaultConfig: Map<string, Accelerator> )
| 44 | } |
| 45 | |
| 46 | export function loadFile( |
| 47 | file: string, |
| 48 | defaultConfig: Map<string, Accelerator> |
| 49 | ): Map<string, Accelerator> { |
| 50 | try { |
| 51 | const config = JSON.parse(fs.readFileSync(file, "utf-8")); |
| 52 | if (!compatible(config.version)) { |
| 53 | throw "config incompatible"; |
| 54 | } else { |
| 55 | delete config.version; |
| 56 | return objToMap(config); |
| 57 | } |
| 58 | } catch (e) { |
| 59 | resetFile(file, defaultConfig); |
| 60 | return defaultConfig; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export function loadGlobalShortcuts(): Map<string, Accelerator> { |
| 65 | return loadFile(env.shortcut, defaultGlobalShortcuts); |
no test coverage detected