@@ -27,11 +27,11 @@ export interface Config {
2727 tabs : boolean ;
2828 tasks : boolean ;
2929 time : boolean ;
30- }
30+ } ;
3131}
3232
3333// ==================== VARIABLES ====================
34- let defaultLogDir : string = '' ;
34+ let defaultLogDir : string = "" ;
3535
3636// ==================== MODULE FUNCTIONS ====================
3737/**
@@ -48,7 +48,6 @@ let defaultLogDir : string = '';
4848 * @function toggleNotifications - Toggles the notifications
4949 */
5050export namespace config {
51-
5251 /**
5352 * Initializes the config module
5453 *
@@ -59,7 +58,7 @@ export namespace config {
5958 * @returns {void }
6059 */
6160 export function activate ( context : vscode . ExtensionContext ) : void {
62- defaultLogDir = path . join ( context . globalStorageUri . fsPath , ' logs' ) ;
61+ defaultLogDir = path . join ( context . globalStorageUri . fsPath , " logs" ) ;
6362
6463 const config = getConfig ( ) ;
6564 logger . setLogLevel ( config . logLevel ) ;
@@ -80,22 +79,28 @@ export namespace config {
8079 * @returns {void }
8180 */
8281 function handleSetUsername ( ) {
83- vscode . window . showInformationMessage ( 'For a better experience, please set your username' , 'Set Username' ) . then ( ( selection ) => {
84- if ( selection === 'Set Username' ) {
85- vscode . window . showInputBox ( {
86- prompt : 'Enter your username' ,
87- placeHolder : webview . DEFAULT_USER ,
88- validateInput : ( input ) => {
89- return input . trim ( ) ? null : 'Username cannot be empty' ;
90- }
91- } )
92- . then ( ( username ) => {
93- if ( username ) {
94- setUsername ( username ) ;
95- }
96- } ) ;
97- }
98- } ) ;
82+ vscode . window
83+ . showInformationMessage (
84+ "For a better experience, please set your username" ,
85+ "Set Username"
86+ )
87+ . then ( ( selection ) => {
88+ if ( selection === "Set Username" ) {
89+ vscode . window
90+ . showInputBox ( {
91+ prompt : "Enter your username" ,
92+ placeHolder : webview . DEFAULT_USER ,
93+ validateInput : ( input ) => {
94+ return input . trim ( ) ? null : "Username cannot be empty" ;
95+ } ,
96+ } )
97+ . then ( ( username ) => {
98+ if ( username ) {
99+ setUsername ( username ) ;
100+ }
101+ } ) ;
102+ }
103+ } ) ;
99104 }
100105
101106 /**
@@ -108,35 +113,47 @@ export namespace config {
108113 * @throws {Error } - If the module has not been initialized
109114 */
110115 export function getConfig ( ) : Readonly < Config > {
111- const extensionRawConfig = vscode . workspace . getConfiguration ( 'achievements' ) ;
112- let extensionConfig : Config = {
113- enabled : extensionRawConfig . get < boolean > ( 'enabled' , true ) ,
114- logLevel : extensionRawConfig . get < string > ( 'logLevel' , 'info' ) ,
115- notifications : extensionRawConfig . get < boolean > ( 'notifications' , true ) ,
116- logDirectory : extensionRawConfig . get < string > ( 'logDirectory' , defaultLogDir ) . trim ( ) ,
117- username : extensionRawConfig . get < string > ( 'username' , webview . DEFAULT_USER ) . trim ( ) ,
116+ const extensionRawConfig =
117+ vscode . workspace . getConfiguration ( "achievements" ) ;
118+ let extensionConfig : Config = {
119+ enabled : extensionRawConfig . get < boolean > ( "enabled" , true ) ,
120+ logLevel : extensionRawConfig . get < string > ( "logLevel" , "info" ) ,
121+ notifications : extensionRawConfig . get < boolean > ( "notifications" , true ) ,
122+ logDirectory : extensionRawConfig
123+ . get < string > ( "logDirectory" , defaultLogDir )
124+ . trim ( ) ,
125+ username : extensionRawConfig
126+ . get < string > ( "username" , webview . DEFAULT_USER )
127+ . trim ( ) ,
118128 listeners : {
119- debug : extensionRawConfig . get < boolean > ( 'listeners.debug' , true ) ,
120- extensions : extensionRawConfig . get < boolean > ( 'listeners.extensions' , true ) ,
121- files : extensionRawConfig . get < boolean > ( 'listeners.files' , true ) ,
122- git : extensionRawConfig . get < boolean > ( 'listeners.git' , true ) ,
123- tabs : extensionRawConfig . get < boolean > ( 'listeners.tabs' , true ) ,
124- tasks : extensionRawConfig . get < boolean > ( 'listeners.tasks' , true ) ,
125- time : extensionRawConfig . get < boolean > ( 'listeners.time' , true )
126- }
129+ debug : extensionRawConfig . get < boolean > ( "listeners.debug" , true ) ,
130+ extensions : extensionRawConfig . get < boolean > (
131+ "listeners.extensions" ,
132+ true
133+ ) ,
134+ files : extensionRawConfig . get < boolean > ( "listeners.files" , true ) ,
135+ git : extensionRawConfig . get < boolean > ( "listeners.git" , true ) ,
136+ tabs : extensionRawConfig . get < boolean > ( "listeners.tabs" , true ) ,
137+ tasks : extensionRawConfig . get < boolean > ( "listeners.tasks" , true ) ,
138+ time : extensionRawConfig . get < boolean > ( "listeners.time" , true ) ,
139+ } ,
127140 } ;
128-
141+
129142 // Check if the log directory is a valid path, if not, set it to the default
130- if ( ! path . isAbsolute ( extensionConfig . logDirectory ) ) {
131- logger . warn ( `Invalid log directory path: ${ extensionConfig . logDirectory } , setting to default` ) ;
132- updateConfig ( 'logDirectory' , defaultLogDir ) ;
143+ if ( ! path . isAbsolute ( extensionConfig . logDirectory ) ) {
144+ logger . warn (
145+ `Invalid log directory path: ${ extensionConfig . logDirectory } , setting to default`
146+ ) ;
147+ updateConfig ( "logDirectory" , defaultLogDir ) ;
133148 extensionConfig . logDirectory = defaultLogDir ;
134149 }
135150 try {
136151 fs . mkdirSync ( extensionConfig . logDirectory , { recursive : true } ) ;
137152 } catch ( error ) {
138- logger . error ( `Error creating log directory: ${ error } , setting to default` ) ;
139- updateConfig ( 'logDirectory' , defaultLogDir ) ;
153+ logger . error (
154+ `Error creating log directory: ${ error } , setting to default`
155+ ) ;
156+ updateConfig ( "logDirectory" , defaultLogDir ) ;
140157 extensionConfig . logDirectory = defaultLogDir ;
141158 }
142159 return extensionConfig ;
@@ -155,9 +172,9 @@ export namespace config {
155172 export function enableExtension ( ) : void {
156173 const config = getConfig ( ) ;
157174 const enabled = ! config . enabled ;
158- updateConfig ( ' enabled' , enabled ) ;
175+ updateConfig ( " enabled" , enabled ) ;
159176
160- let enabledString = enabled ? ' enabled' : ' disabled' ;
177+ let enabledString = enabled ? " enabled" : " disabled" ;
161178 let enabledMessage = `Achievement ${ enabledString } !` ;
162179 logger . info ( enabledMessage ) ;
163180 vscode . window . showInformationMessage ( enabledMessage ) ;
@@ -189,10 +206,10 @@ export namespace config {
189206 export function setUsername ( username : string ) : void {
190207 username = username . trim ( ) ;
191208 if ( ! username ) {
192- logger . error ( ' Username cannot be empty' ) ;
193- throw new Error ( ' username cannot be empty' ) ;
209+ logger . error ( " Username cannot be empty" ) ;
210+ throw new Error ( " username cannot be empty" ) ;
194211 }
195- updateConfig ( ' username' , username ) ;
212+ updateConfig ( " username" , username ) ;
196213 logger . info ( `Username set to: ${ username } ` ) ;
197214 }
198215
@@ -209,20 +226,21 @@ export namespace config {
209226 return getConfig ( ) . username ;
210227 }
211228
212- function updateConfig ( key : string , value : any ) {
213- const config = vscode . workspace . getConfiguration ( ' achievements' ) ;
229+ function updateConfig ( key : string , value : any ) {
230+ const config = vscode . workspace . getConfiguration ( " achievements" ) ;
214231 config . update ( key , value , vscode . ConfigurationTarget . Global ) ;
215232 }
216233
217- export function isListenerEnabled ( listener : keyof Config [ "listeners" ] ) : boolean {
234+ export function isListenerEnabled (
235+ listener : keyof Config [ "listeners" ]
236+ ) : boolean {
218237 const listeners = getConfig ( ) . listeners ;
219-
238+
220239 if ( listener in listeners ) {
221240 return listeners [ listener ] ;
222241 } else {
223242 logger . warn ( `Listener "${ listener } " does not exist` ) ;
224243 return false ;
225244 }
226245 }
227-
228246}
0 commit comments