11package com .project .system_log_analyzer .controller ;
22
3+ import com .project .system_log_analyzer .SystemLogAnalyzerApp ;
34import com .project .system_log_analyzer .config .ApplicationContextProvider ;
45import com .project .system_log_analyzer .config .appConfig ;
6+ import com .project .system_log_analyzer .system .WindowsElevationManager ;
7+ import javafx .application .Platform ;
58import javafx .event .ActionEvent ;
69import javafx .fxml .FXML ;
710import javafx .fxml .FXMLLoader ;
@@ -34,6 +37,11 @@ public class WelcomeViewFXController {
3437 @ FXML
3538 public void initialize () {
3639 System .out .println ("Controller initialized, appConfig = " + appConfig );
40+
41+ if (appConfig .isCsvSecurity ()) {
42+ securityButton .setSelected (true );
43+ securityLabel .setText ("Admin permission granted!" );
44+ }
3745 }
3846
3947
@@ -57,7 +65,7 @@ private void scan(ActionEvent event) throws IOException {
5765 ApplicationContext springContext = ApplicationContextProvider .getApplicationContext ();
5866
5967 FXMLLoader loader = new FXMLLoader (getClass ().getResource ("/view/LoadingScreen.fxml" ));
60- loader .setControllerFactory (springContext ::getBean ); // Spring Boot starter by JavaFX !!IMPORTANT!!
68+ loader .setControllerFactory (springContext ::getBean ); // Spring starter by JavaFX !!IMPORTANT!!
6169 Parent root = loader .load ();
6270
6371 Stage stage = (Stage ) ((Node ) event .getSource ()).getScene ().getWindow ();
@@ -103,17 +111,26 @@ private void systemButtonON(ActionEvent event) throws IOException {
103111
104112 @ FXML
105113 private void securityButtonON (ActionEvent event ) throws IOException {
114+
115+ if (SystemLogAnalyzerApp .isElevated ()) { // Admin ckeck for Security Logs
116+ securityLabel .setText ("Admin permission granted!" );
117+ appConfig .setCsvSecurity (securityButton .isSelected ());
118+ return ;
119+ }
120+
106121 if (securityButton .isSelected ()) {
107122 boolean proceed = askForSecurityPermission ();
108123 if (!proceed ) {
109124 securityButton .setSelected (false );
110- securityLabel .setText ("Admin permission required!" );
111125 appConfig .setCsvSecurity (false );
126+ securityLabel .setText ("Admin permission required!" );
112127 return ;
113- } else {
114- securityLabel .setText ("Admin permission granted!" );
115- appConfig .setCsvSecurity (true );
116128 }
129+
130+ boolean relaunchStarted = WindowsElevationManager .relaunchAsAdmin ("--elevated" );
131+
132+ if (relaunchStarted ) Platform .exit ();
133+
117134 } else {
118135 appConfig .setCsvSecurity (false );
119136 securityLabel .setText ("(Requires Admin Permission)" );
0 commit comments