mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
Dont flush settings on exit after import (#1179)
Fixes bug when importing settings zip that would have the new settings be over written, and would not actually update
This commit is contained in:
@@ -50,6 +50,10 @@ public class ConfigManager {
|
||||
private final Thread settingsSaveThread;
|
||||
private long saveRequestTimestamp = -1;
|
||||
|
||||
// special case flag to disable flushing settings to disk at shutdown. Avoids the jvm shutdown
|
||||
// hook overwriting the settings we just uploaded
|
||||
private boolean flushOnShutdown = true;
|
||||
|
||||
enum ConfigSaveStrategy {
|
||||
SQL,
|
||||
LEGACY,
|
||||
@@ -303,4 +307,19 @@ public class ConfigManager {
|
||||
if (!ret.exists()) ret.mkdirs();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable flushing settings to disk as part of our JVM exit hook. Used to prevent uploading all
|
||||
* settings from getting its new configs overwritten at program exit and before theyre all loaded.
|
||||
*/
|
||||
public void disableFlushOnShutdown() {
|
||||
this.flushOnShutdown = false;
|
||||
}
|
||||
|
||||
public void onJvmExit() {
|
||||
if (flushOnShutdown) {
|
||||
logger.info("Force-flushing settings...");
|
||||
saveToDisk();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,8 +145,7 @@ public class HardwareManager {
|
||||
logger.info("Shutting down LEDs...");
|
||||
if (visionLED != null) visionLED.setState(false);
|
||||
|
||||
logger.info("Force-flushing settings...");
|
||||
ConfigManager.getInstance().saveToDisk();
|
||||
ConfigManager.getInstance().onJvmExit();
|
||||
}
|
||||
|
||||
public boolean restartDevice() {
|
||||
|
||||
@@ -94,6 +94,7 @@ public class RequestHandler {
|
||||
ctx.status(200);
|
||||
ctx.result("Successfully saved the uploaded settings zip, rebooting...");
|
||||
logger.info("Successfully saved the uploaded settings zip, rebooting...");
|
||||
ConfigManager.getInstance().disableFlushOnShutdown();
|
||||
restartProgram();
|
||||
} else {
|
||||
ctx.status(500);
|
||||
|
||||
Reference in New Issue
Block a user