Compare commits

..

2 commits

4 changed files with 27 additions and 15 deletions

View file

@ -4,7 +4,7 @@ import com.russhwolf.settings.Settings
import com.russhwolf.settings.set import com.russhwolf.settings.set
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowState import mg.dot.feufaro.WindowState
expect class SaveSettings() { expect class SaveSettings() {
val settings: Settings val settings: Settings

View file

@ -118,7 +118,6 @@ class SharedScreenModel() : ScreenModel {
private val _isPlayMid = MutableStateFlow(false) private val _isPlayMid = MutableStateFlow(false)
val isPlayMid = _isPlayMid.asStateFlow() val isPlayMid = _isPlayMid.asStateFlow()
private var midiFile = "whawyd3.mid"
fun loadNewSong(newMidiFile: String) { fun loadNewSong(newMidiFile: String) {
_mediaPlayer?.stop() _mediaPlayer?.stop()
@ -126,9 +125,10 @@ class SharedScreenModel() : ScreenModel {
_isPlay.value = false _isPlay.value = false
_currentPos.value = 0f _currentPos.value = 0f
_mediaPlayer = MediaPlayer(filename = newMidiFile, onFinished = { _mediaPlayer = MediaPlayer(filename = newMidiFile, onFinished = {
_isPos.value = true // _isPos.value = true
_isPlay.value = false // _isPlay.value = false
_currentPos.value = 0f _currentPos.value = 0f
seekTo(0f)
println("fin de lecture du Midi $newMidiFile") println("fin de lecture du Midi $newMidiFile")
}) })
println("New media Player crée $newMidiFile") println("New media Player crée $newMidiFile")

View file

@ -2,10 +2,10 @@ package mg.dot.feufaro
import com.russhwolf.settings.Settings import com.russhwolf.settings.Settings
import com.russhwolf.settings.set import com.russhwolf.settings.set
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import mg.dot.feufaro.WindowState
actual class SaveSettings actual constructor() { actual class SaveSettings actual constructor() {
actual val settings: Settings = Settings() actual val settings: Settings = Settings()
@ -29,18 +29,17 @@ actual class SaveSettings actual constructor() {
actual fun loadWindowState(): WindowState { actual fun loadWindowState(): WindowState {
val bounds = loadWindowBounds() val bounds = loadWindowBounds()
return WindowState( return WindowState(bounds[0], bounds[1],
size = DpSize(bounds[0].dp, bounds[1].dp), bounds[2], bounds[3]
position = WindowPosition(bounds[2].dp, bounds[3].dp)
) )
} }
actual fun saveWindowState(state: WindowState) { actual fun saveWindowState(state: WindowState) {
saveWindowBounds( saveWindowBounds(
state.size.width.value.toInt(), state.width,
state.size.height.value.toInt(), state.height,
state.position.x.value.toInt(), state.x,
state.position.y.value.toInt() state.y
) )
} }
} }

View file

@ -1,3 +1,4 @@
@file:JvmName("MainKt")
package mg.dot.feufaro package mg.dot.feufaro
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
@ -9,6 +10,7 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
//import androidx.compose.ui.window.rememberWindowState
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -19,6 +21,7 @@ import org.koin.compose.KoinContext
import org.koin.core.context.GlobalContext.startKoin import org.koin.core.context.GlobalContext.startKoin
import org.koin.core.context.KoinContext import org.koin.core.context.KoinContext
import org.koin.core.logger.Level import org.koin.core.logger.Level
import mg.dot.feufaro.WindowState as MyWindowState
fun main() = application { fun main() = application {
@ -32,10 +35,14 @@ fun main() = application {
println("FileRepository initialized for Desktop: $fileRepository") println("FileRepository initialized for Desktop: $fileRepository")
val stateManager = remember { SaveSettings() } val stateManager = remember { SaveSettings() }
val windowState = remember { stateManager.loadWindowState() } val saved: MyWindowState = stateManager.loadWindowState()
val composeWindowState = rememberWindowState(
position = WindowPosition(saved.x.dp, saved.y.dp),
size = DpSize(saved.width.dp, saved.height.dp)
)
Window( Window(
state = windowState, state = composeWindowState,
onCloseRequest = { onCloseRequest = {
exitApplication(); exitApplication();
}, },
@ -46,7 +53,13 @@ fun main() = application {
} }
DisposableEffect(Unit){ DisposableEffect(Unit){
onDispose { onDispose {
stateManager.saveWindowState(windowState) val stateToSave = MyWindowState(
x = composeWindowState.position.x.value.toInt(),
y = composeWindowState.position.y.value.toInt(),
width = composeWindowState.size.width.value.toInt(),
height = composeWindowState.size.height.value.toInt()
)
stateManager.saveWindowState(stateToSave)
} }
} }
} }