good fuckin lord this is complicated

This commit is contained in:
Cadey Ratio 2019-09-22 10:58:03 -04:00
parent f513b2b855
commit 3a60f8d23c
8 changed files with 79 additions and 22 deletions

View File

@ -36,6 +36,7 @@
{ {
"size" : "44x44", "size" : "44x44",
"idiom" : "watch", "idiom" : "watch",
"filename" : "Switch.png",
"scale" : "2x", "scale" : "2x",
"role" : "appLauncher", "role" : "appLauncher",
"subtype" : "40mm" "subtype" : "40mm"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -28,12 +28,14 @@ class ComplicationController: NSObject, CLKComplicationDataSource {
// MARK: - Timeline Population // MARK: - Timeline Population
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
NSLog("get current timeline entry")
// Call the handler with the current timeline entry // Call the handler with the current timeline entry
if (complication.family == .graphicCorner) { if (complication.family == .graphicCorner) {
handler(getEntryForGraphicCorner()) getFront() { front in
} handler(self.getEntryForGraphicCorner(front))
}
handler(nil) } else { handler(nil) }
} }
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) { func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
@ -47,17 +49,16 @@ class ComplicationController: NSObject, CLKComplicationDataSource {
} }
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
NSLog("get sample template")
// This method will be called once per supported complication, and the results will be cached // This method will be called once per supported complication, and the results will be cached
if (complication.family == .graphicCorner) { if (complication.family == .graphicCorner) {
handler(getTemplateForGraphicCorner("Example")) handler(self.getTemplateForGraphicCorner("Example"))
} } else { handler(nil) }
handler(nil)
} }
func getEntryForGraphicCorner() -> CLKComplicationTimelineEntry { func getEntryForGraphicCorner(_ front: String) -> CLKComplicationTimelineEntry {
let gc = getTemplateForGraphicCorner(getFront()) let gc = getTemplateForGraphicCorner(front)
return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: gc) return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: gc)
} }

View File

@ -34,8 +34,9 @@ struct SwitchButton: View {
var parent: ContentView var parent: ContentView
var body: some View { var body: some View {
Button(action: { Button(action: {
setFront(self.who) setFront(self.who) {front in
self.parent.front = self.who self.parent.front = front
}
}) { }) {
Text(self.who) Text(self.who)
} }
@ -43,15 +44,30 @@ struct SwitchButton: View {
} }
struct ContentView: View { struct ContentView: View {
@State var front = getFront() @State var front: String = ""
func refresh() { func refresh() {
self.front = getFront() getFront() { front in
self.front = front
}
reloadComplications() reloadComplications()
NSLog("reloaded...")
} }
var body: some View { var body: some View {
ScrollView{ ScrollView{
Text(self.front + " is front") HStack{
if self.front != "" {
Text(self.front + " is front")
}
Spacer()
Button(action: {
self.refresh()
}) {
Text("🔄")
}.fixedSize()
}
if self.front != "Cadey" { if self.front != "Cadey" {
SwitchButton(who: "Cadey", parent: self) SwitchButton(who: "Cadey", parent: self)
} }
@ -70,12 +86,9 @@ struct ContentView: View {
if self.front != "Mai" { if self.front != "Mai" {
SwitchButton(who: "Mai", parent: self) SwitchButton(who: "Mai", parent: self)
} }
Button(action: { }.onAppear() {
self.refresh() self.refresh()
}) { }.navigationBarTitle("Switch")
Text("🔄")
}
}
} }
} }

View File

@ -8,17 +8,30 @@
import Foundation import Foundation
func getFront(_ callback: @escaping (String) -> Void) {
let task = URLSession.shared.dataTask(with: url) { data, resp, error in
guard data != nil else { return }
let frontString = String(decoding: data!, as: UTF8.self)
callback(frontString)
}
task.resume()
}
func getFront() -> String { func getFront() -> String {
let data = try! Data(contentsOf: url) let data = try! Data(contentsOf: url)
return String(decoding: data, as: UTF8.self) return String(decoding: data, as: UTF8.self)
} }
func setFront(_ to: String) { func setFront(_ to: String, _ callback: @escaping (String) -> Void) {
var request = URLRequest(url: url) var request = URLRequest(url: url)
request.httpMethod = "POST" request.httpMethod = "POST"
request.httpBody = to.data(using: .utf8) request.httpBody = to.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, resp, error in let task = URLSession.shared.dataTask(with: request) { data, resp, error in
guard data != nil else { return } guard data != nil else { return }
let frontString = String(decoding: data!, as: UTF8.self)
callback(frontString)
} }
task.resume() task.resume()
} }

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>

View File

@ -4,6 +4,11 @@
<dict> <dict>
<key>SchemeUserState</key> <key>SchemeUserState</key>
<dict> <dict>
<key>Switch WatchKit App (Complication).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Switch WatchKit App.xcscheme_^#shared#^_</key> <key>Switch WatchKit App.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>