@@ -18,8 +18,14 @@ class SimpleNotesApplication : Application() {
1818 override fun onCreate () {
1919 super .onCreate()
2020
21- // File-Logging ZUERST aktivieren (damit alle Logs geschrieben werden!)
2221 val prefs = getSharedPreferences(Constants .PREFS_NAME , Context .MODE_PRIVATE )
22+
23+ // 🔧 Hotfix v1.6.2: Migrate offline mode setting BEFORE any ViewModel initialization
24+ // This prevents the offline mode bug where users updating from v1.5.0 incorrectly
25+ // appear as offline even though they have a configured server
26+ migrateOfflineModeSetting(prefs)
27+
28+ // File-Logging ZUERST aktivieren (damit alle Logs geschrieben werden!)
2329 if (prefs.getBoolean(" file_logging_enabled" , false )) {
2430 Logger .enableFileLogging(this )
2531 Logger .d(TAG , " 📝 File logging enabled at Application startup" )
@@ -50,4 +56,30 @@ class SimpleNotesApplication : Application() {
5056 // WorkManager läuft weiter auch nach onTerminate!
5157 // Nur bei deaktiviertem Auto-Sync stoppen wir es
5258 }
59+
60+ /* *
61+ * 🔧 Hotfix v1.6.2: Migrate offline mode setting for updates from v1.5.0
62+ *
63+ * Problem: KEY_OFFLINE_MODE didn't exist in v1.5.0, but MainViewModel
64+ * and NoteEditorViewModel use `true` as default, causing existing users
65+ * with configured servers to appear in offline mode after update.
66+ *
67+ * Fix: Set the key BEFORE any ViewModel is initialized based on whether
68+ * a server was already configured.
69+ */
70+ private fun migrateOfflineModeSetting (prefs : android.content.SharedPreferences ) {
71+ if (! prefs.contains(Constants .KEY_OFFLINE_MODE )) {
72+ val serverUrl = prefs.getString(Constants .KEY_SERVER_URL , null )
73+ val hasServerConfig = ! serverUrl.isNullOrEmpty() &&
74+ serverUrl != " http://" &&
75+ serverUrl != " https://"
76+
77+ // If server was configured → offlineMode = false (continue syncing)
78+ // If no server → offlineMode = true (new users / offline users)
79+ val offlineModeValue = ! hasServerConfig
80+ prefs.edit().putBoolean(Constants .KEY_OFFLINE_MODE , offlineModeValue).apply ()
81+
82+ Logger .i(TAG , " 🔄 Migrated offline_mode_enabled: hasServer=$hasServerConfig → offlineMode=$offlineModeValue " )
83+ }
84+ }
5385}
0 commit comments