Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refresh dynamic config if sufficiently old #598

Merged
merged 6 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- Minor: Pull latest dynamic configuration if sufficiently old. (#598)
- Minor: Allow overwriting webhooks or item lists on config import, rather than merging. (#595)
- Minor: Allow specifying tag IDs to apply for new forum thread messages. (#599)
- Minor: Add herbiboar support to kill count notifier. (#602)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dinkplugin/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import javax.swing.SwingUtilities;
import java.io.IOException;
import java.lang.reflect.Type;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -104,6 +106,8 @@ public class SettingsManager {
private final ConfigManager configManager;
private final OkHttpClient httpClient;

private volatile Instant lastDynamicImport = null;

/**
* Check whether a username complies with the configured RSN filter list.
*
Expand Down Expand Up @@ -305,6 +309,12 @@ void onGameState(GameState oldState, GameState newState) {

return true;
});

// refresh dynamic config if it's been 3+ hours
var lastImport = lastDynamicImport;
if (lastImport != null && Duration.between(lastImport, Instant.now()).toHours() >= 3) {
importDynamicConfig(config.dynamicConfigUrl());
}
}

void onTick() {
Expand Down Expand Up @@ -417,6 +427,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) {
map.remove(DYNAMIC_IMPORT_CONFIG_KEY);

handleImport(map, true);
lastDynamicImport = Instant.now();
}

@Override
Expand Down