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",
"idiom" : "watch",
"filename" : "Switch.png",
"scale" : "2x",
"role" : "appLauncher",
"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
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
NSLog("get current timeline entry")
// Call the handler with the current timeline entry
if (complication.family == .graphicCorner) {
handler(getEntryForGraphicCorner())
}
handler(nil)
getFront() { front in
handler(self.getEntryForGraphicCorner(front))
}
} else { handler(nil) }
}
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) {
NSLog("get sample template")
// This method will be called once per supported complication, and the results will be cached
if (complication.family == .graphicCorner) {
handler(getTemplateForGraphicCorner("Example"))
}
handler(nil)
handler(self.getTemplateForGraphicCorner("Example"))
} else { handler(nil) }
}
func getEntryForGraphicCorner() -> CLKComplicationTimelineEntry {
let gc = getTemplateForGraphicCorner(getFront())
func getEntryForGraphicCorner(_ front: String) -> CLKComplicationTimelineEntry {
let gc = getTemplateForGraphicCorner(front)
return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: gc)
}

View File

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

View File

@ -8,17 +8,30 @@
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 {
let data = try! Data(contentsOf: url)
return String(decoding: data, as: UTF8.self)
}
func setFront(_ to: String) {
func setFront(_ to: String, _ callback: @escaping (String) -> Void) {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = to.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, resp, error in
guard data != nil else { return }
let frontString = String(decoding: data!, as: UTF8.self)
callback(frontString)
}
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>
<key>SchemeUserState</key>
<dict>
<key>Switch WatchKit App (Complication).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Switch WatchKit App.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>