-
Notifications
You must be signed in to change notification settings - Fork 76
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
Provide platform name to self-updater #541
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
import com.google.common.base.Preconditions; | ||
|
||
import javax.json.JsonObject; | ||
import javax.json.JsonValue; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Simplified interface for GitHub releases. | ||
|
@@ -46,4 +51,14 @@ public String getTagName() { | |
public String getBody() { | ||
return json.getString("body"); | ||
} | ||
|
||
public String getDownloadUrl(String platform) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of putting utility methods with logic in here, just expose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easy to implement 👍. That's surely the most object-oriented approach, but let me ask if it's really necessary? Like if we are supposed to work with a single target asset (depending on the user's platform), why should we provide a list of assets or their names? 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep all the classes in the The current way we use the github api library is not ideal, as we are dealing with the plain JSON objects. In principle, those libraries offer interfaces similar to what is implemented in that package, so I'm preparing an easy switch. |
||
return json.getJsonArray("assets") | ||
.stream() | ||
.map(JsonValue::asJsonObject) | ||
.filter(asset -> asset.getString("name").contains(platform)) | ||
.findFirst() | ||
.map(asset -> asset.getString("browser_download_url")) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid platform")); // Should not reach | ||
} | ||
} |
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.
System.getProperty("os.name")
- why not print out theos
instead? Mabye update thetoString
to contain more information, if needed.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.
That can be a quick fix. 👍 Since we're planning to get rid of that enum or maybe refactor it at least, it should contain just four constants: windows, mac, linux, and unsupported. So we might need to get it refactored while solving #542 too.
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.
Why would we need the
unsupported
constant?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.
That'd be the default if someone somehow tries to run the launcher on anything other than the three supported platforms. We can use
null
of course, but I'd suggest avoiding that.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 get what "unsupported" means ;)
I just don't get why we'd need a specific value for that...
Consider you want somebody to slice apples, peel potatoes and throw everything else you find in your kitchen cabinet away, which of the following would you rather write down and why?
A)
B)
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.
(B) seems natural 👍 (and that's what the
else
keyword was invented for)