Resolve conflit androidx.compose.ui.window.WindowState & import mg.dot.feufaro.WindowState
This commit is contained in:
parent
8ad6675793
commit
607e7c675d
3 changed files with 24 additions and 12 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue