Skip to content

Commit

Permalink
set a name on first start of app
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jan 2, 2024
1 parent b20cbde commit cea676c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1493,18 +1500,31 @@ 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
{
val tmp = global_prefs.getBoolean("main.show_intro_screen", true)
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 -----------
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ 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()

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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit cea676c

Please sign in to comment.