mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Simplify usage reporting config options (fixes #370)
This commit is contained in:
parent
d09c71b688
commit
b05fcbc9d7
File diff suppressed because one or more lines are too long
@ -250,30 +250,18 @@ func restPostConfig(req *http.Request, m *model.Model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if newCfg.Options.UREnabled && !cfg.Options.UREnabled {
|
if newCfg.Options.URAccepted > cfg.Options.URAccepted {
|
||||||
// UR was enabled
|
// UR was enabled
|
||||||
cfg.Options.UREnabled = true
|
|
||||||
cfg.Options.URDeclined = false
|
|
||||||
cfg.Options.URAccepted = usageReportVersion
|
|
||||||
// Set the corresponding options in newCfg so we don't trigger the restart check if this was the only option change
|
|
||||||
newCfg.Options.URDeclined = false
|
|
||||||
newCfg.Options.URAccepted = usageReportVersion
|
newCfg.Options.URAccepted = usageReportVersion
|
||||||
err := sendUsageReport(m)
|
err := sendUsageReport(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Infoln("Usage report:", err)
|
l.Infoln("Usage report:", err)
|
||||||
}
|
}
|
||||||
go usageReportingLoop(m)
|
go usageReportingLoop(m)
|
||||||
} else if !newCfg.Options.UREnabled && cfg.Options.UREnabled {
|
} else if newCfg.Options.URAccepted < cfg.Options.URAccepted {
|
||||||
// UR was disabled
|
// UR was disabled
|
||||||
cfg.Options.UREnabled = false
|
newCfg.Options.URAccepted = -1
|
||||||
cfg.Options.URDeclined = true
|
|
||||||
cfg.Options.URAccepted = 0
|
|
||||||
// Set the corresponding options in newCfg so we don't trigger the restart check if this was the only option change
|
|
||||||
newCfg.Options.URDeclined = true
|
|
||||||
newCfg.Options.URAccepted = 0
|
|
||||||
stopUsageReporting()
|
stopUsageReporting()
|
||||||
} else {
|
|
||||||
cfg.Options.URDeclined = newCfg.Options.URDeclined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(cfg.Options, newCfg.Options) || !reflect.DeepEqual(cfg.GUI, newCfg.GUI) {
|
if !reflect.DeepEqual(cfg.Options, newCfg.Options) || !reflect.DeepEqual(cfg.GUI, newCfg.GUI) {
|
||||||
|
@ -415,11 +415,11 @@ nextRepo:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Options.UREnabled && cfg.Options.URAccepted < usageReportVersion {
|
if cfg.Options.URAccepted > 0 && cfg.Options.URAccepted < usageReportVersion {
|
||||||
l.Infoln("Anonymous usage report has changed; revoking acceptance")
|
l.Infoln("Anonymous usage report has changed; revoking acceptance")
|
||||||
cfg.Options.UREnabled = false
|
cfg.Options.URAccepted = 0
|
||||||
}
|
}
|
||||||
if cfg.Options.UREnabled {
|
if cfg.Options.URAccepted >= usageReportVersion {
|
||||||
go usageReportingLoop(m)
|
go usageReportingLoop(m)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10 * time.Minute)
|
time.Sleep(10 * time.Minute)
|
||||||
|
@ -107,7 +107,10 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stopUsageReporting() {
|
func stopUsageReporting() {
|
||||||
stopUsageReportingCh <- struct{}{}
|
select {
|
||||||
|
case stopUsageReportingCh <- struct{}{}:
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
// Returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
||||||
|
@ -16,9 +16,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/calmh/syncthing/scanner"
|
|
||||||
"code.google.com/p/go.crypto/bcrypt"
|
"code.google.com/p/go.crypto/bcrypt"
|
||||||
"github.com/calmh/syncthing/logger"
|
"github.com/calmh/syncthing/logger"
|
||||||
|
"github.com/calmh/syncthing/scanner"
|
||||||
)
|
)
|
||||||
|
|
||||||
var l = logger.DefaultLogger
|
var l = logger.DefaultLogger
|
||||||
@ -156,11 +156,10 @@ type OptionsConfiguration struct {
|
|||||||
MaxChangeKbps int `xml:"maxChangeKbps" default:"10000"`
|
MaxChangeKbps int `xml:"maxChangeKbps" default:"10000"`
|
||||||
StartBrowser bool `xml:"startBrowser" default:"true"`
|
StartBrowser bool `xml:"startBrowser" default:"true"`
|
||||||
UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
|
UPnPEnabled bool `xml:"upnpEnabled" default:"true"`
|
||||||
|
URAccepted int `xml:"urAccepted"` // Accepted usage reporting version; 0 for off (undecided), -1 for off (permanently)
|
||||||
|
|
||||||
UREnabled bool `xml:"urEnabled"` // If true, send usage reporting data
|
Deprecated_UREnabled bool `xml:"urEnabled,omitempty" json:"-"`
|
||||||
URDeclined bool `xml:"urDeclined"` // If true, don't ask again
|
Deprecated_URDeclined bool `xml:"urDeclined,omitempty" json:"-"`
|
||||||
URAccepted int `xml:"urAccepted"` // Accepted usage reporting version
|
|
||||||
|
|
||||||
Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
|
Deprecated_ReadOnly bool `xml:"readOnly,omitempty" json:"-"`
|
||||||
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
|
Deprecated_GUIEnabled bool `xml:"guiEnabled,omitempty" json:"-"`
|
||||||
Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
|
Deprecated_GUIAddress string `xml:"guiAddress,omitempty" json:"-"`
|
||||||
@ -345,6 +344,12 @@ func Load(rd io.Reader, myID string) (Configuration, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Options.Deprecated_URDeclined {
|
||||||
|
cfg.Options.URAccepted = -1
|
||||||
|
}
|
||||||
|
cfg.Options.Deprecated_URDeclined = false
|
||||||
|
cfg.Options.Deprecated_UREnabled = false
|
||||||
|
|
||||||
// Upgrade to v2 configuration if appropriate
|
// Upgrade to v2 configuration if appropriate
|
||||||
if cfg.Version == 1 {
|
if cfg.Version == 1 {
|
||||||
convertV1V2(&cfg)
|
convertV1V2(&cfg)
|
||||||
|
34
gui/app.js
34
gui/app.js
@ -279,8 +279,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
|
|
||||||
$scope.editSettings = function () {
|
$scope.editSettings = function () {
|
||||||
// Make a working copy
|
// Make a working copy
|
||||||
$scope.config.workingOptions = angular.copy($scope.config.Options);
|
$scope.tmpOptions = angular.copy($scope.config.Options);
|
||||||
$scope.config.workingGUI = angular.copy($scope.config.GUI);
|
$scope.tmpOptions.UREnabled = ($scope.tmpOptions.URAccepted > 0);
|
||||||
|
$scope.tmpGUI = angular.copy($scope.config.GUI);
|
||||||
$('#settings').modal({backdrop: 'static', keyboard: true});
|
$('#settings').modal({backdrop: 'static', keyboard: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -296,17 +297,24 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
|
|
||||||
$scope.saveSettings = function () {
|
$scope.saveSettings = function () {
|
||||||
// Make sure something changed
|
// Make sure something changed
|
||||||
var changed = ! angular.equals($scope.config.Options, $scope.config.workingOptions) ||
|
var changed = !angular.equals($scope.config.Options, $scope.tmpOptions) ||
|
||||||
! angular.equals($scope.config.GUI, $scope.config.workingGUI);
|
!angular.equals($scope.config.GUI, $scope.tmpGUI);
|
||||||
if(changed){
|
if (changed) {
|
||||||
// see if protocol will need to be changed on restart
|
// Check if usage reporting has been enabled or disabled
|
||||||
if($scope.config.GUI.UseTLS !== $scope.config.workingGUI.UseTLS){
|
if ($scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted <= 0) {
|
||||||
|
$scope.tmpOptions.URAccepted = 1000;
|
||||||
|
} else if (!$scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted > 0){
|
||||||
|
$scope.tmpOptions.URAccepted = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if protocol will need to be changed on restart
|
||||||
|
if($scope.config.GUI.UseTLS !== $scope.tmpGUI.UseTLS){
|
||||||
$scope.protocolChanged = true;
|
$scope.protocolChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply new settings locally
|
// Apply new settings locally
|
||||||
$scope.config.Options = angular.copy($scope.config.workingOptions);
|
$scope.config.Options = angular.copy($scope.tmpOptions);
|
||||||
$scope.config.GUI = angular.copy($scope.config.workingGUI);
|
$scope.config.GUI = angular.copy($scope.tmpGUI);
|
||||||
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
|
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
|
||||||
|
|
||||||
$scope.saveConfig();
|
$scope.saveConfig();
|
||||||
@ -561,7 +569,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
|
|
||||||
$scope.refresh();
|
$scope.refresh();
|
||||||
|
|
||||||
if (!$scope.config.Options.UREnabled && !$scope.config.Options.URDeclined) {
|
if ($scope.config.Options.URAccepted == 0) {
|
||||||
// If usage reporting has been neither accepted nor declined,
|
// If usage reporting has been neither accepted nor declined,
|
||||||
// we want to ask the user to make a choice. But we don't want
|
// we want to ask the user to make a choice. But we don't want
|
||||||
// to bug them during initial setup, so we set a cookie with
|
// to bug them during initial setup, so we set a cookie with
|
||||||
@ -590,15 +598,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.acceptUR = function () {
|
$scope.acceptUR = function () {
|
||||||
$scope.config.Options.UREnabled = true;
|
$scope.config.Options.URAccepted = 1000; // Larger than the largest existing report version
|
||||||
$scope.config.Options.URDeclined = false;
|
|
||||||
$scope.saveConfig();
|
$scope.saveConfig();
|
||||||
$('#ur').modal('hide');
|
$('#ur').modal('hide');
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.declineUR = function () {
|
$scope.declineUR = function () {
|
||||||
$scope.config.Options.UREnabled = false;
|
$scope.config.Options.URAccepted = -1;
|
||||||
$scope.config.Options.URDeclined = true;
|
|
||||||
$scope.saveConfig();
|
$scope.saveConfig();
|
||||||
$('#ur').modal('hide');
|
$('#ur').modal('hide');
|
||||||
};
|
};
|
||||||
|
@ -583,11 +583,11 @@ found in the LICENSE file.
|
|||||||
<div class="form-group" ng-repeat="setting in settings">
|
<div class="form-group" ng-repeat="setting in settings">
|
||||||
<div ng-if="setting.type == 'text' || setting.type == 'number'">
|
<div ng-if="setting.type == 'text' || setting.type == 'number'">
|
||||||
<label for="{{setting.id}}">{{setting.descr}}</label>
|
<label for="{{setting.id}}">{{setting.descr}}</label>
|
||||||
<input id="{{setting.id}}" class="form-control" type="{{setting.type}}" ng-model="config.workingOptions[setting.id]"></input>
|
<input id="{{setting.id}}" class="form-control" type="{{setting.type}}" ng-model="tmpOptions[setting.id]"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox" ng-if="setting.type == 'bool'">
|
<div class="checkbox" ng-if="setting.type == 'bool'">
|
||||||
<label>
|
<label>
|
||||||
{{setting.descr}} <input id="{{setting.id}}" type="checkbox" ng-model="config.workingOptions[setting.id]"></input>
|
{{setting.descr}} <input id="{{setting.id}}" type="checkbox" ng-model="tmpOptions[setting.id]"></input>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -596,17 +596,17 @@ found in the LICENSE file.
|
|||||||
<div class="form-group" ng-repeat="setting in guiSettings">
|
<div class="form-group" ng-repeat="setting in guiSettings">
|
||||||
<div ng-if="setting.type == 'text' || setting.type == 'number' || setting.type == 'password'">
|
<div ng-if="setting.type == 'text' || setting.type == 'number' || setting.type == 'password'">
|
||||||
<label for="{{setting.id}}">{{setting.descr}}</label>
|
<label for="{{setting.id}}">{{setting.descr}}</label>
|
||||||
<input id="{{setting.id}}" class="form-control" type="{{setting.type}}" ng-model="config.workingGUI[setting.id]"></input>
|
<input id="{{setting.id}}" class="form-control" type="{{setting.type}}" ng-model="tmpGUI[setting.id]"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox" ng-if="setting.type == 'bool'">
|
<div class="checkbox" ng-if="setting.type == 'bool'">
|
||||||
<label>
|
<label>
|
||||||
{{setting.descr}} <input id="{{setting.id}}" type="checkbox" ng-model="config.workingGUI[setting.id]"></input>
|
{{setting.descr}} <input id="{{setting.id}}" type="checkbox" ng-model="tmpGUI[setting.id]"></input>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div ng-if="setting.type == 'apikey'">
|
<div ng-if="setting.type == 'apikey'">
|
||||||
<label>{{setting.descr}} (<a href="http://discourse.syncthing.net/t/v0-8-14-api-keys/335">Usage</a>)</label>
|
<label>{{setting.descr}} (<a href="http://discourse.syncthing.net/t/v0-8-14-api-keys/335">Usage</a>)</label>
|
||||||
<div class="well well-sm text-monospace">{{config.workingGUI[setting.id] || "-"}}</div>
|
<div class="well well-sm text-monospace">{{tmpGUI[setting.id] || "-"}}</div>
|
||||||
<button type="button" class="btn btn-sm btn-default" ng-click="setAPIKey(config.workingGUI)">Generate</button>
|
<button type="button" class="btn btn-sm btn-default" ng-click="setAPIKey(tmpGUI)">Generate</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -97,6 +97,7 @@ func TestIgnore(t *testing.T) {
|
|||||||
r bool
|
r bool
|
||||||
}{
|
}{
|
||||||
{"foo/bar", true},
|
{"foo/bar", true},
|
||||||
|
{"foofoo", false},
|
||||||
{"foo/quux", false},
|
{"foo/quux", false},
|
||||||
{"foo/zuux", true},
|
{"foo/zuux", true},
|
||||||
{"foo/qzuux", false},
|
{"foo/qzuux", false},
|
||||||
|
Loading…
Reference in New Issue
Block a user