Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed Oct 26, 2023
1 parent a9b8093 commit c54d55c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 108 deletions.
51 changes: 21 additions & 30 deletions src/main/java/mediathek/mainwindow/MediathekGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,71 +1051,62 @@ public boolean quitApplication(boolean shouldDownloadAndQuit) {

manageAboAction.closeDialog();

ShutdownDialogController shutdownProgress = new ShutdownDialogController(this);
shutdownProgress.show();

var historyWorker = CompletableFuture.runAsync(() -> {
try (SeenHistoryController history = new SeenHistoryController()) {
history.performMaintenance();
}
});
logger.info("Perform history maintenance.");
try (SeenHistoryController history = new SeenHistoryController()) {
history.performMaintenance();
}

var bookmarkWorker = CompletableFuture.runAsync(() ->
daten.getListeBookmarkList().saveToFile(StandardLocations.getBookmarkFilePath()));
logger.info("Save bookmark list.");
daten.getListeBookmarkList().saveToFile(StandardLocations.getBookmarkFilePath());

// stop the download thread
shutdownProgress.setStatus(ShutdownState.TERMINATE_STARTER_THREAD);
logger.info("Stop Starter Thread.");
daten.getStarterClass().getStarterThread().interrupt();

shutdownProgress.setStatus(ShutdownState.SHUTDOWN_NOTIFICATION_CENTER);
logger.info("Close Notification center.");
closeNotificationCenter();

// Tabelleneinstellungen merken
shutdownProgress.setStatus(ShutdownState.SAVE_FILM_DATA);
logger.info("Save Tab Filme data.");
tabFilme.tabelleSpeichern();
tabFilme.saveSettings(); // needs thread pools active!
tabFilme.filmActionPanel.getFilterDialog().dispose();

shutdownProgress.setStatus(ShutdownState.SAVE_DOWNLOAD_DATA);
logger.info("Save Tab Download data.");
tabDownloads.tabelleSpeichern();

shutdownProgress.setStatus(ShutdownState.STOP_DOWNLOADS);
logger.info("Stop all downloads.");
stopDownloads();

shutdownProgress.setStatus(ShutdownState.SAVE_APP_DATA);
logger.info("Save app data.");
daten.allesSpeichern();

shutdownProgress.setStatus(ShutdownState.SHUTDOWN_THREAD_POOL);
logger.info("Shutdown pools.");
shutdownTimerPool();
waitForCommonPoolToComplete();

//shutdown JavaFX
shutdownProgress.setStatus(ShutdownState.TERMINATE_JAVAFX_SUPPORT);
logger.info("Shutdown JavaFX.");
shutdownJavaFx();

try {
shutdownProgress.setStatus(ShutdownState.SAVE_BOOKMARKS);
bookmarkWorker.get();

shutdownProgress.setStatus(ShutdownState.PERFORM_SEEN_HISTORY_MAINTENANCE);
historyWorker.get();
} catch (InterruptedException | ExecutionException e) {
logger.error("Async task error", e);
}

//close main window
logger.info("Close main window.");
dispose();

//write all settings if not done already...
logger.info("Write app config.");
ApplicationConfiguration.getInstance().writeConfiguration();

RuntimeStatistics.printRuntimeStatistics();
RuntimeStatistics.printDataUsageStatistics();
shutdownProgress.setStatus(ShutdownState.COMPLETE);
if (Config.isEnhancedLoggingEnabled()) {
RuntimeStatistics.printDataUsageStatistics();
}

logger.info("Cleanup Lucene index.");
cleanupLuceneIndex();

if (isShutdownRequested()) {
logger.info("Requesting computer shutdown.");
shutdownComputer();
}

Expand Down
44 changes: 0 additions & 44 deletions src/main/java/mediathek/mainwindow/ShutdownDialogController.kt

This file was deleted.

13 changes: 5 additions & 8 deletions src/main/java/mediathek/tool/RuntimeStatistics.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mediathek.tool;

import mediathek.config.Config;
import mediathek.tool.http.MVHttpClient;
import org.apache.logging.log4j.LogManager;

Expand All @@ -19,7 +18,7 @@ public class RuntimeStatistics {
public static void printRuntimeStatistics() {
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
final var endZeit = LocalDateTime.now();
final var runTime = LocalTime.MIN.plusSeconds(Duration.between(startZeit,endZeit).toSeconds());
final var runTime = LocalTime.MIN.plusSeconds(Duration.between(startZeit, endZeit).toSeconds());

var logger = LogManager.getLogger();
logger.info("################################################################################");
Expand All @@ -29,11 +28,9 @@ public static void printRuntimeStatistics() {
}

public static void printDataUsageStatistics() {
if (Config.isEnhancedLoggingEnabled()) {
var byteCounter = MVHttpClient.getInstance().getByteCounter();
var logger = LogManager.getLogger();
logger.info("total data sent: {}", FileUtils.humanReadableByteCountBinary(byteCounter.totalBytesWritten()));
logger.info("total data received: {}", FileUtils.humanReadableByteCountBinary(byteCounter.totalBytesRead()));
}
var byteCounter = MVHttpClient.getInstance().getByteCounter();
var logger = LogManager.getLogger();
logger.info("total data sent: {}", FileUtils.humanReadableByteCountBinary(byteCounter.totalBytesWritten()));
logger.info("total data received: {}", FileUtils.humanReadableByteCountBinary(byteCounter.totalBytesRead()));
}
}
26 changes: 0 additions & 26 deletions src/main/java/mediathek/tool/ShutdownState.java

This file was deleted.

0 comments on commit c54d55c

Please sign in to comment.