mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
support backing up data directory on windows with shut down #996
This commit is contained in:
parent
f6c35ba6f3
commit
e12ec197bf
@ -89,6 +89,8 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
||||
private static Consumer<Application> appLaunchedHandler;
|
||||
@Getter
|
||||
private static Runnable shutDownHandler;
|
||||
@Setter
|
||||
private static Runnable onGracefulShutDownHandler;
|
||||
|
||||
@Setter
|
||||
private Injector injector;
|
||||
@ -145,6 +147,7 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
||||
new Thread(() -> {
|
||||
gracefulShutDownHandler.gracefulShutDown(() -> {
|
||||
log.info("App shutdown complete");
|
||||
if (onGracefulShutDownHandler != null) onGracefulShutDownHandler.run();
|
||||
});
|
||||
}).start();
|
||||
shutDownRequested = true;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package haveno.desktop.main.account.content.backup;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import haveno.common.UserThread;
|
||||
import haveno.common.config.Config;
|
||||
import haveno.common.file.FileUtil;
|
||||
import haveno.common.persistence.PersistenceManager;
|
||||
@ -27,6 +28,7 @@ import haveno.core.api.XmrLocalNode;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.user.Preferences;
|
||||
import haveno.core.xmr.wallet.XmrWalletService;
|
||||
import haveno.desktop.app.HavenoApp;
|
||||
import haveno.desktop.common.view.ActivatableView;
|
||||
import haveno.desktop.common.view.FxmlView;
|
||||
import haveno.desktop.main.overlays.popups.Popup;
|
||||
@ -40,6 +42,8 @@ import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
@ -125,6 +129,30 @@ public class BackupView extends ActivatableView<GridPane, Void> {
|
||||
openFileOrShowWarning(openLogsButton, logFile);
|
||||
|
||||
backupNow.setOnAction(event -> {
|
||||
|
||||
// windows requires closing wallets for read access
|
||||
if (Utilities.isWindows()) {
|
||||
new Popup().information(Res.get("settings.net.needRestart"))
|
||||
.actionButtonText(Res.get("shared.applyAndShutDown"))
|
||||
.onAction(() -> {
|
||||
UserThread.runAfter(() -> {
|
||||
HavenoApp.setOnGracefulShutDownHandler(() -> doBackup());
|
||||
HavenoApp.getShutDownHandler().run();
|
||||
}, 500, TimeUnit.MILLISECONDS);
|
||||
})
|
||||
.closeButtonText(Res.get("shared.cancel"))
|
||||
.onClose(() -> {
|
||||
// nothing to do
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
doBackup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doBackup() {
|
||||
log.info("Backing up data directory");
|
||||
String backupDirectory = preferences.getBackupDirectory();
|
||||
if (backupDirectory != null && backupDirectory.length() > 0) { // We need to flush data to disk
|
||||
PersistenceManager.flushAllDataToDiskAtBackup(() -> {
|
||||
@ -149,7 +177,6 @@ public class BackupView extends ActivatableView<GridPane, Void> {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openFileOrShowWarning(Button button, File dataDir) {
|
||||
|
Loading…
Reference in New Issue
Block a user