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

Also set date, which shows on iPad status bars #4

Merged
merged 2 commits into from
Apr 12, 2020

Conversation

tfe
Copy link
Contributor

@tfe tfe commented Apr 1, 2020

iPad status bars also show the date, so I wanted to set that to the appropriate date for 9:41am.

simctl allows setting the date with the time arg, but it needs to be ISO format. That means the time we include in the ISO date string needs to be in the current time zone. So we need to get that at runtime from the system. Per this answer on SO we can get that from the system via date.

This PR adds another function to shell out and get that magic date string, and passes it into xcrun_fix_status_bar for use as the time argument.

This is what we get in the simulator:

Screen Shot 2020-04-01 at 2 44 35 PM

Copy link
Owner

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

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

Thanks @tfe ! 💯 I really appreciate this.

Just a few minor comments. What do you think?

nine41.swift Outdated
@@ -50,10 +50,10 @@ extension Process {
/// Executes `xcrun simctl status_bar` on the specified device.
///
/// - Parameter device: The device for which status bar values should be overridden.
func xcrun_fix_status_bar(_ device: String) {
func xcrun_fix_status_bar(_ device: String, time: String) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think I would prefer having this just be a local var instead.

 func xcrun_fix_status_bar(_ device: String) {
    let time = // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I actually tried that first but got some errors about running a Process inside another Process, so I had to break it out. But I'll try the Foundation date formatter instead which will solve this problem and that one.

nine41.swift Outdated
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String

return output
Copy link
Owner

Choose a reason for hiding this comment

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

why not just use Foundation's Date and NSISO8601DateFormatter?

that would be simpler and more familiar to folks who are likely to contribute to this project. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That... would make a ton of sense. I'm not an experienced iOS dev and was in a rush, so I just grabbed whatever was working from that Stack Overflow answer and didn't think much further about it. 🙃

I'll try that.

nine41.swift Outdated
@@ -72,6 +88,9 @@ let json = (try! JSONSerialization.jsonObject(with: deviceData, options: [])) as
let runtimes = json["devices"] as! Dictionary<String, Array<Any>>
let allDevices = runtimes.values.flatMap { $0 } as! Array<Dictionary<String, AnyHashable>>

// 9:41 AM PT on Tuesday January 9, 2007
Copy link
Owner

Choose a reason for hiding this comment

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

😄 💯

@tfe
Copy link
Contributor Author

tfe commented Apr 11, 2020

Thanks for your patience. That was a really dumb way of doing it. 😬 This should be much better.

@tfe tfe requested a review from jessesquires April 11, 2020 07:28
@jessesquires
Copy link
Owner

Thanks for your patience. That was a really dumb way of doing it.

@tfe No problem at all! 😄 We all have to learn some time. This is a great contribution. 💯

Copy link
Owner

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

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

🥇 very nice work @tfe !

I'll send you an invite to be a collaborator and have push access.

@jessesquires jessesquires merged commit e5b1fa5 into jessesquires:master Apr 12, 2020
@jessesquires
Copy link
Owner

@tfe This got me curious about what this actual date should be.

I found out and opened #7 if you want to take a look. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants