Skip to content

Commit aaa3f75

Browse files
authored
Create PreferencesEvents to glue into base and other deps (#1386)
To avoid creating dependencies within Preferences.kt, create an event structure that will listen to changes triggered by saving the Preferences.
1 parent 8466ee1 commit aaa3f75

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ static private void createAndShowGUI(String[] args) {
198198
// run static initialization that grabs all the prefs
199199
Preferences.init();
200200

201+
PreferencesEvents.onUpdated(Preferences::init);
202+
201203
// boolean flag indicating whether to create new server instance or not
202204
boolean createNewInstance = DEBUG || !SingleInstance.alreadyRunning(args);
203205

app/src/processing/app/Preferences.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package processing.app
22

33
import androidx.compose.runtime.*
4-
import kotlinx.coroutines.Dispatchers
5-
import kotlinx.coroutines.FlowPreview
6-
import kotlinx.coroutines.delay
4+
import kotlinx.coroutines.*
75
import kotlinx.coroutines.flow.debounce
86
import kotlinx.coroutines.flow.dropWhile
9-
import kotlinx.coroutines.launch
107
import processing.utils.Settings
118
import java.io.File
129
import java.io.InputStream
@@ -134,10 +131,9 @@ fun PreferencesProvider(content: @Composable () -> Unit) {
134131
.joinToString("\n") { (key, value) -> "$key=$value" }
135132
.toByteArray()
136133
)
137-
138-
// Reload legacy Preferences
139-
Preferences.init()
140134
output.close()
135+
136+
PreferencesEvents.updated()
141137
}
142138
}
143139
}
@@ -205,4 +201,19 @@ fun watchFile(file: File): Any? {
205201
}
206202
}
207203
return event
204+
}
205+
206+
class PreferencesEvents {
207+
companion object {
208+
val updatedListeners = mutableListOf<Runnable>()
209+
210+
@JvmStatic
211+
fun onUpdated(callback: Runnable) {
212+
updatedListeners.add(callback)
213+
}
214+
215+
fun updated() {
216+
updatedListeners.forEach { it.run() }
217+
}
218+
}
208219
}

app/src/processing/app/ui/Editor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public void actionPerformed(ActionEvent e) {
371371
});
372372
}
373373

374+
PreferencesEvents.onUpdated(this::updateTheme);
374375
}
375376

376377

0 commit comments

Comments
 (0)