From 445c4edeca8f70bec8ae02a17db234ed06e88d62 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Thu, 7 Dec 2017 07:08:24 +0000 Subject: [PATCH] gui, lib/config, lib/model: Support auto-accepting folders (fixes #2299) Also introduces a new Waiter interface for config changes and segments the configuration GUI. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4551 --- cmd/syncthing/gui.go | 10 +- cmd/syncthing/main.go | 11 +- cmd/syncthing/mocked_config_test.go | 12 +- gui/default/assets/css/overrides.css | 4 + gui/default/assets/lang/lang-en.json | 8 + gui/default/index.html | 2 +- .../syncthing/device/editDeviceModalView.html | 74 +++-- .../syncthing/settings/settingsModalView.html | 291 ++++++++++------- lib/config/commit_test.go | 6 +- lib/config/config_test.go | 2 +- lib/config/deviceconfiguration.go | 1 + lib/config/folderconfiguration.go | 17 +- lib/config/optionsconfiguration.go | 24 +- lib/config/wrapper.go | 71 ++-- lib/connections/service.go | 3 +- lib/model/model.go | 120 +++++-- lib/model/model_test.go | 302 ++++++++++++++++-- lib/model/requests_test.go | 4 +- lib/nat/registry.go | 5 +- lib/upnp/upnp.go | 4 +- lib/util/utils.go | 26 ++ lib/util/utils_test.go | 58 ++++ 22 files changed, 771 insertions(+), 284 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index ea8c63e8..b6a19d1b 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -112,12 +112,12 @@ type configIntf interface { GUI() config.GUIConfiguration RawCopy() config.Configuration Options() config.OptionsConfiguration - Replace(cfg config.Configuration) error + Replace(cfg config.Configuration) (config.Waiter, error) Subscribe(c config.Committer) Folders() map[string]config.FolderConfiguration Devices() map[protocol.DeviceID]config.DeviceConfiguration - SetDevice(config.DeviceConfiguration) error - SetDevices([]config.DeviceConfiguration) error + SetDevice(config.DeviceConfiguration) (config.Waiter, error) + SetDevices([]config.DeviceConfiguration) (config.Waiter, error) Save() error ListenAddresses() []string RequiresRestart() bool @@ -809,7 +809,7 @@ func (s *apiService) postSystemConfig(w http.ResponseWriter, r *http.Request) { // Activate and save - if err := s.cfg.Replace(to); err != nil { + if _, err := s.cfg.Replace(to); err != nil { l.Warnln("Replacing config:", err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -1201,7 +1201,7 @@ func (s *apiService) makeDevicePauseHandler(paused bool) http.HandlerFunc { cfgs = append(cfgs, cfg) } - if err := s.cfg.SetDevices(cfgs); err != nil { + if _, err := s.cfg.SetDevices(cfgs); err != nil { http.Error(w, err.Error(), 500) } } diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index e6ae111f..07118fd2 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -1080,14 +1080,7 @@ func defaultConfig(cfgFile string) *config.Wrapper { if !noDefaultFolder { l.Infoln("Default folder created and/or linked to new config") - defaultFolder = config.NewFolderConfiguration("default", fs.FilesystemTypeBasic, locations[locDefFolder]) - defaultFolder.Label = "Default Folder" - defaultFolder.RescanIntervalS = 60 - defaultFolder.FSWatcherDelayS = 10 - defaultFolder.MinDiskFree = config.Size{Value: 1, Unit: "%"} - defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}} - defaultFolder.AutoNormalize = true - defaultFolder.MaxConflicts = -1 + defaultFolder = config.NewFolderConfiguration(myID, "default", "Default Folder", fs.FilesystemTypeBasic, locations[locDefFolder]) } else { l.Infoln("We will skip creation of a default folder on first start since the proper envvar is set") } @@ -1331,7 +1324,7 @@ func setPauseState(cfg *config.Wrapper, paused bool) { for i := range raw.Folders { raw.Folders[i].Paused = paused } - if err := cfg.Replace(raw); err != nil { + if _, err := cfg.Replace(raw); err != nil { l.Fatalln("Cannot adjust paused state:", err) } } diff --git a/cmd/syncthing/mocked_config_test.go b/cmd/syncthing/mocked_config_test.go index bc825d40..41869f54 100644 --- a/cmd/syncthing/mocked_config_test.go +++ b/cmd/syncthing/mocked_config_test.go @@ -34,8 +34,8 @@ func (c *mockedConfig) Options() config.OptionsConfiguration { return config.OptionsConfiguration{} } -func (c *mockedConfig) Replace(cfg config.Configuration) error { - return nil +func (c *mockedConfig) Replace(cfg config.Configuration) (config.Waiter, error) { + return nil, nil } func (c *mockedConfig) Subscribe(cm config.Committer) {} @@ -48,12 +48,12 @@ func (c *mockedConfig) Devices() map[protocol.DeviceID]config.DeviceConfiguratio return nil } -func (c *mockedConfig) SetDevice(config.DeviceConfiguration) error { - return nil +func (c *mockedConfig) SetDevice(config.DeviceConfiguration) (config.Waiter, error) { + return nil, nil } -func (c *mockedConfig) SetDevices([]config.DeviceConfiguration) error { - return nil +func (c *mockedConfig) SetDevices([]config.DeviceConfiguration) (config.Waiter, error) { + return nil, nil } func (c *mockedConfig) Save() error { diff --git a/gui/default/assets/css/overrides.css b/gui/default/assets/css/overrides.css index 2d965e0d..b35f5f57 100644 --- a/gui/default/assets/css/overrides.css +++ b/gui/default/assets/css/overrides.css @@ -367,3 +367,7 @@ ul.three-columns li, ul.two-columns li { width: 100%; } } + +.tab-content { + padding-top: 10px; +} diff --git a/gui/default/assets/lang/lang-en.json b/gui/default/assets/lang/lang-en.json index 79a107d2..b4673766 100644 --- a/gui/default/assets/lang/lang-en.json +++ b/gui/default/assets/lang/lang-en.json @@ -28,8 +28,10 @@ "Any devices configured on an introducer device will be added to this device as well.": "Any devices configured on an introducer device will be added to this device as well.", "Are you sure you want to remove device {%name%}?": "Are you sure you want to remove device {{name}}?", "Are you sure you want to remove folder {%label%}?": "Are you sure you want to remove folder {{label}}?", + "Auto Accept": "Auto Accept", "Automatic upgrade now offers the choice between stable releases and release candidates.": "Automatic upgrade now offers the choice between stable releases and release candidates.", "Automatic upgrades": "Automatic upgrades", + "Automatically create or share folders that this device advertises at the default path.": "Automatically create or share folders that this device advertises at the default path.", "Be careful!": "Be careful!", "Bugs": "Bugs", "CPU Utilization": "CPU Utilization", @@ -43,12 +45,14 @@ "Configured": "Configured", "Connection Error": "Connection Error", "Connection Type": "Connection Type", + "Connections": "Connections", "Copied from elsewhere": "Copied from elsewhere", "Copied from original": "Copied from original", "Copyright © 2014-2016 the following Contributors:": "Copyright © 2014-2016 the following Contributors:", "Copyright © 2014-2017 the following Contributors:": "Copyright © 2014-2017 the following Contributors:", "Creating ignore patterns, overwriting an existing file at {%path%}.": "Creating ignore patterns, overwriting an existing file at {{path}}.", "Danger!": "Danger!", + "Default Folder Path": "Default Folder Path", "Deleted": "Deleted", "Device": "Device", "Device \"{%name%}\" ({%device%} at {%address%}) wants to connect. Add new device?": "Device \"{{name}}\" ({{device}} at {{address}}) wants to connect. Add new device?", @@ -101,6 +105,7 @@ "GUI Listen Address": "GUI Listen Address", "GUI Listen Addresses": "GUI Listen Addresses", "GUI Theme": "GUI Theme", + "General": "General", "Generate": "Generate", "Global Changes": "Global Changes", "Global Discovery": "Global Discovery", @@ -156,6 +161,7 @@ "Override Changes": "Override Changes", "Path": "Path", "Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for": "Path to the folder on the local computer. Will be created if it does not exist. The tilde character (~) can be used as a shortcut for", + "Path where new auto accepted folders will be created, as well as the default suggested path when adding new folders via the UI. Tilde character (~) expands to {%tilde%}.": "Path where new auto accepted folders will be created, as well as the default suggested path when adding new folders via the UI. Tilde character (~) expands to {{tilde}}.", "Path where versions should be stored (leave empty for the default .stversions directory in the shared folder).": "Path where versions should be stored (leave empty for the default .stversions directory in the shared folder).", "Path where versions should be stored (leave empty for the default .stversions folder in the folder).": "Path where versions should be stored (leave empty for the default .stversions folder in the folder).", "Pause": "Pause", @@ -264,6 +270,8 @@ "Time": "Time", "Trash Can File Versioning": "Trash Can File Versioning", "Type": "Type", + "Unavailable": "Unavailable", + "Unavailable/Disabled by administrator or maintainer": "Unavailable/Disabled by administrator or maintainer", "Undecided (will prompt)": "Undecided (will prompt)", "Unknown": "Unknown", "Unshared": "Unshared", diff --git a/gui/default/index.html b/gui/default/index.html index 2ef44ac9..c8705fd5 100644 --- a/gui/default/index.html +++ b/gui/default/index.html @@ -402,7 +402,7 @@  Shared With {{sharesFolder(folder)}} - +  Last Scan Never diff --git a/gui/default/syncthing/device/editDeviceModalView.html b/gui/default/syncthing/device/editDeviceModalView.html index 9072e867..cbd2c7f5 100644 --- a/gui/default/syncthing/device/editDeviceModalView.html +++ b/gui/default/syncthing/device/editDeviceModalView.html @@ -24,31 +24,59 @@
{{currentDevice.deviceID}}
-
- - -

Shown instead of Device ID in the cluster status. Will be advertised to other devices as an optional default name.

-

Shown instead of Device ID in the cluster status. Will be updated to the name the device advertises if left empty.

+
+
+
+ + +

Shown instead of Device ID in the cluster status. Will be advertised to other devices as an optional default name.

+

Shown instead of Device ID in the cluster status. Will be updated to the name the device advertises if left empty.

+
+
+
+
+ + +

Enter comma separated ("tcp://ip:port", "tcp://host:port") addresses or "dynamic" to perform automatic discovery of the address.

+
+
-
- - -

Enter comma separated ("tcp://ip:port", "tcp://host:port") addresses or "dynamic" to perform automatic discovery of the address.

+
+
+
+ + +
+
+
+
-
- - -
-
-
- -

Add devices from the introducer to our device list, for mutually shared folders.

+
+
+
+
+ +
+
+
+
+
+
+ +
+
diff --git a/gui/default/syncthing/settings/settingsModalView.html b/gui/default/syncthing/settings/settingsModalView.html index d406831a..deb15ab4 100644 --- a/gui/default/syncthing/settings/settingsModalView.html +++ b/gui/default/syncthing/settings/settingsModalView.html @@ -1,36 +1,180 @@