import { injectable } from "inversify" ; import path from "path" ; const electron = require ( "electron" ) ; const app = electron . app || electron . remote . app ; import { IDirectoryManager } from "managers" ; import Utils from "Utils" ; /** The base functionality of a configuration manager class. */ @ injectable ( ) abstract class ConfigManager { /** A directory manager for reading user-defined key map files. */ protected directoryManager : IDirectoryManager ; param directoryManager public constructor ( directoryManager ) { this . directoryManager = directoryManager ; } returns protected parseFile < T > ( fileName ) { const fullPath = path . join ( app . getPath ( "userData" ) , fileName ) ; try { const userKeys = this . directoryManager . readFileSync ( fullPath ) ; Utils . trace ( `Retrieving settings from ${ fileName }` ) ; return JSON . parse ( userKeys ) ; } catch { Utils . trace ( `Cannot parse settings from ${ fileName }` ) ; return null ; } } } export default ConfigManager ;