SHA256
Compare commits
2
Commits
30541ae4af
...
d138bd9464
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
d138bd9464 | ||
|
|
e14e3dfa21 |
@@ -49,11 +49,12 @@ case "${MODE}" in
|
||||
lvgl-russian-font-test) SKETCH_DIR="${ROOT_DIR}/test_sketches/lvgl_russian_font_test" ;;
|
||||
usb-contact-test) SKETCH_DIR="${ROOT_DIR}/test_sketches/usb_contact_sensor_test" ;;
|
||||
usb-contact-debug-test) SKETCH_DIR="${ROOT_DIR}/test_sketches/usb_contact_sensor_debug_test" ;;
|
||||
usb-contact-resistance-test) SKETCH_DIR="${ROOT_DIR}/test_sketches/usb_contact_resistance_test" ;;
|
||||
usb-contact-screen-start-stub) SKETCH_DIR="${ROOT_DIR}/test_sketches/usb_contact_screen_start_stub" ;;
|
||||
lvgl-nav-minimal-test) SKETCH_DIR="${ROOT_DIR}/shine_homeserver_main" ;;
|
||||
*)
|
||||
echo "Unknown mode: ${MODE}" >&2
|
||||
echo "Use one of: hello, widgets, audio, simple, argon2, homeserver-ui, shine-homeserver-main, shine-homeserver-ui-main, legacy-homeserver-ui, text-test, gfx-text-test, gfx-layout-test, lvgl-basic-test, lvgl-interaction-test, lvgl-touch-debug-test, lvgl-official-based-test, lvgl-subserver-touch-test, lvgl-russian-font-test, usb-contact-test, usb-contact-debug-test, usb-contact-screen-start-stub" >&2
|
||||
echo "Use one of: hello, widgets, audio, simple, argon2, homeserver-ui, shine-homeserver-main, shine-homeserver-ui-main, legacy-homeserver-ui, text-test, gfx-text-test, gfx-layout-test, lvgl-basic-test, lvgl-interaction-test, lvgl-touch-debug-test, lvgl-official-based-test, lvgl-subserver-touch-test, lvgl-russian-font-test, usb-contact-test, usb-contact-debug-test, usb-contact-resistance-test, usb-contact-screen-start-stub" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
- `lvgl_russian_font_test/` - тест кастомного кириллического `LVGL`-шрифта с русскими кнопками, длинными строками и рабочим touch
|
||||
- `usb_contact_sensor_test/` - тест переключения нативных USB D-/D+ (`GPIO19/20`) в режим простого замыкаемого контакта после нажатия Start; после перезагрузки снова обычный USB
|
||||
- `usb_contact_sensor_debug_test/` - debug-версия теста замыкания контакта: экранная кнопка проверяет touch, а переход в sensor mode выполняется физической кнопкой BOOT
|
||||
- `usb_contact_resistance_test/` - тест измерения сопротивления между USB D-/D+ через ADC на GPIO20; рассчитан на внешний известный резистор 10 kΩ с D+ на GND
|
||||
- `lvgl_nav_minimal_test/` - старое тестовое имя, этот скетч перенесён в `shine_homeserver_main/` и теперь является основным
|
||||
|
||||
## Запуск
|
||||
@@ -33,3 +34,4 @@
|
||||
- `./burn.sh lvgl-russian-font-test`
|
||||
- `./burn.sh usb-contact-test`
|
||||
- `./burn.sh usb-contact-debug-test`
|
||||
- `./burn.sh usb-contact-resistance-test`
|
||||
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <lvgl.h>
|
||||
#include <Arduino_GFX_Library.h>
|
||||
#include "pin_config.h"
|
||||
#include "TouchDrvCSTXXX.hpp"
|
||||
|
||||
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
|
||||
|
||||
// ESP32-S3 native USB data pins.
|
||||
static constexpr int kUsbDmPin = 19; // USB D-
|
||||
static constexpr int kUsbDpPin = 20; // USB D+, ADC input in resistance mode.
|
||||
static constexpr uint32_t kUiRefreshMs = 120;
|
||||
static constexpr uint32_t kAdcSamples = 32;
|
||||
|
||||
// For a stable ohm reading connect a known resistor from D+ / GPIO20 to GND.
|
||||
// The measured resistance must be connected between D- / GPIO19 and D+ / GPIO20.
|
||||
static constexpr float kKnownPulldownOhms = 10000.0f;
|
||||
static constexpr float kSourceMillivolts = 3300.0f;
|
||||
static constexpr float kOpenThresholdMillivolts = 25.0f;
|
||||
|
||||
static lv_disp_draw_buf_t gDrawBuf;
|
||||
static lv_color_t *gBuf1 = nullptr;
|
||||
static lv_color_t *gBuf2 = nullptr;
|
||||
static lv_obj_t *gModeLabel = nullptr;
|
||||
static lv_obj_t *gResistanceLabel = nullptr;
|
||||
static lv_obj_t *gRawLabel = nullptr;
|
||||
static lv_obj_t *gHintLabel = nullptr;
|
||||
static lv_obj_t *gActionButton = nullptr;
|
||||
static lv_obj_t *gActionButtonLabel = nullptr;
|
||||
|
||||
static TouchDrvCST92xx gTouch;
|
||||
static int16_t gTouchX[5];
|
||||
static int16_t gTouchY[5];
|
||||
|
||||
static bool gSensorMode = false;
|
||||
static uint32_t gLastUiRefreshMs = 0;
|
||||
|
||||
Arduino_DataBus *gBus = new Arduino_ESP32QSPI(
|
||||
LCD_CS, LCD_SCLK, LCD_SDIO0, LCD_SDIO1, LCD_SDIO2, LCD_SDIO3);
|
||||
Arduino_CO5300 *gfx = new Arduino_CO5300(
|
||||
gBus, LCD_RESET, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, 0, 0);
|
||||
|
||||
static void lvglFlushCb(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *colorP) {
|
||||
uint32_t w = area->x2 - area->x1 + 1;
|
||||
uint32_t h = area->y2 - area->y1 + 1;
|
||||
#if (LV_COLOR_16_SWAP != 0)
|
||||
gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&colorP->full, w, h);
|
||||
#else
|
||||
gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&colorP->full, w, h);
|
||||
#endif
|
||||
lv_disp_flush_ready(disp);
|
||||
}
|
||||
|
||||
static void lvglTick(void *arg) {
|
||||
LV_UNUSED(arg);
|
||||
lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
static void lvglTouchRead(lv_indev_drv_t *indevDrv, lv_indev_data_t *data) {
|
||||
LV_UNUSED(indevDrv);
|
||||
uint8_t touched = gTouch.getPoint(gTouchX, gTouchY, gTouch.getSupportTouchPoint());
|
||||
if (touched > 0) {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
data->point.x = gTouchX[0];
|
||||
data->point.y = gTouchY[0];
|
||||
return;
|
||||
}
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
static uint32_t readAverageRaw() {
|
||||
uint32_t sum = 0;
|
||||
for (uint32_t i = 0; i < kAdcSamples; i++) {
|
||||
sum += analogRead(kUsbDpPin);
|
||||
delayMicroseconds(250);
|
||||
}
|
||||
return sum / kAdcSamples;
|
||||
}
|
||||
|
||||
static uint32_t readAverageMillivolts() {
|
||||
uint32_t sum = 0;
|
||||
for (uint32_t i = 0; i < kAdcSamples; i++) {
|
||||
sum += analogReadMilliVolts(kUsbDpPin);
|
||||
delayMicroseconds(250);
|
||||
}
|
||||
return sum / kAdcSamples;
|
||||
}
|
||||
|
||||
static void setResistanceText(float ohms) {
|
||||
if (ohms >= 1000000.0f) {
|
||||
String text = String(ohms / 1000000.0f, 2) + " Mohm";
|
||||
lv_label_set_text(gResistanceLabel, text.c_str());
|
||||
} else if (ohms >= 1000.0f) {
|
||||
String text = String(ohms / 1000.0f, 2) + " kohm";
|
||||
lv_label_set_text(gResistanceLabel, text.c_str());
|
||||
} else {
|
||||
String text = String(ohms, 0) + " ohm";
|
||||
lv_label_set_text(gResistanceLabel, text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static void updateResistanceUi() {
|
||||
if (!gSensorMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
if (now - gLastUiRefreshMs < kUiRefreshMs) {
|
||||
return;
|
||||
}
|
||||
gLastUiRefreshMs = now;
|
||||
|
||||
uint32_t raw = readAverageRaw();
|
||||
uint32_t millivolts = readAverageMillivolts();
|
||||
|
||||
if (millivolts <= kOpenThresholdMillivolts) {
|
||||
lv_label_set_text(gResistanceLabel, "OPEN");
|
||||
lv_obj_set_style_text_color(gResistanceLabel, lv_color_hex(0xFFD166), 0);
|
||||
} else if (millivolts >= (uint32_t)(kSourceMillivolts - 80.0f)) {
|
||||
lv_label_set_text(gResistanceLabel, "SHORT / LOW");
|
||||
lv_obj_set_style_text_color(gResistanceLabel, lv_color_hex(0x7CFF8A), 0);
|
||||
} else {
|
||||
float rx = kKnownPulldownOhms * ((kSourceMillivolts / (float)millivolts) - 1.0f);
|
||||
lv_obj_set_style_text_color(gResistanceLabel, lv_color_hex(0x7CFF8A), 0);
|
||||
setResistanceText(rx);
|
||||
}
|
||||
|
||||
String rawText = "ADC raw: " + String(raw);
|
||||
rawText += "\nD+ voltage: " + String(millivolts) + " mV";
|
||||
rawText += "\nKnown pulldown: 10 kohm to GND";
|
||||
lv_label_set_text(gRawLabel, rawText.c_str());
|
||||
}
|
||||
|
||||
static void enterSensorMode() {
|
||||
Serial.flush();
|
||||
delay(30);
|
||||
|
||||
pinMode(kUsbDmPin, OUTPUT);
|
||||
digitalWrite(kUsbDmPin, HIGH);
|
||||
|
||||
pinMode(kUsbDpPin, INPUT);
|
||||
analogReadResolution(12);
|
||||
analogSetPinAttenuation(kUsbDpPin, ADC_11db);
|
||||
|
||||
gSensorMode = true;
|
||||
gLastUiRefreshMs = 0;
|
||||
|
||||
lv_label_set_text(gModeLabel, "Resistance mode");
|
||||
lv_label_set_text(gHintLabel, "D- is 3.3V source. D+ is ADC input.\nUse 10 kohm from D+ to GND for accurate readings.");
|
||||
lv_label_set_text(gActionButtonLabel, "Restart to USB");
|
||||
updateResistanceUi();
|
||||
}
|
||||
|
||||
static void actionButtonEventCb(lv_event_t *event) {
|
||||
if (lv_event_get_code(event) != LV_EVENT_CLICKED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gSensorMode) {
|
||||
enterSensorMode();
|
||||
return;
|
||||
}
|
||||
|
||||
lv_label_set_text(gModeLabel, "Restarting...");
|
||||
lv_label_set_text(gHintLabel, "USB mode will return after reboot.");
|
||||
lv_timer_handler();
|
||||
delay(150);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
static void createUi() {
|
||||
lv_obj_t *screen = lv_scr_act();
|
||||
lv_obj_set_style_bg_color(screen, lv_color_hex(0x0B1320), 0);
|
||||
lv_obj_set_style_bg_opa(screen, LV_OPA_COVER, 0);
|
||||
|
||||
lv_obj_t *title = lv_label_create(screen);
|
||||
lv_label_set_text(title, "USB RESISTANCE TEST");
|
||||
lv_obj_set_style_text_color(title, lv_color_hex(0xFFFFFF), 0);
|
||||
lv_obj_set_style_text_font(title, &lv_font_montserrat_22, 0);
|
||||
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 24);
|
||||
|
||||
gModeLabel = lv_label_create(screen);
|
||||
lv_label_set_text(gModeLabel, "USB mode");
|
||||
lv_obj_set_style_text_color(gModeLabel, lv_color_hex(0xB8C8DC), 0);
|
||||
lv_obj_set_style_text_font(gModeLabel, &lv_font_montserrat_18, 0);
|
||||
lv_obj_align(gModeLabel, LV_ALIGN_TOP_MID, 0, 68);
|
||||
|
||||
gResistanceLabel = lv_label_create(screen);
|
||||
lv_label_set_text(gResistanceLabel, "READY");
|
||||
lv_obj_set_style_text_color(gResistanceLabel, lv_color_hex(0x72D6FF), 0);
|
||||
lv_obj_set_style_text_font(gResistanceLabel, &lv_font_montserrat_40, 0);
|
||||
lv_obj_align(gResistanceLabel, LV_ALIGN_CENTER, 0, -72);
|
||||
|
||||
gRawLabel = lv_label_create(screen);
|
||||
lv_label_set_text(gRawLabel, "ADC raw: -\nD+ voltage: -\nKnown pulldown: 10 kohm to GND");
|
||||
lv_obj_set_width(gRawLabel, 420);
|
||||
lv_label_set_long_mode(gRawLabel, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_style_text_align(gRawLabel, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_color(gRawLabel, lv_color_hex(0xD5DCE5), 0);
|
||||
lv_obj_set_style_text_font(gRawLabel, &lv_font_montserrat_16, 0);
|
||||
lv_obj_align(gRawLabel, LV_ALIGN_CENTER, 0, -8);
|
||||
|
||||
gHintLabel = lv_label_create(screen);
|
||||
lv_label_set_text(gHintLabel, "USB is normal now.\nTap Start to measure resistance between D- and D+.");
|
||||
lv_obj_set_width(gHintLabel, 420);
|
||||
lv_label_set_long_mode(gHintLabel, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_style_text_align(gHintLabel, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_color(gHintLabel, lv_color_hex(0xAAB7C6), 0);
|
||||
lv_obj_set_style_text_font(gHintLabel, &lv_font_montserrat_14, 0);
|
||||
lv_obj_align(gHintLabel, LV_ALIGN_CENTER, 0, 72);
|
||||
|
||||
gActionButton = lv_btn_create(screen);
|
||||
lv_obj_set_size(gActionButton, 260, 72);
|
||||
lv_obj_align(gActionButton, LV_ALIGN_BOTTOM_MID, 0, -42);
|
||||
lv_obj_set_style_radius(gActionButton, 18, 0);
|
||||
lv_obj_set_style_bg_color(gActionButton, lv_color_hex(0x2A9D8F), 0);
|
||||
lv_obj_set_style_border_width(gActionButton, 0, 0);
|
||||
lv_obj_add_event_cb(gActionButton, actionButtonEventCb, LV_EVENT_CLICKED, nullptr);
|
||||
|
||||
gActionButtonLabel = lv_label_create(gActionButton);
|
||||
lv_label_set_text(gActionButtonLabel, "Start");
|
||||
lv_obj_set_style_text_color(gActionButtonLabel, lv_color_hex(0xFFFFFF), 0);
|
||||
lv_obj_set_style_text_font(gActionButtonLabel, &lv_font_montserrat_22, 0);
|
||||
lv_obj_center(gActionButtonLabel);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Wire.begin(IIC_SDA, IIC_SCL);
|
||||
|
||||
pinMode(TP_RST, OUTPUT);
|
||||
pinMode(TP_INT, INPUT);
|
||||
digitalWrite(TP_RST, LOW);
|
||||
delay(30);
|
||||
digitalWrite(TP_RST, HIGH);
|
||||
delay(50);
|
||||
delay(1000);
|
||||
|
||||
gTouch.setPins(TP_RST, TP_INT);
|
||||
bool touchOk = gTouch.begin(Wire, 0x5A, IIC_SDA, IIC_SCL);
|
||||
if (!touchOk) {
|
||||
Serial.println("Touch init failed");
|
||||
} else {
|
||||
gTouch.sleep();
|
||||
gTouch.reset();
|
||||
gTouch.setMaxCoordinates(480, 480);
|
||||
gTouch.setSwapXY(true);
|
||||
gTouch.setMirrorXY(true, false);
|
||||
}
|
||||
|
||||
gfx->begin();
|
||||
gBus->writeC8D8(0x36, 0xA0);
|
||||
gfx->setBrightness(220);
|
||||
gfx->fillScreen(0x0000);
|
||||
|
||||
lv_init();
|
||||
|
||||
uint32_t screenWidth = gfx->width();
|
||||
uint32_t screenHeight = gfx->height();
|
||||
gBuf1 = (lv_color_t *)heap_caps_malloc(screenWidth * screenHeight / 4 * sizeof(lv_color_t), MALLOC_CAP_DMA);
|
||||
gBuf2 = (lv_color_t *)heap_caps_malloc(screenWidth * screenHeight / 4 * sizeof(lv_color_t), MALLOC_CAP_DMA);
|
||||
lv_disp_draw_buf_init(&gDrawBuf, gBuf1, gBuf2, screenWidth * screenHeight / 4);
|
||||
|
||||
static lv_disp_drv_t dispDrv;
|
||||
lv_disp_drv_init(&dispDrv);
|
||||
dispDrv.hor_res = screenWidth;
|
||||
dispDrv.ver_res = screenHeight;
|
||||
dispDrv.flush_cb = lvglFlushCb;
|
||||
dispDrv.draw_buf = &gDrawBuf;
|
||||
lv_disp_drv_register(&dispDrv);
|
||||
|
||||
static lv_indev_drv_t indevDrv;
|
||||
lv_indev_drv_init(&indevDrv);
|
||||
indevDrv.type = LV_INDEV_TYPE_POINTER;
|
||||
indevDrv.read_cb = lvglTouchRead;
|
||||
lv_indev_drv_register(&indevDrv);
|
||||
|
||||
const esp_timer_create_args_t lvglTickTimerArgs = {
|
||||
.callback = &lvglTick,
|
||||
.name = "lvgl_tick"};
|
||||
esp_timer_handle_t lvglTickTimer = nullptr;
|
||||
esp_timer_create(&lvglTickTimerArgs, &lvglTickTimer);
|
||||
esp_timer_start_periodic(lvglTickTimer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000);
|
||||
|
||||
createUi();
|
||||
Serial.println("USB resistance test ready; native USB remains active until Start is tapped.");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
updateResistanceUi();
|
||||
lv_timer_handler();
|
||||
delay(5);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ Diagnostic sketches:
|
||||
|
||||
- `main-device/test_sketches/usb_contact_sensor_test/usb_contact_sensor_test.ino`
|
||||
- `main-device/test_sketches/usb_contact_sensor_debug_test/usb_contact_sensor_debug_test.ino`
|
||||
- `main-device/test_sketches/usb_contact_resistance_test/usb_contact_resistance_test.ino`
|
||||
- `main-device/test_sketches/usb_contact_screen_start_stub/usb_contact_screen_start_stub.ino`
|
||||
|
||||
## Purpose
|
||||
@@ -51,6 +52,33 @@ Sensor mode starts from the physical BOOT/user button on GPIO0, active LOW. The
|
||||
|
||||
While in sensor mode, pressing the BOOT/user button again restarts the device and returns normal USB mode on the next boot.
|
||||
|
||||
## Resistance version
|
||||
|
||||
The `usb_contact_resistance_test` sketch starts in normal USB mode and does not reconfigure GPIO19/20 until `Start` is tapped.
|
||||
|
||||
Initial screen:
|
||||
|
||||
- title: `USB RESISTANCE TEST`
|
||||
- mode: `USB mode`
|
||||
- state: `READY`
|
||||
- action button: `Start`
|
||||
|
||||
After `Start`:
|
||||
|
||||
- GPIO19 / USB `D-` is configured as `OUTPUT HIGH`
|
||||
- GPIO20 / USB `D+` is configured as ADC input
|
||||
- the measured resistance is connected between `D-` and `D+`
|
||||
- a known external 10 kΩ pulldown resistor must be connected from `D+` to `GND` for meaningful ohm calculation
|
||||
- UI shows calculated resistance, raw ADC value, and measured `D+` millivolts
|
||||
- very low ADC voltage is shown as `OPEN`
|
||||
- near-source voltage is shown as `SHORT / LOW`
|
||||
|
||||
The calculation assumes a divider where the unknown resistance is the high-side resistor from 3.3 V to ADC and the known 10 kΩ resistor is the low-side resistor from ADC to GND:
|
||||
|
||||
`Rx = 10000 * (3300 / Vadc - 1)`
|
||||
|
||||
This test is intended to check whether the USB contact pair can be reused as an ADC-measured resistance input, for example before wiring a 10 kΩ potentiometer. Native USB data is unavailable while resistance mode owns GPIO19/20. Pressing `Restart to USB` calls `ESP.restart()`; after reboot normal USB mode is restored.
|
||||
|
||||
## GFX breath monitor version
|
||||
|
||||
The `usb_contact_screen_start_stub` sketch is a breath monitor firmware based on the production `Arduino_GFX` display path instead of LVGL.
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
client.version=1.15.0
|
||||
client.version=1.15.2
|
||||
server.version=1.13.0
|
||||
|
||||
@@ -1395,6 +1395,14 @@ async function redirectToActiveKeyRotationIfNeeded() {
|
||||
function renderApp() {
|
||||
syncTrackedRouteHistory(window.location.pathname || '/');
|
||||
const route = getRoute();
|
||||
if (state.session.isAuthorized) {
|
||||
const returnPath = window.sessionStorage.getItem('shine-public-return-path');
|
||||
if (returnPath && returnPath.startsWith('/SHiNE/')) {
|
||||
window.sessionStorage.removeItem('shine-public-return-path');
|
||||
navigate(returnPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const pageId = route.pageId || (state.session.isAuthorized ? 'messages-list' : 'start-view');
|
||||
|
||||
if (!state.session.isAuthorized && !PRE_AUTH_PAGES.includes(pageId) && !GUEST_ALLOWED_PAGES.has(pageId)) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mountPublicChannelSidebar } from '../services/public-channel-sidebar.js';
|
||||
import { confirmDialog } from '../components/confirm-dialog.js';
|
||||
import { iconHtml } from '../components/ui-icon.js';
|
||||
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
|
||||
@@ -1617,7 +1618,7 @@ export function render({ navigate, route, chrome }) {
|
||||
try {
|
||||
let resolvedMessage = selector.message;
|
||||
if (selector.short?.ownerBlockchainName && selector.short?.channelName) {
|
||||
const ownFeed = await authService.listSubscriptionsFeed(state.session.login, 1000);
|
||||
const ownFeed = state.session.isAuthorized ? await authService.listSubscriptionsFeed(state.session.login, 1000) : {};
|
||||
if (disposed || seq !== refreshSeq) return;
|
||||
const allRows = [
|
||||
...(Array.isArray(ownFeed?.ownedChannels) ? ownFeed.ownedChannels : []),
|
||||
@@ -1666,6 +1667,17 @@ export function render({ navigate, route, chrome }) {
|
||||
// ignore owner feed lookup errors
|
||||
}
|
||||
}
|
||||
if (!channel && ownerLoginFromBch) {
|
||||
try {
|
||||
const publicChannels = await authService.listUserProfileChannels(ownerLoginFromBch, 'owned', 500, 0, true);
|
||||
const row = (Array.isArray(publicChannels?.channels) ? publicChannels.channels : []).find((item) =>
|
||||
String(item?.slug || '').trim().toLowerCase() === channelNameNormalized);
|
||||
if (row) channel = { channel: {
|
||||
ownerBlockchainName: row.ownerBlockchainName,
|
||||
channelRoot: { blockNumber: Number(row.rootBlockNumber), blockHash: normalizeRouteHash(row.rootBlockHashHex) },
|
||||
} };
|
||||
} catch { /* Public profile may be unavailable. */ }
|
||||
}
|
||||
const ownerBch = String(channel?.channel?.ownerBlockchainName || '').trim();
|
||||
const rootNo = Number(channel?.channel?.channelRoot?.blockNumber);
|
||||
const rootHash = normalizeRouteHash(channel?.channel?.channelRoot?.blockHash);
|
||||
@@ -1732,6 +1744,12 @@ export function render({ navigate, route, chrome }) {
|
||||
|
||||
clearContent();
|
||||
const channelOwner = extractLoginFromBlockchainName(selector?.channel?.ownerBlockchainName || focus?.channelInfo?.ownerBlockchainName || '');
|
||||
if (!state.session.isAuthorized) mountPublicChannelSidebar(screen, {
|
||||
owner: channelOwner,
|
||||
channel: resolvedChannelTitle,
|
||||
subscribers: payload?.channel?.subscribersCount ?? payload?.focus?.channelInfo?.subscribersCount ?? null,
|
||||
navigate,
|
||||
});
|
||||
const openPost = () => {
|
||||
const routeToChannel = buildChannelRouteFromThread(selector, resolvedChannelLabel);
|
||||
if (routeToChannel) navigate(routeToChannel);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mountPublicChannelSidebar } from '../services/public-channel-sidebar.js';
|
||||
import { confirmDialog } from '../components/confirm-dialog.js';
|
||||
import { iconHtml } from '../components/ui-icon.js';
|
||||
import { rememberChannelPosition, readChannelPosition, restoreChannelPosition } from '../services/channel-view-state.js';
|
||||
@@ -41,6 +42,7 @@ import {
|
||||
extractLoginFromBlockchainName,
|
||||
makeProfileRoute,
|
||||
makeShineMessageRoute,
|
||||
makeShineChannelStreamRoute,
|
||||
makeShineChannelAboutRoute,
|
||||
makeShineChannelDonateRoute,
|
||||
} from '../services/shine-routes.js';
|
||||
@@ -243,6 +245,8 @@ function buildThreadRoute(messageRef, selector) {
|
||||
ownerLogin,
|
||||
messageBlockchainName: messageRef.blockchainName,
|
||||
messageBlockNumber: messageRef.blockNumber,
|
||||
channelName: selector.channelName,
|
||||
channelOwnerBlockchainName: selector.ownerBlockchainName,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2136,6 +2140,14 @@ function renderPostCard(post, {
|
||||
|
||||
// Порядок как в макете V4: лайк → поделиться → обсуждение; дата и «⋯» — справа
|
||||
actions.append(likeButton, shareButton, discussionButton);
|
||||
if (post.messageRef?.blockNumber != null) {
|
||||
const streamRoute = makeShineChannelStreamRoute({
|
||||
ownerBlockchainName: selector?.ownerBlockchainName,
|
||||
channelName: selector?.channelName || '',
|
||||
messageBlockNumber: post.messageRef.blockNumber,
|
||||
});
|
||||
if (streamRoute) menuItems.unshift({ label: 'Ссылка на сообщение в ленте', iconHtml: iconHtml('share'), action: () => onShare(streamRoute) });
|
||||
}
|
||||
menuItems.unshift({ label: 'Ответить', iconHtml: iconHtml('reply'), action: () => replyButton.click() });
|
||||
if (post.msgSubType === MSG_SUBTYPE_TEXT_REPOST && post.targetRef?.blockchainName && Number.isFinite(post.targetRef?.blockNumber) && post.targetRef?.blockHash) {
|
||||
const originalBtn = document.createElement('button');
|
||||
@@ -2368,6 +2380,14 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
screen.append(feed);
|
||||
}
|
||||
|
||||
const requestedBlock = String(handlers.scrollToMessageBlockNumber || '').trim();
|
||||
if (/^[0-9]+$/.test(requestedBlock)) {
|
||||
const card = [...screen.querySelectorAll('.channel-message-card[data-message-key]')].find((el) => {
|
||||
const parts = String(el.dataset.messageKey || '').split(':');
|
||||
return parts.length >= 3 && parts[parts.length - 2] === requestedBlock;
|
||||
});
|
||||
if (card) pendingScrollByRoute.set(routeKey, card.dataset.messageKey);
|
||||
}
|
||||
const hasPendingScrollTarget = pendingScrollByRoute.has(routeKey);
|
||||
const restorePosition = handlers.restorePosition;
|
||||
const pendingScrollTimer = Number.isFinite(restorePosition) && !hasPendingScrollTarget ? 0 : applyPendingScroll(screen, routeKey, channelData.isOwnChannel || channelData.isDiary || unreadCount === 0);
|
||||
@@ -2442,12 +2462,14 @@ function renderSkeleton(screen) {
|
||||
|
||||
export function render({ navigate, route, chrome }) {
|
||||
const channelId = route.params.channelId || '';
|
||||
const scrollToMessageBlockNumber = route.params.scrollToMessageBlockNumber || '';
|
||||
const routeSelector = buildSelectorFromRoute(route, channelId);
|
||||
const routeKey = `${routeSelector?.ownerBlockchainName || ''}:${routeSelector?.channelRootBlockNumber || ''}:${routeSelector?.channelRootBlockHash || ''}`;
|
||||
|
||||
const screen = document.createElement('section');
|
||||
screen.className = 'stack channels-screen channels-screen--channel';
|
||||
const positionKey = `${state.session.login}:channel:${routeKey}`;
|
||||
// A deep link must take precedence over a saved scroll position.
|
||||
|
||||
let disposed = false;
|
||||
let refreshSeq = 0;
|
||||
@@ -2963,6 +2985,7 @@ export function render({ navigate, route, chrome }) {
|
||||
};
|
||||
}
|
||||
activeChannelData = apiData;
|
||||
|
||||
if (channelMoreButton) {
|
||||
channelMoreButton.disabled = false;
|
||||
}
|
||||
@@ -2982,6 +3005,7 @@ export function render({ navigate, route, chrome }) {
|
||||
cleanupSeenTracking = renderBody(screen, navigate, routeKey, apiData, {
|
||||
chrome,
|
||||
restorePosition,
|
||||
scrollToMessageBlockNumber,
|
||||
showStatus,
|
||||
isActive: () => !disposed,
|
||||
onAddMessage: activeAddMessage = async () => {
|
||||
@@ -3072,6 +3096,10 @@ export function render({ navigate, route, chrome }) {
|
||||
},
|
||||
onSubscribeChannel: (event) => subscribeToChannel(apiData, event),
|
||||
});
|
||||
if (!state.session.isAuthorized && !apiData?.isDiary) mountPublicChannelSidebar(screen, {
|
||||
owner: apiData?.channel?.ownerName || extractLoginFromBlockchainName(apiData?.selector?.ownerBlockchainName),
|
||||
channel: titleLabel, subscribers: apiData?.channel?.subscribersCount, navigate,
|
||||
});
|
||||
} catch (error) {
|
||||
if (disposed || seq !== refreshSeq) return;
|
||||
skeleton?.remove();
|
||||
|
||||
@@ -149,6 +149,11 @@ export function parseRouteFromPath(pathname = '') {
|
||||
if (segments.length >= baseOffset + 1) {
|
||||
const ownerBlockchainName = shineLogin;
|
||||
const channelName = decodePart(segments[baseOffset] || '');
|
||||
const streamMode = decodePart(segments[baseOffset + 1] || '').toLowerCase() === 's';
|
||||
const streamBlockNumber = streamMode ? decodePart(segments[baseOffset + 2] || '') : '';
|
||||
if (ownerBlockchainName && channelName && streamMode && /^[0-9]+$/.test(streamBlockNumber) && segments.length === baseOffset + 3) {
|
||||
return { pageId: 'channel-view', params: { ownerBlockchainName, channelName, channelId: '', scrollToMessageBlockNumber: streamBlockNumber } };
|
||||
}
|
||||
const messageBlockNumber = segments[baseOffset + 1] || '';
|
||||
if (ownerBlockchainName && channelName && messageBlockNumber) {
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { renderUserAvatar } from '../components/avatar-image.js';
|
||||
// Minimal public preview sidebar, shown only to visitors without a session.
|
||||
export function mountPublicChannelSidebar(screen, { owner = '', channel = '', subscribers = null, avatar = null, navigate }) {
|
||||
screen.querySelector('.shine-public-sidebar')?.remove();
|
||||
const panel = document.createElement('aside');
|
||||
panel.className = 'shine-public-sidebar';
|
||||
const identity = document.createElement('div');
|
||||
identity.className = 'shine-public-sidebar__identity';
|
||||
const face = document.createElement('span');
|
||||
face.className = 'shine-public-sidebar__face';
|
||||
face.replaceChildren(renderUserAvatar({ login: owner || 'unknown', size: 'sm' }));
|
||||
const details = document.createElement('div');
|
||||
const author = document.createElement('strong');
|
||||
author.textContent = owner || 'Автор';
|
||||
details.append(author);
|
||||
identity.append(face, details);
|
||||
const name = document.createElement('h2');
|
||||
name.textContent = channel || 'Канал';
|
||||
const count = document.createElement('p');
|
||||
count.textContent = subscribers == null ? '' : `${Math.max(0, Number(subscribers) || 0)} подписчиков`;
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'primary-btn';
|
||||
button.textContent = 'Открыть в SHiNE';
|
||||
button.addEventListener('click', () => {
|
||||
window.sessionStorage.setItem('shine-public-return-path', window.location.pathname);
|
||||
navigate('login-view');
|
||||
});
|
||||
panel.append(identity, name, count, button);
|
||||
screen.append(panel);
|
||||
}
|
||||
@@ -73,13 +73,23 @@ export function makeShineChannelShortRoute({ ownerLogin = '', ownerBlockchainNam
|
||||
const cleanOwnerLogin = normalizeLogin(ownerLogin) || extractLoginFromBlockchainName(ownerBlockchainName);
|
||||
const chName = String(channelName || '').trim();
|
||||
if (!cleanOwnerLogin || !chName) return '';
|
||||
return `${encodeRoutePart(cleanOwnerLogin)}/${encodeRoutePart(chName)}`;
|
||||
return `${SHINE_ROUTE_SEGMENT}/${encodeRoutePart(cleanOwnerLogin)}/${encodeRoutePart(chName)}`;
|
||||
}
|
||||
|
||||
export function makeShineMessageRoute({ ownerLogin = '', messageBlockchainName = '', messageBlockNumber = '' }) {
|
||||
export function makeShineChannelStreamRoute({ ownerLogin = '', ownerBlockchainName = '', channelName = '', messageBlockNumber = '' }) {
|
||||
const base = makeShineChannelShortRoute({ ownerLogin, ownerBlockchainName, channelName });
|
||||
const no = String(messageBlockNumber || '').trim();
|
||||
return base && /^[0-9]+$/.test(no) ? `${base}/s/${no}` : '';
|
||||
}
|
||||
|
||||
export function makeShineMessageRoute({ ownerLogin = '', messageBlockchainName = '', messageBlockNumber = '', channelName = '', channelOwnerBlockchainName = '' }) {
|
||||
const msgBch = String(messageBlockchainName || '').trim();
|
||||
const msgNo = String(messageBlockNumber || '').trim();
|
||||
if (!msgBch || !msgNo) return '';
|
||||
if (channelName) {
|
||||
const base = makeShineChannelShortRoute({ ownerLogin, ownerBlockchainName: channelOwnerBlockchainName || msgBch, channelName });
|
||||
if (base) return `${base}/${encodeRoutePart(msgNo)}`;
|
||||
}
|
||||
return `${SHINE_ROUTE_SEGMENT}/${encodeRoutePart(msgBch)}/${encodeRoutePart(msgNo)}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -418,3 +418,13 @@
|
||||
}
|
||||
}
|
||||
.channel-about-tiles:empty { display: none; }
|
||||
|
||||
/* Guest-only public preview, inspired by compact channel web viewers. */
|
||||
.shine-public-sidebar { position:fixed; right:24px; top:110px; width:260px; box-sizing:border-box; padding:22px; border:1px solid var(--border-color, #ddd); border-radius:16px; background:var(--surface, #fff); z-index:5; display:flex; flex-direction:column; gap:14px; box-shadow:0 8px 30px #0000000c; }
|
||||
.shine-public-sidebar__identity { display:flex; align-items:center; gap:12px; overflow-wrap:anywhere; }
|
||||
.shine-public-sidebar__face { display:grid; place-items:center; width:44px; height:44px; border-radius:50%; background:#ececf3; color:#34343e; flex-shrink:0; font-weight:700; }
|
||||
.shine-public-sidebar h2 { margin:0; font-size:19px; overflow-wrap:anywhere; }
|
||||
.shine-public-sidebar p { margin:0; }
|
||||
.shine-public-sidebar .primary-btn { width:100%; }
|
||||
@media (min-width:1050px) { .channels-screen--channel:has(.shine-public-sidebar) .channel-feed, .channels-screen--thread:has(.shine-public-sidebar) .thread-block { max-width:calc(100% - 310px); } }
|
||||
@media (max-width:1049px) { .shine-public-sidebar { position:relative; inset:auto; order:-1; width:100%; margin-bottom:14px; } }
|
||||
|
||||
Reference in New Issue
Block a user