diff --git a/openpilot/starpilot/galaxy/projection_layout.py b/openpilot/starpilot/galaxy/projection_layout.py index 2b928b694e..79315b3d36 100644 --- a/openpilot/starpilot/galaxy/projection_layout.py +++ b/openpilot/starpilot/galaxy/projection_layout.py @@ -11,7 +11,7 @@ from openpilot.starpilot.system.starport.display_profile import ( SCREEN_PATH, MAX_BYTES as SCREEN_MAX_BYTES, record_screen, validate_screen, ) from openpilot.starpilot.system.starport.projection_layout import ( - DOCUMENT_KEY, JETLINK_WIDGET, MAX_BYTES, ProjectionLayoutSource, comma_display, decode_layout, default_layout, layout_metadata, validate_layout, + DOCUMENT_KEY, MAX_BYTES, ProjectionLayoutSource, comma_display, decode_layout, default_layout, layout_metadata, validate_layout, ) from openpilot.starpilot.ui.appearance_preferences import onroad_appearance from openpilot.starpilot.ui.onroad_customization import read_customization @@ -83,9 +83,6 @@ class ProjectionLayoutOwner: 'Saved projection layout is unavailable' if not readable else None) base = read_customization(self.params) metadata = layout_metadata(screen) if screen is not None else None - if metadata is not None: - mode = self.params.get('JetlinkMode') - metadata['widgets'][JETLINK_WIDGET]['available'] = type(mode) is int and mode in (1, 2) return {'version': 1, 'document': document, 'defaults': defaults, 'metadata': metadata, 'screen': screen, 'revision': _revision(screen_raw, raw), diff --git a/openpilot/starpilot/galaxy/test_projection_layout.py b/openpilot/starpilot/galaxy/test_projection_layout.py index b1b8bb247d..0e11d22a6b 100644 --- a/openpilot/starpilot/galaxy/test_projection_layout.py +++ b/openpilot/starpilot/galaxy/test_projection_layout.py @@ -61,19 +61,11 @@ class TestProjectionLayoutOwner(unittest.TestCase): self.assertIsNone(value['defaults']) self.assertIn('actual screen', value['reason']) - def test_jetlink_widget_available_when_selected_and_placement_retained_when_off(self): + def test_big_model_widget_available_without_jetlink_or_chestnut(self): self.screen() - self.assertFalse(self.owner.snapshot()['metadata']['widgets']['jetlink_status']['available']) - for mode in (1, 2): + for mode in (0, 1, 2): self.params.jetlink_mode = mode - self.assertTrue(self.owner.snapshot()['metadata']['widgets']['jetlink_status']['available']) - payload = self.payload() - payload['document']['widgets']['jetlink_status'].update(enabled=True, x=700, y=500) - self.owner.save(payload, session_valid=lambda: True) - self.params.jetlink_mode = 0 - snapshot = self.owner.snapshot() - self.assertFalse(snapshot['metadata']['widgets']['jetlink_status']['available']) - self.assertEqual(snapshot['document'], payload['document']) + self.assertNotIn('available', self.owner.snapshot()['metadata']['widgets']['jetlink_status']) def test_defaults_valid_false_then_exact_saved_document(self): self.screen() diff --git a/openpilot/starpilot/galaxy/tests/test_native_navigation_widgets.mjs b/openpilot/starpilot/galaxy/tests/test_native_navigation_widgets.mjs index 0df884dbc9..61b3dd3405 100644 --- a/openpilot/starpilot/galaxy/tests/test_native_navigation_widgets.mjs +++ b/openpilot/starpilot/galaxy/tests/test_native_navigation_widgets.mjs @@ -1,6 +1,7 @@ +import { compile } from "../web/vendor/vue/vue.esm-browser.js" import assert from "node:assert/strict" import { execFileSync } from "node:child_process" -import { OnroadLayoutPage, validSnapshot, validDocument, widgetSize, clampPlacement } from "../web/js/onroad-layout.js" +import { LayoutWidgetPreview, OnroadLayoutPage, validSnapshot, validDocument, widgetSize, clampPlacement } from "../web/js/onroad-layout.js" // Use the server's real registry so a UI gate cannot silently reject a newly exposed widget. const data = JSON.parse(execFileSync(process.env.PYTHON || "python3", ["-c", ` @@ -10,6 +11,21 @@ print(json.dumps(dict(document=default_document(), defaults=default_document(), revision="native", editable=True, valid=True, activeProfile="large", supportedProfiles=["large"]))) `], { encoding: "utf8" })) assert.equal(validSnapshot(data), true) +const signalEdges = JSON.parse(execFileSync(process.env.PYTHON || "python3", ["-c", ` +import json +from openpilot.starpilot.ui.onroad_customization import SIGNAL_SIZES, default_document, signal_size, validate_document, widget_bounds +documents = [] +for style in SIGNAL_SIZES: + document = default_document() + placed = document['layouts']['large']['network_signal'] + placed.update(size=style, scale=50, enabled=True, wifiName=True) + bounds = widget_bounds('large', 'network_signal') + width, height = signal_size(placed) + placed.update(x=bounds['x'] + bounds['width'] - width, y=bounds['y'] + bounds['height'] - height) + documents.append(validate_document(document)) +print(json.dumps(documents)) +`], { encoding: "utf8" })) +for (const document of signalEdges) assert.equal(validDocument(document, data.metadata), true) for (const version of [11, 12, 13, 14, 15]) { assert.equal(validSnapshot({ ...data, document: { ...data.document, version } }), true) assert.equal(validSnapshot({ ...data, defaults: { ...data.defaults, version } }), true) @@ -121,6 +137,42 @@ assert.equal(validDocument(beyondNewPromptWidth, data.metadata), false) Object.assign(vm.layout.speed_limit_actions, {x:600, y:500}) vm.setSpeedSources("speedSources", false) assert.deepEqual([vm.layout.speed_limit_actions.x, vm.layout.speed_limit_actions.y], [600, 500]) +const signal = vm.profile.widgets.network_signal, signalBounds = signal.bounds || vm.profile.bounds +assert.equal(signal.label, "Connections") +vm.layout.network_signal.enabled = true +vm.state.selected = "network_signal" +vm.setWidgetSize("horizontal") +assert.deepEqual(widgetSize(signal, vm.layout.network_signal), signal.sizes.horizontal) +assert.ok(vm.layout.network_signal.x + signal.sizes.horizontal[0] <= signalBounds.x + signalBounds.width) +assert.equal(validDocument(vm.state.draft, data.metadata), true) +vm.setWidgetSize("vertical") +assert.deepEqual(widgetSize(signal, vm.layout.network_signal), signal.sizes.vertical) +// Every style shrinks from full size down to 30%; growing back pulls it inside the screen. +assert.deepEqual(signal.scale, {min: 30, max: 100, default: 100}) +assert.equal(vm.layout.network_signal.scale, 100) +assert.equal(vm.layout.network_signal.bluetooth, true) +vm.setWidgetToggle("bluetooth", "Off") +assert.equal(vm.layout.network_signal.bluetooth, false) +vm.setWidgetToggle("bluetooth", "On") +assert.equal(vm.layout.network_signal.bluetooth, true) +for (const style of ["ring", "horizontal", "vertical"]) { + vm.setWidgetSize(style) + for (const scale of [30, 50, 100]) { + vm.scaleInput({ target: { value: String(scale) } }) + assert.deepEqual(widgetSize(signal, vm.layout.network_signal), signal.sizes[style].map(side => Math.round(side * scale / 100))) + assert.equal(validDocument(vm.state.draft, data.metadata), true) + } +} +vm.scaleInput({ target: { value: "30" } }) +vm.scaleInput({ target: { value: "25" } }) +assert.equal(vm.layout.network_signal.scale, 30) +vm.layout.network_signal.x = signalBounds.x + signalBounds.width - widgetSize(signal, vm.layout.network_signal)[0] +vm.scaleInput({ target: { value: "100" } }) +assert.ok(vm.layout.network_signal.x + signal.sizes.vertical[0] <= signalBounds.x + signalBounds.width) +assert.equal(validDocument(vm.state.draft, data.metadata), true) +const badScale = JSON.parse(JSON.stringify(vm.state.draft)) +badScale.layouts.large.network_signal.scale = 20 +assert.equal(validDocument(badScale, data.metadata), false) vm.state.profile = "compact" vm.add("stopped_timer") assert.equal(vm.layout.stopped_timer.enabled, true) @@ -137,3 +189,20 @@ assert.equal(compact.document.layouts.compact.nav_card.enabled, true) compact.document.layouts.compact.nav_card.enabled = false assert.equal(validDocument(compact.document, compact.metadata), true) assert.equal(compact.document.layouts.large.nav_card.enabled, true) + +// Exercise the rendered fallback, not just the stored toggle value. +const renderSignal = compile(LayoutWidgetPreview.template, { decodeEntities: value => value.replaceAll("&", "&") }) +function previewText(node) { + if (!node || typeof node !== "object") return "" + if (Array.isArray(node)) return node.map(previewText).join(" ") + return typeof node.children === "string" ? node.children : previewText(node.children) +} +for (const size of ["ring", "horizontal", "vertical"]) { + for (const bluetooth of [true, false]) { + const tree = renderSignal({ widget: { kind: "network_signal", size, width: 268, height: 196, bluetooth }, + palette: {}, profile: "large", scene: "engaged", native: false, art: null }, []) + const text = previewText(tree) + assert.equal(text.includes("iPhone 15"), bluetooth, `${size} Bluetooth preview follows the toggle`) + if (!bluetooth) assert(!text.includes("Connected") && !text.includes("AirPods")) + } +} diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js index 02ebbf60e2..19334766f4 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js @@ -42,7 +42,12 @@ export const withAlpha = (color, factor) => color.slice(0, 7) + Math.floor(parse // Steering wheels resize as a square ("size"); box widgets such as the Android Auto map take a width and height. export function widgetSize(widget, position) { if (widget.iconSize && position?.display === "icons") return [widget.iconSize, widget.iconSize] - if (widget.sizes && Array.isArray(widget.sizes[position?.size])) return [...widget.sizes[position.size]] + if (widget.sizes && Array.isArray(widget.sizes[position?.size])) { + // A widget with a size percentage (the signal widget) shrinks its chosen style. + const scale = widget.scale && Number.isInteger(position?.scale) ? position.scale / 100 : 1 + const [width, height] = widget.sizes[position.size] + return [width, height + (widget.wifiNameHeight && position.wifiName === true ? widget.wifiNameHeight : 0)].map(side => Math.round(side * scale)) + } if (widget.box) return [position?.width ?? widget.width, position?.height ?? widget.height] if (widget.resizable) return [position?.size ?? widget.width, position?.size ?? widget.height] return [widget.width, widget.height] @@ -109,8 +114,10 @@ export function overlapsReserved(profile, id, x, y, layout = null) { if ((id !== owner && id !== key) || !positions[key]?.enabled) return false const [width, height] = widgetSize(profile.widgets[key], positions[key]) const obstacle = profile.widgets[key].confirmationObstacle || { x: 0, y: 0, width, height } - return overlaps(panel, { x: (id === key ? x : positions[key].x) + obstacle.x, - y: (id === key ? y : positions[key].y) + obstacle.y, width: obstacle.width, height: obstacle.height }) + return overlaps(panel, { + x: (id === key ? x : positions[key].x) + obstacle.x, + y: (id === key ? y : positions[key].y) + obstacle.y, width: obstacle.width, height: obstacle.height + }) })) return true } if (widget.layer === "underlay") return false @@ -182,11 +189,14 @@ export function validDocument(document, metadata) { const widget = profile.widgets[id], limits = placementLimits(profile, id, layout) const resizable = widget.resizable, box = widget.box, opacity = widget.opacity return keysEqual(position, ["x", "y", "enabled", ...(resizable ? ["size"] : []), ...(box ? ["width", "height"] : []), - ...(opacity ? ["opacity"] : []), ...(widget.iconSize ? ["display"] : []), ...(widget.backgroundToggle ? ["background"] : []), ...(widget.collapseToggle ? ["collapse"] : []), ...(widget.sizes ? ["size"] : [])]) && + ...(opacity ? ["opacity"] : []), ...(widget.iconSize ? ["display"] : []), ...(widget.backgroundToggle ? ["background"] : []), ...(widget.collapseToggle ? ["collapse"] : []), ...(widget.bluetoothToggle ? ["bluetooth"] : []), ...(widget.wifiNameHeight ? ["wifiName"] : []), ...(widget.sizes ? ["size"] : []), ...(widget.scale ? ["scale"] : [])]) && (!widget.iconSize || ["words", "icons"].includes(position.display)) && (!widget.backgroundToggle || typeof position.background === "boolean") && (!widget.collapseToggle || typeof position.collapse === "boolean") && + (!widget.bluetoothToggle || typeof position.bluetooth === "boolean") && + (!widget.wifiNameHeight || typeof position.wifiName === "boolean") && (!widget.sizes || Object.hasOwn(widget.sizes, position.size)) && + (!widget.scale || (Number.isInteger(position.scale) && position.scale >= widget.scale.min && position.scale <= widget.scale.max)) && (!opacity || (Number.isInteger(position.opacity) && position.opacity >= opacity.min && position.opacity <= opacity.max)) && (!resizable || (Number.isInteger(position.size) && position.size >= resizable.min && position.size <= resizable.max)) && (!box || (Number.isInteger(position.width) && position.width >= box.minWidth && position.width <= box.maxWidth && @@ -265,14 +275,19 @@ export function validSnapshot(data) { widget.box.minHeight > widget.box.maxHeight || widget.box.maxWidth > area.width || widget.box.maxHeight > area.height)) return false if (widget.aspectRatio != null && (!projection || !widget.box || !["nav_card", "pip_camera"].includes(widget.kind) || !positive(widget.aspectRatio) || widget.aspectRatio !== widget.width / widget.height)) return false - if (widget.opacity && (!(["nav_map", "jetlink_status"].includes(widget.kind) || projection && ["nav_home", "nav_work", "bookmark", "car_exit", "cruise_limits", "now_playing"].includes(widget.kind)) || + if (widget.opacity && (!(["nav_map", "jetlink_status", "network_signal"].includes(widget.kind) || projection && ["nav_home", "nav_work", "bookmark", "car_exit", "cruise_limits", "now_playing"].includes(widget.kind)) || !object(widget.opacity) || ![widget.opacity.min, widget.opacity.max, widget.opacity.default].every(Number.isInteger) || widget.opacity.min < 0 || widget.opacity.max > 100 || widget.opacity.min > widget.opacity.default || widget.opacity.default > widget.opacity.max)) return false if (widget.collapseToggle != null && (!projection || widget.kind !== "now_playing" || widget.collapseToggle !== true)) return false - if (widget.sizes != null && (!projection || widget.kind !== "now_playing" || !object(widget.sizes) || + if (widget.bluetoothToggle != null && (widget.kind !== "network_signal" || widget.bluetoothToggle !== true)) return false + if (widget.wifiNameHeight != null && (widget.kind !== "network_signal" || !positive(widget.wifiNameHeight))) return false + if (widget.sizes != null && (!(projection && widget.kind === "now_playing" || widget.kind === "network_signal") || !object(widget.sizes) || !Object.values(widget.sizes).every(size => Array.isArray(size) && size.length === 2 && size.every(positive) && size[0] <= area.width && size[1] <= area.height))) return false + if (widget.scale != null && (widget.kind !== "network_signal" || !widget.sizes || !object(widget.scale) || + ![widget.scale.min, widget.scale.max, widget.scale.default].every(Number.isInteger) || widget.scale.min < 10 || + widget.scale.max > 100 || widget.scale.min > widget.scale.default || widget.scale.default > widget.scale.max)) return false if (widget.backgroundToggle != null && (!projection || !["nav_home", "nav_work", "bookmark", "car_exit"].includes(widget.kind) || widget.backgroundToggle !== true || !widget.opacity)) return false if (widget.resizable && (!["steering_wheel", "driver_monitor"].includes(widget.kind) || !Number.isInteger(widget.resizable.min) || diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js index 40d694559c..0004e39381 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js @@ -252,23 +252,32 @@ export const ONROAD_LAYOUT_TEMPLATE = ` -
- Size -
- + @click="setWidgetSize(size)">{{ size[0].toUpperCase() + size.slice(1) }}
+ + +

The default position follows the driver’s side. A moved position stays where you place it.

{{ selectedWidget.note }}

Use 24-hour time
diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout.js b/openpilot/starpilot/galaxy/web/js/onroad-layout.js index aec2c7210d..6897779f97 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout.js @@ -263,13 +263,102 @@ export const LayoutWidgetPreview = { + + + Home Wi-Fi + + + + + + + + + + + + + + + + + + + + + + + iPhone 15 + AirPods + + Wi-Fi + + + + + Home Wi-Fi + + + + + + + + + + + + + + + + + + + + + + + iPhone 15, AirPods + + + + + + Home Wi-Fi + + + + + + + + + + + + + + + + + + + + + + iPhone 15 + AirPods + + + - - Link up - Jetlink • iPhone - 24.6 - ms + + BIG • JETLINK + 24.6 + ms + Cinque v3