@@ -108,14 +108,28 @@ const rollback = () => {
108108 logger . error ( "Failed to create codes.authme folder" , err )
109109 } else {
110110 logger . log ( "rollback successful, codes.authme file created" )
111+
112+ dialog . showMessageBox ( {
113+ title : "Authme" ,
114+ buttons : [ "Close" ] ,
115+ type : "info" ,
116+ message : "Rollback successful! \n\nGo back to the main page to check out the changes!" ,
117+ } )
111118 }
112119 } )
113120 } else {
114121 fs . writeFile ( path . join ( file_path , "hash.authme" ) , data , ( err ) => {
115122 if ( err ) {
116123 logger . error ( "Failed to create hash.authme" , err )
117124 } else {
118- logger . log ( "hash.authme file created" )
125+ logger . log ( "rollback successful, hash.authme file created" )
126+
127+ dialog . showMessageBox ( {
128+ title : "Authme" ,
129+ buttons : [ "Close" ] ,
130+ type : "info" ,
131+ message : "Rollback successful! \n\nGo back to the main page to check out the changes!" ,
132+ } )
119133 }
120134 } )
121135 }
@@ -178,7 +192,7 @@ const go = () => {
178192 <h2>${ issuers [ counter ] } </h2>
179193 </div>
180194 <div class="flex justify-center items-center">
181- <input class="input" type="text" id="edit_inp_${ [ counter ] } " value="${ names [ counter ] } " readonly/>
195+ <input class="input w-[320px] " type="text" id="edit_inp_${ [ counter ] } " value="${ names [ counter ] } " readonly/>
182196 </div>
183197 <div class="flex justify-center items-center mb-10 mt-5 gap-2">
184198 <button class="buttonr button" id="edit_but_${ [ counter ] } " onclick="edit(${ [ counter ] } )">
@@ -364,53 +378,64 @@ const newSaveCodes = () => {
364378const addMore = ( ) => {
365379 dialog
366380 . showOpenDialog ( {
367- title : "Import from Authme Import Text file" ,
381+ title : "Import from Authme file" ,
368382 properties : [ "openFile" , "multiSelections" ] ,
369- filters : [ { name : "Authme import/export file" , extensions : [ "authme" , "txt "] } ] ,
383+ filters : [ { name : "Authme file" , extensions : [ "authme" ] } ] ,
370384 } )
371385 . then ( ( result ) => {
372386 canceled = result . canceled
373387 files = result . filePaths
374388
375389 if ( canceled === false ) {
376- dialog . showMessageBox ( {
377- title : "Authme" ,
378- buttons : [ "Close" ] ,
379- defaultId : 0 ,
380- cancelId : 0 ,
381- type : "info" ,
382- noLink : true ,
383- message : "Code(s) added! \n\nScroll down to view them!" ,
384- } )
385-
386390 for ( let i = 0 ; i < files . length ; i ++ ) {
387391 fs . readFile ( files [ i ] , ( err , input ) => {
388392 if ( err ) {
389393 logger . error ( "Error loading file" )
390394 } else {
391395 logger . log ( "File readed" )
392396
393- data = [ ]
397+ const /** @type {LibAuthmeFile } */ loaded = JSON . parse ( input . toString ( ) )
398+
399+ if ( loaded . role === "import" || loaded . role === "export" ) {
400+ dialog . showMessageBox ( {
401+ title : "Authme" ,
402+ buttons : [ "Close" ] ,
403+ defaultId : 0 ,
404+ cancelId : 0 ,
405+ type : "info" ,
406+ noLink : true ,
407+ message : "Code(s) added! \n\nScroll down to view them!" ,
408+ } )
409+
410+ data = [ ]
394411
395- const container = document . querySelector ( ".codes_container" )
396- container . innerHTML = ""
412+ const container = document . querySelector ( ".codes_container" )
413+ container . innerHTML = ""
397414
398- counter = 0
415+ counter = 0
399416
400- if ( extension === "authme" ) {
401- const codes = Buffer . from ( JSON . parse ( input . toString ( ) ) . codes , "base64" ) . toString ( )
417+ const codes = Buffer . from ( loaded . codes , "base64" )
402418
403419 const /** @type {LibImportFile } */ imported = convert . fromText ( codes . toString ( ) , 0 )
404- const /** @type {LibImportFile } */ imported = convert . fromText ( input . toString ( ) , 0 )
405420
406421 for ( let i = 0 ; i < imported . names . length ; i ++ ) {
407422 names . push ( imported . names [ i ] )
408423 secrets . push ( imported . secrets [ i ] )
409424 issuers . push ( imported . issuers [ i ] )
410425 }
411- }
412426
413- go ( )
427+ go ( )
428+ } else {
429+ dialog . showMessageBox ( {
430+ title : "Authme" ,
431+ buttons : [ "Close" ] ,
432+ defaultId : 0 ,
433+ cancelId : 0 ,
434+ type : "error" ,
435+ noLink : true ,
436+ message : `This file is an Authme ${ loaded . role } file! \n\nYou need an Authme export or import file!` ,
437+ } )
438+ }
414439 }
415440 } )
416441 }
@@ -599,3 +624,38 @@ const deleteCodes = () => {
599624
600625 fs . rm ( path . join ( file_path , "hash.authme" ) , ( err ) => {
601626 if ( err ) {
627+ return logger . warn ( `Error deleting hash - ${ err } ` )
628+ } else {
629+ logger . log ( "Codes deleted" )
630+ }
631+ } )
632+
633+ /**
634+ * Load storage
635+ * @type {LibStorage }
636+ */
637+ let storage
638+
639+ if ( dev === false ) {
640+ storage = JSON . parse ( localStorage . getItem ( "storage" ) )
641+
642+ storage . issuers = undefined
643+
644+ localStorage . setItem ( "storage" , JSON . stringify ( storage ) )
645+ } else {
646+ storage = JSON . parse ( localStorage . getItem ( "dev_storage" ) )
647+
648+ storage . issuers = undefined
649+
650+ localStorage . setItem ( "dev_storage" , JSON . stringify ( storage ) )
651+ }
652+
653+ reloadApplication ( )
654+ reloadSettings ( )
655+
656+ setTimeout ( ( ) => {
657+ location . reload ( )
658+ } , 100 )
659+ }
660+ } )
661+ }
0 commit comments