Copy online settings if they're newer than offline (#285)
* Copy online settings if they're newer than offline * Add range for opacity
This commit is contained in:
@@ -147,7 +147,7 @@ public class SessionManager
|
||||
{
|
||||
// Initialize config for new session
|
||||
// If the session isn't logged in yet, don't switch to the new config
|
||||
configManager.switchSession(session);
|
||||
configManager.switchSession();
|
||||
}
|
||||
|
||||
eventBus.post(new SessionOpen());
|
||||
@@ -177,7 +177,7 @@ public class SessionManager
|
||||
accountSession = null; // No more account
|
||||
|
||||
// Restore config
|
||||
configManager.switchSession(null);
|
||||
configManager.switchSession();
|
||||
|
||||
eventBus.post(new SessionClose());
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.account.AccountSession;
|
||||
import static net.runelite.client.RuneLite.PROFILES_DIR;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
|
||||
@@ -71,14 +71,14 @@ import net.runelite.client.util.ColorUtil;
|
||||
public class ConfigManager
|
||||
{
|
||||
private static final String SETTINGS_FILE_NAME = "runeliteplus.properties";
|
||||
private static final String STANDARD_SETTINGS_FILE_NAME = "settings.properties";
|
||||
private static final File SETTINGS_FILE = new File(RuneLite.RUNELITE_DIR, SETTINGS_FILE_NAME);
|
||||
private static final File STANDARD_SETTINGS_FILE = new File(RuneLite.RUNELITE_DIR, "settings.properties");
|
||||
private static final File STANDARD_SETTINGS_FILE = new File(RuneLite.RUNELITE_DIR, STANDARD_SETTINGS_FILE_NAME);
|
||||
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
private final ScheduledExecutorService executor;
|
||||
|
||||
private final ConfigInvocationHandler handler = new ConfigInvocationHandler(this);
|
||||
private final Properties properties = new Properties();
|
||||
private final Map<String, String> pendingChanges = new HashMap<>();
|
||||
@@ -91,7 +91,7 @@ public class ConfigManager
|
||||
executor.scheduleWithFixedDelay(this::sendConfig, 30, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public final void switchSession(AccountSession session)
|
||||
public final void switchSession()
|
||||
{
|
||||
// Ensure existing config is saved
|
||||
load();
|
||||
@@ -164,7 +164,7 @@ public class ConfigManager
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
log.debug("Unable to load settings - no such file, syncing from standard settings");
|
||||
syncPropertiesFromFile(STANDARD_SETTINGS_FILE);
|
||||
syncLastModified();
|
||||
}
|
||||
catch (IllegalArgumentException | IOException ex)
|
||||
{
|
||||
@@ -201,11 +201,11 @@ public class ConfigManager
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToFile(final File propertiesFile) throws IOException
|
||||
private void saveToFile() throws IOException
|
||||
{
|
||||
propertiesFile.getParentFile().mkdirs();
|
||||
ConfigManager.SETTINGS_FILE.getParentFile().mkdirs();
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(propertiesFile))
|
||||
try (FileOutputStream out = new FileOutputStream(ConfigManager.SETTINGS_FILE))
|
||||
{
|
||||
final FileLock lock = out.getChannel().lock();
|
||||
|
||||
@@ -589,7 +589,7 @@ public class ConfigManager
|
||||
{
|
||||
try
|
||||
{
|
||||
saveToFile(SETTINGS_FILE);
|
||||
saveToFile();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -597,4 +597,32 @@ public class ConfigManager
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncLastModified()
|
||||
{
|
||||
File newestFile;
|
||||
|
||||
newestFile = STANDARD_SETTINGS_FILE;
|
||||
|
||||
for (File profileDir : PROFILES_DIR.listFiles())
|
||||
{
|
||||
if (!profileDir.isDirectory())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (File settings : profileDir.listFiles())
|
||||
{
|
||||
if (!settings.getName().equals(STANDARD_SETTINGS_FILE_NAME) ||
|
||||
settings.lastModified() < newestFile.lastModified())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
newestFile = settings;
|
||||
}
|
||||
}
|
||||
|
||||
syncPropertiesFromFile(newestFile);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ package net.runelite.client.plugins.runeliteplus;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Range;
|
||||
|
||||
@ConfigGroup("runeliteplus")
|
||||
public interface RuneLitePlusConfig extends Config
|
||||
@@ -55,6 +56,10 @@ public interface RuneLitePlusConfig extends Config
|
||||
return false;
|
||||
}
|
||||
|
||||
@Range(
|
||||
min = 15,
|
||||
max = 100
|
||||
)
|
||||
@ConfigItem(
|
||||
keyName = "opacityPercentage",
|
||||
name = "Opacity percentage",
|
||||
|
||||
Reference in New Issue
Block a user