diff --git a/Bundler.toml b/Bundler.toml
index cc33fa4..a42c273 100644
--- a/Bundler.toml
+++ b/Bundler.toml
@@ -1,9 +1,9 @@
format_version = 2
[apps.AmtrakStatus]
-identifier = 'com.tonybark.AmtrakStatus'
+identifier = 'com.example.AmtrakStatus'
product = 'AmtrakStatus'
-version = '0.2.102'
+version = '0.1.0'
icon = "./assets/icon.png"
diff --git a/README.md b/README.md
index b132b6e..41fc07d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
-
-
+
## 🖥️ Supported Platforms
@@ -8,7 +7,7 @@
| Platform | Minimum Version |
| ---------------------------- | --------------- |
| macOS | 10.15+ |
-| Windows | 11+ |
+| Windows | 10+ |
| Linux | gtk 3+ |
## 🔨 Setup
@@ -36,9 +35,9 @@ swift-bundler bundle -c (release|debug)
This was intended to solve a rather awkward dilemma. I turned a bunch of online Amtrak status boards made by [Dixieland Software](http://dixielandsoftware.net/Amtrak/status/StatusMaps/) into PWAs (standalone web apps) for stations that I viewed on Virtual Railfan. While it was convenient - don't get me wrong - I had to create a new web app for each and every station, and it was becoming overwhelming.
-So I created simple frontend that mapped to Dixieland Software's API using Tauri. You could type in simple station code and it'd take you their status board from within the app. Simple, right? Unfortunately, I didn't know how to get it go back to change the station, my attempted UI redesigns kept failing, and I accidentally botched a migration to Tauri 2.0. I'm just not that good with Node.
+So I created simple frontend that mapped to Dixieland Software's API using Tauri. You could type in simple station code and it'd take you their status board from within the app. Simple, right? Unfortunately, I didn't know how to get it go back to change the station, my attempted UI redesigns kept failing, and I accidentally botched a migration to Tauri 2.0.
-So it sat abandoned until I discovered [SwiftCrossUI](https://github.com/moreSwift/swift-cross-ui). Now it directly makes use of [Amtraker](https://amtraker.com/)'s API.
+So it sat abandoned until I discovered SwiftCrossUI. Now it directly makes use of [Amtraker](https://amtraker.com/)'s API.
## ⚖️ License
diff --git a/Sources/AmtrakStatus/AmtrakClient.swift b/Sources/AmtrakStatus/AmtrakClient.swift
index 0fbe23f..3430066 100644
--- a/Sources/AmtrakStatus/AmtrakClient.swift
+++ b/Sources/AmtrakStatus/AmtrakClient.swift
@@ -7,12 +7,6 @@ enum AmtrakError: Error {
case stationNotFound(String)
}
-
-struct TrainStationLookUp: Sendable {
- var trainNumbers: [String]
- var timeZone: TimeZone?
-}
-
struct AmtrakClient {
var decoder = JSONDecoder()
@@ -47,21 +41,15 @@ struct AmtrakClient {
.first
.map(String.init) ?? trainId
}
-
- func trainStationLookup(stationCode code: String) async throws -> TrainStationLookUp {
+ func fetchStationTrainNumbers(stationCode code: String) async throws -> [String] {
let reponse = try await fetchStation(code: code)
guard let meta = reponse[code] else {
throw AmtrakError.stationNotFound(code)
}
-
- let trainNumbers = Array(Set(meta.trains.map(trainNumber(fromTrainId:))))
- let timeZone = meta.tz.flatMap(TimeZone.init(identifier:))
- return TrainStationLookUp(
- trainNumbers: trainNumbers,
- timeZone: timeZone
- )
+
+ return Array(Set(meta.trains.map(trainNumber(fromTrainId:))))
}
func get(_ urlString: String) async throws -> T {
diff --git a/Sources/AmtrakStatus/AmtrakDateFormatting.swift b/Sources/AmtrakStatus/AmtrakDateFormatting.swift
index d1f4fdd..912c9c7 100644
--- a/Sources/AmtrakStatus/AmtrakDateFormatting.swift
+++ b/Sources/AmtrakStatus/AmtrakDateFormatting.swift
@@ -1,52 +1,32 @@
import Foundation
struct AmtrakDateFormatting {
- let isoFormatter = ISO8601DateFormatter()
+ static let isoFormatter = ISO8601DateFormatter()
- let timeFormatter: DateFormatter = {
+ static let timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
return formatter
}()
- let dateFormatter: DateFormatter = {
+ static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .none
return formatter
}()
- func parsedDate(from isoString: String?) -> Date? {
- guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
- from: isoString) else {
- return nil
- }
-
- return isoFormatter.date(from: isoString)
- }
-
- func time(from isoString: String?, timeZone: TimeZone? = nil) -> String? {
+ static func time(from isoString: String?) -> String? {
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
from: isoString) else {
return nil
}
- timeFormatter.timeZone = timeZone
+
return timeFormatter.string(from: date)
}
- func localTime(timeZone: TimeZone?) -> String {
- let now = Date()
- timeFormatter.timeZone = timeZone
- return timeFormatter.string(from: now)
- }
-
- func updateTime(timeZone: TimeZone?) {
- let now = Date()
- timeFormatter.timeZone = timeZone
- }
-
- func date(from isoString: String?) -> String? {
+ static func date(from isoString: String?) -> String? {
guard let isoString, !isoString.isEmpty, let date = isoFormatter.date(
from: isoString) else {
return nil
diff --git a/Sources/AmtrakStatus/ContentView.swift b/Sources/AmtrakStatus/ContentView.swift
index 09d601c..316a852 100644
--- a/Sources/AmtrakStatus/ContentView.swift
+++ b/Sources/AmtrakStatus/ContentView.swift
@@ -1,6 +1,11 @@
import SwiftCrossUI
import Foundation
+extension Train {
+ var serviceDate: String {
+ AmtrakDateFormatting.date(from: createdAt) ?? "-"
+ }
+}
struct ContentView: View {
@State var client = AmtrakClient()
@@ -10,9 +15,7 @@ struct ContentView: View {
@State var isLoading = false
@State var errorMessage: String?
@State var currentStation: String = ""
- @State var localTimeZone: TimeZone?
- let amtrakDate = AmtrakDateFormatting()
let unknown = "Unknown"
var body: some View {
@@ -22,11 +25,11 @@ struct ContentView: View {
TextField("e.g. ASD", text: $stationCode)
.frame(width: 100)
- Button("Submit") {
+ Button("Refresh") {
Task {
await loadTrainStatus(forStationCode: normalizedStationCode)
}
- }.disabled(normalizedStationCode.isEmpty)
+ }.disabled(normalizedStationCode.isEmpty || isLoading)
}.padding(10)
// Most popular Virtual Railfan stations
@@ -54,22 +57,12 @@ struct ContentView: View {
TableColumn("Time", value: \TrainStatusRow.arrival)
TableColumn("Number", value: \TrainStatusRow.trainNum)
TableColumn("Train", value: \TrainStatusRow.routeName)
- TableColumn("To", value: \TrainStatusRow.destination)
- TableColumn("From", value: \TrainStatusRow.origin)
- TableColumn("Status") {
- (row: TrainStatusRow) in
- ZStack {
- RoundedRectangle(cornerRadius: 0)
- .fill(row.status.color)
- Text(row.status.descrption)
- .foregroundColor(
- statusColour(row.status.color)
- )
- }
- }
+ TableColumn("To", value: \TrainStatusRow.origin)
+ TableColumn("From", value: \TrainStatusRow.destination)
+ TableColumn("Status", value: \TrainStatusRow.status)
TableColumn("Track", value: \TrainStatusRow.platform)
- }.frame(minWidth: 600)
- .overlay(alignment: .bottomTrailing) {
+
+ }.overlay(alignment: .bottomTrailing) {
if isLoading {
ProgressView()
.frame(alignment: .topTrailing)
@@ -81,9 +74,7 @@ struct ContentView: View {
if let errorMessage {
Text(errorMessage)
} else if !currentStation.isEmpty {
- Text(
- "It is \(amtrakDate.localTime(timeZone: localTimeZone)) at \(currentStation) station"
- )
+ Text(currentStation)
}
}.padding(10)
}
@@ -98,21 +89,6 @@ struct ContentView: View {
var normalizedStationCode: String {
stationCode.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
}
-
- func statusColour(_ color: Color) -> Color {
- switch color {
- case .green:
- return .black
- default:
- return .white
- }
- }
-
- func loadStationStatus(forStationCode code: String) async {
- guard !code.isEmpty else {
- return
- }
- }
func loadTrainStatus(forStationCode code: String) async {
guard !code.isEmpty else {
@@ -125,32 +101,25 @@ struct ContentView: View {
defer { isLoading = false }
do {
- let lookup = try await client.trainStationLookup(
+ let trainNumbers = try await client.fetchStationTrainNumbers(
stationCode: code,
)
- guard !lookup.trainNumbers.isEmpty else {
+ guard !trainNumbers.isEmpty else {
errorMessage = "\(code) has no trains listed right now"
rows = []
return
}
var newRows: [TrainStatusRow] = []
- for number in lookup.trainNumbers {
+ for number in trainNumbers {
let trains = try await client.fetchAllTrainStatus(num: number)
for train in trains {
let platform = train.stations?.first(
where: { $0.code == code
},
)?.platform
- newRows
- .append(
- trainStatus(
- for: train,
- atStationCode: code,
- timeZone: lookup.timeZone
- )
- )
+ newRows.append(trainStatus(for: train, atStationCode: code))
}
}
@@ -165,39 +134,30 @@ struct ContentView: View {
}
}
- func isOnTime(arr: String?, schArr: String?) -> TrainLateness {
-
- guard
- let actualDate = amtrakDate.parsedDate(from: arr),
- let scheduledDate = amtrakDate.parsedDate(from: schArr)
- else {
- return .unknown
+ func isOnTime(arr: String?, schArr: String?) -> String {
+ let amtrakDate = AmtrakDateFormatting()
+
+ if AmtrakDateFormatting
+ .time(from: arr) != AmtrakDateFormatting
+ .time(from: schArr) {
+ return "Late"
}
- let differenceInMinutes = Int(actualDate.timeIntervalSince(scheduledDate) / 60)
-
- switch differenceInMinutes {
- case -1...1:
- return .onTime
- case ..<0:
- return .early(minutes: -differenceInMinutes)
- default:
- return .late(minutes: differenceInMinutes)
- }
+ return "On Time"
}
- func trainStatus(for train: Train, atStationCode code: String, timeZone: TimeZone?) -> TrainStatusRow {
+ func trainStatus(for train: Train, atStationCode code: String) -> TrainStatusRow {
let leg = train.stations?.first { $0.code == code }
+ let platform = leg?.platform ?? "-"
let stationName = leg?.name ?? unknown
- let arrival = amtrakDate.time(from: leg?.arr, timeZone: timeZone) ?? amtrakDate.time(
- from: leg?.schArr,
- timeZone: timeZone)
- let depature = amtrakDate.time(from: leg?.dep, timeZone: timeZone) ?? amtrakDate.time(
- from: leg?.schDep,
- timeZone: timeZone)
+ let arrival = AmtrakDateFormatting.time(from: leg?.arr) ?? AmtrakDateFormatting.time(
+ from: leg?.schArr
+ )
+ let depature = AmtrakDateFormatting.time(from: leg?.dep) ?? AmtrakDateFormatting.time(
+ from: leg?.schDep
+ )
- currentStation = stationName
- localTimeZone = timeZone
+ currentStation = "\(stationName) station"
return TrainStatusRow(
trainID: train.trainID,
diff --git a/Sources/AmtrakStatus/Models.swift b/Sources/AmtrakStatus/Models.swift
index eba059c..401b91c 100644
--- a/Sources/AmtrakStatus/Models.swift
+++ b/Sources/AmtrakStatus/Models.swift
@@ -97,7 +97,7 @@ struct TrainStatusRow: Identifiable {
var trainID: String
var trainNum: String
var routeName: String
- var status: TrainLateness
+ var status: String
var platform: String
var arrival: String
var departure: String
diff --git a/Sources/AmtrakStatus/TrainLateness.swift b/Sources/AmtrakStatus/TrainLateness.swift
deleted file mode 100644
index cd59dd1..0000000
--- a/Sources/AmtrakStatus/TrainLateness.swift
+++ /dev/null
@@ -1,45 +0,0 @@
-import Foundation
-import SwiftCrossUI
-
-enum TrainLateness {
- case onTime
- case early(minutes: Int)
- case late(minutes: Int)
- case unknown
-
- var descrption: String {
- switch self {
- case .onTime:
- return "On Time"
- case .early(minutes: let minutes):
- return "\(Self.formatted(minutes)) early"
- case .late(minutes: let minutes):
- return "\(Self.formatted(minutes)) late"
- case .unknown:
- return ""
- }
- }
-
- var color: Color {
- switch self {
- case .onTime:
- return .green
- case .early:
- return .blue
- case .late:
- return .red
- case .unknown:
- return .gray
- }
- }
-
-
- static func formatted(_ minutes: Int) -> String {
- let hours = minutes / 60
- let remainder = minutes % 60
- guard hours > 0 else {
- return "\(minutes) mins"
- }
- return "\(hours) hrs"
- }
-}
diff --git a/assets/screenshot.png b/assets/screenshot.png
deleted file mode 100644
index e293d5b..0000000
Binary files a/assets/screenshot.png and /dev/null differ
diff --git a/changelog.md b/changelog.md
deleted file mode 100644
index 8a28089..0000000
--- a/changelog.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# Change Log
-
-## 0.2.102
-
-- The status bar at the bottom now shows ``It is