Your home as a live 3D model in the Mac menu bar and on iPhone — lights and ACs via Smart Life, Home Assistant, Philips Hue and Apple Home.
Keep views in step from the first frame; small sync and island fixes
0xProbability40d041fd5a23
diff --git a/core/Sources/HouseCore/SyncServer.swift b/core/Sources/HouseCore/SyncServer.swiftindex 6216d27..f1fcae0 100644--- a/core/Sources/HouseCore/SyncServer.swift+++ b/core/Sources/HouseCore/SyncServer.swift@@ -46,11 +46,17 @@ public final class SyncServer {/// Makes sure this Mac can be paired with and returns what the phone has to scan.@discardableResultpublic func enable(name: String) -> SyncPairing {- if let pairing {+ guard var current = pairing else { return reset(name: name) }+ if current.name != name {+ // The Mac was renamed: same key, new name on the network and in the code.+ current.name = name+ pairing = current+ store.write(try? JSONEncoder().encode(current))+ restart()+ } else {start()- return pairing}- return reset(name: name)+ return current}/// New key: every phone paired so far has to be paired again.diff --git a/core/Tests/HouseCoreTests/SyncTests.swift b/core/Tests/HouseCoreTests/SyncTests.swiftindex ef24b76..dc6b2d1 100644--- a/core/Tests/HouseCoreTests/SyncTests.swift+++ b/core/Tests/HouseCoreTests/SyncTests.swift@@ -136,6 +136,17 @@ final class SyncTests: XCTestCase {XCTAssertTrue(server.connectedDevices.isEmpty)}+ func testRenamingTheMacKeepsTheKey() {+ let server = SyncServer(store: MemorySecretStore())+ let first = server.reset(name: "Old name")+ server.stop()+ let renamed = server.enable(name: "New name")+ server.stop()+ XCTAssertEqual(renamed.name, "New name")+ XCTAssertEqual(renamed.key, first.key)+ XCTAssertEqual(renamed.id, first.id)+ }+func testPairingSurvivesARestart() {let store = MemorySecretStore()let pairing = SyncServer(store: store).reset(name: "Mac")diff --git a/ios/Config/Base.xcconfig b/ios/Config/Base.xcconfigindex b1ab8a9..5c941b2 100644--- a/ios/Config/Base.xcconfig+++ b/ios/Config/Base.xcconfig@@ -1,6 +1,6 @@// Version of the iPhone app. CURRENT_PROJECT_VERSION is the build number TestFlight sees.MARKETING_VERSION = 0.1.0-CURRENT_PROJECT_VERSION = 1+CURRENT_PROJECT_VERSION = 2CODE_SIGN_STYLE = Automaticdiff --git a/ios/Sources/PairingView.swift b/ios/Sources/PairingView.swiftindex 213899a..95b7d0c 100644--- a/ios/Sources/PairingView.swift+++ b/ios/Sources/PairingView.swift@@ -18,7 +18,7 @@ struct PairingView: View {ScrollView {VStack(spacing: 22) {if let paired {- success(paired)+ success(model.macName ?? paired)} else {stepsviewfinderdiff --git a/macos/Sources/HouseControl/AppDelegate.swift b/macos/Sources/HouseControl/AppDelegate.swiftindex efd900a..724d2d3 100644--- a/macos/Sources/HouseControl/AppDelegate.swift+++ b/macos/Sources/HouseControl/AppDelegate.swift@@ -196,6 +196,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {private func handle(_ message: [String: Any], from host: WebHost) {switch message["type"] as? String {case "ready", "summary":+ // A view that has just loaded takes over what the panel shows.+ if message["type"] as? String == "ready", host !== panel.host { panel.host.call("share") }if let summary = (message["summary"] as? [String: Any]) ?? (message["lightsOn"] != nil ? message : nil) {updateStatus(summary)}@@ -352,7 +354,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {// MARK: - iPhone sync- private var computerName: String { Host.current().localizedName ?? "Mac" }+ /// The name paired iPhones see (HOUSE_COMPUTER_NAME replaces it for screenshots).+ private var computerName: String {+ ProcessInfo.processInfo.environment["HOUSE_COMPUTER_NAME"] ?? Host.current().localizedName ?? "Mac"+ }private func startSync() {sync.snapshot = { [unowned self] indiff --git a/macos/Sources/HouseControl/IslandController.swift b/macos/Sources/HouseControl/IslandController.swiftindex 62941fc..c9a302b 100644--- a/macos/Sources/HouseControl/IslandController.swift+++ b/macos/Sources/HouseControl/IslandController.swift@@ -15,7 +15,7 @@ final class IslandController: NSObject {// Must match island.css: the open island below the notch, and room for its shadow.private static let open = NSSize(width: 664, height: 292)private static let canvas = NSSize(width: 820, height: 470)- private static let ear: CGFloat = 60+ private static let ear: CGFloat = 64let host: WebHostprivate let window: IslandPaneldiff --git a/web/src/island/island.css b/web/src/island/island.cssindex edc3035..d223a9f 100644--- a/web/src/island/island.css+++ b/web/src/island/island.css@@ -7,7 +7,7 @@ html.mode-island #app { display: block; padding: 0; height: 100%; }.isle {--notch-w: 190px;--notch-h: 34px;- --ear: 50px;+ --ear: 64px;--mood: #17274f;--w: calc(var(--notch-w) + var(--ear) * 2);--h: var(--notch-h);diff --git a/web/src/main.js b/web/src/main.jsindex 97ad15f..46a3a1c 100644--- a/web/src/main.js+++ b/web/src/main.js@@ -16,9 +16,15 @@ const app = document.getElementById('app');if (isNative) document.documentElement.classList.add('native');if (isPhone) document.documentElement.classList.add('ios');+// ?safeTop=62&safeBottom=34 stands in for a phone's safe areas when its layout is looked at in a browser.+for (const edge of ['top', 'bottom']) {+ const px = Number(new URLSearchParams(location.search).get(edge === 'top' ? 'safeTop' : 'safeBottom'));+ if (isPhone && px) document.documentElement.style.setProperty(`--safe-${edge}-preview`, `${px}px`);+}+// Height of the status bar / Dynamic Island on a phone; 0 everywhere else.function safeAreaTop() {- const probe = document.body.appendChild(h('div', { style: { position: 'fixed', paddingTop: 'env(safe-area-inset-top, 0px)' } }));+ const probe = document.body.appendChild(h('div', { style: { position: 'fixed', paddingTop: 'var(--safe-top-preview, env(safe-area-inset-top, 0px))' } }));const top = parseFloat(getComputedStyle(probe).paddingTop) || 0;probe.remove();return top;@@ -100,6 +106,7 @@ async function boot() {}incoming.applyRemote = (update) => store.applyRemote(update);incoming.adopt = (state) => store.adopt(state);+ incoming.share = () => store.share();store.onDeviceError = (id, message) => {const name = store.lightCfg.get(id)?.name || store.acCfg.get(id)?.name || id;panel.toast(`${name}: ${message}`);diff --git a/web/src/store.js b/web/src/store.jsindex 831a373..1c1a70c 100644--- a/web/src/store.js+++ b/web/src/store.js@@ -215,6 +215,9 @@ export function createStore(config) {emit({ type: 'bulk', scene: sceneId });},+ /** Reports the state again, for a view that has only just started. */+ share() { post('state', { lights: state.lights, acs: state.acs, scene: state.scene }); },+// The state of another view of this home (see emit). Nothing goes to the devices:// the view where the change was made has already sent it.adopt(other) {diff --git a/web/src/style.css b/web/src/style.cssindex ee63486..5f3dd69 100644--- a/web/src/style.css+++ b/web/src/style.css@@ -669,8 +669,8 @@ html.ios * { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: nohtml.ios #app { padding: 0; place-items: stretch; }html.ios .card {--stage-h: min(470px, 52%);- --safe-top: env(safe-area-inset-top, 0px);- --safe-bottom: env(safe-area-inset-bottom, 0px);+ --safe-top: var(--safe-top-preview, env(safe-area-inset-top, 0px));+ --safe-bottom: var(--safe-bottom-preview, env(safe-area-inset-bottom, 0px));width: auto;height: auto;border-radius: 0;