-
Notifications
You must be signed in to change notification settings - Fork 1
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
zetashift
wants to merge
5
commits into
s5bug:main
Choose a base branch
from
zetashift:add/mac
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2154190
Initial try at a Mac implementation
zetashift 3e9ce17
Correctly return Paths and attempt at JS implementation
zetashift b9de4dc
Remove parenthesis
zetashift 40ec956
Fix double scala file extenison in os.scala
zetashift 785b875
Add Target trait for JS/JVM/Native differences
zetashift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tf.bug.dirs | ||
|
||
import java.nio.file.{Path, Paths} | ||
|
||
object MacPlatform extends Mac { | ||
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")) | ||
def data: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/Application Support")) | ||
def dataLocal: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/Preferences")) | ||
def preference: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/Preferences")) | ||
def audio: Option[Path] = home.map(h => Paths.get(h + "/Music")) | ||
def desktop: Option[Path] = home.map(h => Paths.get(h + "/Desktop")) | ||
def document: Option[Path] = home.map(h => Paths.get(h + "/Documents")) | ||
def download: Option[Path] = home.map(h => Paths.get(h + "/Downloads")) | ||
def font: Option[Path] = home.map(h => Paths.get(h + "/Library/)Fonts")) | ||
def picture: Option[Path] = home.map(h => Paths.get(h + "/Pictures")) | ||
def public: Option[Path] = home.map(h => Paths.get(h + "/Public")) | ||
def video: Option[Path] = home.map(h => Paths.get(h + "/Movies")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
Platform.Unknown(osName) | ||
} | ||
} | ||
|
||
def homeDir: Option[Path] = Some(Paths.get(System.getProperty("user.home"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tf.bug.dirs | ||
|
||
import java.nio.file.{Path, Paths} | ||
|
||
object MacPlatform extends Mac { | ||
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")) | ||
def data: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/)Application Support")) | ||
def dataLocal: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/)Preferences")) | ||
zetashift marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def preference: Option[Path] = | ||
home.map(h => Paths.get(h + "/Library/)Preferences")) | ||
def audio: Option[Path] = home.map(h => Paths.get(h + "/Music")) | ||
def desktop: Option[Path] = home.map(h => Paths.get(h + "/Desktop")) | ||
def document: Option[Path] = home.map(h => Paths.get(h + "/Documents")) | ||
def download: Option[Path] = home.map(h => Paths.get(h + "/Downloads")) | ||
def font: Option[Path] = home.map(h => Paths.get(h + "/Library/)Fonts")) | ||
def picture: Option[Path] = home.map(h => Paths.get(h + "/Pictures")) | ||
def public: Option[Path] = home.map(h => Paths.get(h + "/Public")) | ||
def video: Option[Path] = home.map(h => Paths.get(h + "/Movies")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tf.bug.dirs | ||
|
||
import java.nio.file.Path | ||
|
||
trait Mac { | ||
def home: Option[Path] | ||
def cache: Option[Path] | ||
def config: Option[Path] | ||
def data: Option[Path] | ||
def dataLocal: Option[Path] | ||
def preference: Option[Path] | ||
def executable: Option[Path] | ||
def runtime: Option[Path] | ||
def state: Option[Path] | ||
def audio: Option[Path] | ||
def desktop: Option[Path] | ||
def document: Option[Path] | ||
def download: Option[Path] | ||
def font: Option[Path] | ||
def picture: Option[Path] | ||
def public: Option[Path] | ||
def template: Option[Path] | ||
def video: Option[Path] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ifdarwin
will report lower-case here though...There was a problem hiding this comment.
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 running
getProperty
locally.AFAIK,
os.name
never returns "darwin". However only evidence I can find is are blogposts.