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 androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowState
import mg.dot.feufaro.WindowState
expect class SaveSettings() {
val settings: Settings

View file

@ -118,7 +118,6 @@ class SharedScreenModel() : ScreenModel {
private val _isPlayMid = MutableStateFlow(false)
val isPlayMid = _isPlayMid.asStateFlow()
private var midiFile = "whawyd3.mid"
fun loadNewSong(newMidiFile: String) {
_mediaPlayer?.stop()
@ -126,9 +125,10 @@ class SharedScreenModel() : ScreenModel {
_isPlay.value = false
_currentPos.value = 0f
_mediaPlayer = MediaPlayer(filename = newMidiFile, onFinished = {
_isPos.value = true
_isPlay.value = false
// _isPos.value = true
// _isPlay.value = false
_currentPos.value = 0f
seekTo(0f)
println("fin de lecture du Midi $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.set
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import mg.dot.feufaro.WindowState
actual class SaveSettings actual constructor() {
actual val settings: Settings = Settings()
@ -29,18 +29,17 @@ actual class SaveSettings actual constructor() {
actual fun loadWindowState(): WindowState {
val bounds = loadWindowBounds()
return WindowState(
size = DpSize(bounds[0].dp, bounds[1].dp),
position = WindowPosition(bounds[2].dp, bounds[3].dp)
return WindowState(bounds[0], bounds[1],
bounds[2], bounds[3]
)
}
actual fun saveWindowState(state: WindowState) {
saveWindowBounds(
state.size.width.value.toInt(),
state.size.height.value.toInt(),
state.position.x.value.toInt(),
state.position.y.value.toInt()
state.width,
state.height,
state.x,
state.y
)
}
}

View file

@ -1,3 +1,4 @@
@file:JvmName("MainKt")
package mg.dot.feufaro
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.application
import androidx.compose.ui.window.rememberWindowState
//import androidx.compose.ui.window.rememberWindowState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
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.KoinContext
import org.koin.core.logger.Level
import mg.dot.feufaro.WindowState as MyWindowState
fun main() = application {
@ -32,10 +35,14 @@ fun main() = application {
println("FileRepository initialized for Desktop: $fileRepository")
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(
state = windowState,
state = composeWindowState,
onCloseRequest = {
exitApplication();
},
@ -46,7 +53,13 @@ fun main() = application {
}
DisposableEffect(Unit){
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)
}
}
}