From cea676c964baee83f8b4abdda9f50985da9fcab0 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Tue, 2 Jan 2024 19:55:13 +0100 Subject: [PATCH] set a name on first start of app --- src/main/kotlin/Main.kt | 21 ++++++++++++++ .../applications/trifa/TrifaToxService.kt | 16 +++++++++++ .../trifa/savepathenabled_state.kt | 28 ++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 1c4e5ff9..9ac994e7 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -252,6 +252,13 @@ fun App() println("Site config dir: " + APPDIRS.getSiteConfigDir()) println("Site config dir (multi path): " + APPDIRS.getSiteConfigDir(multiPath = true)) println("Shared dir: " + APPDIRS.getSharedDir()) + try + { + println("Prefs dir (estimation for linux): " + "~/.java/.userPrefs/" + global_prefs.absolutePath()) + } + catch(_: Exception) + { + } Log.i(TAG, "resources dir: " + RESOURCESDIR) Log.i(TAG, "resources dir canonical: " + RESOURCESDIR.canonicalPath + File.separator) @@ -1493,6 +1500,7 @@ object AboutIcon : Painter() { private fun MainAppStart() { var showIntroScreen by remember { mutableStateOf(true) } + var firstRun by remember { mutableStateOf(true) } var inputTextToxSelfName by remember { mutableStateOf(RandomNameGenerator.getFullName(Random())) } try { @@ -1500,11 +1508,23 @@ private fun MainAppStart() if (tmp == false) { showIntroScreen = false + firstRun = false } } catch (_: Exception) { } + println("globalstore.updateFirstRun:" + firstRun) + if (firstRun) + { + globalstore.updateFirstRun(firstRun) + } + // ************* DEBUG ONLY ************* + // ************* DEBUG ONLY ************* + // ************* DEBUG ONLY ************* // showIntroScreen = true + // ************* DEBUG ONLY ************* + // ************* DEBUG ONLY ************* + // ************* DEBUG ONLY ************* val appIcon = painterResource("icon-linux.png") if (showIntroScreen) { // ----------- intro screen ----------- @@ -1561,6 +1581,7 @@ private fun MainAppStart() { // ----------- main app screen ----------- // ----------- main app screen ----------- // ----------- main app screen ----------- + globalstore.updateStartupSelfname(inputTextToxSelfName) var isOpen by remember { mutableStateOf(true) } var isAskingToClose by remember { mutableStateOf(false) } var state = rememberWindowState() diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 576a5169..c97764ea 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -50,6 +50,7 @@ import com.zoffcc.applications.trifa.MainActivity.Companion.tox_iteration_interv import com.zoffcc.applications.trifa.MainActivity.Companion.tox_kill import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_get_connection_status import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_get_friend_list +import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_set_name import com.zoffcc.applications.trifa.MainActivity.Companion.tox_util_friend_resend_message_v2 import com.zoffcc.applications.trifa.TRIFAGlobals.GROUP_ID_LENGTH import com.zoffcc.applications.trifa.TRIFAGlobals.MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION @@ -116,6 +117,21 @@ class TrifaToxService init_tox_callbacks() update_savedata_file_wrapper() } // ------ correct startup order ------ + + try + { + Log.i(TAG, "StartupSelfname: " + globalstore.getStartupSelfname()) + Log.i(TAG, "FirstRun: " + globalstore.isFirstRun()) + if (globalstore.isFirstRun()) + { + globalstore.updateFirstRun(false) + tox_self_set_name(globalstore.getStartupSelfname()) + update_savedata_file_wrapper() + } + } + catch(_: Exception) + { + } clear_friends() load_friends() clear_groups() diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt b/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt index bb03ff55..4f42b809 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/savepathenabled_state.kt @@ -16,7 +16,9 @@ data class globalstore_state( val mainwindow_minimized: Boolean = false, val mainwindow_focused: Boolean = true, val contacts_unread_message_count: Int = 0, - val contacts_unread_group_message_count: Int = 0 + val contacts_unread_group_message_count: Int = 0, + val firstRun: Boolean = false, + val startupSelfname: String = "" ) private val globalstore_state_lock = Any() @@ -24,8 +26,12 @@ private val globalstore_state_lock = Any() interface GlobalStore { fun updateMinimized(value: Boolean) fun updateFocused(value: Boolean) + fun updateFirstRun(value: Boolean) + fun updateStartupSelfname(value: String) fun isMinimized(): Boolean fun isFocused(): Boolean + fun isFirstRun(): Boolean + fun getStartupSelfname(): String fun increase_unread_message_count() fun get_unread_message_count(): Int fun try_clear_unread_message_count() @@ -54,6 +60,15 @@ fun CoroutineScope.createGlobalStore(): GlobalStore { mutableStateFlow.value = state.copy(mainwindow_focused = value) } + override fun updateFirstRun(value: Boolean) + { + mutableStateFlow.value = state.copy(firstRun = value) + } + + override fun updateStartupSelfname(value: String) + { mutableStateFlow.value = state.copy(startupSelfname = value) + } + override fun isMinimized(): Boolean { return state.mainwindow_minimized @@ -63,10 +78,21 @@ fun CoroutineScope.createGlobalStore(): GlobalStore { { return state.mainwindow_focused } + + override fun isFirstRun(): Boolean + { + return state.firstRun + } + override fun getStartupSelfname(): String + { + return state.startupSelfname + } + override fun increase_unread_message_count() { mutableStateFlow.value = state.copy(contacts_unread_message_count = (state.contacts_unread_message_count + 1)) } + override fun get_unread_message_count(): Int { return state.contacts_unread_message_count