Skip to content

Commit

Permalink
Merge pull request #3396 from Hannah-Sten/run-command-freeze
Browse files Browse the repository at this point in the history
Fix UI freeze in case of timed out system command
  • Loading branch information
PHPirates authored Jan 18, 2024
2 parents 0d0624a + 40eca73 commit 714c5e1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class LatexRunConfiguration(
}

fun setDefaultPdfViewer() {
pdfViewer = InternalPdfViewer.firstAvailable()
pdfViewer = InternalPdfViewer.firstAvailable
}

fun setDefaultOutputFormat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexR
runConfiguration.enableSumatraPath = enableSumatraPath.isSelected
}

runConfiguration.pdfViewer = pdfViewer.component.selectedItem as? PdfViewer ?: InternalPdfViewer.firstAvailable()
runConfiguration.pdfViewer = pdfViewer.component.selectedItem as? PdfViewer ?: InternalPdfViewer.firstAvailable

// Apply custom pdf viewer command
runConfiguration.viewerCommand = if (enableViewerCommand.isSelected) viewerCommand.text else null
Expand Down Expand Up @@ -381,7 +381,7 @@ class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexR
}

private fun updatePdfViewerComboBox() {
val viewers = InternalPdfViewer.availableSubset().filter { it != InternalPdfViewer.NONE } +
val viewers = InternalPdfViewer.availableSubset.filter { it != InternalPdfViewer.NONE } +
ExternalPdfViewers.getExternalPdfViewers() +
listOf(InternalPdfViewer.NONE)

Expand Down Expand Up @@ -446,7 +446,7 @@ class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexR
* Optional custom pdf viewer command text field.
*/
private fun addPdfViewerCommandField(panel: JPanel) {
val viewers = InternalPdfViewer.availableSubset().filter { it != InternalPdfViewer.NONE } +
val viewers = InternalPdfViewer.availableSubset.filter { it != InternalPdfViewer.NONE } +
ExternalPdfViewers.getExternalPdfViewers() +
listOf(InternalPdfViewer.NONE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ enum class InternalPdfViewer(

companion object {

fun availableSubset(): List<InternalPdfViewer> = values().filter { it.isAvailable() }
// These properties may be used often when opening a project or during project use because of settings state initialization, so we cache them.
val availableSubset: List<InternalPdfViewer> = values().filter { it.isAvailable() }

fun firstAvailable(): InternalPdfViewer = availableSubset().first()
val firstAvailable: InternalPdfViewer = availableSubset.first()
}
}
2 changes: 1 addition & 1 deletion src/nl/hannahsten/texifyidea/settings/TexifySettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
* We keep it here so that when the user migrates from when the pdf viewer was set in TeXiFy settings to when it is
* set in the run config, we can recover their old setting.
*/
var pdfViewer = InternalPdfViewer.firstAvailable()
var pdfViewer = InternalPdfViewer.firstAvailable

override fun getState(): TexifySettingsState {
return TexifySettingsState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ data class TexifySettingsState(
var latexIndentOptions: String = "",
var automaticQuoteReplacement: TexifySettings.QuoteReplacement = TexifySettings.QuoteReplacement.NONE,
var missingLabelMinimumLevel: LatexCommand = LatexGenericRegularCommand.SUBSECTION,
var pdfViewer: InternalPdfViewer = InternalPdfViewer.firstAvailable()
var pdfViewer: InternalPdfViewer = InternalPdfViewer.firstAvailable
)
14 changes: 5 additions & 9 deletions src/nl/hannahsten/texifyidea/util/SystemEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,12 @@ fun runCommandWithExitCode(vararg commands: String, workingDirectory: File? = nu
}
else {
var output = ""
if (nonBlocking) {
if (proc.inputStream.bufferedReader().ready()) {
output += proc.inputStream.bufferedReader().readText().trim()
}
if (proc.errorStream.bufferedReader().ready()) {
output += proc.errorStream.bufferedReader().readText().trim()
}
// If the program has timed out, something is stuck so we are not going to wait until it prints its stdout/stderr, we just check if ready and otherwise are out of luck
if (proc.inputStream.bufferedReader().ready()) {
output += proc.inputStream.bufferedReader().readText().trim()
}
else {
output = proc.inputStream.bufferedReader().readText().trim() + proc.errorStream.bufferedReader().readText().trim()
if (proc.errorStream.bufferedReader().ready()) {
output += proc.errorStream.bufferedReader().readText().trim()
}
proc.destroy()
proc.waitFor()
Expand Down

0 comments on commit 714c5e1

Please sign in to comment.