settings-sync: move saving all settings before initializing the setting sync to a...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Wed, 5 Oct 2022 10:05:06 +0000 (12:05 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 6 Oct 2022 09:21:29 +0000 (09:21 +0000)
This should fix IDEA-301776 when current settings were saved during the initialization, and that led to overwriting of settings applied by the settings sync.

This is an improvement of 53aa0fce: we need to save in all scenarios. Especially, the case IDEA-301776 was not covered in 53aa0fce because enabling settings doesn't invoke the initialize method from SettingsSynchronizer.

GitOrigin-RevId: 726ccf7eb783a2f388f37379fc919ce562387b5e

plugins/settings-sync/src/com/intellij/settingsSync/SettingsSyncBridge.kt
plugins/settings-sync/src/com/intellij/settingsSync/SettingsSynchronizer.kt

index 8d6887d01f8ffaaac076121aacee7859a9e307d8..f429c41291d5c2d4d3da00dfbfe516ee28630cc3 100644 (file)
@@ -1,7 +1,10 @@
 package com.intellij.settingsSync
 
+import com.intellij.configurationStore.saveSettings
 import com.intellij.openapi.Disposable
+import com.intellij.openapi.application.ApplicationManager
 import com.intellij.openapi.diagnostic.logger
+import com.intellij.openapi.progress.runBlockingMaybeCancellable
 import com.intellij.settingsSync.SettingsSyncBridge.PushRequestMode.*
 import com.intellij.util.Alarm
 import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
@@ -49,6 +52,8 @@ class SettingsSyncBridge(parentDisposable: Disposable,
 
   @RequiresBackgroundThread
   internal fun initialize(initMode: InitMode) {
+    saveIdeSettings()
+
     settingsLog.initialize()
 
     // the queue is not activated initially => events will be collected but not processed until we perform all initialization tasks
@@ -60,6 +65,12 @@ class SettingsSyncBridge(parentDisposable: Disposable,
     queue.activate()
   }
 
+  private fun saveIdeSettings() {
+    runBlockingMaybeCancellable {
+      saveSettings(ApplicationManager.getApplication(), forceSavingAllSettings = true)
+    }
+  }
+
   private fun applyInitialChanges(initMode: InitMode) {
     val previousState = collectCurrentState()
 
index 327d49c780691f231a4ef8d521be2795eb7bb035..fdbd750b9c15ac094cdc91b56666065db0ed2ac5 100644 (file)
@@ -1,6 +1,5 @@
 package com.intellij.settingsSync
 
-import com.intellij.configurationStore.saveSettings
 import com.intellij.ide.ApplicationInitializedListener
 import com.intellij.openapi.application.ApplicationActivationListener
 import com.intellij.openapi.application.ApplicationManager
@@ -13,7 +12,6 @@ import com.intellij.util.concurrency.AppExecutorUtil
 import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
 import com.intellij.util.concurrency.annotations.RequiresEdt
 import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.runBlocking
 import java.util.concurrent.ScheduledFuture
 import java.util.concurrent.TimeUnit
 
@@ -70,9 +68,6 @@ internal class SettingsSynchronizer : ApplicationInitializedListener, Applicatio
 
   private fun initializeSyncing(initMode: SettingsSyncBridge.InitMode): Runnable = Runnable {
     LOG.info("Initializing settings sync")
-    runBlocking {
-      saveSettings(ApplicationManager.getApplication(), forceSavingAllSettings = true)
-    }
     val settingsSyncMain = SettingsSyncMain.getInstance()
     settingsSyncMain.controls.bridge.initialize(initMode)
     syncSettings()