100 lines
2.6 KiB
Swift
100 lines
2.6 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Switch WatchKit Extension
|
|
//
|
|
// Created by Within on 2019-09-21.
|
|
// Copyright © 2019 Within. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
func reloadComplications() {
|
|
if let complications: [CLKComplication] = CLKComplicationServer.sharedInstance().activeComplications {
|
|
if complications.count > 0 {
|
|
for complication in complications {
|
|
CLKComplicationServer.sharedInstance().reloadTimeline(for: complication)
|
|
NSLog("Reloading complication \(complication.description)...")
|
|
}
|
|
WKInterfaceDevice.current().play(WKHapticType.click) // haptic only for debugging
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SwitchTo: Codable {
|
|
struct WebhookCommand: Codable {
|
|
var command: String
|
|
var member_name: String
|
|
}
|
|
|
|
var webhook: WebhookCommand
|
|
}
|
|
|
|
struct SwitchButton: View {
|
|
var who: String
|
|
var parent: ContentView
|
|
var body: some View {
|
|
Button(action: {
|
|
setFront(self.who) {front in
|
|
self.parent.front = front
|
|
}
|
|
}) {
|
|
Text(self.who)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView: View {
|
|
@State var front: String = ""
|
|
|
|
func refresh() {
|
|
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)
|
|
}
|
|
if self.front != "Nicole" {
|
|
SwitchButton(who: "Nicole", parent: self)
|
|
}
|
|
if self.front != "Jessie" {
|
|
SwitchButton(who: "Jessie", parent: self)
|
|
}
|
|
if self.front != "Ashe" {
|
|
SwitchButton(who: "Ashe", parent: self)
|
|
}
|
|
if self.front != "Sephie" {
|
|
SwitchButton(who: "Sephie", parent: self)
|
|
}
|
|
if self.front != "Mai" {
|
|
SwitchButton(who: "Mai", parent: self)
|
|
}
|
|
}.onAppear() {
|
|
self.refresh()
|
|
}.navigationBarTitle("Switch")
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|