Skip to content

Commit

Permalink
Merge pull request #27 from sadphi/wsl-fix
Browse files Browse the repository at this point in the history
Add look and feel checks for WSL. fix #26
  • Loading branch information
bjornregnell authored Sep 22, 2021
2 parents 7a6e998 + 1fa77be commit 8055736
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/scala/introprog/Swing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ object Swing {
def isOS(partOfName: String): Boolean =
scala.sys.props("os.name").toLowerCase.contains(partOfName.toLowerCase)

/** Check whether `/proc/version` on this filesystem contains any of the strings in `s`. */
def isInProc(s: String*): Boolean = {
val searchString = s.mkString("|")
val cmd = Seq("grep", "-i", "-P", "-s", "-q", searchString, "/proc/version")
val p = sys.process.Process(cmd)
util.Try(p.! == 0).getOrElse(false)
}

private var isInit = false

/** Init the Swing GUI toolkit and set platform-specific look and feel.*/
Expand All @@ -43,8 +51,8 @@ object Swing {

private def setPlatformSpecificLookAndFeel(): Unit = {
import javax.swing.UIManager.setLookAndFeel
if (isOS("linux")) findLookAndFeel("gtk").foreach(setLookAndFeel)
else if (isOS("win")) findLookAndFeel("win").foreach(setLookAndFeel)
if (isOS("win") || isInProc("windows", "wsl", "microsoft")) findLookAndFeel("win").foreach(setLookAndFeel)
else if (isOS("linux")) findLookAndFeel("gtk").foreach(setLookAndFeel)
else if (isOS("mac")) findLookAndFeel("apple").foreach(setLookAndFeel)
else javax.swing.UIManager.setLookAndFeel(
javax.swing.UIManager.getSystemLookAndFeelClassName()
Expand Down

0 comments on commit 8055736

Please sign in to comment.