Skip to content

Commit b8afe92

Browse files
committed
Update function to set correct platform feel for
systems running WSL. Also add new function isInProc().
1 parent 7a6e998 commit b8afe92

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/scala/introprog/Swing.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ 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 the argument `s`. */
37+
def isInProc(s: String): Boolean = {
38+
val cmd = isOS("mac") match {
39+
case true => Seq("grep", "-qs", s, "/proc/version")
40+
case _ => Seq("grep", "-q", s, "/proc/version")
41+
}
42+
43+
val p = sys.process.Process(cmd)
44+
util.Try(p.! == 0).getOrElse(false)
45+
}
46+
3647
private var isInit = false
3748

3849
/** Init the Swing GUI toolkit and set platform-specific look and feel.*/
@@ -46,6 +57,7 @@ object Swing {
4657
if (isOS("linux")) findLookAndFeel("gtk").foreach(setLookAndFeel)
4758
else if (isOS("win")) findLookAndFeel("win").foreach(setLookAndFeel)
4859
else if (isOS("mac")) findLookAndFeel("apple").foreach(setLookAndFeel)
60+
else if (isInProc("WSL")) findLookAndFeel("win").foreach(setLookAndFeel)
4961
else javax.swing.UIManager.setLookAndFeel(
5062
javax.swing.UIManager.getSystemLookAndFeelClassName()
5163
)

0 commit comments

Comments
 (0)