code commit

This commit is contained in:
Cadey Ratio 2019-09-21 17:00:13 -04:00
parent abbe88be5f
commit 45b3791922
7 changed files with 178 additions and 3 deletions

View File

@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>Switch WatchKit App</string> <string>Switch</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>

1
Switch WatchKit Extension/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
SwitchURL.swift

View File

@ -0,0 +1,67 @@
//
// ComplicationController.swift
// Switch WatchKit Extension
//
// Created by Within on 2019-09-21.
// Copyright © 2019 Within. All rights reserved.
//
import WatchKit
class ComplicationController: NSObject, CLKComplicationDataSource {
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([])
}
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
handler(.showOnLockScreen)
}
// MARK: - Timeline Population
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
if (complication.family == .graphicCorner) {
handler(getTemplateForGraphicCorner())
}
handler(nil)
}
func getTemplateForGraphicCorner() -> CLKComplicationTemplateGraphicCornerStackText {
let gc = CLKComplicationTemplateGraphicCornerStackText()
let front = "Cadey"
let text = CLKSimpleTextProvider()
text.text = front + " foo"
text.shortText = "hi"
text.tintColor = UIColor.white
gc.innerTextProvider = text
return gc;
}
}

View File

@ -8,9 +8,74 @@
import SwiftUI import SwiftUI
struct ContentView: View { 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 { var body: some View {
Text("Hello World") Button(action: {
setFront(self.who)
self.parent.front = self.who
}) {
Text(self.who)
}
}
}
struct ContentView: View {
@State var front = getFront()
func refresh() {
self.front = getFront()
reloadComplications()
}
var body: some View {
ScrollView{
Text(self.front + " is front")
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)
}
Button(action: {
self.refresh()
}) {
Text("🔄")
}
}
} }
} }

View File

@ -20,6 +20,12 @@
<string>1.0</string> <string>1.0</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>1</string>
<key>CLKComplicationPrincipalClass</key>
<string>ComplicationController</string>
<key>CLKComplicationSupportedFamilies</key>
<array>
<string>CLKComplicationFamilyGraphicCorner</string>
</array>
<key>NSExtension</key> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionAttributes</key> <key>NSExtensionAttributes</key>

View File

@ -0,0 +1,24 @@
//
// Switch.swift
// Switch WatchKit Extension
//
// Created by Within on 2019-09-21.
// Copyright © 2019 Within. All rights reserved.
//
import Foundation
func getFront() -> String {
let data = try! Data(contentsOf: url)
return String(decoding: data, as: UTF8.self)
}
func setFront(_ to: String) {
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 }
}
task.resume()
}

View File

@ -16,6 +16,9 @@
4225D8E32336B5B000B8B625 /* ExtensionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4225D8E22336B5B000B8B625 /* ExtensionDelegate.swift */; }; 4225D8E32336B5B000B8B625 /* ExtensionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4225D8E22336B5B000B8B625 /* ExtensionDelegate.swift */; };
4225D8E52336B5B100B8B625 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4225D8E42336B5B100B8B625 /* Assets.xcassets */; }; 4225D8E52336B5B100B8B625 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4225D8E42336B5B100B8B625 /* Assets.xcassets */; };
4225D8E82336B5B100B8B625 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4225D8E72336B5B100B8B625 /* Preview Assets.xcassets */; }; 4225D8E82336B5B100B8B625 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4225D8E72336B5B100B8B625 /* Preview Assets.xcassets */; };
4225D8F82336B8BF00B8B625 /* ComplicationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4225D8F72336B8BF00B8B625 /* ComplicationController.swift */; };
4225D8FA2336B92C00B8B625 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4225D8F92336B92C00B8B625 /* Switch.swift */; };
4225D8FC2336C68400B8B625 /* SwitchURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4225D8FB2336C68400B8B625 /* SwitchURL.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -73,6 +76,9 @@
4225D8E42336B5B100B8B625 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 4225D8E42336B5B100B8B625 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4225D8E72336B5B100B8B625 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; }; 4225D8E72336B5B100B8B625 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
4225D8E92336B5B100B8B625 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 4225D8E92336B5B100B8B625 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4225D8F72336B8BF00B8B625 /* ComplicationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComplicationController.swift; sourceTree = "<group>"; };
4225D8F92336B92C00B8B625 /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = "<group>"; };
4225D8FB2336C68400B8B625 /* SwitchURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchURL.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -118,7 +124,10 @@
4225D8DD2336B5B000B8B625 /* Switch WatchKit Extension */ = { 4225D8DD2336B5B000B8B625 /* Switch WatchKit Extension */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4225D8F72336B8BF00B8B625 /* ComplicationController.swift */,
4225D8FB2336C68400B8B625 /* SwitchURL.swift */,
4225D8DE2336B5B000B8B625 /* ContentView.swift */, 4225D8DE2336B5B000B8B625 /* ContentView.swift */,
4225D8F92336B92C00B8B625 /* Switch.swift */,
4225D8E02336B5B000B8B625 /* HostingController.swift */, 4225D8E02336B5B000B8B625 /* HostingController.swift */,
4225D8E22336B5B000B8B625 /* ExtensionDelegate.swift */, 4225D8E22336B5B000B8B625 /* ExtensionDelegate.swift */,
4225D8E42336B5B100B8B625 /* Assets.xcassets */, 4225D8E42336B5B100B8B625 /* Assets.xcassets */,
@ -265,8 +274,11 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
4225D8E12336B5B000B8B625 /* HostingController.swift in Sources */, 4225D8E12336B5B000B8B625 /* HostingController.swift in Sources */,
4225D8F82336B8BF00B8B625 /* ComplicationController.swift in Sources */,
4225D8DF2336B5B000B8B625 /* ContentView.swift in Sources */, 4225D8DF2336B5B000B8B625 /* ContentView.swift in Sources */,
4225D8E32336B5B000B8B625 /* ExtensionDelegate.swift in Sources */, 4225D8E32336B5B000B8B625 /* ExtensionDelegate.swift in Sources */,
4225D8FA2336B92C00B8B625 /* Switch.swift in Sources */,
4225D8FC2336C68400B8B625 /* SwitchURL.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };