mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-23 03:59:36 +00:00
support backing up data directory on windows with shut down #996
This commit is contained in:
parent
f6c35ba6f3
commit
e12ec197bf
2 changed files with 52 additions and 22 deletions
|
@ -89,6 +89,8 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
||||||
private static Consumer<Application> appLaunchedHandler;
|
private static Consumer<Application> appLaunchedHandler;
|
||||||
@Getter
|
@Getter
|
||||||
private static Runnable shutDownHandler;
|
private static Runnable shutDownHandler;
|
||||||
|
@Setter
|
||||||
|
private static Runnable onGracefulShutDownHandler;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
@ -145,6 +147,7 @@ public class HavenoApp extends Application implements UncaughtExceptionHandler {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
gracefulShutDownHandler.gracefulShutDown(() -> {
|
gracefulShutDownHandler.gracefulShutDown(() -> {
|
||||||
log.info("App shutdown complete");
|
log.info("App shutdown complete");
|
||||||
|
if (onGracefulShutDownHandler != null) onGracefulShutDownHandler.run();
|
||||||
});
|
});
|
||||||
}).start();
|
}).start();
|
||||||
shutDownRequested = true;
|
shutDownRequested = true;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package haveno.desktop.main.account.content.backup;
|
package haveno.desktop.main.account.content.backup;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import haveno.common.UserThread;
|
||||||
import haveno.common.config.Config;
|
import haveno.common.config.Config;
|
||||||
import haveno.common.file.FileUtil;
|
import haveno.common.file.FileUtil;
|
||||||
import haveno.common.persistence.PersistenceManager;
|
import haveno.common.persistence.PersistenceManager;
|
||||||
|
@ -27,6 +28,7 @@ import haveno.core.api.XmrLocalNode;
|
||||||
import haveno.core.locale.Res;
|
import haveno.core.locale.Res;
|
||||||
import haveno.core.user.Preferences;
|
import haveno.core.user.Preferences;
|
||||||
import haveno.core.xmr.wallet.XmrWalletService;
|
import haveno.core.xmr.wallet.XmrWalletService;
|
||||||
|
import haveno.desktop.app.HavenoApp;
|
||||||
import haveno.desktop.common.view.ActivatableView;
|
import haveno.desktop.common.view.ActivatableView;
|
||||||
import haveno.desktop.common.view.FxmlView;
|
import haveno.desktop.common.view.FxmlView;
|
||||||
import haveno.desktop.main.overlays.popups.Popup;
|
import haveno.desktop.main.overlays.popups.Popup;
|
||||||
|
@ -40,6 +42,8 @@ import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
@ -125,6 +129,30 @@ public class BackupView extends ActivatableView<GridPane, Void> {
|
||||||
openFileOrShowWarning(openLogsButton, logFile);
|
openFileOrShowWarning(openLogsButton, logFile);
|
||||||
|
|
||||||
backupNow.setOnAction(event -> {
|
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();
|
String backupDirectory = preferences.getBackupDirectory();
|
||||||
if (backupDirectory != null && backupDirectory.length() > 0) { // We need to flush data to disk
|
if (backupDirectory != null && backupDirectory.length() > 0) { // We need to flush data to disk
|
||||||
PersistenceManager.flushAllDataToDiskAtBackup(() -> {
|
PersistenceManager.flushAllDataToDiskAtBackup(() -> {
|
||||||
|
@ -149,7 +177,6 @@ public class BackupView extends ActivatableView<GridPane, Void> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFileOrShowWarning(Button button, File dataDir) {
|
private void openFileOrShowWarning(Button button, File dataDir) {
|
||||||
|
|
Loading…
Reference in a new issue