]> uap-core.de Git - rssreader.git/commitdiff
add Settings class
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 15:00:53 +0000 (17:00 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 15:00:53 +0000 (17:00 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt [new file with mode: 0644]
ui-java/src/main/java/de/unixwork/ui/ToolkitFuncs.java

index 8a151dcf68a26ef07f8ef7d0fb195febb250404b..2e26df61fd112a5d86e226b11484558ed38f3e8e 100644 (file)
@@ -11,9 +11,11 @@ import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.IO
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
+import java.io.IOException
 
-class App : Application {
+object App : Application {
     var window: MainWindow? = null
+    var settings = Settings()
 
     init {
         initToolbar()
@@ -33,10 +35,16 @@ class App : Application {
     }
 
     override fun startup() {
+        try {
+            settings.load()
+        } catch (e: IOException) {
+            e.printStackTrace() // TODO: messagebox
+        }
+
         window = MainWindow()
         window?.show()
 
-        backgroundSync(10 * 1000L) // TODO: config
+        backgroundSync(settings.autoRefreshStartDelay * 1000L)
     }
 
     override fun shutdown() {
@@ -50,7 +58,7 @@ class App : Application {
             while(true) {
                 println("Background sync")
                 try {
-                    val pending = Database.getPendingFeeds(1 * 60) // TODO: config
+                    val pending = Database.getPendingFeeds(settings.defaultRefreshInterval)
                     if(!pending.isEmpty()) {
                         SyncJob { pending }.syncBlocking()
                         GlobalScope.launch(ToolkitDispatcher) {
@@ -65,9 +73,9 @@ class App : Application {
                 println("Background sync done")
 
                 // get time until the next feed is pending, but wait at least the minimum delay time
-                var delayTimeMS = 60 * 1000L // TODO: config
+                var delayTimeMS = settings.minRefreshWaitTime * 1000L
                 try {
-                    val seconds = Database.getUpdateWaitTime(1 * 60) // TODO: config
+                    val seconds = Database.getUpdateWaitTime(settings.defaultRefreshInterval)
                     if(seconds > 0) {
                         println("wait for $seconds seconds until next sync")
                         delayTimeMS = seconds * 1000L
@@ -84,5 +92,5 @@ class App : Application {
 
 fun main() {
     Toolkit.init("rssreader")
-    Toolkit.runApplication(App())
+    Toolkit.runApplication(App)
 }
index 8b1acac50c1d5509ae7e3677b42a308892de34e8..14ed8c56577bdb9ab4c1654d91028f5742a194c4 100644 (file)
@@ -15,13 +15,13 @@ import de.unixwork.ui.kotlin.openFileDialog
 import java.time.ZoneId
 import java.time.format.DateTimeFormatter
 
-class MainWindow {
+class MainWindow() {
     val window : Toplevel
     val sourceList = FeedSourceList()
     val feedList = FeedList()
 
     // TODO: date format config
-    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault())
+    val formatter = DateTimeFormatter.ofPattern(App.settings.dateFormat).withZone(ZoneId.systemDefault())
 
     var newFeedPrevGroup = 0
 
diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt
new file mode 100644 (file)
index 0000000..8cb3663
--- /dev/null
@@ -0,0 +1,27 @@
+package de.unixwork.rssreader
+
+import de.unixwork.ui.Toolkit
+import java.io.File
+import java.util.Properties
+
+class Settings {
+    val properties = Properties()
+
+    val dateFormat = "yyyy-MM-dd HH:mm:ss"
+    val autoRefreshStartDelay = 10
+    val defaultRefreshInterval = 3600
+    val minRefreshWaitTime = 60
+
+    fun load() {
+        val filePath = Toolkit.getConfigFilePath("rssreader.properties")
+        val file = File(filePath)
+        if(file.exists()) {
+            file.inputStream().use {
+                properties.load(it)
+            }
+        } else {
+            println("create new file: $filePath")
+            file.createNewFile()
+        }
+    }
+}
\ No newline at end of file
index 4eabb3bcecf78dd5fee9493f0db9398546ebfca2..68548b26e9c4197499566ec29624fc5e6f2f2268 100644 (file)
@@ -173,8 +173,8 @@ public class ToolkitFuncs {
         MemorySegment ui_malloc_addr = lib.find("ui_malloc").orElseThrow();
         MemorySegment ui_free_addr = lib.find("ui_free").orElseThrow();
 
-        MemorySegment getappdir_addr = lib.find("getappdir").orElseThrow();
-        MemorySegment configfile_addr = lib.find("configfile").orElseThrow();
+        MemorySegment getappdir_addr = lib.find("ui_getappdir").orElseThrow();
+        MemorySegment configfile_addr = lib.find("ui_configfile").orElseThrow();
 
         MemorySegment malloc_addr = lib.find("malloc").orElseThrow();
         MemorySegment free_addr = lib.find("free").orElseThrow();