good fuckin lord this is complicated
This commit is contained in:
parent
f513b2b855
commit
3a60f8d23c
|
@ -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 |
|
@ -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())
|
||||
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) {
|
||||
|
@ -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(self.getTemplateForGraphicCorner("Example"))
|
||||
} else { handler(nil) }
|
||||
}
|
||||
|
||||
handler(nil)
|
||||
}
|
||||
|
||||
func getEntryForGraphicCorner() -> CLKComplicationTimelineEntry {
|
||||
let gc = getTemplateForGraphicCorner(getFront())
|
||||
func getEntryForGraphicCorner(_ front: String) -> CLKComplicationTimelineEntry {
|
||||
let gc = getTemplateForGraphicCorner(front)
|
||||
return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: gc)
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
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: {
|
||||
}.onAppear() {
|
||||
self.refresh()
|
||||
}) {
|
||||
Text("🔄")
|
||||
}
|
||||
}
|
||||
}.navigationBarTitle("Switch")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue