Saving settings and local database on application exit

Fixes #55
This commit is contained in:
2019-12-20 15:05:31 +01:00
parent 16354ef392
commit e8f989902a
2 changed files with 15 additions and 20 deletions

View File

@ -11,6 +11,7 @@ import javax.swing.JOptionPane;
import envoy.client.Client;
import envoy.client.Config;
import envoy.client.LocalDB;
import envoy.client.Settings;
import envoy.client.util.EnvoyLog;
import envoy.exception.EnvoyException;
import envoy.schema.User;
@ -126,5 +127,18 @@ public class Startup {
e.printStackTrace();
}
});
// Save Settings and LocalDB on shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
logger.info("Saving local database...");
localDB.save();
logger.info("Saving settings...");
Settings.getInstance().save();
} catch (IOException e1) {
e1.printStackTrace();
logger.log(Level.WARNING, "Unable to save the messages", e1);
}
}));
}
}