Feat: add an option for disabling large downloads

This commit is contained in:
harlekin
2024-03-26 14:08:46 +00:00
committed by Laurent Clouet
parent c615c9b36d
commit a86c126d39
6 changed files with 49 additions and 12 deletions

View File

@@ -79,6 +79,7 @@ import lombok.Data;
private String UIType;
private String hostname;
private String theme;
private boolean disableLargeDownloads;
public Configuration(File cache_dir_, String login_, String password_) {
this.configFilePath = null;
@@ -110,6 +111,7 @@ import lombok.Data;
this.headless = java.awt.GraphicsEnvironment.isHeadless();
this.UIType = null;
this.theme = null;
this.disableLargeDownloads = false;
}
/**
@@ -145,7 +147,8 @@ import lombok.Data;
c + "headless: " + headless + n +
c + "UIType: " + UIType + n +
c + "hostname: " + hostname + n +
c + "theme: " + theme;
c + "theme: " + theme + n +
c + "disableLargeDownloads: " + disableLargeDownloads;
}
/**

View File

@@ -217,6 +217,7 @@ public class Server extends Thread {
.add("extras", user_config.getExtras())
.add("headless", java.awt.GraphicsEnvironment.isHeadless() ? "1" : (user_config.isHeadless() ? "1" : "0"))
.add("hwid", new HWIdentifier(log).getHardwareHash())
.add("disable_large_downloads", user_config.isDisableLargeDownloads() ? "1" : "0")
.build();
this.log.debug("Server::getConfiguration url " + remoteURL.build().toString());

View File

@@ -63,7 +63,8 @@ public class SettingsLoader {
USE_SYSTRAY("use-systray"),
HEADLESS("headless"),
UI("ui"),
THEME("theme");
THEME("theme"),
DISABLE_LARGE_DOWNLOADS("disable-large-downloads");
String propertyName;
@@ -105,6 +106,7 @@ public class SettingsLoader {
public static final String ARG_THEME = "-theme";
public static final String ARG_HOSTNAME = "-hostname";
public static final String ARG_HEADLESS = "--headless";
public static final String ARG_DISABLE_LARGE_DOWNLOADS = "--disable-large-downloads";
private String path;
@@ -128,6 +130,7 @@ public class SettingsLoader {
private Option<String> ui;
private Option<String> theme;
private Option<Integer> priority;
private Option<String> disableLargeDownloads;
public SettingsLoader(String path_) {
if (path_ == null) {
@@ -141,7 +144,7 @@ public class SettingsLoader {
public void setSettings(String path_, String login_, String password_, String proxy_, String hostname_,
ComputeType computeMethod_, GPUDevice gpu_, Integer cores_, Long maxRam_,
Integer maxRenderTime_, String cacheDir_, String sharedZip_, Boolean autoSignIn_, Boolean useSysTray_,
Boolean isHeadless, String ui_, String theme_, Integer priority_) {
Boolean isHeadless, String ui_, String theme_, Integer priority_, Boolean disableLargeDownloads_) {
if (path_ == null) {
path = OS.getOS().getDefaultConfigFilePath();
}
@@ -160,6 +163,8 @@ public class SettingsLoader {
ui = setValue(ui_, ui, ARG_UI);
priority = setValue(priority_, priority, ARG_PRIORITY);
theme = setValue(theme_, theme, ARG_THEME);
disableLargeDownloads = setValue(disableLargeDownloads_.toString(), disableLargeDownloads, ARG_DISABLE_LARGE_DOWNLOADS);
if (cores_ > 0) {
cores = setValue(cores_.toString(), cores, ARG_CORES);
@@ -212,7 +217,7 @@ public class SettingsLoader {
*/
public void markLaunchSettings(List<String> argsList) {
Option options[] = { login, password, proxy, hostname, computeMethod, gpu, cores, ram, renderTime, cacheDir, sharedZip,
autoSignIn, useSysTray, headless, ui, theme, priority };
autoSignIn, useSysTray, headless, ui, theme, priority, disableLargeDownloads };
for (Option option : options) {
if (option != null && argsList.contains(option.getLaunchFlag())) {
@@ -279,6 +284,7 @@ public class SettingsLoader {
setProperty(prop, configFileProp, PropertyNames.HEADLESS, headless);
setProperty(prop, configFileProp, PropertyNames.UI, ui);
setProperty(prop, configFileProp, PropertyNames.THEME, theme);
setProperty(prop, configFileProp, PropertyNames.DISABLE_LARGE_DOWNLOADS, disableLargeDownloads);
prop.store(output, null);
}
catch (IOException io) {
@@ -381,6 +387,8 @@ public class SettingsLoader {
theme = loadConfigOption(prop, PropertyNames.THEME, theme, ARG_THEME);
disableLargeDownloads = loadConfigOption(prop, PropertyNames.DISABLE_LARGE_DOWNLOADS, disableLargeDownloads, ARG_DISABLE_LARGE_DOWNLOADS);
if (prop.containsKey(PropertyNames.PRIORITY.propertyName)) {
int prio = Integer.parseInt(prop.getProperty(PropertyNames.PRIORITY.propertyName));
if (priority == null) {
@@ -513,6 +521,10 @@ public class SettingsLoader {
}
}
if (config.isDisableLargeDownloads() == false && disableLargeDownloads != null) {
config.setDisableLargeDownloads(Boolean.parseBoolean(disableLargeDownloads.getValue()));
}
// if the user has invoked the app with --no-systray, then we just overwrite the existing configuration with (boolean)false. If no parameter has been
// specified and the settings file contains use-systray=false, then deactivate as well.
if (!config.isUseSysTray() || (config.isUseSysTray() && useSysTray != null && useSysTray.getValue().equals("false"))) {
@@ -543,13 +555,12 @@ public class SettingsLoader {
this.renderTime = null;
this.theme = null;
this.cores = new Option<>(String.valueOf(defaultConfigValues.getNbCores()), ARG_CORES);
this.disableLargeDownloads = new Option<>(String.valueOf(defaultConfigValues.isDisableLargeDownloads()), ARG_DISABLE_LARGE_DOWNLOADS);
}
@Override public String toString() {
return String.format(
"SettingsLoader [path=%s, login=%s, password=%s, computeMethod=%s, gpu=%s, cacheDir=%s, sharedZip=%s, theme=%s, priority=%d, autosign=%s, usetray=%s, headless=%s]",
path, login, password, computeMethod, gpu, cacheDir, sharedZip, theme, priority, autoSignIn, useSysTray, headless);
"SettingsLoader [path=%s, login=%s, password=%s, computeMethod=%s, gpu=%s, cacheDir=%s, sharedZip=%s, theme=%s, priority=%d, autosign=%s, usetray=%s, headless=%s, disableLargeDownloads=%s]",
path, login, password, computeMethod, gpu, cacheDir, sharedZip, theme, priority, autoSignIn, useSysTray, headless, disableLargeDownloads);
}
}

View File

@@ -110,6 +110,7 @@ public class Worker {
@Option(name = SettingsLoader.ARG_HOSTNAME, usage = "Set a custom hostname name (name change will be lost when client is closed)", required = false) private String hostname = null;
@Option(name = SettingsLoader.ARG_HEADLESS, usage = "Mark your client manually as headless to block Eevee projects", required = false) private boolean headless = java.awt.GraphicsEnvironment.isHeadless();
@Option(name = SettingsLoader.ARG_DISABLE_LARGE_DOWNLOADS, usage = "Disable download of larger projects to preserve internet traffic", required = false) private boolean disableLargeDownloads = false;
public static void main(String[] args) {
if (OS.getOS() == null) {
@@ -447,6 +448,8 @@ public class Worker {
config.setConfigFilePath(config_file);
}
config.setDisableLargeDownloads(disableLargeDownloads);
SettingsLoader settingsLoader = new SettingsLoader(config_file);
settingsLoader.merge(config, true);

View File

@@ -22,7 +22,9 @@ public enum SwingTooltips {
COMPUTER_NAME("What this machine will be displayed as on your Sheepit profile page. Only you and admins can see this."),
MAX_TIME_PER_FRAME("How much time a frame should take at most. Sheepit will try to assign jobs to your machine that take less time to compute.");
MAX_TIME_PER_FRAME("How much time a frame should take at most. Sheepit will try to assign jobs to your machine that take less time to compute."),
DISABLE_LARGE_DOWNLOADS("Limits the client to smaller projects <= 750 MB. Consider this option if you are on a metered connection");
private final String explanation;

View File

@@ -92,6 +92,7 @@ public class Settings implements Activity {
private JSlider priority;
private JTextField proxy;
private JTextField hostname;
private JCheckBox disableLargeDownloads;
private ButtonGroup themeOptionsGroup;
private JRadioButton lightMode;
@@ -105,6 +106,7 @@ public class Settings implements Activity {
private boolean haveAutoStarted;
private boolean useSysTrayPrevState;
private boolean isHeadlessPrevState;
private boolean disableLargeDownloadsPrevState;
private boolean sessionStarted; //indicates whether the settings activity gets shown on launch or mid-session.
// it should only be false when the settings activity gets shown right after launch
@@ -121,6 +123,7 @@ public class Settings implements Activity {
parent.getSettingsLoader().merge(config, false);
useSysTrayPrevState = config.isUseSysTray();
isHeadlessPrevState = config.isHeadless();
disableLargeDownloadsPrevState = config.isDisableLargeDownloads();
applyTheme(config.getTheme()); // apply the proper theme (light/dark)
@@ -441,7 +444,7 @@ public class Settings implements Activity {
parent.getContentPanel().add(compute_devices_panel, constraints);
// other
CollapsibleJPanel advanced_panel = new CollapsibleJPanel(new GridLayout(5, 2), this);
CollapsibleJPanel advanced_panel = new CollapsibleJPanel(new GridLayout(6, 2), this);
advanced_panel.setBorder(BorderFactory.createTitledBorder("Advanced options"));
JLabel useSysTrayLabel = new JLabel("Minimize to SysTray");
@@ -458,6 +461,13 @@ public class Settings implements Activity {
advanced_panel.add(headlessLabel);
advanced_panel.add(headlessCheckbox);
JLabel disableLargeDownloadsLabel = new JLabel("Disable large downloads");
disableLargeDownloads = new JCheckBox();
disableLargeDownloads.setSelected(config.isDisableLargeDownloads());
disableLargeDownloadsLabel.setToolTipText(SwingTooltips.DISABLE_LARGE_DOWNLOADS.getText());
advanced_panel.add(disableLargeDownloadsLabel);
advanced_panel.add(disableLargeDownloads);
JLabel proxyLabel = new JLabel("Proxy:");
proxyLabel.setToolTipText("http://login:password@host:port\n" + SwingTooltips.PROXY.getText());
proxy = new JTextField();
@@ -756,6 +766,8 @@ public class Settings implements Activity {
config.setHeadless(headlessCheckbox.isSelected());
config.setDisableLargeDownloads(disableLargeDownloads.isSelected());
String proxyText = null;
if (proxy != null) {
try {
@@ -788,7 +800,7 @@ public class Settings implements Activity {
.setSettings(config.getConfigFilePath(), login.getText(), new String(password.getPassword()), proxyText, hostnameText, method,
selected_gpu, cpu_cores, max_ram, max_rendertime, getCachePath(config), getSharedPath(config), autoSignIn.isSelected(),
useSysTray.isSelected(), headlessCheckbox.isSelected(), GuiSwing.type, themeOptionsGroup.getSelection().getActionCommand(),
config.getPriority());
config.getPriority(), disableLargeDownloads.isSelected());
// wait for successful authentication (to store the public key)
// or do we already have one?
@@ -800,7 +812,8 @@ public class Settings implements Activity {
boolean sysTrayChanged = useSysTray.isSelected() != useSysTrayPrevState;
boolean headlessChanged = headlessCheckbox.isSelected() != isHeadlessPrevState;
boolean restartRequired = sysTrayChanged || headlessChanged;
boolean disableLargeDownloadsChanged = disableLargeDownloads.isSelected() != disableLargeDownloadsPrevState;
boolean restartRequired = sysTrayChanged || headlessChanged || disableLargeDownloadsChanged;
if (restartRequired) {
String warning = "The following changes require a restart to take effect: %s";
List<String> changes = new LinkedList<>();
@@ -813,6 +826,10 @@ public class Settings implements Activity {
changes.add("Block Eevee Projects");
}
if (disableLargeDownloadsChanged && sessionStarted) {
changes.add("Disable large Downloads");
}
if (changes.size() > 0) {
warning = String.format(warning, String.join(", ", changes));
JOptionPane.showMessageDialog(null, warning);