Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates and fixes #98

Merged
merged 7 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asan_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ h=$(echo $HOME)

if [ "$1""x" == "buildx" ]; then
cp -av resources/common/libffmpeg_av_jni.so__ASAN resources/common/libffmpeg_av_jni.so
cp -av resources/common/libjni_notifications.so__ASAN resources/common/libjni_notifications.so
cp -av resources/common/libjni-c-toxcore.so__ASAN resources/common/libjni-c-toxcore.so
./gradlew -Dorg.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64/ packageDistributionForCurrentOS
./gradlew -Dorg.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64/ packageUberJarForCurrentOS
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true
android.defaults.buildfeatures.buildconfig=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental
compose.version=1.5.11
kotlin.version=1.9.21
multiplatform.version=1.9.21
compose.version=1.6.0-dev1354
kotlin.version=1.9.22
multiplatform.version=1.9.22
Binary file added resources/common/libffmpeg_av_jni.so__ASAN
Binary file not shown.
Binary file added resources/common/libjni-c-toxcore.so__ASAN
Binary file not shown.
Binary file added resources/common/libjni_notifications.so__ASAN
Binary file not shown.
68 changes: 52 additions & 16 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import com.zoffcc.applications.trifa.AudioBar
import com.zoffcc.applications.trifa.AudioBar.audio_in_bar
import com.zoffcc.applications.trifa.AudioBar.audio_out_bar
import com.zoffcc.applications.trifa.CustomSemaphore
import com.zoffcc.applications.trifa.GroupSettingDetails
import com.zoffcc.applications.trifa.HelperGeneric.PubkeyShort
import com.zoffcc.applications.trifa.HelperNotification.init_system_tray
import com.zoffcc.applications.trifa.HelperNotification.set_resouces_dir
Expand Down Expand Up @@ -251,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 @@ -951,6 +959,7 @@ fun App()
{
UiMode.CONTACTS ->
{
groupsettingsstore.visible(false)
contactstore.visible(true)
groupstore.visible(false)
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -983,51 +992,64 @@ fun App()
Row(modifier = Modifier.fillMaxWidth()) {
GroupList(groupList = groups)
VerticalDivider()
clear_grouppeers()
if (groups.selectedGroupId != null)
val groupsettings by groupsettingsstore.stateFlow.collectAsState()
if ((groupsettings.visible) && (groups.selectedGroupId != null)) // show group settings
{
load_grouppeers(groups.selectedGroupId!!)
GroupSettingDetails(groups.selectedGroupId)
}
GroupPeerList(grouppeerList = grouppeers)
VerticalDivider()
if (groups.selectedGroupId == null)
{
ExplainerGroup()
} else
else // -- show group messages and peer
{
Log.i(TAG, "GROUPS -> draw")
load_groupmessages_for_friend(groups.selectedGroupId)
GlobalScope.launch { globalstore.try_clear_unread_group_message_count() }
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
//LaunchedEffect(groups.selectedGroupId) {
// groupfocusRequester.requestFocus()
//}
clear_grouppeers()
if (groups.selectedGroupId != null)
{
load_grouppeers(groups.selectedGroupId!!)
}
GroupPeerList(grouppeerList = grouppeers)
VerticalDivider()
if (groups.selectedGroupId == null)
{
ExplainerGroup()
} else
{
Log.i(TAG, "GROUPS -> draw")
load_groupmessages_for_friend(groups.selectedGroupId)
GlobalScope.launch { globalstore.try_clear_unread_group_message_count() }
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
//LaunchedEffect(groups.selectedGroupId) {
// groupfocusRequester.requestFocus()
//}
}
}
}
}
UiMode.ADDFRIEND -> {
groupsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
if (tox_running_state == "running") AddFriend()
else ExplainerToxNotRunning()
}
UiMode.ADDGROUP -> {
groupsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
if (tox_running_state == "running") AddGroup()
else ExplainerToxNotRunning()
}
UiMode.SETTINGS -> {
groupsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
SettingDetails()
}
UiMode.ABOUT -> {
groupsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
AboutScreen()
}
else -> {
groupsettingsstore.visible(false)
contactstore.visible(false)
groupstore.visible(false)
UiPlaceholder()
Expand Down Expand Up @@ -1478,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 @@ -1546,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
132 changes: 132 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/GroupSettingDetails.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.zoffcc.applications.trifa

import SETTINGS_HEADER_SIZE
import SnackBarToast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedButton
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_self_get_peer_id
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_self_set_name
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_set_name
import org.briarproject.briar.desktop.ui.VerticallyScrollableArea
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n

@Composable
fun GroupSettingDetails(selectedGroupId: String?)
{
SettingDetail(i18n("ui.group_settings_headline")) {

// ---- change own name for one-on-one chats ----
var self_name_in_group = ""
try
{
val group_num = HelperGroup.tox_group_by_groupid__wrapper(selectedGroupId)
val self_peernum = tox_group_self_get_peer_id(group_num)
self_name_in_group = MainActivity.tox_group_peer_get_name(group_num, self_peernum)!!
} catch (e: java.lang.Exception)
{
e.printStackTrace()
}
var tox_own_name_in_group by remember { mutableStateOf(self_name_in_group) }

Row(Modifier.wrapContentHeight().fillMaxWidth().padding(start = 15.dp)) {
TextField(enabled = true, singleLine = true,
textStyle = TextStyle(fontSize = 16.sp),
modifier = Modifier.padding(0.dp).weight(1.0f),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White),
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.None,
autoCorrect = false,
), value = tox_own_name_in_group,
onValueChange = {
tox_own_name_in_group = it
})

Button(modifier = Modifier.width(300.dp).padding(start = 20.dp, end = 20.dp),
enabled = true,
onClick = {
val group_num = HelperGroup.tox_group_by_groupid__wrapper(selectedGroupId)
if (group_num != -1L)
{
if (tox_group_self_set_name(group_num, tox_own_name_in_group) == 1)
{
HelperGeneric.update_savedata_file_wrapper()
SnackBarToast("You have changed your own peer name")
} else
{
SnackBarToast("Error while trying to set your own peer name")
}
}
else
{
SnackBarToast("Error while trying to set your own peer name")
}
})
{
Text("Update your Peer Name")
}
}
}
}

