Skip to content

Commit 97ec5e4

Browse files
committed
Merge branch 'gradle-welcome-screen' into runner
2 parents 221ee28 + 3d6a6ce commit 97ec5e4

29 files changed

+1170
-157
lines changed
File renamed without changes.

app/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import org.gradle.internal.jvm.Jvm
2+
import org.gradle.kotlin.dsl.support.zipTo
3+
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
4+
import org.jetbrains.compose.ExperimentalComposeLibrary
25
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
36
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
47
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
@@ -61,7 +64,7 @@ compose.desktop {
6164
jvmArgs(*variables.entries.map { "-D${it.key}=${it.value}" }.toTypedArray())
6265

6366
nativeDistributions{
64-
modules("jdk.jdi", "java.compiler", "jdk.accessibility", "java.management.rmi")
67+
modules("jdk.jdi", "java.compiler", "jdk.accessibility", "jdk.zipfs", "java.management.rmi")
6568
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
6669
packageName = "Processing"
6770

@@ -112,6 +115,7 @@ dependencies {
112115
implementation(compose.ui)
113116
implementation(compose.components.resources)
114117
implementation(compose.components.uiToolingPreview)
118+
implementation(compose.materialIconsExtended)
115119

116120
implementation(compose.desktop.currentOs)
117121

@@ -126,6 +130,8 @@ dependencies {
126130
testImplementation(libs.junitJupiterParams)
127131

128132
implementation(gradleApi())
133+
@OptIn(ExperimentalComposeLibrary::class)
134+
testImplementation(compose.uiTest)
129135
}
130136

131137
tasks.test {

app/src/main/resources/default.png

1.86 KB
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 17 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Loading

app/src/processing/app/Language.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ static public Language init() {
183183
return instance;
184184
}
185185

186+
static public void reload(){
187+
if(instance == null) return;
188+
synchronized (Language.class) {
189+
instance = new Language();
190+
}
191+
}
186192

187193
static private String get(String key) {
188194
LanguageBundle bundle = init().bundle;

app/src/processing/app/Preferences.kt

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,82 @@ package processing.app
22

33
import androidx.compose.runtime.*
44
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.FlowPreview
6+
import kotlinx.coroutines.flow.debounce
7+
import kotlinx.coroutines.flow.dropWhile
58
import kotlinx.coroutines.launch
69
import java.io.File
710
import java.io.InputStream
11+
import java.io.OutputStream
812
import java.nio.file.*
913
import java.util.Properties
1014

1115

1216
const val PREFERENCES_FILE_NAME = "preferences.txt"
1317
const val DEFAULTS_FILE_NAME = "defaults.txt"
1418

15-
fun PlatformStart(){
16-
Platform.inst ?: Platform.init()
17-
}
19+
class ReactiveProperties: Properties() {
20+
val _stateMap = mutableStateMapOf<String, String>()
21+
22+
override fun setProperty(key: String, value: String) {
23+
super.setProperty(key, value)
24+
_stateMap[key] = value
25+
}
1826

27+
override fun getProperty(key: String): String? {
28+
return _stateMap[key] ?: super.getProperty(key)
29+
}
30+
31+
operator fun get(key: String): String? = getProperty(key)
32+
33+
operator fun set(key: String, value: String) {
34+
setProperty(key, value)
35+
}
36+
}
37+
val LocalPreferences = compositionLocalOf<ReactiveProperties> { error("No preferences provided") }
38+
@OptIn(FlowPreview::class)
1939
@Composable
20-
fun loadPreferences(): Properties{
21-
PlatformStart()
40+
fun PreferencesProvider(content: @Composable () -> Unit){
41+
remember {
42+
Platform.init()
43+
}
2244

2345
val settingsFolder = Platform.getSettingsFolder()
2446
val preferencesFile = settingsFolder.resolve(PREFERENCES_FILE_NAME)
25-
2647
if(!preferencesFile.exists()){
48+
preferencesFile.mkdirs()
2749
preferencesFile.createNewFile()
2850
}
29-
watchFile(preferencesFile)
3051

31-
return Properties().apply {
32-
load(ClassLoader.getSystemResourceAsStream(DEFAULTS_FILE_NAME) ?: InputStream.nullInputStream())
33-
load(preferencesFile.inputStream())
52+
val update = watchFile(preferencesFile)
53+
val properties = remember(preferencesFile, update) { ReactiveProperties().apply {
54+
load((ClassLoader.getSystemResourceAsStream(DEFAULTS_FILE_NAME)?: InputStream.nullInputStream()).reader(Charsets.UTF_8))
55+
load(preferencesFile.inputStream().reader(Charsets.UTF_8))
56+
}}
57+
58+
val initialState = remember(properties) { properties._stateMap.toMap() }
59+
60+
LaunchedEffect(properties) {
61+
snapshotFlow { properties._stateMap.toMap() }
62+
.dropWhile { it == initialState }
63+
.debounce(100)
64+
.collect {
65+
preferencesFile.outputStream().use { output ->
66+
output.write(
67+
properties.entries
68+
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.key.toString() })
69+
.joinToString("\n") { (key, value) -> "$key=$value" }
70+
.toByteArray()
71+
)
72+
}
73+
}
74+
}
75+
76+
CompositionLocalProvider(LocalPreferences provides properties){
77+
content()
3478
}
35-
}
3679

80+
}
3781
@Composable
3882
fun watchFile(file: File): Any? {
3983
val scope = rememberCoroutineScope()
@@ -63,12 +107,4 @@ fun watchFile(file: File): Any? {
63107
}
64108
}
65109
return event
66-
}
67-
val LocalPreferences = compositionLocalOf<Properties> { error("No preferences provided") }
68-
@Composable
69-
fun PreferencesProvider(content: @Composable () -> Unit){
70-
val preferences = loadPreferences()
71-
CompositionLocalProvider(LocalPreferences provides preferences){
72-
content()
73-
}
74110
}

app/src/processing/app/contrib/ui/ContributionManager.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import androidx.compose.ui.window.application
2222
import com.charleskorn.kaml.Yaml
2323
import com.charleskorn.kaml.YamlConfiguration
2424
import kotlinx.serialization.Serializable
25+
import processing.app.LocalPreferences
2526
import processing.app.Platform
26-
import processing.app.loadPreferences
27+
import processing.app.ReactiveProperties
2728
import java.net.URL
2829
import java.util.*
2930
import javax.swing.JFrame
@@ -106,7 +107,7 @@ fun contributionsManager(){
106107
var localContributions by remember { mutableStateOf(listOf<Contribution>()) }
107108
var error by remember { mutableStateOf<Exception?>(null) }
108109

109-
val preferences = loadPreferences()
110+
val preferences = LocalPreferences.current
110111

111112
LaunchedEffect(preferences){
112113
try {
@@ -284,9 +285,9 @@ fun contributionsManager(){
284285
}
285286

286287

287-
fun loadContributionProperties(preferences: Properties): List<Pair<Type, Properties>>{
288+
fun loadContributionProperties(preferences: ReactiveProperties): List<Pair<Type, Properties>>{
288289
val result = mutableListOf<Pair<Type, Properties>>()
289-
val sketchBook = Path(preferences.getProperty("sketchbook.path.four", Platform.getDefaultSketchbookFolder().path))
290+
val sketchBook = Path(preferences.getProperty("sketchbook.path.four") ?: Platform.getDefaultSketchbookFolder().path)
290291
sketchBook.forEachDirectoryEntry{ contributionsFolder ->
291292
if(!contributionsFolder.isDirectory()) return@forEachDirectoryEntry
292293
val typeName = contributionsFolder.fileName.toString()

0 commit comments

Comments
 (0)