From e967859d5f83b154783255510379178d98081990 Mon Sep 17 00:00:00 2001 From: creesch Date: Fri, 30 Mar 2018 09:32:20 +0200 Subject: [PATCH 1/4] Force sync button --- client/js/options.js | 19 +++++++++++++++---- client/js/socket-events/setting.js | 2 +- client/views/windows/settings.tpl | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/client/js/options.js b/client/js/options.js index b4eaaaa1..cbf6724d 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -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. diff --git a/client/js/socket-events/setting.js b/client/js/socket-events/setting.js index f8a2eb17..6a97cd6d 100644 --- a/client/js/socket-events/setting.js +++ b/client/js/socket-events/setting.js @@ -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]); diff --git a/client/views/windows/settings.tpl b/client/views/windows/settings.tpl index cf414f4b..821a9512 100644 --- a/client/views/windows/settings.tpl +++ b/client/views/windows/settings.tpl @@ -28,6 +28,10 @@

Warning Checking this box will override the settings of this client with those stored on the server.

Warning No settings have been synced before. Enabling this will sync all settings of this client as the base for other clients.

+ {{/unless}}
From 107749e91a50c8d6c1bb04e1b59a4836391d993f Mon Sep 17 00:00:00 2001 From: creesch Date: Fri, 30 Mar 2018 09:46:59 +0200 Subject: [PATCH 2/4] Enable sync on empty localstorage --- client/js/options.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/js/options.js b/client/js/options.js index cbf6724d..606dfb92 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -49,11 +49,16 @@ const noSync = ["syncSettings"]; const alwaysSync = []; // Process usersettings from localstorage. -let userSettings = JSON.parse(storage.get("settings")) || {}; +let userSettings = JSON.parse(storage.get("settings")) || false; -for (const key in settings) { - if (userSettings[key] !== undefined) { - settings[key] = userSettings[key]; +if (!userSettings) { + // Enable sync by default if there are no user defined settings. + settings.syncSettings = true; +} else { + for (const key in settings) { + if (userSettings[key] !== undefined) { + settings[key] = userSettings[key]; + } } } From 95dc519019483cf8f85197b61e9f799c0987a87c Mon Sep 17 00:00:00 2001 From: creesch Date: Fri, 30 Mar 2018 09:49:02 +0200 Subject: [PATCH 3/4] Sync on both load and reconnect. --- client/js/options.js | 2 +- client/js/socket-events/configuration.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client/js/options.js b/client/js/options.js index 606dfb92..88781bee 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -319,5 +319,5 @@ function initialize() { // 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. - socket.emit("settings:get"); + socket.emit("setting:get"); } diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index 2a6fec17..12125234 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -8,6 +8,8 @@ const webpush = require("../webpush"); socket.on("configuration", function(data) { if (options.initialized) { + // Likely a reconnect, request sync for possibly missed settings. + socket.emit("setting:get"); return; } From 63c84cd3625731c4f70f2c61d7a163b703ccbdea Mon Sep 17 00:00:00 2001 From: creesch Date: Sat, 31 Mar 2018 22:28:39 +0200 Subject: [PATCH 4/4] Don't use event delegation for sync button --- client/js/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/js/options.js b/client/js/options.js index 88781bee..9600d71a 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -312,7 +312,7 @@ function initialize() { } }); - $settings.on("click", "#forceSync", () => { + $settings.find("#forceSync").on("click", () => { syncAllSettings(true); });