Added a background task to handle updating the system information

This commit is contained in:
Gregory Ballantine 2023-01-15 13:40:02 -05:00
parent c15472b54f
commit aa277adcc0
3 changed files with 29 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import javafx.stage.Stage;
import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
import net.metaunix.controllers.HomeController;
/**
* JavaFX App
@ -35,6 +37,11 @@ public class App extends Application {
stage.show();
}
@Override
public void stop() {
HomeController.ust.cancel();
}
public static void main(String[] args) {
launch();
}

View File

@ -5,8 +5,12 @@ import javafx.scene.control.Label;
import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
import net.metaunix.tasks.UpdateSystemTask;
public class HomeController {
public static UpdateSystemTask ust = new UpdateSystemTask();
@FXML
private Label osInfo;
@ -15,6 +19,8 @@ public class HomeController {
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
osInfo.setText(String.valueOf(os));
new Thread(this.ust).start();
}
}

View File

@ -0,0 +1,16 @@
package net.metaunix.tasks;
import java.lang.Thread;
import javafx.concurrent.Task;
public class UpdateSystemTask extends Task<Void> {
@Override
protected Void call() throws Exception {
while (true) {
System.out.println("Test");
Thread.sleep(2000);
}
}
}