Fixup Update editor: build using temp files and save directly to source

This commit is contained in:
Hasinjato 2026-05-19 14:47:16 +03:00
parent 1223416923
commit bf797762ea

View file

@ -1083,11 +1083,11 @@ fun EditSourceCompose(
// println("path $sourcePath\n" +
// "contenu $sourceContent")
val originalPath = remember(sourceTitle) {
if (!sourcePath.contains("_tmp") && !sourcePath.contains("/tmp/")) {
sourcePath
} else {
sourcePath
val fileNam = sourcePath.substringAfterLast('/').substringAfterLast(':')
var originalPath by remember(fileNam) { mutableStateOf(sourcePath) }
LaunchedEffect(sourcePath) {
if (sourcePath.isNotEmpty() && !sourcePath.contains("/tmp/") && !sourcePath.contains("tmp") && !sourcePath.contains("_tmp")) {
originalPath = sourcePath
}
}
@ -1100,8 +1100,8 @@ fun EditSourceCompose(
val pathValidator = remember { getPathValidator() }
// restricted path pour les fichiers interne de l'app
val isRestrictedPath = remember(sourcePath) {
pathValidator.isRestrictedPath(sourcePath)
val isRestrictedPath = remember(originalPath) {
pathValidator.isRestrictedPath(originalPath)
}
val isModified = remember(codeContent, sourceContent) { codeContent != sourceContent }
@ -1157,7 +1157,6 @@ fun EditSourceCompose(
Spacer(modifier = Modifier.weight(1f))
EditorActionButtons(
isSaveVisible = isModified || isRestrictedPath,
isUndoVisible = isModified,
onUndo = {
scope.launch {
@ -1181,7 +1180,7 @@ fun EditSourceCompose(
if (currentTempFile == null || !currentTempFile!!.exists()) {
val tempDir = System.getProperty("java.io.tmpdir")
currentTempFile = File(tempDir, fileName.ifEmpty { "preview_solfa.txt" })
currentTempFile = File(tempDir, fileName)
currentTempFile?.deleteOnExit()
}
@ -1192,7 +1191,7 @@ fun EditSourceCompose(
withContext(Dispatchers.Main) {
solfaScreenModel.justeCompile(currentTempFile!!.absolutePath)
println("Compilation temporaire réussie : ${currentTempFile?.absolutePath}")
println("Compilation : ${currentTempFile?.absolutePath}")
currentTempFile?.deleteOnExit()
}
@ -1205,16 +1204,16 @@ fun EditSourceCompose(
scope.launch {
try {
if (!isRestrictedPath) {
val externalFile = File(sourcePath)
val externalFile = File(originalPath)
withContext(Dispatchers.IO) {
externalFile.writeText(codeContent)
}
withContext(Dispatchers.Main) {
sharedScreenModel.setFileContent(codeContent, sourcePath)
solfaScreenModel.loadExternalFile(sourcePath)
sharedScreenModel.setFileContent(codeContent, originalPath)
solfaScreenModel.loadExternalFile(originalPath)
}
println("Vraie source écrasée avec succès : $sourcePath")
println("Source écrasé : $originalPath")
} else {
val initialDir = solfaScreenModel.fileRepository.getAppPublicFolder().absolutePath
saveLauncher.launch(fileName, initialDir)
@ -1256,15 +1255,13 @@ fun EditSourceCompose(
}
@Composable
fun EditorActionButtons(isSaveVisible: Boolean, isUndoVisible: Boolean, onUndo: () -> Unit, onBuild: () -> Unit, onSave: () -> Unit, onClose: () -> Unit) {
fun EditorActionButtons(isUndoVisible: Boolean, onUndo: () -> Unit, onBuild: () -> Unit, onSave: () -> Unit, onClose: () -> Unit) {
Row(horizontalArrangement = Arrangement.SpaceBetween) {
if(isUndoVisible) {
IconButton(onClick = onUndo) { Icon(Icons.AutoMirrored.Filled.Undo, null, tint = Color.Gray) }
}
IconButton(onClick = onBuild) { Icon(Icons.Default.Build, null, tint = Color(0xFF2196F3)) }
if(isSaveVisible) {
IconButton(onClick = onSave) { Icon(Icons.Default.Save, null, tint = Color(0xFF4CAF50)) }
}
IconButton(onClick = onSave) { Icon(Icons.Default.Save, null, tint = Color(0xFF4CAF50)) }
IconButton(onClick = onClose) { Icon(Icons.Default.Close, null, tint = Color.Red) }
}
}