mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-29 13:03:11 +00:00
Add an Apple Watch app that can control the glasses
This commit is contained in:
1 parent
c896ce9ac8
commit
2696f3b76c
46 files changed
+3877
-88
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import Foundation
|
||||
|
||||
/** What we know about the phone and the Faceclaw app on it. */
|
||||
struct LinkStatus: Equatable {
|
||||
/** The WatchConnectivity session is up; until then nothing below is known. */
|
||||
var activated = false
|
||||
/** The iPhone can be messaged right now. */
|
||||
var phoneReachable = false
|
||||
/** That iPhone has Faceclaw installed. */
|
||||
var phoneAppInstalled = false
|
||||
/**
|
||||
Whether the phone app's dashboard (the JS side) answered our last message;
|
||||
nil until we have heard anything. False means Faceclaw is installed but its
|
||||
dashboard isn't running, so the user has to open it.
|
||||
*/
|
||||
var appRunning: Bool?
|
||||
}
|
||||
|
||||
enum StatusTone { case good, busy, off, problem }
|
||||
|
||||
/**
|
||||
The pad's indicator line, with a tone that picks its colour, and an optional
|
||||
smaller line under it (the charging case's level while charging).
|
||||
*/
|
||||
struct StatusLine: Equatable {
|
||||
var text: String
|
||||
var tone: StatusTone
|
||||
var detail: String?
|
||||
}
|
||||
|
||||
/**
|
||||
The pad's indicator: what the next gesture lands on when everything is
|
||||
connected (the foreground app, or the screen/lock state in the way of it),
|
||||
otherwise the connection problem to fix first.
|
||||
*/
|
||||
func padLine(state: PhoneState?, link: LinkStatus) -> StatusLine {
|
||||
guard link.activated else { return StatusLine(text: "Waiting for phone", tone: .busy) }
|
||||
guard link.phoneAppInstalled else { return StatusLine(text: "Install Faceclaw on phone", tone: .problem) }
|
||||
guard link.phoneReachable else { return StatusLine(text: "No phone", tone: .problem) }
|
||||
if link.appRunning == false { return StatusLine(text: "Open Faceclaw on phone", tone: .problem) }
|
||||
guard let state else { return StatusLine(text: "Waiting for phone", tone: .busy) }
|
||||
if !state.remoteEnabled { return StatusLine(text: "Watch control off", tone: .problem) }
|
||||
if state.connected {
|
||||
if state.charging || state.phase == "charging" {
|
||||
return StatusLine(text: chargingLine(state.battery), tone: .busy, detail: caseLine(state))
|
||||
}
|
||||
if state.silentMode { return StatusLine(text: "Silent mode", tone: .off) }
|
||||
if state.locked { return StatusLine(text: "Locked", tone: .off) }
|
||||
if !state.screenOn { return StatusLine(text: "●● Wake", tone: .off) }
|
||||
if state.listening { return StatusLine(text: "Listening…", tone: .busy) }
|
||||
return StatusLine(text: state.foreground?.title ?? "Launcher", tone: .good)
|
||||
}
|
||||
switch state.phase {
|
||||
case "connecting": return StatusLine(text: "Connecting…", tone: .busy)
|
||||
case "retrying": return StatusLine(text: "Reconnecting…", tone: .busy)
|
||||
case "disconnecting": return StatusLine(text: "Disconnecting…", tone: .busy)
|
||||
default: break
|
||||
}
|
||||
if state.preview {
|
||||
if state.locked { return StatusLine(text: "Locked", tone: .off) }
|
||||
if !state.screenOn { return StatusLine(text: "●● Wake", tone: .off) }
|
||||
return StatusLine(text: state.foreground?.title ?? "Launcher", tone: .good, detail: "Phone preview")
|
||||
}
|
||||
return StatusLine(text: "Disconnected", tone: .off)
|
||||
}
|
||||
|
||||
private func chargingLine(_ battery: Int?) -> String {
|
||||
battery.map { "Charging · G2 \($0)%" } ?? "Charging"
|
||||
}
|
||||
|
||||
/**
|
||||
"Case 64%", with ⚡ while the case is on USB; nil when the level is unknown. The
|
||||
case only reports while the glasses are docked, so this is only drawn while they charge.
|
||||
*/
|
||||
private func caseLine(_ state: PhoneState) -> String? {
|
||||
state.caseBattery.map { "Case \($0)%" + (state.caseCharging == true ? " ⚡" : "") }
|
||||
}
|
||||
Reference in new issue
Block a user