Skip to content

Commit

Permalink
Revert "load controllers on new thread"
Browse files Browse the repository at this point in the history
This reverts commit 9b4da19.
  • Loading branch information
ShirosakiMio committed Mar 15, 2024
1 parent 19babbf commit 6bb51e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
22 changes: 8 additions & 14 deletions FCL/src/main/java/com/tungsten/fcl/setting/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ public class Controllers {
private Controllers() {
}

private static final ObservableList<Controller> controllers = observableArrayList(controller -> new Observable[]{controller});
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 {
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();
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();
} catch (IOException e) {
Logging.LOG.log(Level.SEVERE, "Failed to generate default controller!", e.getMessage());
}
Expand Down Expand Up @@ -108,9 +104,7 @@ private static ArrayList<Controller> getControllersFromDisk() {
.registerTypeAdapterFactory(new JavaFxPropertyTypeAdapterFactory(true, true))
.setPrettyPrinting()
.create().fromJson(str, Controller.class);
if (controller != null) {
list.add(controller);
}
list.add(controller);
} catch (IOException e) {
Logging.LOG.log(Level.WARNING, "Can't read file: " + json.getAbsolutePath(), e.getMessage());
}
Expand Down
3 changes: 1 addition & 2 deletions FCL/src/main/java/com/tungsten/fcl/setting/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.tungsten.fcl.game.FCLCacheRepository;
import com.tungsten.fclauncher.utils.FCLPath;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fclcore.util.CacheRepository;

public final class Settings {
Expand All @@ -44,7 +43,7 @@ private Settings() {
DownloadProviders.init();
Accounts.init();
Profiles.init();
Schedulers.io().execute(Controllers::init);
Controllers.init();
AuthlibInjectorServers.init();

CacheRepository.setInstance(FCLCacheRepository.REPOSITORY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ControllerUI(Context context, FCLUILayout parent, int id) {
public void onCreate() {
super.onCreate();

selectedController.set(Controllers.DEFAULT_CONTROLLER);
selectedController.set(Controllers.controllersProperty().get(0));

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

0 comments on commit 6bb51e7

Please sign in to comment.