Skip to content

Commit 8055736

Browse files
authored
Merge pull request #27 from sadphi/wsl-fix
Add look and feel checks for WSL. fix #26
2 parents 7a6e998 + 1fa77be commit 8055736

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/scala/introprog/Swing.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ object Swing {
3333
def isOS(partOfName: String): Boolean =
3434
scala.sys.props("os.name").toLowerCase.contains(partOfName.toLowerCase)
3535

36+
/** Check whether `/proc/version` on this filesystem contains any of the strings in `s`. */
37+
def isInProc(s: String*): Boolean = {
38+
val searchString = s.mkString("|")
39+
val cmd = Seq("grep", "-i", "-P", "-s", "-q", searchString, "/proc/version")
40+
val p = sys.process.Process(cmd)
41+
util.Try(p.! == 0).getOrElse(false)
42+
}
43+
3644
private var isInit = false
3745

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

4452
private def setPlatformSpecificLookAndFeel(): Unit = {
4553
import javax.swing.UIManager.setLookAndFeel
46-
if (isOS("linux")) findLookAndFeel("gtk").foreach(setLookAndFeel)
47-
else if (isOS("win")) findLookAndFeel("win").foreach(setLookAndFeel)
54+
if (isOS("win") || isInProc("windows", "wsl", "microsoft")) findLookAndFeel("win").foreach(setLookAndFeel)
55+
else if (isOS("linux")) findLookAndFeel("gtk").foreach(setLookAndFeel)
4856
else if (isOS("mac")) findLookAndFeel("apple").foreach(setLookAndFeel)
4957
else javax.swing.UIManager.setLookAndFeel(
5058
javax.swing.UIManager.getSystemLookAndFeelClassName()

0 commit comments

Comments
 (0)