Skip to content

Commit

Permalink
- First changes to fix/workaround multiple hangs on macOS Sonoma 14.1
Browse files Browse the repository at this point in the history
- disable shutdown progress dialog when quitting app as it does not work on macOS Sonoma 14.1
- bump library version
  • Loading branch information
derreisende77 committed Oct 26, 2023
1 parent a9b8093 commit cc045fa
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 245 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
- **FEATURE:** Fehlerhafte Downloads werden nun automatisch aus der Gesehen Datenbank entfernt.
-
# **14.0.0**
- Es wird nun Java 20 verwendet.
- **ACHTUNG: macOS Sonoma 14.1 verursacht diverse Probleme und Programmhänger! Einige dieser Probleme konnten beseitigt werden, führen aber zu kleineren Einschränkungen.**
- macOS: Speicherverbrauchsanzeige wurde deaktiviert. Sie verursacht bisher unbekannte Programmanomalien unter macOS Sonoma 14.1
- Beim Beenden wird kein Fortschrittsdialog mehr angezeigt.
- Es wird nun Java 21 verwendet.
- User Interface wurde primär für neue macOS-Versionen überarbeitet.
- Die *macOS Intel* Version nutzt nun Liberica JDK full mit integriertem JavaFX. Dadurch kann MediathekView nun auch wieder fehlerfrei mit Apple Silicon Macs gebaut werden.
- Das Programm überprüft beim Start ob die JVM-Parameter korrekt sind und gibt ansonsten eine Warnung aus. Dies kann über die Paramter `-nj` oder `--no-jvm-param-checks` deaktiviert werden.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<install4j-maven-plugin.version>1.1.2</install4j-maven-plugin.version>
<jackson.version>2.15.2</jackson.version>
<jaffree.version>2022.06.03</jaffree.version>
<javafx.version>20.0.1</javafx.version>
<javafx.version>21.0.1</javafx.version>
<javax.transaction-api.version>1.3</javax.transaction-api.version>
<jna.version>5.13.0</jna.version>
<junit.jupiter.version>5.9.2</junit.jupiter.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public MemoryMonitorAction(@NotNull JFrame parent) {
public void closeMemoryMonitor() {
if (dialog != null) {
dialog.dispose();
dialog = null;
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/main/java/mediathek/javafx/tool/JFXHiddenApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class JFXHiddenApplication extends Application {

private static Stage primaryStage;
private static final String ICON_NAME = "MediathekView.png";
private static final String ICON_PATH = "/mediathek/res/";

public static void launchApplication() {
new Thread(JFXHiddenApplication::launch).start();
}

public static Image getApplicationImage() {
return new Image(JFXHiddenApplication.class.getResourceAsStream(ICON_PATH + ICON_NAME));
}

@Override
public void start(Stage primaryStage) {
JFXHiddenApplication.primaryStage = primaryStage;
Expand All @@ -30,7 +22,6 @@ public void start(Stage primaryStage) {
primaryStage.setTitle("MediathekView Invisible Helper Window");


primaryStage.getIcons().add(getApplicationImage());
primaryStage.show();
primaryStage.hide();
}
Expand Down
70 changes: 37 additions & 33 deletions src/main/java/mediathek/mainwindow/MediathekGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,15 @@ private void createFileMenu() {

private void createViewMenu() {
jMenuAnsicht.addSeparator();
jMenuAnsicht.add(showMemoryMonitorAction);
if (!SystemUtils.IS_OS_MAC_OSX) {
jMenuAnsicht.add(showMemoryMonitorAction);
}
else {
// only show for debug purposes...wil cause hang at shutdown
if (Config.isDebugModeEnabled()) {
jMenuAnsicht.add(showMemoryMonitorAction);
}
}
jMenuAnsicht.add(showBandwidthUsageAction);
jMenuAnsicht.addSeparator();
jMenuAnsicht.add(tabFilme.toggleFilterDialogVisibilityAction);
Expand Down Expand Up @@ -1036,6 +1044,8 @@ public boolean quitApplication(boolean shouldDownloadAndQuit) {
setShutdownRequested(dialogBeenden.isShutdownRequested());
}

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

if (automaticFilmlistUpdate != null)
automaticFilmlistUpdate.close();

Expand All @@ -1051,71 +1061,64 @@ 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();

setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

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

Expand All @@ -1140,9 +1143,10 @@ private void cleanupLuceneIndex() {
* Gracefully shutdown the JavaFX environment.
*/
private void shutdownJavaFx() {
//FIXME macOS Sonoma 14.1 causes freezes here :-(
if (!SystemUtils.IS_OS_MAC_OSX)
//causes system hang on Sonoma 14.1
if (!SystemUtils.IS_OS_MAC_OSX) {
JavaFxUtils.invokeInFxThreadAndWait(() -> JFXHiddenApplication.getPrimaryStage().close());
}

Platform.exit();
}
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/mediathek/mainwindow/MemoryUsagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import mediathek.tool.MessageBus;
import net.engio.mbassy.listener.Handler;
import org.jetbrains.annotations.NotNull;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
Expand Down Expand Up @@ -64,7 +62,6 @@ public MemoryUsagePanel(int maxAge, @NotNull TimeUnit timeUnit) {
var chart = new JFreeChart(plot);
chart.removeLegend();
var chartPanel = new ChartPanel(chart);
chartPanel.addChartMouseListener(new GarbageCollectionMouseListener());
chartPanel.setPopupMenu(null);
add(chartPanel);

Expand Down Expand Up @@ -92,18 +89,6 @@ private void addTotalObservation(double y) {
total.add(new Millisecond(), y);
}

private static class GarbageCollectionMouseListener implements ChartMouseListener {
@Override
public void chartMouseClicked(ChartMouseEvent event) {
System.gc();
}

@Override
public void chartMouseMoved(ChartMouseEvent event) {

}
}

public class MemoryUsageDataGenerator extends Timer implements ActionListener {

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

This file was deleted.

6 changes: 4 additions & 2 deletions src/main/java/mediathek/tool/ApplicationConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class ApplicationConfiguration {
* A custom small thread scheduler exclusively for config changes.
*/
private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
private final TimerTaskListener timerTaskListener = new TimerTaskListener();
private XMLConfiguration config;
private FileHandler handler;
/**
Expand Down Expand Up @@ -147,7 +148,7 @@ public void setBlacklistDoNotShowGeoblockedFilms(boolean newValue) {
}

private void initializeTimedEventWriting() {
config.addEventListener(ConfigurationEvent.ANY, new TimerTaskListener());
config.addEventListener(ConfigurationEvent.ANY, timerTaskListener);
}

private void setupXmlConfiguration() {
Expand Down Expand Up @@ -179,7 +180,8 @@ private void loadOrCreateConfiguration() {
public void writeConfiguration() {
try {
// cancel a pending writer task first
if (future != null) future.cancel(false);
config.removeEventListener(ConfigurationEvent.ANY, timerTaskListener);
if (future != null) future.cancel(true);

handler.save();
} catch (ConfigurationException configurationException) {
Expand Down
Loading

0 comments on commit cc045fa

Please sign in to comment.