Skip to content

Commit

Permalink
fix a strange crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Mar 15, 2024
1 parent 6bb51e7 commit 9030c3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 9 additions & 6 deletions FCL/src/main/java/com/tungsten/fcl/setting/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ private Controllers() {

private static final ObservableList<Controller> controllers = observableArrayList(controller -> new Observable[] { controller });
private static final ReadOnlyListWrapper<Controller> controllersWrapper = new ReadOnlyListWrapper<>(controllers);
public static Controller DEFAULT_CONTROLLER;

public static void checkControllers() {
if (controllers.isEmpty()) {
try {
String str = IOUtils.readFullyAsString(Controllers.class.getResourceAsStream("/assets/controllers/Default.json"));
Controller controller = new GsonBuilder()
.registerTypeAdapterFactory(new JavaFxPropertyTypeAdapterFactory(true, true))
.setPrettyPrinting()
.create().fromJson(str, Controller.class);
controller.saveToDisk();
if (DEFAULT_CONTROLLER == null) {
String str = IOUtils.readFullyAsString(Controllers.class.getResourceAsStream("/assets/controllers/Default.json"));
DEFAULT_CONTROLLER = new GsonBuilder()
.registerTypeAdapterFactory(new JavaFxPropertyTypeAdapterFactory(true, true))
.setPrettyPrinting()
.create().fromJson(str, Controller.class);
}
DEFAULT_CONTROLLER.saveToDisk();
} catch (IOException e) {
Logging.LOG.log(Level.SEVERE, "Failed to generate default controller!", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public ControllerUI(Context context, FCLUILayout parent, int id) {
public void onCreate() {
super.onCreate();

selectedController.set(Controllers.controllersProperty().get(0));
if (Controllers.controllersProperty().size() != 0) {
selectedController.set(Controllers.controllersProperty().get(0));
} else {
selectedController.set(Controllers.DEFAULT_CONTROLLER);
}

listView = findViewById(R.id.controller_list);
importController = findViewById(R.id.import_controller);
Expand Down

0 comments on commit 9030c3c

Please sign in to comment.