Force sync button

This commit is contained in:
creesch 2018-03-30 09:32:20 +02:00
parent 153d9c6b2c
commit e967859d5f
3 changed files with 20 additions and 5 deletions

View file

@ -18,6 +18,7 @@ const noCSSparamReg = /[?&]nocss/;
// Will be assigned when `initialize` is called.
let $syncWarningOverride;
let $syncWarningBase;
let $forceSyncButton;
let $warningUnsupported;
let $warningBlocked;
@ -76,7 +77,7 @@ module.exports = {
highlightsRE: null,
settings,
shouldOpenMessagePreview,
noServerSettings,
syncAllSettings,
processSetting,
initialize,
};
@ -102,6 +103,7 @@ function updateDesktopNotificationStatus() {
function applySetting(name, value) {
if (name === "syncSettings" && value) {
$syncWarningOverride.hide();
$forceSyncButton.hide();
} else if (name === "motd") {
$chat.toggleClass("hide-" + name, !value);
} else if (name === "statusMessages") {
@ -198,8 +200,10 @@ function updateSetting(name, value, sync) {
socket.emit("setting:get");
$syncWarningOverride.hide();
$syncWarningBase.hide();
$forceSyncButton.hide();
} else if (name === "syncSettings") {
$syncWarningOverride.show();
$forceSyncButton.show();
}
if (settings.syncSettings && !noSync.includes(name) && sync) {
@ -210,9 +214,9 @@ function updateSetting(name, value, sync) {
}
}
function noServerSettings() {
// Sync is enabled but the server has no settings so we sync all settings from this client.
if (settings.syncSettings) {
function syncAllSettings(force = false) {
// Sync all settings if sync is enabled or force is true.
if (settings.syncSettings || force) {
for (const name in settings) {
if (!noSync.includes(name)) {
settingSetEmit(name, settings[name]);
@ -223,8 +227,10 @@ function noServerSettings() {
$syncWarningOverride.hide();
$syncWarningBase.hide();
$forceSyncButton.hide();
} else {
$syncWarningOverride.hide();
$forceSyncButton.hide();
$syncWarningBase.show();
}
}
@ -262,6 +268,7 @@ function initialize() {
$syncWarningOverride = $settings.find(".sync-warning-override");
$syncWarningBase = $settings.find(".sync-warning-base");
$forceSyncButton = $settings.find(".force-sync-button");
$warningBlocked.hide();
module.exports.initialized = true;
@ -300,6 +307,10 @@ function initialize() {
}
});
$settings.on("click", "#forceSync", () => {
syncAllSettings(true);
});
// Local init is done, let's sync
// We always ask for synced settings even if it is disabled.
// Settings can be mandatory to sync and it is used to determine sync base state.

View file

@ -19,7 +19,7 @@ socket.on("setting:new", function(data) {
socket.on("setting:all", function(settings) {
if (Object.keys(settings).length === 0) {
options.noServerSettings();
options.syncAllSettings();
} else {
for (const name in settings) {
evaluateSetting(name, settings[name]);

View file

@ -28,6 +28,10 @@
</label>
<p class="sync-warning-override"><strong>Warning</strong> Checking this box will override the settings of this client with those stored on the server.</p>
<p class="sync-warning-base"><strong>Warning</strong> No settings have been synced before. Enabling this will sync all settings of this client as the base for other clients.</p>
<label class="opt force-sync-button">
<button type="button" class="btn" id="forceSync">Force sync settings</button><br>
This will override any settings already synced to the server.
</label>
</div>
{{/unless}}
<div class="col-sm-12">