Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial try at a Mac implementation #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions core/js/src/main/scala/tf/bug/dirs/JSTarget.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tf.bug.dirs
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

/** Necessary facades around the Node.js `os` module for discovering dirs
*/
object os {
@js.native
@JSImport("os", "homedir")
def homedir(): String = js.native

@js.native
@JSImport("process", "platform")
def platform(): String = js.native

}
object JSTarget extends Target {
def homedir: Option[Path] = Some(Path.get(os.homedir()))
def platform: Platform = {
val osName = jsPlatform()
osName match {
case "win32" => Platform.Windows
case "darwin" => Platform.Mac
case _ => Platform.Unknown(osName)
}
}
}
2 changes: 1 addition & 1 deletion core/js/src/main/scala/tf/bug/dirs/MacPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tf.bug.dirs
import java.nio.file.{Path, Paths}

object MacPlatform extends Mac {
def home: Option[Path] = Some(Paths.get(os.homedir()))
def home: Option[Path] = JSTarget.homedir
def cache: Option[Path] = home.map(h => Paths.get(h + "/Library/Caches"))
def config: Option[Path] =
home.map(h => Paths.get(h + "/Library/Application Support"))
Expand Down
13 changes: 0 additions & 13 deletions core/js/src/main/scala/tf/bug/dirs/os.scala

This file was deleted.

13 changes: 0 additions & 13 deletions core/js/src/main/scala/tf/bug/dirs/os.scala.scala

This file was deleted.

16 changes: 16 additions & 0 deletions core/jvm/src/main/scala/tf/bug/dirs/JVMTarget.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tf.bug.dirs



object JVMTarget extends Target {
def platform: Platform = {
val osName = System.getProperty("os.name")
if (osName.contains("Windows")) {
Platform.Windows
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains("Mac") || contains("Darwin")? Not sure if darwin will report lower-case here though...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the "Mac" part by runninggetProperty locally.
AFAIK, os.name never returns "darwin". However only evidence I can find is are blogposts.

Platform.Unknown(osName)
}
}

def homeDir: Option[Path] = Some(Paths.get(System.getProperty("user.home")))
}
2 changes: 1 addition & 1 deletion core/jvm/src/main/scala/tf/bug/dirs/MacPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tf.bug.dirs
import java.nio.file.{Path, Paths}

object MacPlatform extends Mac {
def home: Option[Path] = Some(Paths.get(System.getProperty("user.home")))
def home: Option[Path] = JVMTarget.homeDir
def cache: Option[Path] = home.map(h => Paths.get(h + "/Library/)Caches"))
def config: Option[Path] =
home.map(h => Paths.get(h + "/Library/)Application Support"))
Expand Down
11 changes: 1 addition & 10 deletions core/shared/src/main/scala/tf/bug/dirs/Dirs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ object Dirs {
lazy val windows: Windows = WindowsPlatform
lazy val mac: Mac = MacPlatform

lazy val platform: Platform = {
val osName = System.getProperty("os.name")
if(osName.contains("Windows")) {
Platform.Windows
} else if (osName.contains("Mac")) {
Platform.Mac
} else {
Platform.Unknown(osName)
}
}
lazy val platform: Platform = Target.platform

def audio: Option[Path] = platform match {
case Platform.Windows => this.windows.shGetKnownFolderPath(this.windows.folderIdMusic)
Expand Down
8 changes: 8 additions & 0 deletions core/shared/src/main/scala/tf/bug/dirs/Target.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tf.bug.dirs

import java.nio.file.Path

trait Target {
def homeDir: Option[Path]
def platform: Platform
}