From 3a60f8d23c390467ec8e5e84a74361a46018e9c6 Mon Sep 17 00:00:00 2001 From: Within Date: Sun, 22 Sep 2019 10:58:03 -0400 Subject: [PATCH] good fuckin lord this is complicated --- .../AppIcon.appiconset/Contents.json | 1 + .../AppIcon.appiconset/Switch.png | Bin 0 -> 2391 bytes .../ComplicationController.swift | 21 ++++++----- Switch WatchKit Extension/ContentView.swift | 35 ++++++++++++------ Switch WatchKit Extension/Switch.swift | 15 +++++++- .../xcshareddata/WorkspaceSettings.xcsettings | 8 ++++ .../WorkspaceSettings.xcsettings | 16 ++++++++ .../xcschemes/xcschememanagement.plist | 5 +++ 8 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Switch.png create mode 100644 Switch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 Switch.xcodeproj/project.xcworkspace/xcuserdata/within.xcuserdatad/WorkspaceSettings.xcsettings diff --git a/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json b/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json index 6c0f2b4..1b164f3 100644 --- a/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -36,6 +36,7 @@ { "size" : "44x44", "idiom" : "watch", + "filename" : "Switch.png", "scale" : "2x", "role" : "appLauncher", "subtype" : "40mm" diff --git a/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Switch.png b/Switch WatchKit App/Assets.xcassets/AppIcon.appiconset/Switch.png new file mode 100644 index 0000000000000000000000000000000000000000..ef267be2f629ae5276d75a3b8f7221641f37cff4 GIT binary patch literal 2391 zcmV-d38?moP)EX>4Tx04R}tkv&MmKpe$iQ>7|Z2aAX}1gTCIL`5963Pq?8YK2xEOfLO`CJjl7 zi=*ILaPVWX>fqw6tAnc`2!4RLxH>7iNQwVT3N2ziIPS;0dyl(!f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1Ak#1~nM{&lB+)QTip8Qh84ly{&}}&q3SxMCY@sX^YM8nh zya3lCR1~lRR=_F>SOKeme(=cGw1(Zgc~x~aW66BX~C$#HsLj!S|Vk9)^g^ zcWeO7H~uK)+ynp-5G9F}fTUqycw$@(4GoE&E}sYt4`F0#k`(27fmaI=AQ2G};Qh4* zA|en%kZs$POeSeE92TKaPz((Y%G-mtWMpcJ3S~21VFR!8MIe}41VY5QsjrlfOe8Q8 ziO5hWD1w22@b`T#C&tIk7FOU4!@$we5z*1!ZuNF|iG1&bbOe})WQM<= z^OdpmLQgCjm43h9?r3kbd%JyddNNF<1`Ghih``bJtp9v?$!foT zMHDi2HozM`=1OP}`q^4BO%sQQhwM)~JMC`YO))g!$3gg0`fniw-M&3&pF8`PL|;!AD&Qa=ZBN5>80 z?CXCtoT||!4V+Fa7L)&a@7=^Z=g-*+*ue>m-`{V&`Nr9t*5{Hs$*m{0ZPVosFC|`o z?To3~H0KTmfk43i(;t2}o9$>W&WXnSMTSl%7K_Q>zWVD}Hl0SXPL8*U{(9b8Y41lV1M?g{7IgV;8ZZ6omx<-bYV%(%Y7Jv>7 z!7k^BxgJM7?{6MUI9O#t5}4c@zyXRg8shGmwbf6{{Wn+$L(wiviAT0002ov JPDHLkV1iOhe3JkG literal 0 HcmV?d00001 diff --git a/Switch WatchKit Extension/ComplicationController.swift b/Switch WatchKit Extension/ComplicationController.swift index 4d5dff9..cdd1360 100644 --- a/Switch WatchKit Extension/ComplicationController.swift +++ b/Switch WatchKit Extension/ComplicationController.swift @@ -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) } diff --git a/Switch WatchKit Extension/ContentView.swift b/Switch WatchKit Extension/ContentView.swift index f2296e9..a43a84f 100644 --- a/Switch WatchKit Extension/ContentView.swift +++ b/Switch WatchKit Extension/ContentView.swift @@ -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") } } diff --git a/Switch WatchKit Extension/Switch.swift b/Switch WatchKit Extension/Switch.swift index d96d525..c40d5c9 100644 --- a/Switch WatchKit Extension/Switch.swift +++ b/Switch WatchKit Extension/Switch.swift @@ -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() } diff --git a/Switch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Switch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/Switch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/Switch.xcodeproj/project.xcworkspace/xcuserdata/within.xcuserdatad/WorkspaceSettings.xcsettings b/Switch.xcodeproj/project.xcworkspace/xcuserdata/within.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..dd7403b --- /dev/null +++ b/Switch.xcodeproj/project.xcworkspace/xcuserdata/within.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,16 @@ + + + + + BuildLocationStyle + UseAppPreferences + CustomBuildLocationType + RelativeToDerivedData + DerivedDataLocationStyle + Default + IssueFilterStyle + ShowActiveSchemeOnly + LiveSourceIssuesEnabled + + + diff --git a/Switch.xcodeproj/xcuserdata/within.xcuserdatad/xcschemes/xcschememanagement.plist b/Switch.xcodeproj/xcuserdata/within.xcuserdatad/xcschemes/xcschememanagement.plist index c076e62..684f67f 100644 --- a/Switch.xcodeproj/xcuserdata/within.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Switch.xcodeproj/xcuserdata/within.xcuserdatad/xcschemes/xcschememanagement.plist @@ -4,6 +4,11 @@ SchemeUserState + Switch WatchKit App (Complication).xcscheme_^#shared#^_ + + orderHint + 1 + Switch WatchKit App.xcscheme_^#shared#^_ orderHint