@Composable
fun SettingDetail(header: String, content: @Composable (ColumnScope.() -> Unit)) =
Column(Modifier.fillMaxSize()) {
Row(Modifier.fillMaxWidth().height(SETTINGS_HEADER_SIZE).padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween)
{
Text(header, style = MaterialTheme.typography.h4, color = MaterialTheme.colors.onSurface)
}
VerticallyScrollableArea { scrollState ->
LazyColumn(state = scrollState) {
item {
content()
}
}
}

}

@Composable
fun DetailItem(
label: String,
description: String,
setting: @Composable (RowScope.() -> Unit),
) = Row(Modifier.fillMaxWidth().height(SETTINGS_HEADER_SIZE).padding(horizontal = 16.dp).semantics(mergeDescendants = true) { // it would be nicer to derive the contentDescriptions from the descendants automatically
// which is currently not supported in Compose for Desktop
// see https://github.com/JetBrains/compose-jb/issues/2111
contentDescription = description
}, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween) {
Text(label)
setting()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.zoffcc.applications.trifa

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

data class StateGroupSettings(val visible: Boolean = false,
val selectedGroupId: String? = null
)

const val StateGroupSettingsTAG = "trifa.GroupSettingsStore"

interface GroupSettingsStore
{
val stateFlow: StateFlow<StateGroupSettings>
val state get() = stateFlow.value
fun visible(value: Boolean)
}

fun CoroutineScope.createGroupSettingsStore(): GroupSettingsStore
{
val mutableStateFlow = MutableStateFlow(StateGroupSettings())

return object : GroupSettingsStore
{
override val stateFlow: StateFlow<StateGroupSettings> = mutableStateFlow
override fun visible(value: Boolean)
{
mutableStateFlow.value = state.copy(visible = value)
}
}
}
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
Loading
Loading