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

@@ -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);