diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index a02b75c6..81704963 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -14,7 +14,6 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -463,7 +462,7 @@ public class CamrecApplication extends Application { } private void checkForUpdates() { - CompletableFuture.runAsync(() -> { + Thread updateCheck = new Thread(() -> { String url = "https://pastebin.com/raw/mUxtKzyB"; Request request = new Request.Builder().url(url).build(); try (Response response = httpClient.execute(request)) { @@ -490,6 +489,9 @@ public class CamrecApplication extends Application { LOG.warn("Update check failed: {}", e.getMessage()); } }); + updateCheck.setName("Update Check"); + updateCheck.setDaemon(true); + updateCheck.start(); } public static Version getVersion() throws IOException { diff --git a/client/src/main/java/ctbrec/ui/PreviewPopupHandler.java b/client/src/main/java/ctbrec/ui/PreviewPopupHandler.java index 5b8434a2..5c05eb98 100644 --- a/client/src/main/java/ctbrec/ui/PreviewPopupHandler.java +++ b/client/src/main/java/ctbrec/ui/PreviewPopupHandler.java @@ -1,7 +1,6 @@ package ctbrec.ui; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import org.slf4j.Logger; @@ -146,7 +145,7 @@ public class PreviewPopupHandler implements EventHandler { } private void createTimerThread() { - CompletableFuture.runAsync(() -> { + Thread timerThread = new Thread(() -> { while(true) { openCountdown--; if(openCountdown == 0) { @@ -182,5 +181,9 @@ public class PreviewPopupHandler implements EventHandler { } } }); + timerThread.setDaemon(true); + timerThread.setPriority(Thread.MIN_PRIORITY); + timerThread.setName("PreviewPopupTimer"); + timerThread.start(); } } diff --git a/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java b/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java index 42c7c854..2aa64e8f 100644 --- a/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java +++ b/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java @@ -4,7 +4,6 @@ import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Function; @@ -62,7 +61,7 @@ public class StreamSourceSelectionDialog { } }); selectStreamSource.setOnFailed(e -> onFail.apply(selectStreamSource.getException())); - CompletableFuture.runAsync(selectStreamSource); + new Thread(selectStreamSource).start(); } private static class BestStreamSource extends StreamSource { diff --git a/client/src/main/java/ctbrec/ui/TipDialog.java b/client/src/main/java/ctbrec/ui/TipDialog.java index 5c1b8ecd..459d8d8a 100644 --- a/client/src/main/java/ctbrec/ui/TipDialog.java +++ b/client/src/main/java/ctbrec/ui/TipDialog.java @@ -2,7 +2,6 @@ package ctbrec.ui; import java.text.DecimalFormat; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.slf4j.Logger; @@ -79,7 +78,7 @@ public class TipDialog extends TextInputDialog { } } }; - CompletableFuture.runAsync(task); + new Thread(task).start(); } private void showErrorDialog(Throwable throwable) { diff --git a/client/src/main/java/ctbrec/ui/TokenLabel.java b/client/src/main/java/ctbrec/ui/TokenLabel.java index 6a5cd5c8..917dad12 100644 --- a/client/src/main/java/ctbrec/ui/TokenLabel.java +++ b/client/src/main/java/ctbrec/ui/TokenLabel.java @@ -3,7 +3,6 @@ package ctbrec.ui; import java.text.DecimalFormat; import java.util.Map; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.slf4j.Logger; @@ -84,6 +83,6 @@ public class TokenLabel extends Label { } } }; - CompletableFuture.runAsync(task); + new Thread(task).start(); } } diff --git a/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java b/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java index fdcf4d5c..e9f3b188 100644 --- a/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java +++ b/client/src/main/java/ctbrec/ui/action/CheckModelAccountAction.java @@ -3,7 +3,6 @@ package ctbrec.ui.action; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +29,7 @@ public class CheckModelAccountAction { public void execute() { String buttonText = b.getText(); b.setDisable(true); - CompletableFuture.runAsync(() -> { + Runnable checker = (() -> { List deletedAccounts = new ArrayList<>(); try { List models = recorder.getModels(); @@ -67,5 +66,6 @@ public class CheckModelAccountAction { }); } }); + new Thread(checker).start(); } } diff --git a/client/src/main/java/ctbrec/ui/action/EditNotesAction.java b/client/src/main/java/ctbrec/ui/action/EditNotesAction.java index e55b77c0..2a23edec 100644 --- a/client/src/main/java/ctbrec/ui/action/EditNotesAction.java +++ b/client/src/main/java/ctbrec/ui/action/EditNotesAction.java @@ -2,7 +2,6 @@ package ctbrec.ui.action; import java.io.IOException; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +30,7 @@ public class EditNotesAction { public void execute() { source.setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> Platform.runLater(() -> { + new Thread(() -> Platform.runLater(() -> { String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), ""); Optional newNotes = Dialogs.showTextInput(source.getScene(), "Model Notes", "Notes for " + model.getName(), notes); newNotes.ifPresent(n -> { @@ -48,6 +47,6 @@ public class EditNotesAction { }); table.refresh(); source.setCursor(Cursor.DEFAULT); - })); + })).start(); } } diff --git a/client/src/main/java/ctbrec/ui/action/ModelMassEditAction.java b/client/src/main/java/ctbrec/ui/action/ModelMassEditAction.java index f6da2d5d..70c6dfc1 100644 --- a/client/src/main/java/ctbrec/ui/action/ModelMassEditAction.java +++ b/client/src/main/java/ctbrec/ui/action/ModelMassEditAction.java @@ -2,7 +2,11 @@ package ctbrec.ui.action; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletableFuture; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import ctbrec.Model; @@ -12,6 +16,9 @@ import javafx.scene.Node; public class ModelMassEditAction { + static BlockingQueue queue = new LinkedBlockingQueue<>(); + static ExecutorService threadPool = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MINUTES, queue); + protected List models; protected Consumer action; protected Node source; @@ -35,7 +42,7 @@ public class ModelMassEditAction { Consumer cb = Objects.requireNonNull(callback, "Callback is null, call execute() instead"); source.setCursor(Cursor.WAIT); for (Model model : models) { - CompletableFuture.runAsync(() -> { + threadPool.submit(() -> { action.accept(model); cb.accept(model); Platform.runLater(() -> source.setCursor(Cursor.DEFAULT)); diff --git a/client/src/main/java/ctbrec/ui/action/OpenRecordingsDir.java b/client/src/main/java/ctbrec/ui/action/OpenRecordingsDir.java index b7d8d37c..4ef67fd0 100644 --- a/client/src/main/java/ctbrec/ui/action/OpenRecordingsDir.java +++ b/client/src/main/java/ctbrec/ui/action/OpenRecordingsDir.java @@ -2,7 +2,6 @@ package ctbrec.ui.action; import java.io.File; import java.time.Instant; -import java.util.concurrent.CompletableFuture; import ctbrec.Config; import ctbrec.Model; @@ -27,7 +26,7 @@ public class OpenRecordingsDir { File fileForRecording = Config.getInstance().getFileForRecording(selectedModel, ".mp4", Instant.now()); final File dir = getModelDirectory(fileForRecording); if (dir.exists()) { - CompletableFuture.runAsync(() -> DesktopIntegration.open(dir)); + new Thread(() -> DesktopIntegration.open(dir)).start(); } else { Dialogs.showError(source.getScene(), "Directory does not exist", "There are no recordings for this model", null); } diff --git a/client/src/main/java/ctbrec/ui/action/ToggleRecordingAction.java b/client/src/main/java/ctbrec/ui/action/ToggleRecordingAction.java index f15f3e20..6e9fc155 100644 --- a/client/src/main/java/ctbrec/ui/action/ToggleRecordingAction.java +++ b/client/src/main/java/ctbrec/ui/action/ToggleRecordingAction.java @@ -1,7 +1,5 @@ package ctbrec.ui.action; -import java.util.concurrent.CompletableFuture; - import ctbrec.recorder.Recorder; import ctbrec.ui.controls.Dialogs; import javafx.application.Platform; @@ -22,7 +20,7 @@ public class ToggleRecordingAction { public void execute() { toggleButton.setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + Thread t = new Thread(() -> { try { if (pause) { recorder.pause(); @@ -38,5 +36,7 @@ public class ToggleRecordingAction { Platform.runLater(() -> toggleButton.setCursor(Cursor.DEFAULT)); } }); + t.setDaemon(true); + t.start(); } } diff --git a/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java b/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java index e52c247c..3b469739 100644 --- a/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java +++ b/client/src/main/java/ctbrec/ui/controls/SearchPopoverTreeList.java @@ -34,7 +34,6 @@ package ctbrec.ui.controls; import java.net.URL; import java.util.Objects; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -168,7 +167,7 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop follow = new Button("Follow"); follow.setOnAction(evt -> { setCursor(Cursor.WAIT); - CompletableFuture.runAsync(new Task() { + new Thread(new Task() { @Override protected Boolean call() throws Exception { model.getSite().login(); @@ -184,12 +183,12 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop } Platform.runLater(() -> setCursor(Cursor.DEFAULT)); } - }); + }).start(); }); record = new Button("Record"); record.setOnAction(evt -> { setCursor(Cursor.WAIT); - CompletableFuture.runAsync(new Task() { + new Thread(new Task() { @Override protected Void call() throws Exception { recorder.startRecording(model); @@ -200,7 +199,7 @@ public class SearchPopoverTreeList extends PopoverTreeList implements Pop protected void done() { Platform.runLater(() -> setCursor(Cursor.DEFAULT)); } - }); + }).start(); }); getChildren().addAll(thumb, title, follow, record); diff --git a/client/src/main/java/ctbrec/ui/controls/StreamPreview.java b/client/src/main/java/ctbrec/ui/controls/StreamPreview.java index 249eda45..9b1eb20e 100644 --- a/client/src/main/java/ctbrec/ui/controls/StreamPreview.java +++ b/client/src/main/java/ctbrec/ui/controls/StreamPreview.java @@ -3,7 +3,6 @@ package ctbrec.ui.controls; import java.io.InterruptedIOException; import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -158,14 +157,14 @@ public class StreamPreview extends StackPane { running = false; MediaPlayer old = videoPlayer; Future oldFuture = future; - CompletableFuture.runAsync(() -> { + new Thread(() -> { if(oldFuture != null && !oldFuture.isDone()) { oldFuture.cancel(true); } if(old != null) { old.dispose(); } - }); + }).start(); } private void onError(MediaPlayer videoPlayer) { diff --git a/client/src/main/java/ctbrec/ui/controls/Toast.java b/client/src/main/java/ctbrec/ui/controls/Toast.java index c74b7986..e622013d 100644 --- a/client/src/main/java/ctbrec/ui/controls/Toast.java +++ b/client/src/main/java/ctbrec/ui/controls/Toast.java @@ -1,7 +1,5 @@ package ctbrec.ui.controls; -import java.util.concurrent.CompletableFuture; - import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; @@ -38,7 +36,7 @@ public final class Toast { KeyFrame fadeInKey1 = new KeyFrame(Duration.millis(fadeInDelay), new KeyValue(toastStage.getScene().getRoot().opacityProperty(), 1)); fadeInTimeline.getKeyFrames().add(fadeInKey1); fadeInTimeline.setOnFinished((ae) -> { - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { Thread.sleep(toastDelay); } catch (InterruptedException e) { @@ -49,7 +47,7 @@ public final class Toast { fadeOutTimeline.getKeyFrames().add(fadeOutKey1); fadeOutTimeline.setOnFinished((aeb) -> toastStage.close()); fadeOutTimeline.play(); - }); + }).start(); }); fadeInTimeline.play(); } diff --git a/client/src/main/java/ctbrec/ui/news/NewsTab.java b/client/src/main/java/ctbrec/ui/news/NewsTab.java index 712b5a15..a5f11d8e 100644 --- a/client/src/main/java/ctbrec/ui/news/NewsTab.java +++ b/client/src/main/java/ctbrec/ui/news/NewsTab.java @@ -1,16 +1,7 @@ package ctbrec.ui.news; -import static ctbrec.io.HttpConstants.*; - -import java.io.IOException; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; - -import org.json.JSONObject; - import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; - import ctbrec.io.HttpException; import ctbrec.ui.CamrecApplication; import ctbrec.ui.controls.Dialogs; @@ -23,6 +14,12 @@ import javafx.scene.control.Tab; import javafx.scene.layout.VBox; import okhttp3.Request; import okhttp3.Response; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.Objects; + +import static ctbrec.io.HttpConstants.USER_AGENT; public class NewsTab extends Tab implements TabSelectionListener { private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0"; @@ -39,7 +36,7 @@ public class NewsTab extends Tab implements TabSelectionListener { @Override public void selected() { - CompletableFuture.runAsync(this::loadToots); + new Thread(this::loadToots).start(); } private void loadToots() { diff --git a/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsSiteUi.java b/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsSiteUi.java index a391bc20..a75ab316 100644 --- a/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsSiteUi.java +++ b/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsSiteUi.java @@ -1,19 +1,17 @@ package ctbrec.ui.sites.bonga; -import java.io.IOException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.LinkedBlockingQueue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import ctbrec.sites.bonga.BongaCams; import ctbrec.sites.bonga.BongaCamsHttpClient; import ctbrec.ui.controls.Dialogs; import ctbrec.ui.sites.AbstractSiteUi; import ctbrec.ui.sites.ConfigUI; import ctbrec.ui.tabs.TabProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; public class BongaCamsSiteUi extends AbstractSiteUi { @@ -46,7 +44,7 @@ public class BongaCamsSiteUi extends AbstractSiteUi { } else { BlockingQueue queue = new LinkedBlockingQueue<>(); try { - CompletableFuture.runAsync(() -> { + new Thread(() -> { // login with external browser window try { new BongaCamsElectronLoginDialog(bongaCams.getHttpClient().getCookieJar()); @@ -61,7 +59,7 @@ public class BongaCamsSiteUi extends AbstractSiteUi { Thread.currentThread().interrupt(); LOG.error("Error while signaling termination", e); } - }); + }).start(); queue.take(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java b/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java index bf62446f..c36d0e8e 100644 --- a/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java +++ b/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import org.json.JSONArray; import org.json.JSONObject; @@ -137,7 +136,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { }); } }; - CompletableFuture.runAsync(task); + new Thread(task).start(); } @Override @@ -203,7 +202,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { private void follow(Model model) { setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { SiteUiFactory.getUi(model.getSite()).login(); model.follow(); @@ -215,12 +214,12 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { setCursor(Cursor.DEFAULT); }); } - }); + }).start(); } private void record(Model model) { setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { recorder.startRecording(model); } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) { @@ -230,11 +229,11 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { setCursor(Cursor.DEFAULT); }); } - }); + }).start(); } private void loadImage(Model model, ImageView thumb) { - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { String url = camsoda.getBaseUrl() + "/api/v1/user/" + model.getName(); Request detailRequest = new Request.Builder().url(url).build(); @@ -271,7 +270,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { } catch (Exception e) { LOG.error("Couldn't load model details", e); } - }); + }).start(); } private Node createLabel(String string, boolean bold) { diff --git a/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminSiteUi.java b/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminSiteUi.java index 6ae87f34..5975a489 100644 --- a/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminSiteUi.java +++ b/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminSiteUi.java @@ -2,7 +2,6 @@ package ctbrec.ui.sites.jasmin; import java.io.IOException; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -56,7 +55,7 @@ public class LiveJasminSiteUi extends AbstractSiteUi { lastLoginTime = System.currentTimeMillis(); BlockingQueue queue = new LinkedBlockingQueue<>(); - CompletableFuture.runAsync(() -> { + new Thread (() -> { // login with external browser window try { new LiveJasminElectronLoginDialog(liveJasmin.getHttpClient().getCookieJar()); @@ -70,7 +69,7 @@ public class LiveJasminSiteUi extends AbstractSiteUi { } catch (InterruptedException e) { LOG.error("Error while signaling termination", e); } - }); + }).start(); try { queue.take(); diff --git a/client/src/main/java/ctbrec/ui/sites/myfreecams/MyFreeCamsTableTab.java b/client/src/main/java/ctbrec/ui/sites/myfreecams/MyFreeCamsTableTab.java index 9d283491..8581ca7f 100644 --- a/client/src/main/java/ctbrec/ui/sites/myfreecams/MyFreeCamsTableTab.java +++ b/client/src/main/java/ctbrec/ui/sites/myfreecams/MyFreeCamsTableTab.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -353,7 +352,7 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener { if (Objects.equals(System.getenv("CTBREC_DEV"), "1")) { MenuItem debug = new MenuItem("debug"); - debug.setOnAction(e -> CompletableFuture.runAsync(() -> { + debug.setOnAction(e -> new Thread(() -> { for (Model m : selectedModels) { try { List sources = m.getStreamSources(); @@ -365,7 +364,7 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener { LOG.error("Couldn't get stream sources", e1); } } - })); + }).start()); menu.getItems().add(debug); } diff --git a/client/src/main/java/ctbrec/ui/sites/showup/ShowupSiteUi.java b/client/src/main/java/ctbrec/ui/sites/showup/ShowupSiteUi.java index 7cdd781e..3ab05d27 100644 --- a/client/src/main/java/ctbrec/ui/sites/showup/ShowupSiteUi.java +++ b/client/src/main/java/ctbrec/ui/sites/showup/ShowupSiteUi.java @@ -2,7 +2,6 @@ package ctbrec.ui.sites.showup; import java.io.IOException; import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.LinkedBlockingQueue; import org.slf4j.Logger; @@ -47,7 +46,7 @@ public class ShowupSiteUi extends AbstractSiteUi { } else { BlockingQueue queue = new LinkedBlockingQueue<>(); try { - CompletableFuture.runAsync(() -> { + new Thread(() -> { // login with external browser window try { new ShowupElectronLoginDialog(site.getHttpClient().getCookieJar()); @@ -62,7 +61,7 @@ public class ShowupSiteUi extends AbstractSiteUi { LOG.error("Error while signaling termination", e); Thread.currentThread().interrupt(); } - }); + }).start(); queue.take(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/client/src/main/java/ctbrec/ui/tabs/RecordingsTab.java b/client/src/main/java/ctbrec/ui/tabs/RecordingsTab.java index d8741756..c6f4563c 100644 --- a/client/src/main/java/ctbrec/ui/tabs/RecordingsTab.java +++ b/client/src/main/java/ctbrec/ui/tabs/RecordingsTab.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -498,9 +497,9 @@ public class RecordingsTab extends Tab implements TabSelectionListener { private void openContactSheet(JavaFxRecording recording) { if (config.getSettings().localRecording) { - recording.getContactSheet().ifPresent(f -> CompletableFuture.runAsync(() -> DesktopIntegration.open(f))); + recording.getContactSheet().ifPresent(f -> new Thread(() -> DesktopIntegration.open(f)).start()); } else { - recording.getContactSheet().ifPresent(f -> CompletableFuture.runAsync(() -> { + recording.getContactSheet().ifPresent(f -> new Thread(() -> { File target; try { target = File.createTempFile("cs_", ".jpg"); @@ -518,7 +517,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { } catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e) { Dialogs.showError(getTabPane().getScene(), "Download Error", "An error occurred while downloading the contact sheet", e); } - })); + }).start()); } } @@ -528,7 +527,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { Optional newNote = Dialogs.showTextInput(source.getScene(), "Recording Notes", "", notes); if (newNote.isPresent()) { table.setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + Thread backgroundThread = new Thread(() -> { List exceptions = new ArrayList<>(); try { recording.setNote(newNote.get()); @@ -544,12 +543,13 @@ public class RecordingsTab extends Tab implements TabSelectionListener { }); } }); + backgroundThread.start(); } } private void pin(List recordings) { table.setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + Thread backgroundThread = new Thread(() -> { List exceptions = new ArrayList<>(); try { for (JavaFxRecording javaFxRecording : recordings) { @@ -570,11 +570,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener { }); } }); + backgroundThread.start(); } private void unpin(List recordings) { table.setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + Thread backgroundThread = new Thread(() -> { List exceptions = new ArrayList<>(); try { for (JavaFxRecording javaFxRecording : recordings) { @@ -595,6 +596,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { }); } }); + backgroundThread.start(); } private void jumpToNextModel(KeyCode code) { @@ -645,11 +647,11 @@ public class RecordingsTab extends Tab implements TabSelectionListener { private void onOpenDirectory(JavaFxRecording first) { File tsFile = first.getAbsoluteFile(); - CompletableFuture.runAsync(() -> DesktopIntegration.open(tsFile.getParent())); + new Thread(() -> DesktopIntegration.open(tsFile.getParent())).start(); } private void triggerPostProcessing(List recs) { - CompletableFuture.runAsync(() -> { + new Thread(() -> { for (JavaFxRecording rec : recs) { try { recorder.rerunPostProcessing(rec.getDelegate()); @@ -658,7 +660,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { LOG.error("Error while starting post-processing", e1); } } - }); + }).start(); } private void download(Recording recording) { @@ -794,7 +796,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { } private void deleteAsync(List recordings) { - CompletableFuture.runAsync(() -> { + Thread deleteThread = new Thread(() -> { recordingsLock.lock(); try { List deleted = new ArrayList<>(); @@ -820,6 +822,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { Platform.runLater(() -> table.setCursor(Cursor.DEFAULT)); } }); + deleteThread.start(); } public void saveState() { diff --git a/client/src/main/java/ctbrec/ui/tabs/ThumbCell.java b/client/src/main/java/ctbrec/ui/tabs/ThumbCell.java index 8ae9a2f6..aa2df6ee 100644 --- a/client/src/main/java/ctbrec/ui/tabs/ThumbCell.java +++ b/client/src/main/java/ctbrec/ui/tabs/ThumbCell.java @@ -484,7 +484,7 @@ public class ThumbCell extends StackPane { void pauseResumeAction(boolean pause) { setCursor(Cursor.WAIT); - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { if (pause) { recorder.suspendRecording(model); @@ -504,11 +504,11 @@ public class ThumbCell extends StackPane { } finally { Platform.runLater(() -> setCursor(Cursor.DEFAULT)); } - }); + }).start(); } private void startStopActionAsync(Model model, boolean start) { - CompletableFuture.runAsync(() -> { + new Thread(() -> { try { if (start) { recorder.startRecording(model); @@ -523,7 +523,7 @@ public class ThumbCell extends StackPane { } finally { Platform.runLater(() -> setCursor(Cursor.DEFAULT)); } - }); + }).start(); } CompletableFuture follow(boolean follow) {