Add Store support and unsigned app releases
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sf-launcher"
|
||||
description = "SmartFox TV launcher: Slint UI on top of a Liquid Glass OpenGL layer"
|
||||
description = "Fennec OS TV launcher: Slint UI on top of a Liquid Glass OpenGL layer"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
# Slint is used under GPL-3.0 (or its royalty-free license on desktop).
|
||||
@@ -8,11 +8,14 @@ license = "GPL-3.0-only"
|
||||
|
||||
[dependencies]
|
||||
sf-ipc.workspace = true
|
||||
sf-ui = { path = "../sf-ui", default-features = false }
|
||||
anyhow.workspace = true
|
||||
log.workspace = true
|
||||
env_logger.workspace = true
|
||||
serde_json.workspace = true
|
||||
slint = { version = "1.18", default-features = false, features = ["std", "backend-default", "renderer-femtovg", "compat-1-2"] }
|
||||
serde.workspace = true
|
||||
ureq = "3"
|
||||
slint = { version = "1.18", default-features = false, features = ["std", "backend-default", "renderer-femtovg", "compat-1-2", "image-default-formats"] }
|
||||
glow = "0.16"
|
||||
png = "0.18"
|
||||
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
fn main() {
|
||||
slint_build::compile("ui/app.slint").expect("compiling ui/app.slint");
|
||||
// The Onest font comes from sf-ui's Slint library ("@sf-ui/fonts/...").
|
||||
let sf_ui = std::env::var("DEP_SF_UI_UI_DIR").expect("sf-ui must be a direct dependency");
|
||||
let config = slint_build::CompilerConfiguration::new()
|
||||
.with_library_paths(std::collections::HashMap::from([("sf-ui".to_string(), sf_ui.into())]));
|
||||
slint_build::compile_with_config("ui/app.slint", config).expect("compiling ui/app.slint");
|
||||
}
|
||||
|
||||
65
crates/sf-launcher/src/core_client.rs
Normal file
65
crates/sf-launcher/src/core_client.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
#![cfg_attr(not(unix), allow(dead_code))]
|
||||
//! Connection to sf-core. On the TV sf-core starts, freezes and closes apps;
|
||||
//! without it (desktop testing) the launcher starts apps itself.
|
||||
|
||||
use sf_ipc::{CoreEvent, LauncherRequest};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CoreClient {
|
||||
#[cfg(unix)]
|
||||
stream: std::sync::Arc<std::sync::Mutex<std::os::unix::net::UnixStream>>,
|
||||
}
|
||||
|
||||
impl CoreClient {
|
||||
/// Connects if sf-core is running. `on_event` runs on the Slint event loop.
|
||||
#[cfg(unix)]
|
||||
pub fn connect(on_event: impl Fn(CoreEvent) + Send + Sync + Clone + 'static) -> Option<Self> {
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
let path = sf_ipc::paths::core_socket();
|
||||
// sf-core may start a moment after the launcher.
|
||||
let stream = (0..20).find_map(|i| {
|
||||
if i > 0 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
}
|
||||
UnixStream::connect(&path).ok()
|
||||
});
|
||||
let Some(stream) = stream else {
|
||||
log::info!("no sf-core at {}, starting apps locally", path.display());
|
||||
return None;
|
||||
};
|
||||
log::info!("connected to sf-core");
|
||||
let reader = stream.try_clone().ok()?;
|
||||
std::thread::spawn(move || {
|
||||
for line in BufReader::new(reader).lines().map_while(Result::ok) {
|
||||
match serde_json::from_str::<CoreEvent>(&line) {
|
||||
Ok(ev) => {
|
||||
let f = on_event.clone();
|
||||
let _ = slint::invoke_from_event_loop(move || f(ev));
|
||||
}
|
||||
Err(e) => log::warn!("sf-core: bad event {line:?}: {e}"),
|
||||
}
|
||||
}
|
||||
log::warn!("sf-core connection closed");
|
||||
});
|
||||
Some(CoreClient { stream: std::sync::Arc::new(std::sync::Mutex::new(stream)) })
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
pub fn connect(_on_event: impl Fn(CoreEvent) + Send + Sync + Clone + 'static) -> Option<Self> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn send(&self, req: LauncherRequest) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::io::Write;
|
||||
if let Err(e) = self.stream.lock().unwrap().write_all(req.to_line().as_bytes()) {
|
||||
log::error!("sf-core: {e}");
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = req;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ use slint::ComponentHandle;
|
||||
use slint::platform::{Key, WindowEvent};
|
||||
|
||||
use crate::App;
|
||||
use crate::glass::GlassRenderer;
|
||||
use sf_ui::render::GlassRenderer;
|
||||
|
||||
pub struct Snapshot {
|
||||
path: Option<PathBuf>,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//! "Liquid Glass" layer: an OpenGL pass under the Slint UI that draws the
|
||||
//! animated backdrop and the frosted, refracting glass panels.
|
||||
|
||||
mod renderer;
|
||||
mod shaders;
|
||||
|
||||
pub use renderer::GlassRenderer;
|
||||
|
||||
/// Panels drawn per frame at most (each one is its own small draw call).
|
||||
pub const MAX_RECTS: usize = 48;
|
||||
/// Members of one merged (liquid) group at most.
|
||||
pub const MAX_GROUP: usize = 4;
|
||||
|
||||
/// One glass panel in physical pixels (top-left origin).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Panel {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub w: f32,
|
||||
pub h: f32,
|
||||
pub radius: f32,
|
||||
/// 0..1, brightens the rim and adds the accent glow.
|
||||
pub focus: f32,
|
||||
pub alpha: f32,
|
||||
/// Mip level used for the frost (higher = blurrier). Negative = nested glass.
|
||||
pub blur: f32,
|
||||
pub glow: [f32; 3],
|
||||
/// Consecutive panels with the same group (> 0) melt into one shape.
|
||||
pub group: f32,
|
||||
/// rgb + amount.
|
||||
pub tint: [f32; 4],
|
||||
}
|
||||
|
||||
/// Everything the renderer needs for one frame.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Frame {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub scale: f32,
|
||||
pub time: f32,
|
||||
/// Backdrop palette (highlight, mid, deep), already crossfaded.
|
||||
pub palette: [f32; 9],
|
||||
/// 1 = top shelf visible (bright backdrop), 0 = scrolled down into the grid.
|
||||
pub shelf: f32,
|
||||
pub light: [f32; 2],
|
||||
/// Backdrop zoom (1 = none), used for the launch fly-in.
|
||||
pub zoom: f32,
|
||||
pub rects: Vec<Panel>,
|
||||
}
|
||||
@@ -1,425 +0,0 @@
|
||||
//! OpenGL underlay drawn before Slint renders its items.
|
||||
//!
|
||||
//! Pass 1 renders the backdrop (a smooth gradient) into a small, mipmapped
|
||||
//! texture. Pass 2 upscales it to the window. Pass 3 draws every glass panel
|
||||
//! as its own quad, covering only the panel and its shadow, blended onto the
|
||||
//! window. Uniform locations are looked up once.
|
||||
|
||||
use glow::HasContext;
|
||||
|
||||
use super::shaders;
|
||||
use super::{Frame, MAX_GROUP, MAX_RECTS, Panel};
|
||||
|
||||
/// The backdrop is blurry by design, so it never needs more than this width.
|
||||
const SCENE_MAX_W: i32 = 640;
|
||||
|
||||
type Loc = Option<glow::UniformLocation>;
|
||||
|
||||
struct SceneLocs {
|
||||
res: Loc,
|
||||
time: Loc,
|
||||
pal: Loc,
|
||||
zoom: Loc,
|
||||
shelf: Loc,
|
||||
}
|
||||
|
||||
struct BlitLocs {
|
||||
scene: Loc,
|
||||
time: Loc,
|
||||
}
|
||||
|
||||
struct GlassLocs {
|
||||
box_: Loc,
|
||||
res: Loc,
|
||||
scene: Loc,
|
||||
scale: Loc,
|
||||
time: Loc,
|
||||
light: Loc,
|
||||
count: Loc,
|
||||
rect: Loc,
|
||||
param: Loc,
|
||||
glow: Loc,
|
||||
tint: Loc,
|
||||
}
|
||||
|
||||
pub struct GlassRenderer {
|
||||
gl: glow::Context,
|
||||
vao: glow::VertexArray,
|
||||
scene_prog: glow::Program,
|
||||
blit_prog: glow::Program,
|
||||
glass_prog: glow::Program,
|
||||
scene_locs: SceneLocs,
|
||||
blit_locs: BlitLocs,
|
||||
glass_locs: GlassLocs,
|
||||
fbo: glow::Framebuffer,
|
||||
tex: glow::Texture,
|
||||
tex_size: (i32, i32),
|
||||
/// RGBA16F if the driver can render to it (no banding in dark gradients).
|
||||
half_float: bool,
|
||||
}
|
||||
|
||||
/// GL state we touch and must hand back to the Slint renderer untouched.
|
||||
struct SavedState {
|
||||
program: i32,
|
||||
vao: i32,
|
||||
array_buffer: i32,
|
||||
framebuffer: i32,
|
||||
active_texture: i32,
|
||||
texture0: i32,
|
||||
viewport: [i32; 4],
|
||||
blend: bool,
|
||||
blend_func: [i32; 4],
|
||||
blend_eq: [i32; 2],
|
||||
scissor: bool,
|
||||
depth: bool,
|
||||
stencil: bool,
|
||||
cull: bool,
|
||||
}
|
||||
|
||||
impl GlassRenderer {
|
||||
/// # Safety
|
||||
/// Must be called with the Slint OpenGL context current.
|
||||
pub unsafe fn new(gl: glow::Context) -> anyhow::Result<Self> {
|
||||
unsafe {
|
||||
let version = gl.get_parameter_string(glow::VERSION);
|
||||
let is_es = version.contains("OpenGL ES");
|
||||
log::info!("OpenGL: {version} ({})", gl.get_parameter_string(glow::RENDERER));
|
||||
let header = if is_es {
|
||||
"#version 300 es\nprecision highp float;\nprecision highp int;\n"
|
||||
} else {
|
||||
"#version 330 core\n"
|
||||
};
|
||||
|
||||
let scene_prog = link(&gl, header, shaders::VERTEX, shaders::SCENE)?;
|
||||
let blit_prog = link(&gl, header, shaders::VERTEX, shaders::BLIT)?;
|
||||
let glass_prog = link(&gl, header, shaders::QUAD_VERTEX, shaders::GLASS)?;
|
||||
let loc = |p: glow::Program, name: &str| gl.get_uniform_location(p, name);
|
||||
let scene_locs = SceneLocs {
|
||||
res: loc(scene_prog, "uRes"),
|
||||
time: loc(scene_prog, "uTime"),
|
||||
pal: loc(scene_prog, "uPal"),
|
||||
zoom: loc(scene_prog, "uZoom"),
|
||||
shelf: loc(scene_prog, "uShelf"),
|
||||
};
|
||||
let blit_locs = BlitLocs { scene: loc(blit_prog, "uScene"), time: loc(blit_prog, "uTime") };
|
||||
let glass_locs = GlassLocs {
|
||||
box_: loc(glass_prog, "uBox"),
|
||||
res: loc(glass_prog, "uRes"),
|
||||
scene: loc(glass_prog, "uScene"),
|
||||
scale: loc(glass_prog, "uScale"),
|
||||
time: loc(glass_prog, "uTime"),
|
||||
light: loc(glass_prog, "uLight"),
|
||||
count: loc(glass_prog, "uCount"),
|
||||
rect: loc(glass_prog, "uRect"),
|
||||
param: loc(glass_prog, "uParam"),
|
||||
glow: loc(glass_prog, "uGlow"),
|
||||
tint: loc(glass_prog, "uTint"),
|
||||
};
|
||||
let vao = gl.create_vertex_array().map_err(anyhow::Error::msg)?;
|
||||
let fbo = gl.create_framebuffer().map_err(anyhow::Error::msg)?;
|
||||
let tex = gl.create_texture().map_err(anyhow::Error::msg)?;
|
||||
|
||||
Ok(Self {
|
||||
gl,
|
||||
vao,
|
||||
scene_prog,
|
||||
blit_prog,
|
||||
glass_prog,
|
||||
scene_locs,
|
||||
blit_locs,
|
||||
glass_locs,
|
||||
fbo,
|
||||
tex,
|
||||
tex_size: (0, 0),
|
||||
half_float: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn save(&self) -> SavedState {
|
||||
let gl = &self.gl;
|
||||
unsafe {
|
||||
let mut viewport = [0; 4];
|
||||
gl.get_parameter_i32_slice(glow::VIEWPORT, &mut viewport);
|
||||
let active_texture = gl.get_parameter_i32(glow::ACTIVE_TEXTURE);
|
||||
gl.active_texture(glow::TEXTURE0);
|
||||
SavedState {
|
||||
program: gl.get_parameter_i32(glow::CURRENT_PROGRAM),
|
||||
vao: gl.get_parameter_i32(glow::VERTEX_ARRAY_BINDING),
|
||||
array_buffer: gl.get_parameter_i32(glow::ARRAY_BUFFER_BINDING),
|
||||
framebuffer: gl.get_parameter_i32(glow::FRAMEBUFFER_BINDING),
|
||||
active_texture,
|
||||
texture0: gl.get_parameter_i32(glow::TEXTURE_BINDING_2D),
|
||||
viewport,
|
||||
blend: gl.is_enabled(glow::BLEND),
|
||||
blend_func: [
|
||||
gl.get_parameter_i32(glow::BLEND_SRC_RGB),
|
||||
gl.get_parameter_i32(glow::BLEND_DST_RGB),
|
||||
gl.get_parameter_i32(glow::BLEND_SRC_ALPHA),
|
||||
gl.get_parameter_i32(glow::BLEND_DST_ALPHA),
|
||||
],
|
||||
blend_eq: [
|
||||
gl.get_parameter_i32(glow::BLEND_EQUATION_RGB),
|
||||
gl.get_parameter_i32(glow::BLEND_EQUATION_ALPHA),
|
||||
],
|
||||
scissor: gl.is_enabled(glow::SCISSOR_TEST),
|
||||
depth: gl.is_enabled(glow::DEPTH_TEST),
|
||||
stencil: gl.is_enabled(glow::STENCIL_TEST),
|
||||
cull: gl.is_enabled(glow::CULL_FACE),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn restore(&self, s: SavedState) {
|
||||
let gl = &self.gl;
|
||||
let nz = |v: i32| std::num::NonZeroU32::new(v as u32);
|
||||
unsafe {
|
||||
gl.use_program(nz(s.program).map(glow::NativeProgram));
|
||||
gl.bind_vertex_array(nz(s.vao).map(glow::NativeVertexArray));
|
||||
gl.bind_buffer(glow::ARRAY_BUFFER, nz(s.array_buffer).map(glow::NativeBuffer));
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, nz(s.framebuffer).map(glow::NativeFramebuffer));
|
||||
gl.active_texture(glow::TEXTURE0);
|
||||
gl.bind_texture(glow::TEXTURE_2D, nz(s.texture0).map(glow::NativeTexture));
|
||||
gl.active_texture(s.active_texture as u32);
|
||||
gl.viewport(s.viewport[0], s.viewport[1], s.viewport[2], s.viewport[3]);
|
||||
let [sr, dr, sa, da] = s.blend_func.map(|v| v as u32);
|
||||
gl.blend_func_separate(sr, dr, sa, da);
|
||||
gl.blend_equation_separate(s.blend_eq[0] as u32, s.blend_eq[1] as u32);
|
||||
let set = |cap, on: bool| if on { gl.enable(cap) } else { gl.disable(cap) };
|
||||
set(glow::BLEND, s.blend);
|
||||
set(glow::SCISSOR_TEST, s.scissor);
|
||||
set(glow::DEPTH_TEST, s.depth);
|
||||
set(glow::STENCIL_TEST, s.stencil);
|
||||
set(glow::CULL_FACE, s.cull);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn alloc_target(&self, w: i32, h: i32, half_float: bool) -> bool {
|
||||
let gl = &self.gl;
|
||||
unsafe {
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(self.tex));
|
||||
let (internal, ty) =
|
||||
if half_float { (glow::RGBA16F, glow::HALF_FLOAT) } else { (glow::RGBA8, glow::UNSIGNED_BYTE) };
|
||||
gl.tex_image_2d(
|
||||
glow::TEXTURE_2D,
|
||||
0,
|
||||
internal as i32,
|
||||
w,
|
||||
h,
|
||||
0,
|
||||
glow::RGBA,
|
||||
ty,
|
||||
glow::PixelUnpackData::Slice(None),
|
||||
);
|
||||
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::LINEAR_MIPMAP_LINEAR as i32);
|
||||
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::LINEAR as i32);
|
||||
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_S, glow::CLAMP_TO_EDGE as i32);
|
||||
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_WRAP_T, glow::CLAMP_TO_EDGE as i32);
|
||||
gl.generate_mipmap(glow::TEXTURE_2D);
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(self.fbo));
|
||||
gl.framebuffer_texture_2d(glow::FRAMEBUFFER, glow::COLOR_ATTACHMENT0, glow::TEXTURE_2D, Some(self.tex), 0);
|
||||
gl.check_framebuffer_status(glow::FRAMEBUFFER) == glow::FRAMEBUFFER_COMPLETE
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn ensure_target(&mut self, w: i32, h: i32) {
|
||||
if self.tex_size == (w, h) {
|
||||
return;
|
||||
}
|
||||
unsafe {
|
||||
if self.half_float && !self.alloc_target(w, h, true) {
|
||||
log::info!("glass: RGBA16F not renderable, using RGBA8 for the backdrop");
|
||||
self.half_float = false;
|
||||
}
|
||||
if !self.half_float {
|
||||
self.alloc_target(w, h, false);
|
||||
}
|
||||
}
|
||||
self.tex_size = (w, h);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Must be called from the Slint rendering notifier with the context current.
|
||||
pub unsafe fn render(&mut self, f: &Frame) {
|
||||
let (w, h) = (f.width as i32, f.height as i32);
|
||||
if w <= 0 || h <= 0 {
|
||||
return;
|
||||
}
|
||||
unsafe {
|
||||
let saved = self.save();
|
||||
let gl = &self.gl;
|
||||
gl.disable(glow::BLEND);
|
||||
gl.disable(glow::SCISSOR_TEST);
|
||||
gl.disable(glow::DEPTH_TEST);
|
||||
gl.disable(glow::STENCIL_TEST);
|
||||
gl.disable(glow::CULL_FACE);
|
||||
gl.bind_vertex_array(Some(self.vao));
|
||||
|
||||
// Pass 1: backdrop at low resolution (it is a smooth gradient).
|
||||
let sw = (w / 4).clamp(1, SCENE_MAX_W);
|
||||
let sh = ((sw as i64 * h as i64 / w as i64) as i32).max(1);
|
||||
self.ensure_target(sw, sh);
|
||||
let gl = &self.gl;
|
||||
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(self.fbo));
|
||||
gl.viewport(0, 0, sw, sh);
|
||||
let l = &self.scene_locs;
|
||||
gl.use_program(Some(self.scene_prog));
|
||||
gl.uniform_2_f32(l.res.as_ref(), sw as f32, sh as f32);
|
||||
gl.uniform_1_f32(l.time.as_ref(), f.time);
|
||||
gl.uniform_3_f32_slice(l.pal.as_ref(), &f.palette);
|
||||
gl.uniform_1_f32(l.zoom.as_ref(), f.zoom);
|
||||
gl.uniform_1_f32(l.shelf.as_ref(), f.shelf);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
|
||||
gl.bind_texture(glow::TEXTURE_2D, Some(self.tex));
|
||||
gl.generate_mipmap(glow::TEXTURE_2D);
|
||||
|
||||
// Pass 2: upscale to the window framebuffer.
|
||||
gl.bind_framebuffer(
|
||||
glow::FRAMEBUFFER,
|
||||
std::num::NonZeroU32::new(saved.framebuffer as u32).map(glow::NativeFramebuffer),
|
||||
);
|
||||
gl.viewport(0, 0, w, h);
|
||||
let l = &self.blit_locs;
|
||||
gl.use_program(Some(self.blit_prog));
|
||||
gl.uniform_1_i32(l.scene.as_ref(), 0);
|
||||
gl.uniform_1_f32(l.time.as_ref(), f.time);
|
||||
gl.draw_arrays(glow::TRIANGLES, 0, 3);
|
||||
|
||||
// Pass 3: glass, one quad per panel or merged group: dst * a + rgb.
|
||||
gl.enable(glow::BLEND);
|
||||
gl.blend_equation_separate(glow::FUNC_ADD, glow::FUNC_ADD);
|
||||
gl.blend_func_separate(glow::ONE, glow::SRC_ALPHA, glow::ZERO, glow::ONE);
|
||||
let l = &self.glass_locs;
|
||||
gl.use_program(Some(self.glass_prog));
|
||||
gl.uniform_1_i32(l.scene.as_ref(), 0);
|
||||
gl.uniform_2_f32(l.res.as_ref(), w as f32, h as f32);
|
||||
gl.uniform_1_f32(l.scale.as_ref(), f.scale);
|
||||
gl.uniform_1_f32(l.time.as_ref(), f.time);
|
||||
gl.uniform_2_f32(l.light.as_ref(), f.light[0], f.light[1]);
|
||||
|
||||
let rects = &f.rects[..f.rects.len().min(MAX_RECTS)];
|
||||
let mut rect = [0f32; MAX_GROUP * 4];
|
||||
let mut param = [0f32; MAX_GROUP * 4];
|
||||
let mut glow_c = [0f32; MAX_GROUP * 4];
|
||||
let mut tint = [0f32; MAX_GROUP * 4];
|
||||
for run in runs(rects) {
|
||||
let n = run.len();
|
||||
// Bounds plus room for the shadow (spread + downward offset).
|
||||
let margin = 132.0 * f.scale;
|
||||
let (mut x0, mut y0, mut x1, mut y1) = (f32::MAX, f32::MAX, f32::MIN, f32::MIN);
|
||||
for (i, r) in run.iter().enumerate() {
|
||||
rect[i * 4..i * 4 + 4].copy_from_slice(&[r.x, r.y, r.w, r.h]);
|
||||
param[i * 4..i * 4 + 4].copy_from_slice(&[r.radius, r.focus, r.alpha, r.blur]);
|
||||
glow_c[i * 4..i * 4 + 4].copy_from_slice(&[r.glow[0], r.glow[1], r.glow[2], 0.0]);
|
||||
tint[i * 4..i * 4 + 4].copy_from_slice(&r.tint);
|
||||
x0 = x0.min(r.x);
|
||||
y0 = y0.min(r.y);
|
||||
x1 = x1.max(r.x + r.w);
|
||||
y1 = y1.max(r.y + r.h);
|
||||
}
|
||||
let bx = [
|
||||
(x0 - margin).max(0.0),
|
||||
(y0 - margin).max(0.0),
|
||||
(x1 + margin).min(w as f32),
|
||||
(y1 + margin + 46.0 * f.scale).min(h as f32),
|
||||
];
|
||||
if bx[0] >= bx[2] || bx[1] >= bx[3] {
|
||||
continue;
|
||||
}
|
||||
gl.uniform_4_f32(l.box_.as_ref(), bx[0], bx[1], bx[2], bx[3]);
|
||||
gl.uniform_1_i32(l.count.as_ref(), n as i32);
|
||||
gl.uniform_4_f32_slice(l.rect.as_ref(), &rect[..n * 4]);
|
||||
gl.uniform_4_f32_slice(l.param.as_ref(), ¶m[..n * 4]);
|
||||
gl.uniform_4_f32_slice(l.glow.as_ref(), &glow_c[..n * 4]);
|
||||
gl.uniform_4_f32_slice(l.tint.as_ref(), &tint[..n * 4]);
|
||||
gl.draw_arrays(glow::TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
self.restore(saved);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the current window framebuffer as top-down RGBA8 (dev snapshots).
|
||||
///
|
||||
/// # Safety
|
||||
/// Must be called with the context current, after Slint has rendered.
|
||||
pub unsafe fn read_pixels(&self, w: u32, h: u32) -> Vec<u8> {
|
||||
let mut buf = vec![0u8; (w * h * 4) as usize];
|
||||
unsafe {
|
||||
self.gl.pixel_store_i32(glow::PACK_ALIGNMENT, 1);
|
||||
self.gl.read_pixels(
|
||||
0,
|
||||
0,
|
||||
w as i32,
|
||||
h as i32,
|
||||
glow::RGBA,
|
||||
glow::UNSIGNED_BYTE,
|
||||
glow::PixelPackData::Slice(Some(&mut buf)),
|
||||
);
|
||||
}
|
||||
let row = (w * 4) as usize;
|
||||
let mut flipped = Vec::with_capacity(buf.len());
|
||||
for y in (0..h as usize).rev() {
|
||||
flipped.extend_from_slice(&buf[y * row..(y + 1) * row]);
|
||||
}
|
||||
flipped
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// Must be called with the context current.
|
||||
pub unsafe fn destroy(&mut self) {
|
||||
unsafe {
|
||||
self.gl.delete_program(self.scene_prog);
|
||||
self.gl.delete_program(self.blit_prog);
|
||||
self.gl.delete_program(self.glass_prog);
|
||||
self.gl.delete_vertex_array(self.vao);
|
||||
self.gl.delete_framebuffer(self.fbo);
|
||||
self.gl.delete_texture(self.tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Splits the panels into draw runs: consecutive panels sharing a group
|
||||
/// (> 0) melt together and are drawn as one; the rest are drawn alone.
|
||||
fn runs(rects: &[Panel]) -> impl Iterator<Item = &[Panel]> {
|
||||
let mut rest = rects;
|
||||
std::iter::from_fn(move || {
|
||||
let first = rest.first()?;
|
||||
let mut n = 1;
|
||||
if first.group > 0.5 {
|
||||
while n < rest.len() && n < MAX_GROUP && (rest[n].group - first.group).abs() < 0.5 {
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
let (run, tail) = rest.split_at(n);
|
||||
rest = tail;
|
||||
Some(run)
|
||||
})
|
||||
}
|
||||
|
||||
unsafe fn link(gl: &glow::Context, header: &str, vs: &str, fs: &str) -> anyhow::Result<glow::Program> {
|
||||
unsafe {
|
||||
let program = gl.create_program().map_err(anyhow::Error::msg)?;
|
||||
let mut shaders = Vec::new();
|
||||
for (kind, src) in [(glow::VERTEX_SHADER, vs), (glow::FRAGMENT_SHADER, fs)] {
|
||||
let sh = gl.create_shader(kind).map_err(anyhow::Error::msg)?;
|
||||
gl.shader_source(sh, &format!("{header}{src}"));
|
||||
gl.compile_shader(sh);
|
||||
if !gl.get_shader_compile_status(sh) {
|
||||
anyhow::bail!("shader compile failed: {}", gl.get_shader_info_log(sh));
|
||||
}
|
||||
gl.attach_shader(program, sh);
|
||||
shaders.push(sh);
|
||||
}
|
||||
gl.link_program(program);
|
||||
if !gl.get_program_link_status(program) {
|
||||
anyhow::bail!("program link failed: {}", gl.get_program_info_log(program));
|
||||
}
|
||||
for sh in shaders {
|
||||
gl.detach_shader(program, sh);
|
||||
gl.delete_shader(sh);
|
||||
}
|
||||
Ok(program)
|
||||
}
|
||||
}
|
||||
@@ -1,384 +0,0 @@
|
||||
//! GLSL sources. The `#version` line is added at runtime (desktop GL 3.3 core or GLES 3.0).
|
||||
|
||||
/// Fullscreen triangle without vertex buffers.
|
||||
pub const VERTEX: &str = r#"
|
||||
out vec2 vUv;
|
||||
void main() {
|
||||
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
||||
vUv = p;
|
||||
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
/// A quad over `uBox` (x0, y0, x1, y1 in px, top-left origin), drawn as a
|
||||
/// 4-vertex triangle strip. Glass panels only shade the pixels they can reach.
|
||||
pub const QUAD_VERTEX: &str = r#"
|
||||
uniform vec4 uBox;
|
||||
uniform vec2 uRes;
|
||||
void main() {
|
||||
vec2 c = vec2(float(gl_VertexID & 1), float((gl_VertexID >> 1) & 1));
|
||||
vec2 p = mix(uBox.xy, uBox.zw, c);
|
||||
gl_Position = vec4(p.x / uRes.x * 2.0 - 1.0, 1.0 - p.y / uRes.y * 2.0, 0.0, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
/// Backdrop: a dark, slowly flowing mesh gradient (soft colour fields in the
|
||||
/// focused app's palette), like Apple's dark dynamic wallpapers.
|
||||
///
|
||||
/// It is smooth by design, so it is rendered at low resolution and upscaled.
|
||||
/// Cost per pixel: a handful of exp() calls, no noise, no loops over shapes.
|
||||
pub const SCENE: &str = r#"
|
||||
in vec2 vUv;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform vec2 uRes;
|
||||
uniform float uTime;
|
||||
uniform vec3 uPal[3]; // highlight, mid, deep
|
||||
uniform float uZoom; // launch fly-in
|
||||
uniform float uShelf; // 1 = top shelf showing, 0 = scrolled into the grid
|
||||
|
||||
float field(vec2 d, float r) {
|
||||
return exp(-dot(d, d) / (r * r));
|
||||
}
|
||||
|
||||
// Rotates the hue around the grey axis (keeps brightness roughly the same).
|
||||
vec3 hueRot(vec3 c, float ang) {
|
||||
const vec3 k = vec3(0.57735);
|
||||
float ca = cos(ang);
|
||||
return max(c * ca + cross(k, c) * sin(ang) + k * dot(k, c) * (1.0 - ca), 0.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = vec2(vUv.x, 1.0 - vUv.y); // top-left origin
|
||||
uv = (uv - 0.5) / uZoom + 0.5;
|
||||
float aspect = uRes.x / uRes.y;
|
||||
float t = uTime;
|
||||
|
||||
// Gentle flow: two layers of low-frequency sine warp make the fields drift
|
||||
// and bend like liquid without any visible shapes.
|
||||
vec2 w = uv;
|
||||
w += 0.050 * vec2(sin(uv.y * 3.1 + t * 0.110), sin(uv.x * 2.3 - t * 0.090));
|
||||
w += 0.022 * vec2(sin(uv.y * 5.7 - t * 0.070 + 1.3), sin(uv.x * 4.9 + t * 0.130 + 0.7));
|
||||
vec2 a = vec2(aspect, 1.0);
|
||||
|
||||
vec3 hi = uPal[0];
|
||||
vec3 mid = uPal[1];
|
||||
vec3 deep = uPal[2];
|
||||
|
||||
// Near-black base; colour lives in a few soft fields with dark gaps between.
|
||||
vec3 col = deep * 0.35 + vec3(0.003, 0.003, 0.005);
|
||||
// Fields on slow Lissajous paths. Two are hue-shifted for depth, like
|
||||
// Apple's dark gradients (never a single flat hue).
|
||||
vec2 c0 = vec2(0.76 + 0.10 * sin(t * 0.050), 0.18 + 0.08 * cos(t * 0.043));
|
||||
vec2 c1 = vec2(0.20 + 0.12 * cos(t * 0.037 + 1.0), 0.26 + 0.10 * sin(t * 0.041));
|
||||
vec2 c2 = vec2(0.52 + 0.20 * sin(t * 0.029 + 2.0), 0.62 + 0.08 * cos(t * 0.033 + 0.5));
|
||||
vec2 c3 = vec2(0.96 + 0.05 * cos(t * 0.045), 0.88 + 0.06 * sin(t * 0.052));
|
||||
vec2 c4 = vec2(0.04 + 0.06 * sin(t * 0.031 + 4.0), 0.94 + 0.05 * cos(t * 0.027));
|
||||
col += hi * 0.34 * field((w - c0) * a, 0.40);
|
||||
col += mid * 0.62 * field((w - c1) * a, 0.48);
|
||||
col += hueRot(mix(mid, hi, 0.4), 0.55) * 0.34 * field((w - c2) * a, 0.38);
|
||||
col += hueRot(mid, -0.70) * 0.40 * field((w - c3) * a, 0.36);
|
||||
col += mid * 0.30 * field((w - c4) * a, 0.34);
|
||||
|
||||
// Soft shoulder so bright palettes stay "dark mode".
|
||||
col = col / (1.0 + col * 1.2);
|
||||
|
||||
// Calmer at the bottom where the icons sit; dimmer when the shelf is gone.
|
||||
col *= mix(1.0, 0.62, smoothstep(0.45, 1.0, uv.y));
|
||||
col *= mix(0.42, 1.0, uShelf);
|
||||
vec2 v = uv - 0.5;
|
||||
col *= 1.0 - 0.30 * dot(v, v);
|
||||
|
||||
fragColor = vec4(col, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
/// Upscales the backdrop to the window with dithering (no banding).
|
||||
pub const BLIT: &str = r#"
|
||||
in vec2 vUv;
|
||||
out vec4 fragColor;
|
||||
uniform sampler2D uScene;
|
||||
uniform float uTime;
|
||||
|
||||
float hash12(vec2 p) {
|
||||
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return fract((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 col = textureLod(uScene, vUv, 0.0).rgb;
|
||||
col += (hash12(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) / 255.0;
|
||||
fragColor = vec4(col, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
/// One Liquid Glass panel (or one merged group of panels), drawn as a quad
|
||||
/// over its bounds plus the shadow margin.
|
||||
///
|
||||
/// The model follows Apple's Liquid Glass: light is *bent*, not scattered.
|
||||
/// Each panel is a slab of glass (IOR ~1.5) whose edge is a convex squircle
|
||||
/// bevel. The backdrop seen through it is displaced by a real refraction ray
|
||||
/// (Snell), with per-channel IOR for dispersion. Bigger panels are thicker:
|
||||
/// wider bevel, stronger lensing, deeper shadow. On top: Fresnel reflection,
|
||||
/// a geometry-aware specular rim, light from within when focused, and
|
||||
/// "materialize" (alpha ramps the lensing, not just the opacity).
|
||||
///
|
||||
/// The result is written as `dst * a + rgb` (blend ONE, SRC_ALPHA), so the
|
||||
/// shader never needs to read the framebuffer: shadows multiply, glass
|
||||
/// replaces, and nested glass (on another pane) lights what is already there.
|
||||
pub const GLASS: &str = r#"
|
||||
out vec4 fragColor;
|
||||
|
||||
#define MAX_GROUP 4
|
||||
|
||||
uniform sampler2D uScene;
|
||||
uniform vec2 uRes; // physical px
|
||||
uniform float uScale; // physical px per design px
|
||||
uniform float uTime;
|
||||
uniform vec2 uLight; // direction towards the key light (screen space, y down)
|
||||
uniform int uCount; // members of this run (> 1 = merged group)
|
||||
uniform vec4 uRect[MAX_GROUP]; // x, y, w, h (px, top-left origin)
|
||||
uniform vec4 uParam[MAX_GROUP]; // radius, focus, alpha, frost (mip lod; < 0 = nested on other glass)
|
||||
uniform vec4 uGlow[MAX_GROUP]; // accent rgb, unused
|
||||
uniform vec4 uTint[MAX_GROUP]; // tint rgb, tint amount
|
||||
|
||||
float sdRoundRect(vec2 p, vec2 b, float r) {
|
||||
vec2 q = abs(p) - b + r;
|
||||
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r;
|
||||
}
|
||||
|
||||
// Analytic outward gradient of sdRoundRect.
|
||||
vec2 gradRoundRect(vec2 p, vec2 b, float r) {
|
||||
vec2 w = abs(p) - b + r;
|
||||
vec2 q = max(w, 0.0);
|
||||
vec2 g = (max(w.x, w.y) > 0.0) ? q / max(length(q), 1e-5) : ((w.x > w.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0));
|
||||
return sign(p) * g;
|
||||
}
|
||||
|
||||
float sdPanel(int i, vec2 p) {
|
||||
vec4 R = uRect[i];
|
||||
vec2 hs = R.zw * 0.5;
|
||||
float r = min(uParam[i].x, min(hs.x, hs.y));
|
||||
return sdRoundRect(p - (R.xy + hs), hs, r);
|
||||
}
|
||||
|
||||
// Polynomial smooth minimum: the "liquid bridge" between merged panels.
|
||||
float smin(float a, float b, float k) {
|
||||
float h = max(k - abs(a - b), 0.0) / k;
|
||||
return min(a, b) - h * h * k * 0.25;
|
||||
}
|
||||
|
||||
float sdGroup(vec2 p, float k) {
|
||||
float d = 1e5;
|
||||
for (int i = 0; i < MAX_GROUP; i++) {
|
||||
if (i >= uCount) break;
|
||||
if (uParam[i].z <= 0.001) continue;
|
||||
d = smin(d, sdPanel(i, p), k);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
// uv has a top-left origin; the scene texture is stored GL-style (bottom row first).
|
||||
vec3 sceneAt(vec2 uv, float lod) {
|
||||
uv = clamp(uv, vec2(0.001), vec2(0.999));
|
||||
return textureLod(uScene, vec2(uv.x, 1.0 - uv.y), lod).rgb;
|
||||
}
|
||||
|
||||
float luma(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
|
||||
|
||||
// Convex squircle bevel: height (0 at the rim, 1 on the flat top) and slope.
|
||||
// u = distance from the rim / bevel width.
|
||||
vec2 squircle(float u) {
|
||||
u = clamp(u, 0.0, 1.0);
|
||||
float a = 1.0 - u;
|
||||
float a4 = a * a * a * a;
|
||||
float h = pow(max(1.0 - a4, 1e-4), 0.25);
|
||||
float dh = a * a * a * pow(max(1.0 - a4, 1e-3), -0.75);
|
||||
return vec2(h, dh);
|
||||
}
|
||||
|
||||
// Where a vertical ray through the glass lands on the backdrop (px offset).
|
||||
vec2 refractOffset(vec3 N, float height, float ior) {
|
||||
vec3 t = refract(vec3(0.0, 0.0, -1.0), N, 1.0 / ior);
|
||||
return t.xy / max(-t.z, 0.2) * height;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 p = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y); // px, top-left
|
||||
float s = uScale;
|
||||
float mergeK = 30.0 * s;
|
||||
bool merged = uCount > 1;
|
||||
|
||||
// Combined distance, and parameters blended towards the nearest member.
|
||||
float d = 1e5;
|
||||
float wsum = 0.0;
|
||||
vec4 P = vec4(0.0);
|
||||
vec3 accent = vec3(0.0);
|
||||
vec4 tint = vec4(0.0);
|
||||
vec2 center = vec2(0.0);
|
||||
vec2 halfSize = vec2(0.0);
|
||||
for (int k = 0; k < MAX_GROUP; k++) {
|
||||
if (k >= uCount) break;
|
||||
float a = uParam[k].z;
|
||||
if (a <= 0.001) continue;
|
||||
float dk = sdPanel(k, p);
|
||||
d = merged ? smin(d, dk, mergeK) : dk;
|
||||
float w = exp(-max(dk, 0.0) / (12.0 * s)) + 1e-4;
|
||||
wsum += w;
|
||||
P += uParam[k] * w;
|
||||
accent += uGlow[k].rgb * w;
|
||||
tint += uTint[k] * w;
|
||||
vec4 R = uRect[k];
|
||||
center += (R.xy + R.zw * 0.5) * w;
|
||||
halfSize += R.zw * 0.5 * w;
|
||||
}
|
||||
if (wsum <= 0.0) discard;
|
||||
P /= wsum; accent /= wsum; tint /= wsum; center /= wsum; halfSize /= wsum;
|
||||
|
||||
float focus = P.y;
|
||||
float alpha = P.z;
|
||||
float minHalf = min(halfSize.x, halfSize.y);
|
||||
bool nested = P.w < 0.0;
|
||||
// Size-dependent thickness: small controls are full domes (a drop of
|
||||
// liquid), big panes are thick slabs with a wide rounded edge.
|
||||
float bezel = min(minHalf * 0.80, 9.0 * s + minHalf * 0.10);
|
||||
bezel = clamp(bezel, 5.0 * s, 40.0 * s);
|
||||
float sizeK = clamp(minHalf / (240.0 * s), 0.0, 1.0);
|
||||
float small = 1.0 - clamp(minHalf / (90.0 * s), 0.0, 1.0);
|
||||
|
||||
// Output is dst * mul + add.
|
||||
float mul = 1.0;
|
||||
vec3 add = vec3(0.0);
|
||||
|
||||
// ---- outside: grounding shadow and a little accent light spill ----
|
||||
if (d > 0.0) {
|
||||
vec2 off = vec2(0.0, (10.0 + 18.0 * focus + 14.0 * sizeK) * s);
|
||||
float ds = merged ? sdGroup(p - off, mergeK) : sdPanel(0, p - off);
|
||||
float spread = (34.0 + 34.0 * focus + 50.0 * sizeK) * s * (nested ? 0.5 : 1.0);
|
||||
float shadow = (1.0 - smoothstep(-spread * 0.5, spread, ds)) * (0.26 + 0.22 * focus + 0.18 * sizeK);
|
||||
shadow += (1.0 - smoothstep(0.0, 6.0 * s, d)) * 0.10;
|
||||
mul = 1.0 - shadow * alpha;
|
||||
add = accent * exp(-d / (22.0 * s)) * focus * 0.16 * alpha;
|
||||
if (d > 1.0) {
|
||||
if (mul > 0.998 && dot(add, vec3(1.0)) < 0.002) discard;
|
||||
fragColor = vec4(add, mul);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- surface geometry ----
|
||||
vec2 n2;
|
||||
if (merged) {
|
||||
vec2 e = vec2(0.75, 0.0);
|
||||
vec2 g2 = vec2(sdGroup(p + e.xy, mergeK) - sdGroup(p - e.xy, mergeK),
|
||||
sdGroup(p + e.yx, mergeK) - sdGroup(p - e.yx, mergeK));
|
||||
n2 = g2 / max(length(g2), 1e-5);
|
||||
} else {
|
||||
vec4 R = uRect[0];
|
||||
vec2 hs = R.zw * 0.5;
|
||||
n2 = gradRoundRect(p - (R.xy + hs), hs, min(uParam[0].x, min(hs.x, hs.y)));
|
||||
}
|
||||
|
||||
float inside = max(-d, 0.0);
|
||||
float u = inside / bezel;
|
||||
vec2 hp = squircle(u);
|
||||
float thick = bezel * (1.1 + 0.3 * focus); // glass height in px
|
||||
float height = thick * hp.x;
|
||||
float slope = (u < 1.0) ? hp.y * thick / bezel : 0.0;
|
||||
slope = min(slope, 6.0);
|
||||
vec3 N = normalize(vec3(n2 * slope, 1.0));
|
||||
|
||||
// Materialize: lensing and frost ramp up with alpha instead of a plain fade.
|
||||
float mat = smoothstep(0.0, 1.0, alpha);
|
||||
float lens = (1.25 + 0.35 * focus) * mat;
|
||||
vec2 mag = -(p - center) * (0.025 + 0.035 * focus) * mat;
|
||||
float lod = abs(P.w) * mix(0.35, 1.0, mat);
|
||||
|
||||
// The glass colour is affine in what is underneath: g = dst * A + B.
|
||||
float A = 0.0;
|
||||
vec3 B;
|
||||
if (nested) {
|
||||
A = 1.0;
|
||||
B = vec3(0.0);
|
||||
} else if (slope > 0.02) {
|
||||
// Bevel: refract each channel with its own IOR (dispersion).
|
||||
B.r = sceneAt((p + refractOffset(N, height, 1.46) * lens + mag) / uRes, lod).r;
|
||||
B.g = sceneAt((p + refractOffset(N, height, 1.50) * lens + mag) / uRes, lod).g;
|
||||
B.b = sceneAt((p + refractOffset(N, height, 1.56) * lens + mag) / uRes, lod).b;
|
||||
} else {
|
||||
B = sceneAt((p + mag) / uRes, lod);
|
||||
}
|
||||
|
||||
// ---- body ----
|
||||
// Adaptive tone: lift glass over dark content, hold it back over bright content.
|
||||
float bgL = luma(sceneAt(center / uRes, 6.0));
|
||||
float kb = 1.02 + 0.10 * focus;
|
||||
A *= kb;
|
||||
B = B * kb + mix(0.045, -0.01, clamp(bgL * 2.0, 0.0, 1.0)) + (nested ? 0.025 : 0.0);
|
||||
A *= 1.0 - tint.a;
|
||||
B = mix(B, tint.rgb, tint.a);
|
||||
|
||||
// Light from within when focused: starts at the center, spreads to the rim.
|
||||
vec2 qn = (p - center) / max(halfSize, vec2(1.0));
|
||||
float core = exp(-dot(qn, qn) * 1.3);
|
||||
vec3 inner = mix(vec3(1.0), accent, 0.45);
|
||||
B += inner * focus * (0.06 + 0.12 * core);
|
||||
|
||||
// Focus sheen: a soft diagonal band of light glides across the glass now and then.
|
||||
float sweep = fract(uTime * 0.16 + center.x * 0.0007);
|
||||
float band = (qn.x * 0.8 + qn.y * 0.45) * 0.5 + 0.5;
|
||||
float sheen = exp(-pow((band - (sweep * 1.8 - 0.4)) * 7.0, 2.0));
|
||||
B += vec3(1.0) * sheen * focus * 0.10 * mat;
|
||||
|
||||
// Soft vertical sheen, as if lit from above.
|
||||
float vy = clamp((p.y - (center.y - halfSize.y)) / (2.0 * halfSize.y), 0.0, 1.0);
|
||||
B += vec3(0.06 + 0.05 * focus) * pow(1.0 - vy, 2.5);
|
||||
|
||||
// ---- light ----
|
||||
float wob = focus * 0.35 * sin(uTime * 0.9);
|
||||
vec2 L2 = mat2(cos(wob), sin(wob), -sin(wob), cos(wob)) * uLight;
|
||||
vec3 L = normalize(vec3(L2, 0.55));
|
||||
vec3 V = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
// Fresnel: steep bevel reflects the (blurred, brightened) surroundings.
|
||||
float cosT = clamp(N.z, 0.0, 1.0);
|
||||
float F = 0.04 + 0.96 * pow(1.0 - cosT, 5.0);
|
||||
float Fm = clamp(F, 0.0, 1.0) * 0.35 * mat;
|
||||
vec3 env = mix(sceneAt((p + n2 * 60.0 * s) / uRes, 5.0) * 1.6, vec3(0.92), 0.35);
|
||||
A *= 1.0 - Fm;
|
||||
B = mix(B, env, Fm);
|
||||
|
||||
// Specular on the bevel: key light, plus a weaker bounce on the far side.
|
||||
vec3 H = normalize(L + V);
|
||||
vec3 H2 = normalize(vec3(-L2, 0.55) + V);
|
||||
float spec = pow(max(dot(N, H), 0.0), 26.0);
|
||||
float spec2 = pow(max(dot(N, H2), 0.0), 26.0);
|
||||
float bevelMask = 1.0 - smoothstep(0.0, 1.0, u);
|
||||
B += vec3(1.0) * (spec * 0.60 + spec2 * 0.38) * bevelMask * (0.8 + 0.6 * focus) * mat;
|
||||
|
||||
// Glossy highlight on small domes, like a water drop.
|
||||
vec2 hl = qn - uLight * 0.42;
|
||||
float gloss = exp(-dot(hl * vec2(1.4, 2.2), hl * vec2(1.4, 2.2)) * 3.0);
|
||||
B += vec3(1.0) * gloss * small * 0.14 * mat;
|
||||
|
||||
// Crisp rim: a bright hairline all around, strongest towards the light
|
||||
// and again on the far side where light exits the glass.
|
||||
float facing = max(dot(n2, uLight), 0.0);
|
||||
float away = max(dot(n2, -uLight), 0.0);
|
||||
float rimLine = exp(-inside / (1.0 * s));
|
||||
float rimGlow = exp(-inside / (6.0 * s));
|
||||
B += rimLine * (0.22 + 0.80 * pow(facing, 2.0) + 0.55 * pow(away, 2.0) + 0.22 * focus) * mat;
|
||||
B += rimGlow * (0.06 + 0.10 * facing + 0.06 * away + 0.08 * focus) * mat;
|
||||
B += accent * rimGlow * focus * 0.10 * mat;
|
||||
|
||||
// Subtle inner shade on the side away from the light gives the slab depth.
|
||||
float shade = 1.0 - 0.08 * bevelMask * away * mat;
|
||||
A *= shade;
|
||||
B *= shade;
|
||||
|
||||
float cov = clamp(0.5 - d, 0.0, 1.0) * clamp(alpha * 2.0, 0.0, 1.0);
|
||||
float keep = 1.0 - cov + cov * A;
|
||||
fragColor = vec4(add * keep + cov * B, mul * keep);
|
||||
}
|
||||
"#;
|
||||
@@ -1,5 +1,5 @@
|
||||
#![cfg_attr(not(unix), allow(dead_code))]
|
||||
//! Tiny command socket so other SmartFox components (the remote daemon) can
|
||||
//! Tiny command socket so other Fennec OS components (the remote daemon) can
|
||||
//! reach the launcher even while an app has focus.
|
||||
//! Protocol: one command per line:
|
||||
//! `home` bring the launcher to the front
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::cell::RefCell;
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use crate::App;
|
||||
use crate::glass::Panel;
|
||||
use sf_ui::render::Panel;
|
||||
|
||||
pub struct Request {
|
||||
pub title: String,
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
//! SmartFox launcher.
|
||||
//! Fennec OS launcher.
|
||||
//!
|
||||
//! Slint draws text and icons; the `glass` module draws the animated backdrop
|
||||
//! and frosted glass panels underneath via a rendering notifier.
|
||||
//! Slint draws text and icons; sf-ui's glass renderer draws the animated
|
||||
//! backdrop and frosted glass panels underneath via a rendering notifier.
|
||||
|
||||
mod glass;
|
||||
mod core_client;
|
||||
mod ipc;
|
||||
mod devshot;
|
||||
mod keyboard;
|
||||
mod power;
|
||||
mod runtime;
|
||||
mod settings_screen;
|
||||
mod shelf;
|
||||
mod status;
|
||||
mod store_screen;
|
||||
mod system;
|
||||
#[cfg(windows)]
|
||||
mod winfade;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use chrono::{Datelike, Local, Timelike};
|
||||
use glass::{Frame, GlassRenderer, Panel};
|
||||
use sf_ui::render::{Frame, GlassRenderer, Panel};
|
||||
use sf_ipc::{AppKind, AppManifest, Settings};
|
||||
use slint::{ComponentHandle, Model, ModelRc, SharedString, VecModel};
|
||||
|
||||
@@ -33,18 +36,22 @@ const CROSSFADE: f32 = 0.35;
|
||||
struct Options {
|
||||
/// Factory apps, then installed app packages (`--apps` may repeat).
|
||||
apps_dirs: Vec<PathBuf>,
|
||||
/// Installed store apps (sandboxed; docs/store.md).
|
||||
store_dir: Option<PathBuf>,
|
||||
settings_path: PathBuf,
|
||||
fullscreen: bool,
|
||||
}
|
||||
|
||||
fn parse_args() -> Options {
|
||||
let mut apps_dirs = Vec::new();
|
||||
let mut store_dir = None;
|
||||
let mut settings_path = None;
|
||||
let mut fullscreen = false;
|
||||
let mut args = std::env::args().skip(1);
|
||||
while let Some(a) = args.next() {
|
||||
match a.as_str() {
|
||||
"--apps" => apps_dirs.extend(args.next().map(PathBuf::from)),
|
||||
"--store-apps" => store_dir = args.next().map(PathBuf::from),
|
||||
"--settings" => settings_path = args.next().map(PathBuf::from),
|
||||
"--fullscreen" | "-f" => fullscreen = true,
|
||||
other => log::warn!("unknown argument {other}"),
|
||||
@@ -56,6 +63,7 @@ fn parse_args() -> Options {
|
||||
} else {
|
||||
apps_dirs
|
||||
},
|
||||
store_dir,
|
||||
settings_path: settings_path.unwrap_or_else(default_settings_path),
|
||||
fullscreen,
|
||||
}
|
||||
@@ -114,12 +122,20 @@ fn palette_of(app: &AppManifest) -> [f32; 9] {
|
||||
out
|
||||
}
|
||||
|
||||
fn entry_of(app: &AppManifest, settings: &Settings) -> AppEntry {
|
||||
/// `services`: sf-core runs the background receivers. Without it (an older
|
||||
/// image, or a desktop) a receiver tile starts the app like any other.
|
||||
/// Demo mode (Windows) shows receivers as running, like on the TV.
|
||||
fn entry_of(app: &AppManifest, settings: &Settings, services: bool) -> AppEntry {
|
||||
let (kind, kind_label, target) = match app.kind {
|
||||
AppKind::Web => ("web", "Webes alkalmazás (Chromium)", app.resolved_url(settings).unwrap_or_default()),
|
||||
AppKind::Exec => ("exec", "Natív alkalmazás", app.exec.clone().unwrap_or_default().join(" ")),
|
||||
AppKind::Builtin => ("builtin", "Beépített", String::new()),
|
||||
_ if app.service && services => ("service", "Mindig fut a háttérben", app.exec.clone().unwrap_or_default().join(" ")),
|
||||
AppKind::Web => ("web", "Webes alkalmazás", app.resolved_url(settings).unwrap_or_default()),
|
||||
AppKind::Exec => ("exec", "Alkalmazás", app.exec.clone().unwrap_or_default().join(" ")),
|
||||
AppKind::Builtin => ("builtin", "A rendszer része", String::new()),
|
||||
};
|
||||
let host = if kind == "web" { host_of(&target) } else { String::new() };
|
||||
let kind_label = if app.origin == sf_ipc::Origin::Store { "Store app · saját sandboxban" } else { kind_label };
|
||||
let image = app.icon_file().and_then(|p| slint::Image::load_from_path(&p).map_err(|e| log::warn!("{}: icon {}: {e:?}", app.id, p.display())).ok());
|
||||
let initial = app.name.chars().next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
|
||||
AppEntry {
|
||||
id: app.id.clone().into(),
|
||||
name: app.name.clone().into(),
|
||||
@@ -130,9 +146,132 @@ fn entry_of(app: &AppManifest, settings: &Settings) -> AppEntry {
|
||||
kind: kind.into(),
|
||||
kind_label: kind_label.into(),
|
||||
target: target.into(),
|
||||
version: app.version.clone().into(),
|
||||
host: host.into(),
|
||||
facts: ModelRc::default(),
|
||||
has_image: image.is_some(),
|
||||
image: image.unwrap_or_default(),
|
||||
initial: initial.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the launcher again, in the same process (same pid, so the
|
||||
/// compositor and sf-core carry on and running apps stay as they are): the
|
||||
/// simplest way to pick up a changed app list after a store install.
|
||||
fn restart_launcher() {
|
||||
log::info!("app list changed, restarting the launcher");
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
let Ok(exe) = std::env::current_exe() else { return };
|
||||
let err = std::process::Command::new(exe).args(std::env::args_os().skip(1)).exec();
|
||||
log::error!("restarting the launcher: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
/// "https://netflex.example.com/" -> "netflex.example.com".
|
||||
fn host_of(url: &str) -> String {
|
||||
let rest = url.split_once("://").map_or(url, |(_, r)| r);
|
||||
rest.trim_end_matches('/').to_string()
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// sf-core is running (receivers in the background, DIAL casting).
|
||||
static CORE_UP: Cell<bool> = const { Cell::new(false) };
|
||||
}
|
||||
|
||||
/// Live lines under the focused app's name on the home screen.
|
||||
fn facts_for(entry: &AppEntry, st: &status::Status) -> Vec<Fact> {
|
||||
let fact = |icon: &str, text: &str, tone: &str| Fact { icon: icon.into(), text: text.into(), tone: tone.into() };
|
||||
// The status capsule already shows the network; facts repeat it only as a warning.
|
||||
let offline = st.net == "none";
|
||||
let net = |out: &mut Vec<Fact>| {
|
||||
if offline {
|
||||
out.push(fact("alert", "Nincs hálózat", "warn"));
|
||||
}
|
||||
};
|
||||
let core = CORE_UP.with(Cell::get);
|
||||
match entry.id.as_str() {
|
||||
"youtube" => {
|
||||
let mut out = Vec::new();
|
||||
if core {
|
||||
out.push(fact("cast", "Telefonról is indítható", ""));
|
||||
}
|
||||
net(&mut out);
|
||||
out
|
||||
}
|
||||
"airplay" | "miracast" => {
|
||||
let mut out = Vec::new();
|
||||
if entry.kind == "service" {
|
||||
out.push(fact("check", "Látható „Fennec OS” néven", "ok"));
|
||||
}
|
||||
if entry.id == "miracast" {
|
||||
out.push(fact("alert", "Kísérleti", "warn"));
|
||||
}
|
||||
net(&mut out);
|
||||
out
|
||||
}
|
||||
"settings" => {
|
||||
let mut out = Vec::new();
|
||||
match st.remote_battery {
|
||||
Some(b) => out.push(fact("remote", &format!("Siri Remote · {b}%"), if b <= 15 { "warn" } else { "" })),
|
||||
None if st.remote_connected => out.push(fact("remote", "Siri Remote", "")),
|
||||
None => {}
|
||||
}
|
||||
net(&mut out);
|
||||
if let Some(d) = &st.display {
|
||||
out.push(fact("display", d, ""));
|
||||
}
|
||||
out
|
||||
}
|
||||
_ => {
|
||||
let mut out = Vec::new();
|
||||
net(&mut out);
|
||||
out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Status capsule and the facts of every app.
|
||||
fn apply_status(ui: &App, st: &status::Status) {
|
||||
ui.set_net_icon(st.net.into());
|
||||
ui.set_net_label(st.net_label.clone().into());
|
||||
ui.set_remote_battery(st.remote_battery.map_or(-1, i32::from));
|
||||
let apps = ui.get_apps();
|
||||
for i in 0..apps.row_count() {
|
||||
if let Some(mut entry) = apps.row_data(i) {
|
||||
entry.facts = ModelRc::new(VecModel::from(facts_for(&entry, st)));
|
||||
apps.set_row_data(i, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Top Shelf cards; artwork that does not load falls back to the title.
|
||||
fn apply_shelf(ui: &App, shelf: shelf::Shelf, dir: &Path) {
|
||||
let items: Vec<ShelfItem> = shelf
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
let image = item.image.as_ref().and_then(|name| match slint::Image::load_from_path(&dir.join(name)) {
|
||||
Ok(img) => Some(img),
|
||||
Err(e) => {
|
||||
log::info!("shelf artwork {name}: {e:?}");
|
||||
None
|
||||
}
|
||||
});
|
||||
ShelfItem {
|
||||
title: item.title.into(),
|
||||
detail: item.detail.into(),
|
||||
has_image: image.is_some(),
|
||||
image: image.unwrap_or_default(),
|
||||
progress: item.progress,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ui.set_shelf_title(shelf.title.into());
|
||||
ui.set_shelf_items(ModelRc::new(VecModel::from(items)));
|
||||
}
|
||||
|
||||
/// Backdrop colours, eased towards the focused app's palette every frame.
|
||||
struct Backdrop {
|
||||
palette: [f32; 9],
|
||||
@@ -175,6 +314,7 @@ fn card_rects(ui: &App, scale: f32, accents: &[[f32; 3]]) -> Vec<Panel> {
|
||||
let (fx, fy, active, intro) = (ui.get_focus_x(), ui.get_focus_y(), ui.get_row_active(), ui.get_intro());
|
||||
let (lift, press_in, press) = (ui.get_lift(), ui.get_press_in(), ui.get_press());
|
||||
let scroll = ui.get_grid_scroll();
|
||||
let shelf = ui.get_shelf_t();
|
||||
let menu_t = ui.get_menu_t().clamp(0.0, 1.0);
|
||||
let focus_index = ui.get_focus_index().max(0) as usize;
|
||||
let hidden = (1.0 - ui.get_launch_t()) * (1.0 - ui.get_sheet_t()) * ui.get_dim();
|
||||
@@ -184,6 +324,8 @@ fn card_rects(ui: &App, scale: f32, accents: &[[f32; 3]]) -> Vec<Panel> {
|
||||
let s = 1.0 + (lift - press_in * press) * f;
|
||||
let appear = (intro * 2.2 - col * 0.12 - row * 0.2 - 0.4).clamp(0.0, 1.0);
|
||||
let others = if i == focus_index { 1.0 } else { 1.0 - 0.55 * menu_t };
|
||||
// Lower rows stay hidden under the shelf (no sliver at the screen edge).
|
||||
let others = if row > 0.0 { others * (1.0 - shelf) } else { others };
|
||||
let (w, h) = (cw * s, ch * s);
|
||||
let x = row_x + col * (cw + gap) + (cw - w) / 2.0;
|
||||
let y = row_y + row * step - scroll + (ch - h) / 2.0 + (1.0 - appear) * 60.0 * u;
|
||||
@@ -222,7 +364,8 @@ fn card_rects(ui: &App, scale: f32, accents: &[[f32; 3]]) -> Vec<Panel> {
|
||||
}
|
||||
|
||||
const DAYS: [&str; 7] = ["hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat", "vasárnap"];
|
||||
const MONTHS: [&str; 12] = ["jan.", "febr.", "márc.", "ápr.", "máj.", "jún.", "júl.", "aug.", "szept.", "okt.", "nov.", "dec."];
|
||||
const MONTHS: [&str; 12] =
|
||||
["január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december"];
|
||||
|
||||
fn update_clock(ui: &App) {
|
||||
let now = Local::now();
|
||||
@@ -296,6 +439,73 @@ fn show_toast(ui: &App, text: impl Into<SharedString>, timer: &slint::Timer) {
|
||||
});
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// The app sf-core shows in the foreground, as far as the UI knows.
|
||||
static CORE_APP: RefCell<Option<String>> = const { RefCell::new(None) };
|
||||
static CORE_TOAST: slint::Timer = slint::Timer::default();
|
||||
}
|
||||
|
||||
fn app_name(apps: &[AppManifest], id: &str) -> String {
|
||||
apps.iter().find(|a| a.id == id).map(|a| a.name.clone()).unwrap_or_else(|| id.to_string())
|
||||
}
|
||||
|
||||
/// Shows an app as running: the launch morph covers the home screen.
|
||||
fn show_running(ui: &App, apps: &[AppManifest], id: &str) {
|
||||
let Some(index) = apps.iter().position(|a| a.id == id) else { return };
|
||||
CORE_APP.with(|c| *c.borrow_mut() = Some(id.to_string()));
|
||||
ui.set_focus_index(index as i32);
|
||||
ui.set_menu_open(false);
|
||||
ui.set_sheet_open(false);
|
||||
ui.set_settings_open(false);
|
||||
// The splash (with its loading bar) stays until the compositor fades the
|
||||
// app in on top of it, which waits for the page to load.
|
||||
ui.set_launching(true);
|
||||
}
|
||||
|
||||
/// Events from sf-core (apps starting and stopping, casting).
|
||||
fn on_core_event(ui: &App, apps: &[AppManifest], ev: sf_ipc::CoreEvent) {
|
||||
use sf_ipc::CoreEvent::*;
|
||||
let toast = |text: String| CORE_TOAST.with(|t| show_toast(ui, text, t));
|
||||
match ev {
|
||||
Hello { foreground, switching } => {
|
||||
log::info!("sf-core: switching={switching} foreground={foreground:?}");
|
||||
if let Some(id) = foreground {
|
||||
show_running(ui, apps, &id);
|
||||
}
|
||||
}
|
||||
AppStarted { app_id, cast } => {
|
||||
let current = CORE_APP.with(|c| c.borrow().clone());
|
||||
if current.as_deref() != Some(app_id.as_str()) || !ui.get_launching() {
|
||||
show_running(ui, apps, &app_id);
|
||||
} else {
|
||||
CORE_APP.with(|c| *c.borrow_mut() = Some(app_id.clone()));
|
||||
}
|
||||
if cast {
|
||||
toast(format!("{}: indítás telefonról", app_name(apps, &app_id)));
|
||||
}
|
||||
}
|
||||
AppStopped { app_id } => {
|
||||
let was_shown = CORE_APP.with(|c| {
|
||||
let mut c = c.borrow_mut();
|
||||
let shown = c.as_deref() == Some(app_id.as_str());
|
||||
if shown {
|
||||
*c = None;
|
||||
}
|
||||
shown
|
||||
});
|
||||
if was_shown {
|
||||
// Reverse morph: the full-screen glass shrinks back into the card.
|
||||
ui.set_launching(false);
|
||||
ui.set_app_ready(false);
|
||||
toast(format!("{} bezárva", app_name(apps, &app_id)));
|
||||
}
|
||||
}
|
||||
CastConnected { app_id, device } => toast(format!("{}: {device} csatlakozott", app_name(apps, &app_id))),
|
||||
CastEnded { app_id } => toast(format!("{}: a tükrözés véget ért", app_name(apps, &app_id))),
|
||||
Toast { text } => toast(text),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
let opts = parse_args();
|
||||
@@ -316,14 +526,18 @@ fn main() -> Result<()> {
|
||||
}
|
||||
let data_dir = opts.settings_path.parent().map(Path::to_path_buf).unwrap_or_else(|| PathBuf::from("."));
|
||||
|
||||
let apps = sf_ipc::manifest::load_apps_from(&opts.apps_dirs).with_context(|| format!("loading apps from {:?}", opts.apps_dirs))?;
|
||||
let apps = sf_ipc::manifest::load_all(&opts.apps_dirs, opts.store_dir.as_deref()).with_context(|| format!("loading apps from {:?}", opts.apps_dirs))?;
|
||||
log::info!("{} apps from {:?}", apps.len(), opts.apps_dirs);
|
||||
system::confirm_shell_trial();
|
||||
|
||||
let ui = App::new()?;
|
||||
let entries: Vec<AppEntry> = apps.iter().map(|a| entry_of(a, &settings)).collect();
|
||||
let entries: Vec<AppEntry> = apps.iter().map(|a| entry_of(a, &settings, true)).collect();
|
||||
ui.set_apps(ModelRc::new(VecModel::from(entries)));
|
||||
let _screen = settings_screen::Screen::install(&ui, opts.settings_path.clone());
|
||||
let store = store_screen::Screen::install(&ui);
|
||||
if !system::demo() {
|
||||
store.on_apps_changed(restart_launcher);
|
||||
}
|
||||
keyboard::install(&ui);
|
||||
power::configure_from(&settings);
|
||||
power::install(&ui, opts.settings_path.clone());
|
||||
@@ -349,9 +563,41 @@ fn main() -> Result<()> {
|
||||
});
|
||||
}
|
||||
|
||||
// Launching. Locally the launcher starts apps itself; on the TV this moves to sf-core.
|
||||
// Launching. On the TV sf-core starts apps (and keeps them frozen in the
|
||||
// background on Home); without it the launcher starts them itself.
|
||||
let toast_timer = Rc::new(slint::Timer::default());
|
||||
let running: Rc<RefCell<Option<(String, std::process::Child)>>> = Rc::default();
|
||||
let core = {
|
||||
let weak = ui.as_weak();
|
||||
let apps = apps.clone();
|
||||
core_client::CoreClient::connect(move |ev| {
|
||||
let Some(ui) = weak.upgrade() else { return };
|
||||
on_core_event(&ui, &apps, ev);
|
||||
})
|
||||
};
|
||||
if core.is_none() {
|
||||
let entries: Vec<AppEntry> = apps.iter().map(|a| entry_of(a, &settings, system::demo())).collect();
|
||||
ui.set_apps(ModelRc::new(VecModel::from(entries)));
|
||||
}
|
||||
CORE_UP.with(|c| c.set(core.is_some()));
|
||||
apply_status(&ui, &status::Status { net: "wired", ..Default::default() });
|
||||
{
|
||||
let weak = ui.as_weak();
|
||||
status::spawn(move |st| {
|
||||
let _ = weak.upgrade_in_event_loop(move |ui| apply_status(&ui, &st));
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = ui.as_weak();
|
||||
let source = shelf::Source {
|
||||
server: settings.get("netflex_server").map(str::to_string),
|
||||
token: settings.get("netflex_token").filter(|t| !t.is_empty()).map(str::to_string),
|
||||
dir: data_dir.join("cache").join("shelf"),
|
||||
};
|
||||
shelf::spawn(source, move |shelf, dir| {
|
||||
let _ = weak.upgrade_in_event_loop(move |ui| apply_shelf(&ui, shelf, &dir));
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = ui.as_weak();
|
||||
let apps = apps.clone();
|
||||
@@ -360,20 +606,27 @@ fn main() -> Result<()> {
|
||||
let running = running.clone();
|
||||
let data_dir = data_dir.clone();
|
||||
let fullscreen = opts.fullscreen;
|
||||
let core = core.clone();
|
||||
ui.on_launch(move |index| {
|
||||
let Some(ui) = weak.upgrade() else { return };
|
||||
let Some(app) = apps.get(index as usize) else { return };
|
||||
ui.set_launch_detail("indítása…".into());
|
||||
ui.set_app_ready(false);
|
||||
if let Some(core) = &core {
|
||||
CORE_APP.with(|c| *c.borrow_mut() = Some(app.id.clone()));
|
||||
core.send(sf_ipc::LauncherRequest::Launch { app_id: app.id.clone(), query: None });
|
||||
return;
|
||||
}
|
||||
if let Some((_, mut old)) = running.borrow_mut().take() {
|
||||
runtime::stop(&mut old);
|
||||
}
|
||||
ui.set_launch_detail("indítása…".into());
|
||||
ui.set_app_ready(false);
|
||||
let pos = ui.window().position();
|
||||
let size = ui.window().size();
|
||||
let opts = runtime::LaunchOptions {
|
||||
let opts = sf_ipc::launch::LaunchOptions {
|
||||
data_dir: &data_dir,
|
||||
fullscreen,
|
||||
bounds: Some((pos.x, pos.y, size.width, size.height)),
|
||||
query: None,
|
||||
};
|
||||
match runtime::launch(app, &settings, &opts) {
|
||||
Ok(child) => {
|
||||
@@ -382,7 +635,7 @@ fn main() -> Result<()> {
|
||||
{
|
||||
// Keep the window hidden until the morph finishes and the page loads.
|
||||
let weak = ui.as_weak();
|
||||
let not_before = std::time::Instant::now() + Duration::from_millis(950);
|
||||
let not_before = std::time::Instant::now() + Duration::from_millis(720);
|
||||
winfade::reveal_when_ready(child.id(), not_before, move || {
|
||||
let _ = weak.upgrade_in_event_loop(|ui| ui.set_app_ready(true));
|
||||
});
|
||||
@@ -399,22 +652,38 @@ fn main() -> Result<()> {
|
||||
}
|
||||
{
|
||||
let running = running.clone();
|
||||
let core = core.clone();
|
||||
ui.on_cancel_launch(move || {
|
||||
// Back pressed on the launch splash: close the app that is starting.
|
||||
if let Some(core) = &core {
|
||||
if let Some(id) = CORE_APP.with(|c| c.borrow_mut().take()) {
|
||||
core.send(sf_ipc::LauncherRequest::Stop { app_id: id });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some((name, mut child)) = running.borrow_mut().take() {
|
||||
log::info!("closing {name}");
|
||||
runtime::stop(&mut child);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Global "home" (remote's TV button): close the foreground app and play the reverse morph.
|
||||
// Global "home" (remote's TV button): the foreground app goes to the
|
||||
// background (sf-core) or closes, and the reverse morph plays.
|
||||
{
|
||||
let weak = ui.as_weak();
|
||||
let core = core.clone();
|
||||
ipc::listen(move |cmd| {
|
||||
let Some(ui) = weak.upgrade() else { return };
|
||||
match cmd {
|
||||
ipc::Command::Home => {
|
||||
log::info!("home");
|
||||
ui.invoke_cancel_launch();
|
||||
match &core {
|
||||
Some(core) => {
|
||||
CORE_APP.with(|c| *c.borrow_mut() = None);
|
||||
core.send(sf_ipc::LauncherRequest::GoHome);
|
||||
}
|
||||
None => ui.invoke_cancel_launch(),
|
||||
}
|
||||
ui.set_launching(false);
|
||||
ui.set_app_ready(false);
|
||||
ui.set_sheet_open(false);
|
||||
@@ -527,10 +796,13 @@ fn main() -> Result<()> {
|
||||
scale,
|
||||
time,
|
||||
palette: bd.palette,
|
||||
shelf: ui.get_shelf_t(),
|
||||
brightness: ui.get_shelf_t(),
|
||||
light: [angle.cos(), angle.sin()],
|
||||
zoom: 1.0 + 0.35 * ui.get_launch_t() * ui.get_launch_t(),
|
||||
images: &[],
|
||||
video: None,
|
||||
rects,
|
||||
quality: Default::default(),
|
||||
};
|
||||
drop(bd);
|
||||
// SAFETY: called on the UI thread with the Slint GL context current.
|
||||
|
||||
@@ -1,178 +1,24 @@
|
||||
//! Starts apps. Web apps run in a Chromium-family browser in app/kiosk mode
|
||||
//! with a per-app profile; exec apps are spawned directly.
|
||||
//!
|
||||
//! This lives in the launcher for local testing; on the TV it moves into the
|
||||
//! sf-core daemon (systemd scopes, freeze/thaw).
|
||||
//! Starts apps locally, when no sf-core is running (desktop testing). The
|
||||
//! command line comes from `sf_ipc::launch`; on the TV sf-core does this.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command};
|
||||
use std::process::Child;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use sf_ipc::{AppKind, AppManifest, Settings};
|
||||
|
||||
pub struct Browser {
|
||||
pub exe: PathBuf,
|
||||
/// Full version, used to build a realistic user agent.
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
pub fn find_browser() -> Option<Browser> {
|
||||
let mut candidates: Vec<PathBuf> = Vec::new();
|
||||
if let Ok(p) = std::env::var("SMARTFOX_BROWSER") {
|
||||
candidates.push(p.into());
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
for base in ["ProgramFiles", "ProgramFiles(x86)", "LOCALAPPDATA"] {
|
||||
if let Some(b) = std::env::var_os(base) {
|
||||
let b = PathBuf::from(b);
|
||||
candidates.push(b.join(r"Google\Chrome\Application\chrome.exe"));
|
||||
candidates.push(b.join(r"Chromium\Application\chrome.exe"));
|
||||
candidates.push(b.join(r"Microsoft\Edge\Application\msedge.exe"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
for name in ["chromium", "chromium-browser", "google-chrome-stable", "google-chrome"] {
|
||||
for dir in ["/usr/bin", "/usr/local/bin", "/snap/bin"] {
|
||||
candidates.push(Path::new(dir).join(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
let exe = candidates.into_iter().find(|p| p.is_file())?;
|
||||
let version = browser_version(&exe).unwrap_or_else(|| "141.0.0.0".into());
|
||||
Some(Browser { exe, version })
|
||||
}
|
||||
|
||||
fn browser_version(exe: &Path) -> Option<String> {
|
||||
// Windows installs keep a folder named after the version next to the exe.
|
||||
if cfg!(windows) {
|
||||
let dir = exe.parent()?;
|
||||
let mut versions: Vec<String> = std::fs::read_dir(dir)
|
||||
.ok()?
|
||||
.flatten()
|
||||
.filter_map(|e| e.file_name().into_string().ok())
|
||||
.filter(|n| n.split('.').count() == 4 && n.split('.').all(|p| p.parse::<u32>().is_ok()))
|
||||
.collect();
|
||||
versions.sort_by_key(|v| v.split('.').map(|p| p.parse::<u32>().unwrap_or(0)).collect::<Vec<_>>());
|
||||
return versions.pop();
|
||||
}
|
||||
let out = Command::new(exe).arg("--version").output().ok()?;
|
||||
String::from_utf8_lossy(&out.stdout)
|
||||
.split_whitespace()
|
||||
.find(|w| w.chars().next().is_some_and(|c| c.is_ascii_digit()) && w.contains('.'))
|
||||
.map(str::to_string)
|
||||
}
|
||||
|
||||
fn default_user_agent(version: &str) -> String {
|
||||
let platform = if cfg!(windows) { "Windows NT 10.0; Win64; x64" } else { "X11; Linux x86_64" };
|
||||
let major = version.split('.').next().unwrap_or("141");
|
||||
format!("Mozilla/5.0 ({platform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{major}.0.0.0 Safari/537.36")
|
||||
}
|
||||
|
||||
pub struct LaunchOptions<'a> {
|
||||
pub data_dir: &'a Path,
|
||||
pub fullscreen: bool,
|
||||
/// Windowed mode: open the app exactly over the launcher (x, y, w, h).
|
||||
pub bounds: Option<(i32, i32, u32, u32)>,
|
||||
}
|
||||
use anyhow::{Context, Result};
|
||||
use sf_ipc::launch::{LaunchOptions, command};
|
||||
use sf_ipc::{AppManifest, Settings};
|
||||
|
||||
pub fn launch(app: &AppManifest, settings: &Settings, opts: &LaunchOptions) -> Result<Child> {
|
||||
match app.kind {
|
||||
AppKind::Web => launch_web(app, settings, opts),
|
||||
AppKind::Exec => {
|
||||
let cmd = app.exec.as_deref().unwrap_or_default();
|
||||
let (prog, args) = cmd.split_first().context("empty exec command")?;
|
||||
Command::new(prog).args(args).spawn().with_context(|| format!("starting {prog}"))
|
||||
}
|
||||
AppKind::Builtin => bail!("built-in app has no process"),
|
||||
}
|
||||
}
|
||||
|
||||
/// First-run preferences for an app profile: no translate prompt, Hungarian
|
||||
/// content language. Existing profiles are left alone.
|
||||
fn seed_profile(profile: &Path) -> Result<()> {
|
||||
let prefs = profile.join("Default").join("Preferences");
|
||||
if prefs.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
std::fs::create_dir_all(prefs.parent().unwrap())?;
|
||||
std::fs::write(
|
||||
&prefs,
|
||||
r#"{"translate":{"enabled":false},"intl":{"accept_languages":"hu-HU,hu,en"},"browser":{"has_seen_welcome_page":true}}"#,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn launch_web(app: &AppManifest, settings: &Settings, opts: &LaunchOptions) -> Result<Child> {
|
||||
let browser = find_browser().context("no Chromium/Chrome/Edge found (set SMARTFOX_BROWSER)")?;
|
||||
let url = app.resolved_url(settings).filter(|u| !u.is_empty()).context("app has no URL")?;
|
||||
if url.starts_with('/') {
|
||||
bail!("URL is not set (check settings: {url})");
|
||||
}
|
||||
let profile = opts.data_dir.join("profiles").join(&app.id);
|
||||
seed_profile(&profile)?;
|
||||
|
||||
let ua = match (&app.web.user_agent, &app.web.user_agent_suffix) {
|
||||
(Some(ua), _) => ua.clone(),
|
||||
(None, Some(suffix)) => format!("{} {suffix}", default_user_agent(&browser.version)),
|
||||
(None, None) => default_user_agent(&browser.version),
|
||||
};
|
||||
|
||||
let mut cmd = Command::new(&browser.exe);
|
||||
cmd.arg(format!("--user-data-dir={}", profile.display()))
|
||||
.arg(format!("--user-agent={ua}"))
|
||||
.arg("--no-first-run")
|
||||
.arg("--no-default-browser-check")
|
||||
.arg("--disable-session-crashed-bubble")
|
||||
.arg("--hide-crash-restore-bubble")
|
||||
.arg("--disable-features=Translate,TranslateUI,MediaRouter")
|
||||
.arg("--lang=hu")
|
||||
.arg("--accept-lang=hu-HU,hu,en")
|
||||
// Dark first paint instead of a white flash before the page draws.
|
||||
.arg("--force-dark-mode")
|
||||
.arg("--autoplay-policy=no-user-gesture-required")
|
||||
.arg("--overscroll-history-navigation=0");
|
||||
if opts.fullscreen {
|
||||
cmd.arg("--kiosk").arg(&url);
|
||||
} else {
|
||||
cmd.arg(format!("--app={url}"));
|
||||
match opts.bounds {
|
||||
Some((x, y, w, h)) => {
|
||||
cmd.arg(format!("--window-position={x},{y}")).arg(format!("--window-size={w},{h}"));
|
||||
}
|
||||
None => {
|
||||
cmd.arg("--window-size=1600,900");
|
||||
}
|
||||
}
|
||||
}
|
||||
if cfg!(target_os = "linux") {
|
||||
// Chromium on Linux picks its UI language from the environment, not --lang.
|
||||
cmd.env("LANGUAGE", "hu");
|
||||
cmd.arg("--enable-features=VaapiVideoDecoder,VaapiIgnoreDriverChecks,PlatformHEVCDecoderSupport");
|
||||
if std::env::var_os("WAYLAND_DISPLAY").is_some() {
|
||||
cmd.arg("--ozone-platform=wayland");
|
||||
}
|
||||
}
|
||||
for ext in &app.web.extensions {
|
||||
cmd.arg(format!("--load-extension={}", app.dir.join(ext).display()));
|
||||
}
|
||||
// Own process group, so closing the app also ends Chromium's helper processes.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
cmd.process_group(0);
|
||||
}
|
||||
log::info!("{} {:?}", browser.exe.display(), cmd.get_args().collect::<Vec<_>>());
|
||||
cmd.spawn().with_context(|| format!("starting {}", browser.exe.display()))
|
||||
let mut cmd = command(app, settings, opts)?;
|
||||
log::info!("{} {:?}", cmd.get_program().to_string_lossy(), cmd.get_args().collect::<Vec<_>>());
|
||||
cmd.spawn().with_context(|| format!("starting {}", cmd.get_program().to_string_lossy()))
|
||||
}
|
||||
|
||||
/// Stops an app and everything it started.
|
||||
pub fn stop(child: &mut Child) {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// The app runs in its own process group (see launch_web).
|
||||
use std::process::Command;
|
||||
// The app runs in its own process group (see sf_ipc::launch::command).
|
||||
let _ = Command::new("kill").arg("-TERM").arg("--").arg(format!("-{}", child.id())).status();
|
||||
for _ in 0..20 {
|
||||
if matches!(child.try_wait(), Ok(Some(_))) {
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
||||
|
||||
use crate::system::{self, BtDevice, DeviceInfo, Display, Mode, NetInfo, RemoteDebug, Security, UpdateStatus, Wifi, WifiNetwork};
|
||||
use crate::system::{self, AudioOutput, BtAudioDevice, BtDevice, DeviceInfo, Display, Mode, NetInfo, RemoteDebug, Security, UpdateStatus, Wifi, WifiNetwork};
|
||||
use crate::power;
|
||||
use crate::{App, SettingRow, keyboard};
|
||||
|
||||
@@ -19,9 +19,10 @@ const KEEP_SECS: u64 = 15;
|
||||
|
||||
const DISPLAY: i32 = 0;
|
||||
const DEVICES: i32 = 1;
|
||||
const NETWORK: i32 = 2;
|
||||
const ENERGY: i32 = 3;
|
||||
const SYSTEM: i32 = 4;
|
||||
const AUDIO: i32 = 2;
|
||||
const NETWORK: i32 = 3;
|
||||
const ENERGY: i32 = 4;
|
||||
const SYSTEM: i32 = 5;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum Action {
|
||||
@@ -42,6 +43,9 @@ enum Action {
|
||||
Back,
|
||||
PairRemote,
|
||||
ReplaceRemote,
|
||||
AudioOutput(String),
|
||||
BtAudioScan,
|
||||
BtAudioConnect(String),
|
||||
Restart,
|
||||
ConfirmRestart,
|
||||
RemoteDebug,
|
||||
@@ -82,6 +86,10 @@ struct Pending {
|
||||
enum Loaded {
|
||||
Display(Result<Display, String>),
|
||||
Devices(Result<Vec<BtDevice>, String>),
|
||||
Audio(Result<Vec<AudioOutput>, String>),
|
||||
BtAudio(Result<Vec<BtAudioDevice>, String>),
|
||||
AudioDone(Result<String, String>),
|
||||
BtAudioScanDone(Result<Vec<BtAudioDevice>, String>),
|
||||
Net(NetInfo),
|
||||
Wifi(Result<Option<Wifi>, String>),
|
||||
/// A Wi-Fi action finished: notice text, or the error. `retry` reopens the
|
||||
@@ -105,6 +113,8 @@ struct State {
|
||||
parent_row: i32,
|
||||
display: Option<Result<Display, String>>,
|
||||
devices: Option<Result<Vec<BtDevice>, String>>,
|
||||
audio: Option<Result<Vec<AudioOutput>, String>>,
|
||||
bt_audio: Option<Result<Vec<BtAudioDevice>, String>>,
|
||||
net: Option<NetInfo>,
|
||||
/// Ok(None) = no Wi-Fi adapter.
|
||||
wifi: Option<Result<Option<Wifi>, String>>,
|
||||
@@ -187,6 +197,8 @@ impl Screen {
|
||||
parent_row: 0,
|
||||
display: None,
|
||||
devices: None,
|
||||
audio: None,
|
||||
bt_audio: None,
|
||||
net: None,
|
||||
wifi: None,
|
||||
wifi_pending: None,
|
||||
@@ -205,13 +217,27 @@ impl Screen {
|
||||
SCREEN.with(|s| *s.borrow_mut() = Some(screen.clone()));
|
||||
|
||||
let s = screen.clone();
|
||||
// In store mode (app.slint set-mode) the same pane belongs to store_screen.
|
||||
let store_mode = |s: &Screen| s.ui.upgrade().is_some_and(|ui| ui.get_set_mode() == "store");
|
||||
ui.on_settings_opened(move || {
|
||||
if store_mode(&s) {
|
||||
if let Some(store) = crate::store_screen::current() {
|
||||
store.opened();
|
||||
}
|
||||
return;
|
||||
}
|
||||
s.state.borrow_mut().notice.clear();
|
||||
s.refresh_all();
|
||||
s.rebuild(None);
|
||||
});
|
||||
let s = screen.clone();
|
||||
ui.on_settings_nav_changed(move |i| {
|
||||
if store_mode(&s) {
|
||||
if let Some(store) = crate::store_screen::current() {
|
||||
store.nav_changed(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
{
|
||||
let mut st = s.state.borrow_mut();
|
||||
st.category = i;
|
||||
@@ -226,9 +252,15 @@ impl Screen {
|
||||
s.rebuild(Some(0));
|
||||
});
|
||||
let s = screen.clone();
|
||||
ui.on_settings_activate(move |i| s.activate(i));
|
||||
ui.on_settings_activate(move |i| match crate::store_screen::current().filter(|_| store_mode(&s)) {
|
||||
Some(store) => store.activate(i),
|
||||
None => s.activate(i),
|
||||
});
|
||||
let s = screen.clone();
|
||||
ui.on_settings_back(move || s.run(Action::Back));
|
||||
ui.on_settings_back(move || match crate::store_screen::current().filter(|_| store_mode(&s)) {
|
||||
Some(store) => store.back(),
|
||||
None => s.run(Action::Back),
|
||||
});
|
||||
|
||||
// Ticks the confirm countdown and keeps device/network rows fresh.
|
||||
let s = Rc::downgrade(&screen);
|
||||
@@ -255,12 +287,14 @@ impl Screen {
|
||||
}
|
||||
|
||||
fn is_open(&self) -> bool {
|
||||
self.ui.upgrade().is_some_and(|ui| ui.get_settings_open())
|
||||
self.ui.upgrade().is_some_and(|ui| ui.get_settings_open() && ui.get_set_mode() != "store")
|
||||
}
|
||||
|
||||
fn refresh_all(&self) {
|
||||
post(|| Loaded::Display(system::display().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::Devices(system::bt_devices().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::Audio(system::audio_outputs().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::BtAudio(system::bt_audio_devices().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::Net(system::network()));
|
||||
post(|| Loaded::Wifi(wifi_result(system::wifi())));
|
||||
post(|| Loaded::RemoteDebug(system::remote_debug()));
|
||||
@@ -292,6 +326,10 @@ impl Screen {
|
||||
}
|
||||
match category {
|
||||
DEVICES => post(|| Loaded::Devices(system::bt_devices().map_err(|e| format!("{e:#}")))),
|
||||
AUDIO => {
|
||||
post(|| Loaded::Audio(system::audio_outputs().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::BtAudio(system::bt_audio_devices().map_err(|e| format!("{e:#}"))));
|
||||
}
|
||||
NETWORK => {
|
||||
post(|| Loaded::Net(system::network()));
|
||||
post(|| Loaded::Wifi(wifi_result(system::wifi())));
|
||||
@@ -382,6 +420,30 @@ impl Screen {
|
||||
match loaded {
|
||||
Loaded::Display(d) => self.state.borrow_mut().display = Some(d),
|
||||
Loaded::Devices(d) => self.state.borrow_mut().devices = Some(d),
|
||||
Loaded::Audio(d) => self.state.borrow_mut().audio = Some(d),
|
||||
Loaded::BtAudio(d) => self.state.borrow_mut().bt_audio = Some(d),
|
||||
Loaded::BtAudioScanDone(result) => {
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.busy = false;
|
||||
match result {
|
||||
Ok(devices) => {
|
||||
st.notice = if devices.is_empty() { "Nem található Bluetooth hangeszköz.".into() } else { "Válaszd ki a hangeszközt a csatlakozáshoz.".into() };
|
||||
st.bt_audio = Some(Ok(devices));
|
||||
}
|
||||
Err(e) => st.notice = format!("Keresés sikertelen: {}", short_err(&e)),
|
||||
}
|
||||
}
|
||||
Loaded::AudioDone(result) => {
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.busy = false;
|
||||
st.notice = match result {
|
||||
Ok(message) => message,
|
||||
Err(e) => format!("Hangkimenet: {}", short_err(&e)),
|
||||
};
|
||||
drop(st);
|
||||
post(|| Loaded::Audio(system::audio_outputs().map_err(|e| format!("{e:#}"))));
|
||||
post(|| Loaded::BtAudio(system::bt_audio_devices().map_err(|e| format!("{e:#}"))));
|
||||
}
|
||||
Loaded::Net(n) => self.state.borrow_mut().net = Some(n),
|
||||
Loaded::Wifi(w) => {
|
||||
if let Err(e) = &w {
|
||||
@@ -681,6 +743,33 @@ impl Screen {
|
||||
Loaded::Removed { name, result, then_pair: true }
|
||||
});
|
||||
}
|
||||
Action::AudioOutput(name) => {
|
||||
let label = match &self.state.borrow().audio {
|
||||
Some(Ok(outputs)) => outputs.iter().find(|o| o.name == name).map(|o| o.label.clone()),
|
||||
_ => None,
|
||||
}.unwrap_or_else(|| name.clone());
|
||||
self.state.borrow_mut().busy = true;
|
||||
self.rebuild(None);
|
||||
post(move || Loaded::AudioDone(system::set_audio_output(&name)
|
||||
.map(|()| format!("Hangkimenet: {label}"))
|
||||
.map_err(|e| format!("{e:#}"))));
|
||||
}
|
||||
Action::BtAudioScan => {
|
||||
self.state.borrow_mut().busy = true;
|
||||
self.rebuild(None);
|
||||
post(|| Loaded::BtAudioScanDone(system::bt_audio_scan().map_err(|e| format!("{e:#}"))));
|
||||
}
|
||||
Action::BtAudioConnect(addr) => {
|
||||
let label = match &self.state.borrow().bt_audio {
|
||||
Some(Ok(devices)) => devices.iter().find(|d| d.address == addr).map(|d| d.name.clone()),
|
||||
_ => None,
|
||||
}.unwrap_or_else(|| addr.clone());
|
||||
self.state.borrow_mut().busy = true;
|
||||
self.rebuild(None);
|
||||
post(move || Loaded::AudioDone(system::bt_audio_connect(&addr)
|
||||
.map(|()| format!("Hangkimenet: {label}"))
|
||||
.map_err(|e| format!("{e:#}"))));
|
||||
}
|
||||
Action::Restart => self.enter(Sub::Restart, 1),
|
||||
Action::ConfirmRestart => {
|
||||
log::info!("restarting the launcher (settings)");
|
||||
@@ -776,6 +865,10 @@ impl Screen {
|
||||
/// Pushes the current page to Slint. `row` moves the focus (clamped).
|
||||
fn rebuild(&self, row: Option<i32>) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
// The pane shows the App Store: its rows are store_screen's.
|
||||
if ui.get_set_mode() == "store" {
|
||||
return;
|
||||
}
|
||||
let (title, subtitle, rows, actions) = self.page();
|
||||
let len = rows.len() as i32;
|
||||
let in_sub = self.state.borrow().sub != Sub::None;
|
||||
@@ -978,13 +1071,39 @@ impl Screen {
|
||||
notice_or("Párosított eszközök. Válassz ki egyet az eltávolításhoz."),
|
||||
)
|
||||
}
|
||||
(Sub::None, AUDIO) => {
|
||||
match &st.audio {
|
||||
None => push(row("Hangkimenetek lekérdezése…", "", "", "info"), Action::None),
|
||||
Some(Err(e)) => push(row("A hangrendszer nem érhető el", "", short_err(e), "info"), Action::None),
|
||||
Some(Ok(outputs)) if outputs.is_empty() => push(row("Nincs elérhető hangkimenet", "", "", "info"), Action::None),
|
||||
Some(Ok(outputs)) => {
|
||||
for output in outputs {
|
||||
let kind = if output.bluetooth { "Bluetooth" } else { "Vezetékes / HDMI" };
|
||||
push(row(output.label.clone(), if output.selected { "✓" } else { "" }, kind, "option"), Action::AudioOutput(output.name.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
match &st.bt_audio {
|
||||
Some(Ok(devices)) => for device in devices {
|
||||
let sink_address = device.address.replace(':', "_").to_ascii_uppercase();
|
||||
let shown_as_output = device.connected && matches!(&st.audio, Some(Ok(outputs)) if outputs.iter().any(|o| o.name.to_ascii_uppercase().contains(&sink_address)));
|
||||
if shown_as_output { continue; }
|
||||
let status = if device.connected { "Csatlakozva" } else if device.paired { "Párosítva" } else { "Új eszköz" };
|
||||
push(row(device.name.clone(), status, "Bluetooth hangeszköz", "device"), Action::BtAudioConnect(device.address.clone()));
|
||||
},
|
||||
Some(Err(e)) => push(row("Bluetooth nem érhető el", "", short_err(e), "info"), Action::None),
|
||||
None => {}
|
||||
}
|
||||
push(row(if st.busy { "Folyamatban…" } else { "Bluetooth hangeszközök keresése" }, "", "Kapcsold be az eszköz párosítási módját", "action"), Action::BtAudioScan);
|
||||
("Hangkimenet".to_string(), notice_or("Válaszd ki, hol szóljon a TV. Bluetooth eszközhöz indíts keresést."))
|
||||
}
|
||||
(Sub::None, NETWORK) => {
|
||||
match &st.net {
|
||||
None => push(row("Hálózat lekérdezése…", "", "", "info"), Action::None),
|
||||
Some(n) => {
|
||||
let conn = match (&n.iface, n.ip.is_some(), n.wireless) {
|
||||
(Some(i), true, true) => format!("Wi-Fi · {i}"),
|
||||
(Some(i), true, false) => format!("Vezetékes · {i}"),
|
||||
(Some(_), true, true) => "Wi-Fi".to_string(),
|
||||
(Some(_), true, false) => "Vezetékes".to_string(),
|
||||
_ => "Nincs kapcsolat".to_string(),
|
||||
};
|
||||
push(row("Kapcsolat", conn, "", "info"), Action::None);
|
||||
@@ -1002,7 +1121,8 @@ impl Screen {
|
||||
(false, true) => "Be",
|
||||
(false, false) => "Ki",
|
||||
};
|
||||
push(row("Wi-Fi", value, w.iface.clone(), "action"), Action::WifiPower);
|
||||
let joined = w.networks.iter().find(|n| n.connected).map(|n| format!("Csatlakozva: {}", n.name));
|
||||
push(row("Wi-Fi", value, joined.unwrap_or_default(), "action"), Action::WifiPower);
|
||||
if w.powered {
|
||||
if w.networks.is_empty() {
|
||||
let text = if w.scanning { "Hálózatok keresése…" } else { "Nincs elérhető hálózat" };
|
||||
@@ -1066,7 +1186,7 @@ impl Screen {
|
||||
(Sub::None, _) => {
|
||||
let info = st.info.clone().unwrap_or_default();
|
||||
push(row("Eszköz neve", info.hostname, "", "info"), Action::None);
|
||||
push(row("SmartFox", format!("v{}", env!("CARGO_PKG_VERSION")), "", "info"), Action::None);
|
||||
push(row("Fennec OS", format!("v{}", env!("CARGO_PKG_VERSION")), "", "info"), Action::None);
|
||||
push(row("Operációs rendszer", info.os, "", "info"), Action::None);
|
||||
push(row("Kernel", info.kernel, "", "info"), Action::None);
|
||||
let ip = st.net.as_ref().and_then(|n| n.ip.clone());
|
||||
@@ -1096,8 +1216,8 @@ impl Screen {
|
||||
}
|
||||
|
||||
/// Glass for the settings screen. Mirrors the geometry in ui/settings.slint.
|
||||
pub fn glass(ui: &App, scale: f32) -> Vec<crate::glass::Panel> {
|
||||
use crate::glass::Panel;
|
||||
pub fn glass(ui: &App, scale: f32) -> Vec<sf_ui::render::Panel> {
|
||||
use sf_ui::render::Panel;
|
||||
use slint::Model;
|
||||
|
||||
let t = ui.get_set_t();
|
||||
@@ -1120,51 +1240,63 @@ pub fn glass(ui: &App, scale: f32) -> Vec<crate::glass::Panel> {
|
||||
tint,
|
||||
};
|
||||
let white = [1.0, 1.0, 1.0];
|
||||
let (sx, sy, sw, sh) = (ui.get_sp_x(), ui.get_sp_y(), ui.get_sp_w(), ui.get_sp_h());
|
||||
let mut out = vec![panel(sx, sy, sw, sh, 52.0 * u, 0.15 * t, t, 3.6, [0.79, 0.83, 0.88], [0.04, 0.043, 0.063, 0.40])];
|
||||
// The on-screen keyboard takes over the pane: categories and rows fade out.
|
||||
// The on-screen keyboard takes over the screen: categories and rows fade out.
|
||||
let content = t * (1.0 - ui.get_kb_t());
|
||||
let mut out = Vec::new();
|
||||
|
||||
// Category column: focus glides with nav-pos, the selected one stays lit.
|
||||
// Category column: no glass at rest. The selected category keeps a faint
|
||||
// pill while the rows are focused; the focused one is a white pill.
|
||||
let (nx, ny, nw, nh, nstep) = (ui.get_nav_x(), ui.get_nav_y(), ui.get_nav_w(), ui.get_nav_h(), ui.get_nav_step());
|
||||
let (nav_pos, nav_active) = (ui.get_nav_pos(), ui.get_nav_active());
|
||||
for i in 0..ui.get_set_nav_count() {
|
||||
let sel = (1.0 - (nav_pos - i as f32).abs()).max(0.0);
|
||||
let f = sel * nav_active;
|
||||
let amount = 0.10 * sel * (1.0 - nav_active) + 0.86 * f;
|
||||
if amount <= 0.002 {
|
||||
continue;
|
||||
}
|
||||
let s = 1.0 + 0.03 * f;
|
||||
let (w, h) = (nw * s, nh * s);
|
||||
let y = ny + i as f32 * nstep;
|
||||
out.push(panel(nx - (w - nw) / 2.0, y - (h - nh) / 2.0, w, h, 26.0 * u * s, f, content, -1.0, white, [1.0, 1.0, 1.0, 0.035 + 0.16 * sel + 0.66 * f]));
|
||||
out.push(panel(nx - (w - nw) / 2.0, y - (h - nh) / 2.0, w, h, h / 2.0, f, content, -1.0, white, [1.0, 1.0, 1.0, amount]));
|
||||
}
|
||||
// Back chip.
|
||||
out.push(panel(nx, sy + sh - 92.0 * u, 300.0 * u, 56.0 * u, 28.0 * u, 0.0, t, -1.0, white, [1.0, 1.0, 1.0, 0.03]));
|
||||
|
||||
// Rows, scrolled and faded at the edges of the list area.
|
||||
// One grouped platter behind the visible rows.
|
||||
let (rx, ry, rw) = (ui.get_rows_x(), ui.get_rows_y(), ui.get_rows_w());
|
||||
let (rh, rstep, view, scroll) = (ui.get_set_row_h(), ui.get_set_row_step(), ui.get_rows_view_h(), ui.get_rows_scroll());
|
||||
let rows = ui.get_set_rows();
|
||||
let n = rows.row_count();
|
||||
if n > 0 {
|
||||
let visible = (n as f32 * rstep).min(view);
|
||||
let pad = 8.0 * u;
|
||||
out.push(panel(rx, ry - pad, rw, visible + 2.0 * pad, 32.0 * u, 0.0, content, 2.2, white, [0.04, 0.045, 0.06, 0.30]));
|
||||
}
|
||||
|
||||
// Focus pill on the focused row (rows are inset by the platter padding).
|
||||
let inset = 8.0 * u;
|
||||
let (row_pos, active) = (ui.get_row_pos(), ui.get_content_active());
|
||||
for (j, row) in ui.get_set_rows().iter().enumerate() {
|
||||
for (j, row) in rows.iter().enumerate() {
|
||||
let top = ry + j as f32 * rstep - scroll;
|
||||
let over = (ry - top).max(top + rh - (ry + view)) / rh;
|
||||
let vis = (1.0 - over).clamp(0.0, 1.0);
|
||||
if vis <= 0.01 {
|
||||
let f = (1.0 - (row_pos - j as f32).abs()).max(0.0) * active;
|
||||
if vis <= 0.01 || f <= 0.002 {
|
||||
continue;
|
||||
}
|
||||
let f = (1.0 - (row_pos - j as f32).abs()).max(0.0) * active;
|
||||
let s = 1.0 + 0.02 * f;
|
||||
let (w, h) = (rw * s, rh * s);
|
||||
let (x0, w0) = (rx + inset, rw - 2.0 * inset);
|
||||
let s = 1.0 + 0.015 * f;
|
||||
let (w, h) = (w0 * s, rh * s);
|
||||
let (glow, tint) = if row.kind == "danger" {
|
||||
let red = [1.0, 0.27, 0.23];
|
||||
(red, [1.0, 0.27, 0.23, 0.10 + 0.72 * f])
|
||||
([1.0, 0.27, 0.23], [1.0, 0.27, 0.23, 0.86 * f])
|
||||
} else {
|
||||
(white, [1.0, 1.0, 1.0, 0.04 + 0.80 * f])
|
||||
(white, [1.0, 1.0, 1.0, 0.88 * f])
|
||||
};
|
||||
out.push(panel(rx - (w - rw) / 2.0, top - (h - rh) / 2.0, w, h, 24.0 * u * s, f, content * vis, -1.0, glow, tint));
|
||||
out.push(panel(x0 - (w - w0) / 2.0, top - (h - rh) / 2.0, w, h, 24.0 * u * s, f, content * vis, -1.0, glow, tint));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Value and detail for the Updates row: "2 frissítés" / "SmartFox felület 0.2.0 · YouTube 1.1.0".
|
||||
/// Value and detail for the Updates row: "2 frissítés" / "Fennec OS felület 0.2.0 · YouTube 1.1.0".
|
||||
fn update_summary(u: &UpdateStatus) -> (String, String) {
|
||||
let checked = || {
|
||||
use chrono::TimeZone;
|
||||
|
||||
296
crates/sf-launcher/src/shelf.rs
Normal file
296
crates/sf-launcher/src/shelf.rs
Normal file
@@ -0,0 +1,296 @@
|
||||
//! Top Shelf content for Netflex on the home screen. Optional: the home screen
|
||||
//! is complete without it (the shelf then shows the app itself).
|
||||
//!
|
||||
//! Sources, first that answers wins:
|
||||
//! 1. the Netflex server's `/api/home` with `netflex_token` from settings.toml:
|
||||
//! continue watching, else the first catalog row. Artwork comes through the
|
||||
//! server's image cache (`/api/img`), like in the Netflex apps;
|
||||
//! 2. Cinemeta's public "popular movies" list (the catalog Netflex browses).
|
||||
//!
|
||||
//! The last good result is kept in `<data_dir>/cache/shelf/` and shown at
|
||||
//! start, so the shelf survives restarts without a network.
|
||||
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Cards the home screen shows.
|
||||
const MAX_ITEMS: usize = 4;
|
||||
const REFRESH: Duration = Duration::from_secs(15 * 60);
|
||||
const CINEMETA_TOP: &str = "https://v3-cinemeta.strem.io/catalog/movie/top.json";
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Item {
|
||||
pub title: String,
|
||||
pub detail: String,
|
||||
/// Artwork file name inside the cache folder.
|
||||
pub image: Option<String>,
|
||||
/// 0..1 watched; 0 = no progress bar.
|
||||
pub progress: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Shelf {
|
||||
pub title: String,
|
||||
pub items: Vec<Item>,
|
||||
}
|
||||
|
||||
pub struct Source {
|
||||
/// Netflex server base URL ("https://netflex.example").
|
||||
pub server: Option<String>,
|
||||
pub token: Option<String>,
|
||||
/// `<data_dir>/cache/shelf`.
|
||||
pub dir: PathBuf,
|
||||
}
|
||||
|
||||
/// Loads the cached shelf, then refreshes it every 15 minutes on a background
|
||||
/// thread. `on_update` gets the shelf and the folder its images are in.
|
||||
pub fn spawn(source: Source, on_update: impl Fn(Shelf, PathBuf) + Send + 'static) {
|
||||
let spawned = std::thread::Builder::new().name("shelf".into()).spawn(move || {
|
||||
let cache = source.dir.join("shelf.json");
|
||||
if let Some(shelf) = std::fs::read_to_string(&cache).ok().and_then(|t| serde_json::from_str::<Shelf>(&t).ok()) {
|
||||
on_update(shelf, source.dir.clone());
|
||||
}
|
||||
let agent: ureq::Agent = ureq::Agent::config_builder()
|
||||
.timeout_global(Some(Duration::from_secs(20)))
|
||||
.user_agent(concat!("FennecOS-launcher/", env!("CARGO_PKG_VERSION")))
|
||||
.build()
|
||||
.into();
|
||||
loop {
|
||||
match fetch(&agent, &source) {
|
||||
Ok(shelf) if !shelf.items.is_empty() => {
|
||||
if let Err(e) = std::fs::write(&cache, serde_json::to_string(&shelf).unwrap_or_default()) {
|
||||
log::warn!("shelf cache: {e}");
|
||||
}
|
||||
prune(&source.dir, &shelf);
|
||||
on_update(shelf, source.dir.clone());
|
||||
}
|
||||
Ok(_) => log::info!("shelf: nothing to show"),
|
||||
Err(e) => log::info!("shelf: {e:#}"),
|
||||
}
|
||||
std::thread::sleep(REFRESH);
|
||||
}
|
||||
});
|
||||
if let Err(e) = spawned {
|
||||
log::warn!("shelf thread: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch(agent: &ureq::Agent, source: &Source) -> Result<Shelf> {
|
||||
std::fs::create_dir_all(&source.dir).with_context(|| format!("creating {}", source.dir.display()))?;
|
||||
if let (Some(server), Some(token)) = (&source.server, &source.token) {
|
||||
match netflex(agent, server.trim_end_matches('/'), token, &source.dir) {
|
||||
Ok(shelf) if !shelf.items.is_empty() => return Ok(shelf),
|
||||
Ok(_) => {}
|
||||
Err(e) => log::info!("shelf: Netflex: {e:#}"),
|
||||
}
|
||||
}
|
||||
cinemeta(agent, &source.dir)
|
||||
}
|
||||
|
||||
// ---- Netflex -----------------------------------------------------------------
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Title {
|
||||
id: String,
|
||||
title: String,
|
||||
backdrop: Option<String>,
|
||||
year_label: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Continue {
|
||||
title: Title,
|
||||
season: Option<u32>,
|
||||
episode: Option<u32>,
|
||||
position: Option<f64>,
|
||||
duration: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Row {
|
||||
title: String,
|
||||
items: Vec<Title>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Home {
|
||||
#[serde(default)]
|
||||
rows: Vec<Row>,
|
||||
#[serde(default)]
|
||||
continue_watching: Vec<Continue>,
|
||||
}
|
||||
|
||||
fn netflex(agent: &ureq::Agent, server: &str, token: &str, dir: &Path) -> Result<Shelf> {
|
||||
let auth = format!("Bearer {token}");
|
||||
let resp = agent.get(format!("{server}/api/home")).header("Authorization", &auth).call().context("/api/home")?;
|
||||
let home: Home = serde_json::from_str(&read_text(resp, 4 << 20)?).context("parsing /api/home")?;
|
||||
let image = |t: &Title| {
|
||||
let url = t.backdrop.as_deref()?;
|
||||
let req = agent.get(format!("{server}/api/img")).query("u", url).header("Authorization", &auth);
|
||||
download(req, dir, &t.id)
|
||||
};
|
||||
if !home.continue_watching.is_empty() {
|
||||
let items = home
|
||||
.continue_watching
|
||||
.iter()
|
||||
.take(MAX_ITEMS)
|
||||
.map(|c| {
|
||||
let (pos, dur) = (c.position.unwrap_or(0.0), c.duration.unwrap_or(0.0));
|
||||
let left = if dur > pos && pos > 0.0 { Some(((dur - pos) / 60.0).ceil() as u32) } else { None };
|
||||
let detail = match (c.season, c.episode, left) {
|
||||
(Some(s), Some(e), Some(m)) => format!("{s}. évad, {e}. rész · még {m} perc"),
|
||||
(Some(s), Some(e), None) => format!("{s}. évad, {e}. rész"),
|
||||
(_, _, Some(m)) => format!("Még {m} perc"),
|
||||
_ => c.title.year_label.clone().unwrap_or_default(),
|
||||
};
|
||||
let progress = if dur > 0.0 { (pos / dur).clamp(0.0, 1.0) as f32 } else { 0.0 };
|
||||
Item { title: c.title.title.clone(), detail, image: image(&c.title), progress }
|
||||
})
|
||||
.collect();
|
||||
return Ok(Shelf { title: "Folytatás".into(), items });
|
||||
}
|
||||
let Some(row) = home.rows.into_iter().find(|r| !r.items.is_empty()) else {
|
||||
return Ok(Shelf::default());
|
||||
};
|
||||
let items = row
|
||||
.items
|
||||
.iter()
|
||||
.take(MAX_ITEMS)
|
||||
.map(|t| Item { title: t.title.clone(), detail: t.year_label.clone().unwrap_or_default(), image: image(t), progress: 0.0 })
|
||||
.collect();
|
||||
Ok(Shelf { title: row.title, items })
|
||||
}
|
||||
|
||||
// ---- Cinemeta ------------------------------------------------------------------
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Meta {
|
||||
id: String,
|
||||
name: String,
|
||||
background: Option<String>,
|
||||
release_info: Option<String>,
|
||||
imdb_rating: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Catalog {
|
||||
metas: Vec<Meta>,
|
||||
}
|
||||
|
||||
fn cinemeta(agent: &ureq::Agent, dir: &Path) -> Result<Shelf> {
|
||||
let resp = agent.get(CINEMETA_TOP).call().context("Cinemeta")?;
|
||||
let catalog: Catalog = serde_json::from_str(&read_text(resp, 8 << 20)?).context("parsing Cinemeta")?;
|
||||
let items = catalog
|
||||
.metas
|
||||
.iter()
|
||||
.filter(|m| m.background.is_some())
|
||||
.take(MAX_ITEMS)
|
||||
.map(|m| {
|
||||
let rating = m.imdb_rating.as_ref().filter(|r| !r.trim().is_empty());
|
||||
let year = m.release_info.as_ref().filter(|y| !y.trim().is_empty());
|
||||
let detail = match (year, rating) {
|
||||
(Some(y), Some(r)) => format!("{y} · IMDb {r}"),
|
||||
(Some(y), None) => y.clone(),
|
||||
(None, Some(r)) => format!("IMDb {r}"),
|
||||
(None, None) => String::new(),
|
||||
};
|
||||
let image = m.background.as_deref().and_then(|url| download(agent.get(url), dir, &m.id));
|
||||
Item { title: m.name.clone(), detail, image, progress: 0.0 }
|
||||
})
|
||||
.collect();
|
||||
Ok(Shelf { title: "Népszerű filmek".into(), items })
|
||||
}
|
||||
|
||||
// ---- files ---------------------------------------------------------------------
|
||||
|
||||
fn read_text(resp: ureq::http::Response<ureq::Body>, limit: u64) -> Result<String> {
|
||||
let mut text = String::new();
|
||||
resp.into_body().into_reader().take(limit + 1).read_to_string(&mut text)?;
|
||||
if text.len() as u64 > limit {
|
||||
bail!("response is too large");
|
||||
}
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
const IMAGE_EXTS: [&str; 3] = ["jpg", "png", "webp"];
|
||||
|
||||
/// Image type from the first bytes (the decoder picks it by extension).
|
||||
fn image_ext(bytes: &[u8]) -> Option<&'static str> {
|
||||
match bytes {
|
||||
[0xff, 0xd8, ..] => Some("jpg"),
|
||||
[0x89, b'P', b'N', b'G', ..] => Some("png"),
|
||||
[b'R', b'I', b'F', b'F', _, _, _, _, b'W', b'E', b'B', b'P', ..] => Some("webp"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Saves the artwork as `<id>.<ext>`, reusing a file that is already there.
|
||||
fn download(req: ureq::RequestBuilder<ureq::typestate::WithoutBody>, dir: &Path, id: &str) -> Option<String> {
|
||||
let stem: String = id.chars().filter(|c| c.is_ascii_alphanumeric() || *c == '-' || *c == '_').collect();
|
||||
if stem.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let Some(name) = IMAGE_EXTS.iter().map(|ext| format!("{stem}.{ext}")).find(|n| dir.join(n).exists()) {
|
||||
return Some(name);
|
||||
}
|
||||
let result = (|| -> Result<String> {
|
||||
let resp = req.call()?;
|
||||
let mut bytes = Vec::new();
|
||||
resp.into_body().into_reader().take(8 << 20).read_to_end(&mut bytes)?;
|
||||
let ext = image_ext(&bytes).context("not a JPEG, PNG or WebP image")?;
|
||||
let name = format!("{stem}.{ext}");
|
||||
let tmp = dir.join(format!("{stem}.part"));
|
||||
std::fs::write(&tmp, &bytes)?;
|
||||
std::fs::rename(&tmp, dir.join(&name))?;
|
||||
Ok(name)
|
||||
})();
|
||||
match result {
|
||||
Ok(name) => Some(name),
|
||||
Err(e) => {
|
||||
log::info!("shelf: artwork for {id}: {e:#}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes artwork the current shelf no longer uses.
|
||||
fn prune(dir: &Path, shelf: &Shelf) {
|
||||
let keep: Vec<&str> = shelf.items.iter().filter_map(|i| i.image.as_deref()).collect();
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
for e in entries.flatten() {
|
||||
let name = e.file_name().to_string_lossy().to_string();
|
||||
let artwork = name.rsplit_once('.').is_some_and(|(_, ext)| IMAGE_EXTS.contains(&ext) || ext == "part");
|
||||
if artwork && !keep.contains(&name.as_str()) {
|
||||
let _ = std::fs::remove_file(e.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sniffs_image_types() {
|
||||
assert_eq!(image_ext(&[0xff, 0xd8, 0xff, 0xe0]), Some("jpg"));
|
||||
assert_eq!(image_ext(b"\x89PNG\r\n"), Some("png"));
|
||||
assert_eq!(image_ext(b"RIFF\0\0\0\0WEBPVP8 "), Some("webp"));
|
||||
assert_eq!(image_ext(b"<html>"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_netflex_home() {
|
||||
let json = r#"{"rows":[{"id":"popular-movie","title":"Népszerű filmek","items":[{"type":"movie","id":"tt1","tmdbId":null,"title":"A","originalTitle":null,"overview":null,"poster":null,"backdrop":"https://x/b.jpg","year":2024,"yearLabel":"2024","rating":7.1,"genres":[]}]}],
|
||||
"continueWatching":[{"title":{"type":"tv","id":"tt2","title":"B","backdrop":null,"yearLabel":"2021–"},"season":2,"episode":3,"position":600,"duration":2400,"updatedAt":"2026-10-01T10:00:00Z"}]}"#;
|
||||
let home: Home = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(home.rows[0].items[0].year_label.as_deref(), Some("2024"));
|
||||
assert_eq!(home.continue_watching[0].season, Some(2));
|
||||
}
|
||||
}
|
||||
70
crates/sf-launcher/src/status.rs
Normal file
70
crates/sf-launcher/src/status.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
//! Live TV state for the home screen: network, the Siri Remote's battery and
|
||||
//! the display mode. The probes shell out (ip, busctl, bluetoothctl,
|
||||
//! wlr-randr), so they run on a background thread.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::system;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct Status {
|
||||
/// "wired" | "wifi" | "none" (icon names in ui/icons.slint).
|
||||
pub net: &'static str,
|
||||
/// "Vezetékes hálózat", the Wi-Fi name, or "Nincs hálózat".
|
||||
pub net_label: String,
|
||||
pub remote_battery: Option<u8>,
|
||||
pub remote_connected: bool,
|
||||
/// "4K UHD · 60 Hz".
|
||||
pub display: Option<String>,
|
||||
}
|
||||
|
||||
pub fn probe() -> Status {
|
||||
let info = system::network();
|
||||
let (net, net_label) = match (&info.iface, info.wireless) {
|
||||
(None, _) => ("none", "Nincs hálózat".to_string()),
|
||||
(Some(_), false) => ("wired", "Vezetékes hálózat".to_string()),
|
||||
(Some(_), true) => {
|
||||
let name = system::wifi()
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|w| w.networks.into_iter().find(|n| n.connected).map(|n| n.name));
|
||||
("wifi", name.unwrap_or_else(|| "Wi-Fi".into()))
|
||||
}
|
||||
};
|
||||
let remote = system::bt_devices().ok().and_then(|d| d.into_iter().find(|d| d.remote));
|
||||
let display = system::display().ok().and_then(|d| {
|
||||
d.current_mode().map(|m| {
|
||||
let hz = m.hz.round() as u32;
|
||||
match m.name() {
|
||||
"" => format!("{} × {} · {hz} Hz", m.w, m.h),
|
||||
name => format!("{name} · {hz} Hz"),
|
||||
}
|
||||
})
|
||||
});
|
||||
Status {
|
||||
net,
|
||||
net_label,
|
||||
remote_battery: remote.as_ref().and_then(|r| r.battery),
|
||||
remote_connected: remote.as_ref().is_some_and(|r| r.connected),
|
||||
display,
|
||||
}
|
||||
}
|
||||
|
||||
/// Probes now and then every 20 s; `on_change` runs (on the probe thread)
|
||||
/// whenever something changed.
|
||||
pub fn spawn(on_change: impl Fn(Status) + Send + 'static) {
|
||||
let spawned = std::thread::Builder::new().name("status".into()).spawn(move || {
|
||||
let mut last: Option<Status> = None;
|
||||
loop {
|
||||
let now = probe();
|
||||
if last.as_ref() != Some(&now) {
|
||||
on_change(now.clone());
|
||||
last = Some(now);
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs(20));
|
||||
}
|
||||
});
|
||||
if let Err(e) = spawned {
|
||||
log::warn!("status thread: {e}");
|
||||
}
|
||||
}
|
||||
609
crates/sf-launcher/src/store_screen.rs
Normal file
609
crates/sf-launcher/src/store_screen.rs
Normal file
@@ -0,0 +1,609 @@
|
||||
//! The App Store screen (docs/store.md). It reuses the settings pane: the
|
||||
//! same Slint view and glass, in "store" mode (`set-mode`), with its own
|
||||
//! categories and rows.
|
||||
//!
|
||||
//! The launcher runs as user tv and can't install anything: it writes what
|
||||
//! the user wants into store.toml and asks sf-update (root) to act on it
|
||||
//! (`store` request). It reads back what the sources offer from catalog.json
|
||||
//! and sf-update's progress from status.json.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use sf_ipc::Permission;
|
||||
use sf_ipc::store::{CATALOG_FILE, Catalog, CatalogApp, SourceInfo, WANTED_FILE, Wanted, WantedApp, missing_permissions};
|
||||
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
||||
|
||||
use crate::system::{self, UpdateStatus};
|
||||
use crate::{App, SettingRow, keyboard};
|
||||
|
||||
// Categories, as in app.slint (set-categories in store mode): Felfedezés,
|
||||
// Telepítve, Források (anything else).
|
||||
const DISCOVER: i32 = 0;
|
||||
const INSTALLED: i32 = 1;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum Action {
|
||||
None,
|
||||
App(String),
|
||||
Install(String),
|
||||
Approve(String),
|
||||
Uninstall(String),
|
||||
UninstallWithData(String),
|
||||
Source(String),
|
||||
AddSource,
|
||||
RemoveSource(String),
|
||||
Refresh,
|
||||
Back,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum Sub {
|
||||
None,
|
||||
App(String),
|
||||
Source(String),
|
||||
}
|
||||
|
||||
struct State {
|
||||
category: i32,
|
||||
sub: Sub,
|
||||
parent_row: i32,
|
||||
wanted: Wanted,
|
||||
catalog: Option<Catalog>,
|
||||
status: Option<UpdateStatus>,
|
||||
notice: String,
|
||||
actions: Vec<Action>,
|
||||
/// Ids of installed store apps last time we looked; a change reloads the
|
||||
/// launcher's app list once the store is closed.
|
||||
installed: Vec<String>,
|
||||
reload_pending: bool,
|
||||
}
|
||||
|
||||
pub struct Screen {
|
||||
ui: slint::Weak<App>,
|
||||
state: RefCell<State>,
|
||||
on_apps_changed: RefCell<Option<Box<dyn Fn()>>>,
|
||||
timer: slint::Timer,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static SCREEN: RefCell<Option<Rc<Screen>>> = const { RefCell::new(None) };
|
||||
/// Demo (Windows / SMARTFOX_DEMO_SYSTEM): store.toml and catalog in memory.
|
||||
static DEMO: RefCell<Option<(Wanted, Catalog)>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
pub fn current() -> Option<Rc<Screen>> {
|
||||
SCREEN.with(|s| s.borrow().clone())
|
||||
}
|
||||
|
||||
fn row(title: impl Into<SharedString>, value: impl Into<SharedString>, detail: impl Into<SharedString>, kind: &str) -> SettingRow {
|
||||
SettingRow { title: title.into(), value: value.into(), detail: detail.into(), kind: kind.into(), level: 0, lock: false }
|
||||
}
|
||||
|
||||
fn short(text: &str, max: usize) -> String {
|
||||
let line = text.lines().next().unwrap_or(text);
|
||||
if line.chars().count() > max { format!("{}…", line.chars().take(max).collect::<String>()) } else { line.to_string() }
|
||||
}
|
||||
|
||||
/// "github.com/fox/app" for display.
|
||||
fn pretty_source(url: &str) -> String {
|
||||
url.trim_start_matches("https://").to_string()
|
||||
}
|
||||
|
||||
fn permissions_text(perms: &[Permission]) -> String {
|
||||
if perms.is_empty() {
|
||||
return "Nem kér külön engedélyt".into();
|
||||
}
|
||||
perms.iter().map(|p| p.label()).collect::<Vec<_>>().join(", ")
|
||||
}
|
||||
|
||||
fn wanted_path() -> PathBuf {
|
||||
std::env::var_os("SMARTFOX_STORE_FILE").map(PathBuf::from).unwrap_or_else(|| WANTED_FILE.into())
|
||||
}
|
||||
|
||||
fn demo_catalog() -> Catalog {
|
||||
let app = |id: &str, name: &str, cat: &str, desc: &str, perms: Vec<Permission>| CatalogApp {
|
||||
id: id.into(),
|
||||
name: name.into(),
|
||||
version: "1.2.0".into(),
|
||||
kind: "exec".into(),
|
||||
category: cat.into(),
|
||||
description: desc.into(),
|
||||
author: "Példa Fejlesztő".into(),
|
||||
homepage: format!("https://github.com/example/{name}"),
|
||||
license: "MIT".into(),
|
||||
permissions: perms,
|
||||
source: format!("https://github.com/example/{}", name.to_lowercase()),
|
||||
catalog: Some("https://github.com/example/fennec-catalog".into()),
|
||||
..Default::default()
|
||||
};
|
||||
Catalog {
|
||||
updated_at: 1_792_800_000,
|
||||
sources: vec![SourceInfo {
|
||||
url: "https://github.com/example/fennec-catalog".into(),
|
||||
kind: "catalog".into(),
|
||||
name: "Példa katalógus".into(),
|
||||
apps: 3,
|
||||
error: None,
|
||||
}],
|
||||
apps: vec![
|
||||
app("io.github.example.retro", "RetroArch", "Játékok · Emulátor", "Régi konzolok játékai kontrollerrel.", vec![Permission::Gpu, Permission::Audio, Permission::Gamepad]),
|
||||
app("io.github.example.radio", "Rádió", "Zene", "Internetes rádióállomások.", vec![Permission::Network, Permission::Audio]),
|
||||
app("io.github.example.clock", "Óra", "Eszköz", "Nagy óra és időjárás a TV-n.", vec![Permission::Network]),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
fn load_wanted() -> Wanted {
|
||||
if system::demo() {
|
||||
return DEMO.with(|d| d.borrow().as_ref().map(|(w, _)| w.clone())).unwrap_or_default();
|
||||
}
|
||||
Wanted::load(&wanted_path()).unwrap_or_else(|e| {
|
||||
log::warn!("store: {e:#}");
|
||||
Wanted::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn load_catalog() -> Option<Catalog> {
|
||||
if system::demo() {
|
||||
return DEMO.with(|d| {
|
||||
let mut d = d.borrow_mut();
|
||||
let (_, c) = d.get_or_insert_with(|| (Wanted::default(), demo_catalog()));
|
||||
Some(c.clone())
|
||||
});
|
||||
}
|
||||
Catalog::load(std::path::Path::new(CATALOG_FILE))
|
||||
}
|
||||
|
||||
impl Screen {
|
||||
pub fn install(ui: &App) -> Rc<Screen> {
|
||||
let screen = Rc::new(Screen {
|
||||
ui: ui.as_weak(),
|
||||
state: RefCell::new(State {
|
||||
category: 0,
|
||||
sub: Sub::None,
|
||||
parent_row: 0,
|
||||
wanted: Wanted::default(),
|
||||
catalog: None,
|
||||
status: None,
|
||||
notice: String::new(),
|
||||
actions: Vec::new(),
|
||||
installed: Vec::new(),
|
||||
reload_pending: false,
|
||||
}),
|
||||
on_apps_changed: RefCell::new(None),
|
||||
timer: slint::Timer::default(),
|
||||
});
|
||||
SCREEN.with(|s| *s.borrow_mut() = Some(screen.clone()));
|
||||
screen.state.borrow_mut().installed = installed_ids();
|
||||
|
||||
// While open: follow sf-update's progress and the catalog. Once closed
|
||||
// after apps were installed or removed: reload the app list.
|
||||
let weak = Rc::downgrade(&screen);
|
||||
screen.timer.start(slint::TimerMode::Repeated, Duration::from_secs(2), move || {
|
||||
let Some(s) = weak.upgrade() else { return };
|
||||
if s.is_open() {
|
||||
s.reload();
|
||||
} else if std::mem::take(&mut s.state.borrow_mut().reload_pending) {
|
||||
if let Some(f) = s.on_apps_changed.borrow().as_ref() {
|
||||
f();
|
||||
}
|
||||
}
|
||||
});
|
||||
screen
|
||||
}
|
||||
|
||||
/// Called after the store is closed if store apps were installed or removed.
|
||||
pub fn on_apps_changed(&self, f: impl Fn() + 'static) {
|
||||
*self.on_apps_changed.borrow_mut() = Some(Box::new(f));
|
||||
}
|
||||
|
||||
fn is_open(&self) -> bool {
|
||||
self.ui.upgrade().is_some_and(|ui| ui.get_settings_open() && ui.get_set_mode() == "store")
|
||||
}
|
||||
|
||||
pub fn opened(&self) {
|
||||
{
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.notice.clear();
|
||||
st.sub = Sub::None;
|
||||
st.category = 0;
|
||||
}
|
||||
self.reload();
|
||||
self.rebuild(Some(0));
|
||||
}
|
||||
|
||||
pub fn nav_changed(&self, i: i32) {
|
||||
{
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.category = i;
|
||||
st.sub = Sub::None;
|
||||
st.notice.clear();
|
||||
}
|
||||
self.rebuild(Some(0));
|
||||
}
|
||||
|
||||
pub fn activate(&self, index: i32) {
|
||||
let action = self.state.borrow().actions.get(index as usize).cloned().unwrap_or(Action::None);
|
||||
if !matches!(action, Action::None) && self.state.borrow().sub == Sub::None {
|
||||
self.state.borrow_mut().parent_row = index;
|
||||
}
|
||||
self.run(action);
|
||||
}
|
||||
|
||||
pub fn back(&self) {
|
||||
self.run(Action::Back);
|
||||
}
|
||||
|
||||
/// Re-reads store.toml, catalog.json and status.json.
|
||||
fn reload(&self) {
|
||||
let wanted = load_wanted();
|
||||
let catalog = load_catalog();
|
||||
let status = system::update_status();
|
||||
{
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.wanted = wanted;
|
||||
st.catalog = catalog;
|
||||
st.status = status;
|
||||
}
|
||||
let now = installed_ids();
|
||||
let changed = {
|
||||
let mut st = self.state.borrow_mut();
|
||||
let changed = st.installed != now;
|
||||
st.installed = now;
|
||||
changed
|
||||
};
|
||||
if changed {
|
||||
self.state.borrow_mut().reload_pending = true;
|
||||
}
|
||||
if self.is_open() {
|
||||
self.rebuild(None);
|
||||
}
|
||||
}
|
||||
|
||||
fn busy(&self) -> bool {
|
||||
self.state.borrow().status.as_ref().is_some_and(UpdateStatus::busy)
|
||||
}
|
||||
|
||||
/// Saves store.toml and asks sf-update to act on it.
|
||||
fn save(&self, notice: &str, f: impl FnOnce(&mut Wanted)) {
|
||||
let mut wanted = load_wanted();
|
||||
f(&mut wanted);
|
||||
let result = if system::demo() {
|
||||
DEMO.with(|d| {
|
||||
let mut d = d.borrow_mut();
|
||||
let (w, c) = d.get_or_insert_with(|| (Wanted::default(), demo_catalog()));
|
||||
*w = wanted.clone();
|
||||
for app in &mut c.apps {
|
||||
app.installed = w.apps.contains_key(&app.id).then(|| app.version.clone());
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
} else {
|
||||
wanted.save(&wanted_path()).and_then(|()| system::request_update("store"))
|
||||
};
|
||||
self.state.borrow_mut().notice = match result {
|
||||
Ok(()) => notice.to_string(),
|
||||
Err(e) => {
|
||||
log::warn!("store: {e:#}");
|
||||
format!("Nem sikerült: {}", short(&format!("{e:#}"), 60))
|
||||
}
|
||||
};
|
||||
self.reload();
|
||||
}
|
||||
|
||||
fn app(&self, id: &str) -> Option<CatalogApp> {
|
||||
self.state.borrow().catalog.as_ref().and_then(|c| c.app(id).cloned())
|
||||
}
|
||||
|
||||
fn enter(&self, sub: Sub) {
|
||||
self.state.borrow_mut().sub = sub;
|
||||
self.rebuild(Some(0));
|
||||
}
|
||||
|
||||
fn leave(&self) {
|
||||
let parent = {
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.sub = Sub::None;
|
||||
st.parent_row
|
||||
};
|
||||
self.rebuild(Some(parent));
|
||||
}
|
||||
|
||||
fn run(&self, action: Action) {
|
||||
let with_data = matches!(action, Action::UninstallWithData(_));
|
||||
match action {
|
||||
Action::None => {}
|
||||
Action::Back => {
|
||||
if self.state.borrow().sub != Sub::None {
|
||||
self.leave();
|
||||
}
|
||||
}
|
||||
Action::App(id) => self.enter(Sub::App(id)),
|
||||
Action::Source(url) => self.enter(Sub::Source(url)),
|
||||
Action::Install(id) | Action::Approve(id) => {
|
||||
let Some(app) = self.app(&id) else { return };
|
||||
if self.busy() {
|
||||
return;
|
||||
}
|
||||
let notice = format!("{} telepítése…", app.name);
|
||||
self.save(¬ice, |w| {
|
||||
w.apps.insert(app.id.clone(), WantedApp { source: app.source.clone(), permissions: app.permissions.clone() });
|
||||
});
|
||||
}
|
||||
Action::Uninstall(id) | Action::UninstallWithData(id) => {
|
||||
let name = self.app(&id).map(|a| a.name).unwrap_or_else(|| id.clone());
|
||||
self.save(&format!("{name} eltávolítva."), |w| {
|
||||
w.apps.remove(&id);
|
||||
});
|
||||
if with_data && sf_ipc::manifest::is_store_id(&id) {
|
||||
let dir = sf_ipc::paths::app_data_dir(&id);
|
||||
if dir.is_dir() {
|
||||
if let Err(e) = std::fs::remove_dir_all(&dir) {
|
||||
log::warn!("removing {}: {e}", dir.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
self.leave();
|
||||
}
|
||||
Action::RemoveSource(url) => {
|
||||
self.save("Forrás eltávolítva. Az innen telepített appok megmaradnak.", |w| {
|
||||
w.sources.retain(|s| sf_ipc_canonical(s) != url);
|
||||
});
|
||||
self.leave();
|
||||
}
|
||||
Action::Refresh => {
|
||||
if self.busy() {
|
||||
return;
|
||||
}
|
||||
self.save("Források frissítése…", |_| {});
|
||||
}
|
||||
Action::AddSource => self.ask_source(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// On-screen keyboard for a repo address.
|
||||
fn ask_source(&self, error: Option<String>) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
keyboard::open(
|
||||
&ui,
|
||||
keyboard::Request {
|
||||
title: "Forrás hozzáadása".into(),
|
||||
subtitle: "Egy app vagy egy katalógus repója GitHubon, Giteán vagy GitLabon, pl. github.com/valaki/app".into(),
|
||||
placeholder: "github.com/felhasználó/repó".into(),
|
||||
secret: false,
|
||||
submit_label: "Hozzáadás".into(),
|
||||
min_len: 5,
|
||||
max_len: 200,
|
||||
error,
|
||||
on_submit: Box::new(|text| {
|
||||
if let Some(s) = current() {
|
||||
s.add_source(text);
|
||||
}
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn add_source(&self, text: String) {
|
||||
let url = sf_ipc_canonical(&text);
|
||||
if !looks_like_repo(&url) {
|
||||
self.ask_source(Some("Ez nem egy repó címe (host/tulajdonos/repó).".into()));
|
||||
return;
|
||||
}
|
||||
if load_wanted().sources.iter().any(|s| sf_ipc_canonical(s) == url) {
|
||||
self.state.borrow_mut().notice = "Ez a forrás már szerepel.".into();
|
||||
self.rebuild(None);
|
||||
return;
|
||||
}
|
||||
// Kept as typed: a gitlab:/gitea: prefix tells sf-update the forge of a self-hosted server.
|
||||
let typed = text.trim().trim_end_matches('/').to_string();
|
||||
self.save(&format!("{} hozzáadva, az appjai hamarosan megjelennek.", pretty_source(&url)), |w| w.sources.push(typed));
|
||||
}
|
||||
|
||||
fn rebuild(&self, row: Option<i32>) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let (title, subtitle, rows, actions) = self.page();
|
||||
let len = rows.len() as i32;
|
||||
let in_sub = self.state.borrow().sub != Sub::None;
|
||||
let focused = self.state.borrow().actions.get(ui.get_set_row().max(0) as usize).cloned();
|
||||
let same_item = match (row, focused) {
|
||||
(None, Some(a)) if a != Action::None => actions.iter().position(|b| *b == a).map(|i| i as i32),
|
||||
_ => None,
|
||||
};
|
||||
self.state.borrow_mut().actions = actions;
|
||||
ui.set_set_title(title.into());
|
||||
ui.set_set_subtitle(subtitle.into());
|
||||
ui.set_set_rows(ModelRc::new(VecModel::from(rows)));
|
||||
ui.set_set_sub(in_sub);
|
||||
let target = row.or(same_item).unwrap_or_else(|| ui.get_set_row());
|
||||
ui.set_set_row(target.clamp(0, (len - 1).max(0)));
|
||||
}
|
||||
|
||||
fn page(&self) -> (String, String, Vec<SettingRow>, Vec<Action>) {
|
||||
let st = self.state.borrow();
|
||||
let mut rows = Vec::new();
|
||||
let mut actions = Vec::new();
|
||||
let mut push = |r: SettingRow, a: Action| {
|
||||
rows.push(r);
|
||||
actions.push(a);
|
||||
};
|
||||
let busy = st.status.as_ref().is_some_and(UpdateStatus::busy);
|
||||
let progress = st.status.as_ref().filter(|s| s.busy()).map(|s| match s.state.as_str() {
|
||||
"checking" => "Források lekérdezése…".to_string(),
|
||||
"downloading" => format!("Letöltés: {}", s.message),
|
||||
_ => "Telepítés…".to_string(),
|
||||
});
|
||||
let error = st.status.as_ref().filter(|s| s.state == "error").map(|s| format!("Hiba: {}", short(&s.message, 70)));
|
||||
let notice_or = |text: &str| progress.clone().or_else(|| (!st.notice.is_empty()).then(|| st.notice.clone())).or(error.clone()).unwrap_or_else(|| text.to_string());
|
||||
let catalog = st.catalog.clone().unwrap_or_default();
|
||||
|
||||
let (title, subtitle) = match (&st.sub, st.category) {
|
||||
(Sub::App(id), _) => match catalog.app(id) {
|
||||
None => {
|
||||
push(row("Vissza", "", "", "action"), Action::Back);
|
||||
(id.clone(), "Ez az app már nem érhető el a forrásaidban.".to_string())
|
||||
}
|
||||
Some(app) => {
|
||||
let want = st.wanted.apps.get(&app.id);
|
||||
let missing = want.map(|w| missing_permissions(&app.permissions, &w.permissions)).unwrap_or_default();
|
||||
match (&app.installed, want) {
|
||||
(None, None) => push(row(if busy { "Folyamatban…" } else { "Telepítés" }, "", "Az engedélyeket lent látod", "action"), Action::Install(app.id.clone())),
|
||||
(None, Some(_)) => push(row("Telepítés folyamatban…", "", "", "info"), Action::None),
|
||||
(Some(_), _) if !missing.is_empty() => push(
|
||||
row("Frissítés jóváhagyása", "", format!("Új engedélyt kér: {}", permissions_text(&missing)), "action"),
|
||||
Action::Approve(app.id.clone()),
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
let version = match &app.installed {
|
||||
Some(i) if i != &app.version => format!("{i} → {}", app.version),
|
||||
Some(i) => i.clone(),
|
||||
None => app.version.clone(),
|
||||
};
|
||||
push(row("Verzió", version, "", "info"), Action::None);
|
||||
for p in &app.permissions {
|
||||
let value = if p.risky() { "Kockázatos" } else { "" };
|
||||
push(row(p.label(), value, "Engedély", "info"), Action::None);
|
||||
}
|
||||
if app.permissions.is_empty() {
|
||||
push(row("Engedélyek", "Nem kér", "Csak a saját fájljait és a képernyőt éri el", "info"), Action::None);
|
||||
}
|
||||
if !app.author.is_empty() {
|
||||
push(row("Szerző", app.author.clone(), "", "info"), Action::None);
|
||||
}
|
||||
push(row("Forrás", pretty_source(&app.source), app.license.clone(), "info"), Action::None);
|
||||
if want.is_some() || app.installed.is_some() {
|
||||
push(row("Eltávolítás", "", "Az adatai megmaradnak", "danger"), Action::Uninstall(app.id.clone()));
|
||||
push(row("Eltávolítás az adataival együtt", "", "", "danger"), Action::UninstallWithData(app.id.clone()));
|
||||
}
|
||||
push(row("Vissza", "", "", "action"), Action::Back);
|
||||
let what = if app.category.is_empty() { String::new() } else { format!("{} · ", app.category) };
|
||||
(app.name.clone(), notice_or(&format!("{what}{}", app.description)))
|
||||
}
|
||||
},
|
||||
(Sub::Source(url), _) => {
|
||||
let info = catalog.sources.iter().find(|s| &s.url == url).cloned();
|
||||
push(row("Forrás eltávolítása", "", "Az innen telepített appok megmaradnak", "danger"), Action::RemoveSource(url.clone()));
|
||||
push(row("Vissza", "", "", "action"), Action::Back);
|
||||
let detail = match info {
|
||||
Some(i) if i.error.is_some() => format!("Hiba: {}", short(i.error.as_deref().unwrap_or(""), 80)),
|
||||
Some(i) if i.kind == "catalog" => format!("Katalógus · {} app", i.apps),
|
||||
Some(_) => "App-repó".to_string(),
|
||||
None => "Még nincs lekérdezve.".to_string(),
|
||||
};
|
||||
(pretty_source(url), detail)
|
||||
}
|
||||
(Sub::None, DISCOVER) => {
|
||||
let offer: Vec<&CatalogApp> = catalog.apps.iter().filter(|a| a.installed.is_none() && !st.wanted.apps.contains_key(&a.id)).collect();
|
||||
if st.wanted.sources.is_empty() && catalog.apps.is_empty() {
|
||||
push(row("Forrás hozzáadása", "", "GitHub, Gitea vagy GitLab repó", "action"), Action::AddSource);
|
||||
} else if offer.is_empty() {
|
||||
push(row("Nincs több telepíthető app", "", "Adj hozzá forrást a Források alatt", "info"), Action::None);
|
||||
}
|
||||
for a in offer {
|
||||
let detail = if a.category.is_empty() { pretty_source(&a.source) } else { a.category.clone() };
|
||||
push(row(a.name.clone(), a.version.clone(), detail, "choice"), Action::App(a.id.clone()));
|
||||
}
|
||||
("Felfedezés".to_string(), notice_or("Nyílt forrású appok a forrásaidból. Mindegyik a saját sandboxában fut."))
|
||||
}
|
||||
(Sub::None, INSTALLED) => {
|
||||
if st.wanted.apps.is_empty() {
|
||||
push(row("Még nincs telepített app", "", "", "info"), Action::None);
|
||||
}
|
||||
for (id, want) in &st.wanted.apps {
|
||||
let app = catalog.app(id);
|
||||
let name = app.map(|a| a.name.clone()).unwrap_or_else(|| id.clone());
|
||||
let (value, detail) = match app {
|
||||
None => ("…".to_string(), pretty_source(&want.source)),
|
||||
Some(a) if a.installed.is_none() => ("Telepítés…".to_string(), a.version.clone()),
|
||||
Some(a) if a.blocked.as_deref() == Some("permissions") => (a.installed.clone().unwrap_or_default(), "Új engedélyt kér · jóváhagyás".to_string()),
|
||||
Some(a) if a.installed.as_deref() != Some(a.version.as_str()) => {
|
||||
(format!("{} → {}", a.installed.clone().unwrap_or_default(), a.version), "Frissítés letöltés alatt".to_string())
|
||||
}
|
||||
Some(a) => (a.version.clone(), if a.category.is_empty() { pretty_source(&a.source) } else { a.category.clone() }),
|
||||
};
|
||||
push(row(name, value, detail, "choice"), Action::App(id.clone()));
|
||||
}
|
||||
("Telepítve".to_string(), notice_or("A store appok a többi csomaggal együtt frissülnek (Beállítások → Rendszer → Frissítések)."))
|
||||
}
|
||||
(Sub::None, _) => {
|
||||
push(row("Forrás hozzáadása", "", "GitHub, Gitea vagy GitLab repó", "action"), Action::AddSource);
|
||||
for url in &st.wanted.sources {
|
||||
let url = sf_ipc_canonical(url);
|
||||
let info = catalog.sources.iter().find(|s| s.url == url);
|
||||
let (value, detail) = match info {
|
||||
None => ("…".to_string(), "Lekérdezés…".to_string()),
|
||||
Some(i) if i.error.is_some() => ("Hiba".to_string(), short(i.error.as_deref().unwrap_or(""), 60)),
|
||||
Some(i) if i.kind == "catalog" => (format!("{} app", i.apps), if i.name.is_empty() { "Katalógus".into() } else { i.name.clone() }),
|
||||
Some(i) => ("App".to_string(), i.name.clone()),
|
||||
};
|
||||
push(row(pretty_source(&url), value, detail, "choice"), Action::Source(url.clone()));
|
||||
}
|
||||
let checked = if catalog.updated_at > 0 {
|
||||
use chrono::TimeZone;
|
||||
chrono::Local.timestamp_opt(catalog.updated_at as i64, 0).single().map(|t| t.format("Lekérdezve: %m. %d. %H:%M").to_string()).unwrap_or_default()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
push(row(if busy { "Folyamatban…" } else { "Frissítés most" }, "", checked, "action"), Action::Refresh);
|
||||
("Források".to_string(), notice_or("Minden app a saját repójában él. Egy katalógus-repó sok appot hoz egyszerre."))
|
||||
}
|
||||
};
|
||||
drop(push);
|
||||
(title, subtitle, rows, actions)
|
||||
}
|
||||
}
|
||||
|
||||
/// Ids of the installed store apps (folders under the store apps dir).
|
||||
fn installed_ids() -> Vec<String> {
|
||||
if system::demo() {
|
||||
return DEMO.with(|d| d.borrow().as_ref().map(|(w, _)| w.apps.keys().cloned().collect()).unwrap_or_default());
|
||||
}
|
||||
let mut ids: Vec<String> = std::fs::read_dir(sf_ipc::paths::STORE_APPS)
|
||||
.map(|d| d.flatten().filter(|e| e.path().join("app.toml").exists()).filter_map(|e| e.file_name().into_string().ok()).collect())
|
||||
.unwrap_or_default();
|
||||
ids.sort();
|
||||
ids
|
||||
}
|
||||
|
||||
/// `https://host/owner/repo` from what was typed: the same form sf-update
|
||||
/// uses in catalog.json (forge::Repo::url), so sources can be matched up.
|
||||
fn sf_ipc_canonical(input: &str) -> String {
|
||||
let s = input.trim();
|
||||
let (prefix, rest) = match s.split_once(':') {
|
||||
Some((p @ ("github" | "gitea" | "forgejo" | "gitlab"), r)) => (Some(p), r),
|
||||
_ => (None, s),
|
||||
};
|
||||
let rest = rest.trim_start_matches('/').trim_start_matches("https://").split(['?', '#']).next().unwrap_or("").trim_end_matches('/');
|
||||
let rest = rest.strip_suffix(".git").unwrap_or(rest);
|
||||
let (host, path) = rest.split_once('/').unwrap_or((rest, ""));
|
||||
match prefix {
|
||||
Some("github") if !host.contains('.') => format!("https://github.com/{rest}"),
|
||||
_ => format!("https://{}/{path}", host.to_ascii_lowercase()),
|
||||
}
|
||||
}
|
||||
|
||||
fn looks_like_repo(url: &str) -> bool {
|
||||
let rest = url.trim_start_matches("https://");
|
||||
let parts: Vec<&str> = rest.split('/').collect();
|
||||
parts.len() >= 3 && parts[0].contains('.') && parts.iter().all(|p| !p.is_empty() && !p.contains(' '))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn source_addresses() {
|
||||
assert_eq!(sf_ipc_canonical("github.com/fox/app.git"), "https://github.com/fox/app");
|
||||
assert_eq!(sf_ipc_canonical("github:fox/app"), "https://github.com/fox/app");
|
||||
assert_eq!(sf_ipc_canonical("gitlab:Git.x.org/a/b/"), "https://git.x.org/a/b");
|
||||
assert!(looks_like_repo("https://github.com/fox/app"));
|
||||
assert!(looks_like_repo(&sf_ipc_canonical("gitlab:git.x.org/a/b")));
|
||||
assert!(!looks_like_repo("https://github.com/fox"));
|
||||
assert!(!looks_like_repo("https://hello"));
|
||||
}
|
||||
}
|
||||
@@ -439,6 +439,142 @@ pub fn bt_remove(addr: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ---- audio ---------------------------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AudioOutput {
|
||||
pub name: String,
|
||||
pub label: String,
|
||||
pub bluetooth: bool,
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BtAudioDevice {
|
||||
pub address: String,
|
||||
pub name: String,
|
||||
pub paired: bool,
|
||||
pub connected: bool,
|
||||
}
|
||||
|
||||
static DEMO_AUDIO: Mutex<Option<String>> = Mutex::new(None);
|
||||
|
||||
pub fn audio_outputs() -> Result<Vec<AudioOutput>> {
|
||||
if demo() {
|
||||
let selected = DEMO_AUDIO.lock().unwrap().clone().unwrap_or_else(|| "hdmi".into());
|
||||
return Ok(vec![
|
||||
AudioOutput { name: "hdmi".into(), label: "TV · HDMI".into(), bluetooth: false, selected: selected == "hdmi" },
|
||||
AudioOutput { name: "airpods".into(), label: "AirPods Pro".into(), bluetooth: true, selected: selected == "airpods" },
|
||||
]);
|
||||
}
|
||||
let t = Duration::from_secs(4);
|
||||
let default = run("pactl", &["get-default-sink"], t)?.trim().to_string();
|
||||
let json = run("pactl", &["--format=json", "list", "sinks"], t)?;
|
||||
let sinks: serde_json::Value = serde_json::from_str(&json).context("parsing audio outputs")?;
|
||||
let sinks = sinks.as_array().context("audio outputs are not a list")?;
|
||||
let mut outputs = Vec::new();
|
||||
for sink in sinks {
|
||||
let Some(name) = sink.get("name").and_then(|v| v.as_str()) else { continue };
|
||||
if name == "auto_null" { continue; }
|
||||
let label = sink.get("description").and_then(|v| v.as_str()).unwrap_or(name).to_string();
|
||||
let bluetooth = name.starts_with("bluez_output.");
|
||||
outputs.push(AudioOutput { name: name.into(), label, bluetooth, selected: name == default });
|
||||
}
|
||||
outputs.sort_by_key(|o| (!o.selected, o.bluetooth, o.label.to_lowercase()));
|
||||
Ok(outputs)
|
||||
}
|
||||
|
||||
pub fn set_audio_output(name: &str) -> Result<()> {
|
||||
if demo() {
|
||||
*DEMO_AUDIO.lock().unwrap() = Some(name.into());
|
||||
return Ok(());
|
||||
}
|
||||
// Only accept a sink currently reported by PipeWire.
|
||||
if !audio_outputs()?.iter().any(|o| o.name == name) {
|
||||
bail!("A hangkimenet már nem érhető el");
|
||||
}
|
||||
run("pactl", &["set-default-sink", name], Duration::from_secs(4))?;
|
||||
// Move streams that were already playing when the output changed.
|
||||
if let Ok(streams) = run("pactl", &["list", "short", "sink-inputs"], Duration::from_secs(4)) {
|
||||
for line in streams.lines() {
|
||||
if let Some(index) = line.split_whitespace().next().filter(|s| s.parse::<u32>().is_ok()) {
|
||||
if let Err(e) = run("pactl", &["move-sink-input", index, name], Duration::from_secs(4)) {
|
||||
log::warn!("moving audio stream {index}: {e:#}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn audio_device_info(addr: &str, fallback: &str, info: &str) -> Option<BtAudioDevice> {
|
||||
let device = parse_info(addr, fallback, info);
|
||||
let audio = ["audio-headphones", "audio-headset", "audio-card", "audio-speakers"]
|
||||
.contains(&device.icon.as_str())
|
||||
|| info.lines().any(|line| line.contains("Audio Sink") || line.contains("0000110b"));
|
||||
(audio && !device.remote).then(|| BtAudioDevice {
|
||||
address: addr.into(), name: device.name,
|
||||
paired: info.lines().any(|line| line.trim() == "Paired: yes"),
|
||||
connected: device.connected,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bt_audio_devices() -> Result<Vec<BtAudioDevice>> {
|
||||
if demo() {
|
||||
return Ok(vec![BtAudioDevice { address: "4C:87:5D:0E:22:9B".into(), name: "AirPods Pro".into(), paired: true, connected: false }]);
|
||||
}
|
||||
let t = Duration::from_secs(4);
|
||||
let list = run("bluetoothctl", &["devices"], t)?;
|
||||
let mut devices = Vec::new();
|
||||
for (addr, name) in parse_device_list(&list) {
|
||||
let info = run("bluetoothctl", &["info", &addr], t).unwrap_or_default();
|
||||
if let Some(device) = audio_device_info(&addr, &name, &info) {
|
||||
devices.push(device);
|
||||
}
|
||||
}
|
||||
devices.sort_by_key(|d| (!d.connected, !d.paired, d.name.to_lowercase()));
|
||||
Ok(devices)
|
||||
}
|
||||
|
||||
pub fn bt_audio_scan() -> Result<Vec<BtAudioDevice>> {
|
||||
if !demo() {
|
||||
// Keep scanning long enough for headphones in pairing mode to appear.
|
||||
let result = run("bluetoothctl", &["--timeout", "8", "scan", "on"], Duration::from_secs(10))?;
|
||||
if result.contains("Failed") || result.contains("No default controller") {
|
||||
bail!("{}", result.trim());
|
||||
}
|
||||
}
|
||||
bt_audio_devices()
|
||||
}
|
||||
|
||||
pub fn bt_audio_connect(addr: &str) -> Result<()> {
|
||||
if demo() {
|
||||
*DEMO_AUDIO.lock().unwrap() = Some("airpods".into());
|
||||
return Ok(());
|
||||
}
|
||||
if !is_mac(addr) { bail!("Érvénytelen Bluetooth cím"); }
|
||||
let t = Duration::from_secs(25);
|
||||
let info = run("bluetoothctl", &["info", addr], Duration::from_secs(4))?;
|
||||
if !info.lines().any(|line| line.trim() == "Paired: yes") {
|
||||
let result = run("bluetoothctl", &["pair", addr], t)?;
|
||||
if result.contains("Failed") { bail!("{}", result.trim()); }
|
||||
}
|
||||
let trust = run("bluetoothctl", &["trust", addr], Duration::from_secs(5))?;
|
||||
if trust.contains("Failed") { bail!("{}", trust.trim()); }
|
||||
let result = run("bluetoothctl", &["connect", addr], t)?;
|
||||
if result.contains("Failed") && !result.contains("AlreadyConnected") { bail!("{}", result.trim()); }
|
||||
let sink_prefix = format!("bluez_output.{}", addr.replace(':', "_")).to_ascii_uppercase();
|
||||
for _ in 0..20 {
|
||||
if let Ok(outputs) = audio_outputs() {
|
||||
if let Some(output) = outputs.iter().find(|o| o.name.to_ascii_uppercase().starts_with(&sink_prefix)) {
|
||||
return set_audio_output(&output.name);
|
||||
}
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
}
|
||||
bail!("A Bluetooth eszköz csatlakozott, de még nem jelent meg hangkimenetként")
|
||||
}
|
||||
|
||||
// ---- network & device info -------------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -877,7 +1013,7 @@ pub struct UpdateStatus {
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct UpdatePackage {
|
||||
/// Display name ("SmartFox felület", "YouTube").
|
||||
/// Display name ("Fennec OS felület", "YouTube").
|
||||
pub title: String,
|
||||
pub installed: String,
|
||||
pub available: Option<String>,
|
||||
@@ -906,14 +1042,14 @@ impl UpdateStatus {
|
||||
}
|
||||
}
|
||||
|
||||
/// "sf-shell" -> "SmartFox felület", "sf-app-youtube" -> the app's name.
|
||||
/// "sf-shell" -> "Fennec OS felület", "sf-app-youtube" -> the app's name.
|
||||
fn package_title(name: &str) -> String {
|
||||
if name == "sf-shell" {
|
||||
return "SmartFox felület".into();
|
||||
return "Fennec OS felület".into();
|
||||
}
|
||||
let id = name.strip_prefix("sf-app-").unwrap_or(name);
|
||||
let id = name.strip_prefix("sf-app-").or_else(|| name.strip_prefix(sf_ipc::store::PACKAGE_PREFIX)).unwrap_or(name);
|
||||
let dirs = [PathBuf::from("/usr/share/smartfox/apps"), PathBuf::from("/var/lib/sf-pkg/apps")];
|
||||
sf_ipc::manifest::load_apps_from(&dirs)
|
||||
sf_ipc::manifest::load_all(&dirs, Some(Path::new(sf_ipc::paths::STORE_APPS)))
|
||||
.ok()
|
||||
.and_then(|apps| apps.into_iter().find(|a| a.id == id).map(|a| a.name))
|
||||
.unwrap_or_else(|| id.to_string())
|
||||
@@ -930,8 +1066,8 @@ pub fn update_status() -> Option<UpdateStatus> {
|
||||
staged: None,
|
||||
};
|
||||
let packages = match step {
|
||||
0 => vec![pkg("SmartFox felület", "0.1.0", "0.2.0"), pkg("YouTube", "1.0.0", "1.1.0"), pkg("Netflex", "1.0.0", "1.0.0")],
|
||||
_ => vec![pkg("SmartFox felület", "0.2.0", "0.2.0"), pkg("YouTube", "1.1.0", "1.1.0")],
|
||||
0 => vec![pkg("Fennec OS felület", "0.1.0", "0.2.0"), pkg("YouTube", "1.0.0", "1.1.0"), pkg("Netflex", "1.0.0", "1.0.0")],
|
||||
_ => vec![pkg("Fennec OS felület", "0.2.0", "0.2.0"), pkg("YouTube", "1.1.0", "1.1.0")],
|
||||
};
|
||||
return Some(UpdateStatus { state: "idle".into(), message: String::new(), checked_at: 1_792_800_000, packages });
|
||||
}
|
||||
@@ -1021,6 +1157,16 @@ mod tests {
|
||||
assert_eq!(d.name, "Nappali távirányító");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identifies_only_bluetooth_audio_devices() {
|
||||
let headphones = "Alias: AirPods Pro\nIcon: audio-headphones\nPaired: yes\nConnected: no\n";
|
||||
let audio = audio_device_info("4C:87:5D:0E:22:9B", "AirPods", headphones).unwrap();
|
||||
assert_eq!(audio.name, "AirPods Pro");
|
||||
assert!(audio.paired && !audio.connected);
|
||||
let remote = "Icon: input-gaming\nModalias: bluetooth:v004Cp0315d0001\nPaired: yes\n";
|
||||
assert!(audio_device_info("F0:B3:EC:12:7A:41", "Siri Remote", remote).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_iwd_objects() {
|
||||
let objects: serde_json::Value = serde_json::from_str(
|
||||
|
||||
@@ -86,11 +86,12 @@ pub fn reveal_when_ready(pid: u32, not_before: Instant, on_shown: impl FnOnce()
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(30));
|
||||
}
|
||||
let fade = Duration::from_millis(340);
|
||||
// Same crossfade as sf-compositor on the TV.
|
||||
let fade = Duration::from_millis(560);
|
||||
let t0 = Instant::now();
|
||||
while t0.elapsed() < fade {
|
||||
let x = t0.elapsed().as_secs_f32() / fade.as_secs_f32();
|
||||
let eased = 1.0 - (1.0 - x).powi(3);
|
||||
let eased = if x < 0.5 { 4.0 * x * x * x } else { 1.0 - (-2.0 * x + 2.0).powi(3) / 2.0 };
|
||||
set_alpha(hwnd, (eased * 255.0) as u8);
|
||||
std::thread::sleep(Duration::from_millis(8));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,92 +0,0 @@
|
||||
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION AND CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -3,6 +3,59 @@
|
||||
export component AppIcon inherits Rectangle {
|
||||
in property <string> icon;
|
||||
in property <color> ink: #ffffff;
|
||||
// Store apps bring their own picture (app.toml: icon = "icon.png").
|
||||
in property <image> image;
|
||||
in property <bool> has-image: false;
|
||||
// No picture and no built-in icon: the app name's first letter.
|
||||
in property <string> letter;
|
||||
property <bool> builtin: root.icon == "netflex" || root.icon == "youtube" || root.icon == "airplay" || root.icon == "miracast" || root.icon == "settings" || root.icon == "store" || root.icon == "steam";
|
||||
|
||||
if root.has-image: Image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
source: root.image;
|
||||
image-fit: contain;
|
||||
}
|
||||
|
||||
if !root.has-image && !root.builtin: Text {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
text: root.letter;
|
||||
font-size: root.height * 0.72;
|
||||
font-weight: 700;
|
||||
color: root.ink;
|
||||
}
|
||||
|
||||
if root.icon == "store": Rectangle {
|
||||
// App Store: a shopping bag with a handle.
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M6.5 11h19l-1.4 15a2.5 2.5 0 0 1-2.5 2.3H10.4a2.5 2.5 0 0 1-2.5-2.3z";
|
||||
fill: @linear-gradient(180deg, #8cc4ff 0%, #3d7fe0 100%);
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M11.5 14V9.5a4.5 4.5 0 0 1 9 0V14";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.4px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
if root.icon == "steam": Rectangle {
|
||||
// Steam mark: the piston and valve in a disc (Simple Icons, CC0).
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-x: -3; viewbox-y: -3;
|
||||
viewbox-width: 30; viewbox-height: 30;
|
||||
commands: "M11.979 0C5.678 0 .511 4.86.022 11.037l6.432 2.658c.545-.371 1.203-.59 1.912-.59.063 0 .125.004.188.006l2.861-4.142V8.91c0-2.495 2.028-4.524 4.524-4.524 2.494 0 4.524 2.031 4.524 4.527s-2.03 4.525-4.524 4.525h-.105l-4.076 2.911c0 .052.004.105.004.159 0 1.875-1.515 3.396-3.39 3.396-1.635 0-3.016-1.173-3.331-2.727L.436 15.27C1.862 20.307 6.486 24 11.979 24c6.627 0 11.999-5.373 11.999-12S18.605 0 11.979 0zM7.54 18.21l-1.473-.61c.262.543.714.999 1.314 1.25 1.297.539 2.793-.076 3.332-1.375.263-.63.264-1.319.005-1.949s-.75-1.121-1.377-1.383c-.624-.26-1.29-.249-1.878-.03l1.523.63c.956.4 1.409 1.5 1.009 2.455-.397.957-1.497 1.41-2.454 1.012H7.54zm11.415-9.303c0-1.662-1.353-3.015-3.015-3.015-1.665 0-3.015 1.353-3.015 3.015 0 1.665 1.35 3.015 3.015 3.015 1.663 0 3.015-1.35 3.015-3.015zm-5.273-.005c0-1.252 1.013-2.266 2.265-2.266 1.249 0 2.266 1.014 2.266 2.266 0 1.251-1.017 2.265-2.266 2.265-1.253 0-2.265-1.014-2.265-2.265z";
|
||||
fill: @linear-gradient(160deg, #ffffff 0%, #c7e4f8 100%);
|
||||
}
|
||||
}
|
||||
|
||||
if root.icon == "netflex": Rectangle {
|
||||
// Netflex mark: mirrored "N" in three ribbons (from netflex/apps/web/public/favicon.svg).
|
||||
@@ -107,7 +160,7 @@ export component AppIcon inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// SmartFox brand mark: a geometric fox head.
|
||||
// Fennec OS brand mark: a geometric fox head.
|
||||
export component FoxMark inherits Rectangle {
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
@@ -293,3 +346,273 @@ export component PowerIcon inherits Rectangle {
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component AudioIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M5 12h6l7-6v20l-7-6H5zM22 12a6 6 0 0 1 0 8M25 8a11 11 0 0 1 0 16";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
// Siri Remote, front view (status capsule, facts).
|
||||
export component RemoteIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M12.5 3h7a3 3 0 0 1 3 3v20a3 3 0 0 1-3 3h-7a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3z";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M12.6 10.5a3.4 3.4 0 1 0 6.8 0a3.4 3.4 0 1 0-6.8 0zM13.5 18.5a1.3 1.3 0 1 0 2.6 0a1.3 1.3 0 1 0-2.6 0zM15.9 18.5a1.3 1.3 0 1 0 2.6 0a1.3 1.3 0 1 0-2.6 0z";
|
||||
fill: root.ink;
|
||||
}
|
||||
}
|
||||
|
||||
// Wired network (ethernet plug).
|
||||
export component WiredIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M9 6h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-3v4h-8v-4H9a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2zM16 23v5M12.5 10.5v3M16 10.5v3M19.5 10.5v3";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
// Cast from a phone: screen with broadcast arcs in the corner.
|
||||
export component CastIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M4 11V8.5A2.5 2.5 0 0 1 6.5 6h19A2.5 2.5 0 0 1 28 8.5v15a2.5 2.5 0 0 1-2.5 2.5H17M4 16.5a9.5 9.5 0 0 1 9.5 9.5M4 21.5a4.5 4.5 0 0 1 4.5 4.5";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M3 26a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0z";
|
||||
fill: root.ink;
|
||||
}
|
||||
}
|
||||
|
||||
// Home media server.
|
||||
export component ServerIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M7 5h18a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM7 18h18a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2z";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M9.5 9.5a1.4 1.4 0 1 0 2.8 0a1.4 1.4 0 1 0-2.8 0zM9.5 22.5a1.4 1.4 0 1 0 2.8 0a1.4 1.4 0 1 0-2.8 0z";
|
||||
fill: root.ink;
|
||||
}
|
||||
}
|
||||
|
||||
export component CheckIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M7 16.5l6 6L25.5 10";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component AlertIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M16 8v10";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M14.2 24a1.8 1.8 0 1 0 3.6 0a1.8 1.8 0 1 0-3.6 0z";
|
||||
fill: root.ink;
|
||||
}
|
||||
}
|
||||
|
||||
export component ChevronIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M12 7l9 9-9 9";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.6px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
// Remote buttons in the pairing drawing.
|
||||
export component BackGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M19 8l-8 8 8 8";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component TvGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M7.5 8h17a1.5 1.5 0 0 1 1.5 1.5v11a1.5 1.5 0 0 1-1.5 1.5h-17A1.5 1.5 0 0 1 6 20.5v-11A1.5 1.5 0 0 1 7.5 8zM12 25.5h8";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.6px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component PlayPauseGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M6 9.5v13l9-6.5z";
|
||||
fill: root.ink;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M19.5 10v12M25 10v12";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.8px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component MuteGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M5 12.5h4.5L16 7v18l-6.5-5.5H5z";
|
||||
fill: root.ink;
|
||||
}
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M20.5 12.5l7 7M27.5 12.5l-7 7";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.6px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component PlusGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M16 8v16M8 16h16";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component MinusGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M8 16h16";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component PowerGlyph inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M10.3 9.6a9 9 0 1 0 11.4 0M16 5.5v10";
|
||||
stroke: root.ink;
|
||||
stroke-width: 3px;
|
||||
stroke-line-cap: round;
|
||||
}
|
||||
}
|
||||
|
||||
// One icon by name, for data-driven rows (home screen facts).
|
||||
export component NamedIcon inherits Rectangle {
|
||||
in property <string> name;
|
||||
in property <color> ink: #ffffff;
|
||||
if root.name == "remote": RemoteIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "wifi": WifiIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "wired": WiredIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "display": DisplayIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "cast": CastIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "server": ServerIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "check": CheckIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "alert": AlertIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.name == "bluetooth": BluetoothIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
}
|
||||
|
||||
// Store screen categories (settings.slint NavIcon 5..7).
|
||||
export component StoreIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M6.5 11h19l-1.4 15a2.5 2.5 0 0 1-2.5 2.3H10.4a2.5 2.5 0 0 1-2.5-2.3zM11.5 14V9.5a4.5 4.5 0 0 1 9 0V14";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.2px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
export component LinkIcon inherits Rectangle {
|
||||
in property <color> ink: #ffffff;
|
||||
Path {
|
||||
width: 100%; height: 100%;
|
||||
viewbox-width: 32; viewbox-height: 32;
|
||||
commands: "M14 18a5 5 0 0 0 7.1 0l4-4a5 5 0 0 0-7.1-7.1l-1.5 1.5M18 14a5 5 0 0 0-7.1 0l-4 4a5 5 0 0 0 7.1 7.1l1.5-1.5";
|
||||
stroke: root.ink;
|
||||
stroke-width: 2.4px;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// On-screen keyboard in the tvOS style: one horizontal row of characters,
|
||||
// the text field above it and the mode chips below.
|
||||
//
|
||||
// Drawn inside the settings pane, which stays; the settings content fades out.
|
||||
// Opens in place of the settings content, which fades out.
|
||||
// Only text and icons are drawn here. The glass (field, key track, focus lens,
|
||||
// chips) comes from `keyboard::glass` in Rust, which mirrors the geometry the
|
||||
// App exports (kb-* properties): keep the two in sync.
|
||||
@@ -16,7 +16,6 @@ export component KeyboardView inherits Rectangle {
|
||||
in property <length> pane-y;
|
||||
in property <length> pane-w;
|
||||
in property <length> pane-h;
|
||||
in property <length> back-x;
|
||||
in property <length> field-x;
|
||||
in property <length> field-y;
|
||||
in property <length> field-w;
|
||||
@@ -50,24 +49,23 @@ export component KeyboardView inherits Rectangle {
|
||||
// ---- heading ----------------------------------------------------------
|
||||
Text {
|
||||
x: root.pane-x;
|
||||
y: root.pane-y + 58 * root.u;
|
||||
y: root.pane-y + 88 * root.u;
|
||||
width: root.pane-w;
|
||||
horizontal-alignment: center;
|
||||
text: root.title;
|
||||
font-family: "Inter Display";
|
||||
font-weight: 800;
|
||||
font-size: 46 * root.u;
|
||||
letter-spacing: -1.2 * root.u;
|
||||
font-weight: 700;
|
||||
font-size: 48 * root.u;
|
||||
letter-spacing: -0.8 * root.u;
|
||||
color: #ffffff;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
x: root.pane-x + 80 * root.u;
|
||||
y: root.pane-y + 128 * root.u;
|
||||
y: root.pane-y + 160 * root.u;
|
||||
width: root.pane-w - 160 * root.u;
|
||||
horizontal-alignment: center;
|
||||
text: root.subtitle;
|
||||
font-size: 23 * root.u;
|
||||
font-size: 24 * root.u;
|
||||
color: #ffffffa8;
|
||||
overflow: elide;
|
||||
}
|
||||
@@ -114,12 +112,12 @@ export component KeyboardView inherits Rectangle {
|
||||
}
|
||||
Text {
|
||||
x: root.field-x;
|
||||
y: root.field-y + root.field-h + 18 * root.u;
|
||||
y: root.field-y + root.field-h + 20 * root.u;
|
||||
width: root.field-w;
|
||||
horizontal-alignment: center;
|
||||
text: root.hint;
|
||||
font-size: 21 * root.u;
|
||||
color: root.hint-error ? #ff8278 : #ffffff8c;
|
||||
font-size: 22 * root.u;
|
||||
color: root.hint-error ? #ff8278 : #ffffff99;
|
||||
}
|
||||
|
||||
// ---- key row ---------------------------------------------------------------
|
||||
@@ -175,16 +173,4 @@ export component KeyboardView inherits Rectangle {
|
||||
: self.f > 0.5 ? #121317 : self.selected ? #ff9a5c : #ffffffc8;
|
||||
}
|
||||
|
||||
Text {
|
||||
x: root.back-x;
|
||||
y: root.pane-y + root.pane-h - 92 * root.u;
|
||||
width: 300 * root.u;
|
||||
height: 56 * root.u;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
text: "‹ Mégse · Vissza";
|
||||
font-size: 21 * root.u;
|
||||
font-weight: 500;
|
||||
color: #ffffffc0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// First-run pairing guide for the Apple Siri Remote. The frosted pane behind
|
||||
// it is drawn by the glass layer (see `glass-over` in app.slint).
|
||||
|
||||
import { BackGlyph, TvGlyph, PlayPauseGlyph, MuteGlyph, PlusGlyph, MinusGlyph, PowerGlyph, CheckIcon, AlertIcon } from "icons.slint";
|
||||
|
||||
// Pulsing ring that draws the eye to a button.
|
||||
component Pulse inherits Rectangle {
|
||||
in property <length> size;
|
||||
@@ -17,9 +19,12 @@ component Pulse inherits Rectangle {
|
||||
|
||||
component RemoteButton inherits Rectangle {
|
||||
in property <length> u;
|
||||
// back | tv | playpause | mute | plus
|
||||
in property <string> glyph;
|
||||
in property <bool> hot;
|
||||
in property <color> accent;
|
||||
property <color> ink: self.hot ? self.accent.brighter(0.5) : #e8e8ea;
|
||||
property <length> g: 26 * self.u;
|
||||
width: 52 * self.u;
|
||||
height: self.width;
|
||||
border-radius: self.width / 2;
|
||||
@@ -40,14 +45,11 @@ component RemoteButton inherits Rectangle {
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.glyph;
|
||||
color: root.hot ? root.accent.brighter(0.5) : #e8e8ea;
|
||||
font-size: 24 * root.u;
|
||||
font-weight: 600;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if root.glyph == "back": BackGlyph { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: root.g; height: root.g; ink: root.ink; }
|
||||
if root.glyph == "tv": TvGlyph { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: root.g; height: root.g; ink: root.ink; }
|
||||
if root.glyph == "playpause": PlayPauseGlyph { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: root.g; height: root.g; ink: root.ink; }
|
||||
if root.glyph == "mute": MuteGlyph { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: root.g; height: root.g; ink: root.ink; }
|
||||
if root.glyph == "plus": PlusGlyph { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: root.g; height: root.g; ink: root.ink; }
|
||||
}
|
||||
|
||||
// Apple Siri Remote (2nd gen, aluminium), drawn front-on.
|
||||
@@ -57,7 +59,9 @@ export component SiriRemote inherits Rectangle {
|
||||
width: 150 * self.u;
|
||||
height: 560 * self.u;
|
||||
border-radius: 44 * self.u;
|
||||
background: @linear-gradient(90deg, #8d929a 0%, #d9dde2 22%, #f1f3f5 45%, #c6cad0 75%, #959aa2 100%);
|
||||
background: #c4c8ce;
|
||||
border-width: 2px;
|
||||
border-color: #ffffff40;
|
||||
drop-shadow-blur: 30 * self.u;
|
||||
drop-shadow-color: #000000a0;
|
||||
drop-shadow-offset-y: 16 * self.u;
|
||||
@@ -79,12 +83,12 @@ export component SiriRemote inherits Rectangle {
|
||||
height: 18 * root.u;
|
||||
border-radius: self.width / 2;
|
||||
background: #1b1b1d;
|
||||
Text {
|
||||
text: "⏻";
|
||||
color: #d0d0d4;
|
||||
font-size: 11 * root.u;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
PowerGlyph {
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 12 * root.u;
|
||||
height: 12 * root.u;
|
||||
ink: #d0d0d4;
|
||||
}
|
||||
}
|
||||
// Clickpad: outer touch ring and center.
|
||||
@@ -118,10 +122,10 @@ export component SiriRemote inherits Rectangle {
|
||||
// Button grid below the clickpad.
|
||||
property <length> col1: 18 * root.u;
|
||||
property <length> col2: root.width - 18 * root.u - 52 * root.u;
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 200 * root.u; glyph: "‹"; hot: true; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col2; y: 200 * root.u; glyph: "▭"; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 268 * root.u; glyph: "⏯"; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 336 * root.u; glyph: "🔇"; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 200 * root.u; glyph: "back"; hot: true; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col2; y: 200 * root.u; glyph: "tv"; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 268 * root.u; glyph: "playpause"; }
|
||||
RemoteButton { u: root.u; accent: root.accent; x: root.col1; y: 336 * root.u; glyph: "mute"; }
|
||||
// Volume rocker: + is the one to hold.
|
||||
Rectangle {
|
||||
x: root.col2;
|
||||
@@ -135,19 +139,16 @@ export component SiriRemote inherits Rectangle {
|
||||
accent: root.accent;
|
||||
x: 0;
|
||||
y: 0;
|
||||
glyph: "+";
|
||||
glyph: "plus";
|
||||
hot: true;
|
||||
background: transparent;
|
||||
}
|
||||
Text {
|
||||
y: parent.height - 52 * root.u;
|
||||
width: parent.width;
|
||||
height: 52 * root.u;
|
||||
text: "−";
|
||||
color: #e8e8ea;
|
||||
font-size: 24 * root.u;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
MinusGlyph {
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: parent.height - 52 * root.u + (52 * root.u - self.height) / 2;
|
||||
width: 26 * root.u;
|
||||
height: 26 * root.u;
|
||||
ink: #e8e8ea;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,81 +158,76 @@ component Step inherits Rectangle {
|
||||
in property <int> n;
|
||||
in property <string> label;
|
||||
in property <color> accent;
|
||||
height: 70 * self.u;
|
||||
Rectangle {
|
||||
// The glass bead behind the number is drawn by the glass layer (app.slint),
|
||||
// on the same 48 px square.
|
||||
Text {
|
||||
x: 0;
|
||||
y: 4 * root.u;
|
||||
width: 40 * root.u;
|
||||
height: self.width;
|
||||
// The glass bead behind the number is drawn by the glass layer (app.slint).
|
||||
Text {
|
||||
text: root.n;
|
||||
color: root.accent.brighter(0.6);
|
||||
font-size: 20 * root.u;
|
||||
font-weight: 700;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
y: 0;
|
||||
width: 48 * root.u;
|
||||
height: 48 * root.u;
|
||||
text: root.n;
|
||||
color: root.accent.brighter(0.6);
|
||||
font-size: 22 * root.u;
|
||||
font-weight: 700;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
x: 60 * root.u;
|
||||
y: 10 * root.u;
|
||||
width: parent.width - 60 * root.u;
|
||||
x: 72 * root.u;
|
||||
y: 6 * root.u;
|
||||
width: parent.width - 72 * root.u;
|
||||
text: root.label;
|
||||
wrap: word-wrap;
|
||||
font-size: 24 * root.u;
|
||||
color: #ffffffd8;
|
||||
font-size: 26 * root.u;
|
||||
color: #ffffffe0;
|
||||
}
|
||||
}
|
||||
|
||||
// Pane content; `state` is the remote status from sf-remote.
|
||||
// Pane content; `state` is the remote status from sf-remote. The text column
|
||||
// starts at (content-x, content-y); `steps` and `pill-y` are offsets from
|
||||
// there, shared with the glass beads and pills in app.slint.
|
||||
export component PairingGuide inherits Rectangle {
|
||||
in property <length> u;
|
||||
in property <string> state;
|
||||
in property <color> accent: #ff7a35;
|
||||
in property <length> content-x;
|
||||
in property <length> content-y;
|
||||
in property <[length]> steps;
|
||||
in property <length> pill-y;
|
||||
property <bool> ok: self.state == "paired" || self.state == "connected";
|
||||
property <bool> broken: self.state == "no-adapter";
|
||||
|
||||
SiriRemote {
|
||||
u: root.u;
|
||||
accent: root.accent;
|
||||
x: 120 * root.u;
|
||||
x: (root.content-x - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
x: 420 * root.u;
|
||||
y: 70 * root.u;
|
||||
width: parent.width - 420 * root.u - 80 * root.u;
|
||||
height: parent.height - 140 * root.u;
|
||||
x: root.content-x;
|
||||
y: root.content-y;
|
||||
width: parent.width - root.content-x - 88 * root.u;
|
||||
height: parent.height - root.content-y;
|
||||
|
||||
Text {
|
||||
x: 0;
|
||||
y: 0;
|
||||
text: "ELSŐ LÉPÉS";
|
||||
font-size: 20 * root.u;
|
||||
font-weight: 600;
|
||||
letter-spacing: 3 * root.u;
|
||||
color: root.accent.brighter(0.3);
|
||||
}
|
||||
Text {
|
||||
x: 0;
|
||||
y: 34 * root.u;
|
||||
width: parent.width;
|
||||
text: "Párosítsd a Siri Remote-ot";
|
||||
wrap: word-wrap;
|
||||
font-family: "Inter Display";
|
||||
font-weight: 800;
|
||||
font-size: 58 * root.u;
|
||||
letter-spacing: -1.6 * root.u;
|
||||
font-weight: 700;
|
||||
font-size: 52 * root.u;
|
||||
letter-spacing: -1 * root.u;
|
||||
color: #ffffff;
|
||||
overflow: elide;
|
||||
}
|
||||
Step {
|
||||
u: root.u;
|
||||
accent: root.accent;
|
||||
x: 0;
|
||||
y: 150 * root.u;
|
||||
y: root.steps[0];
|
||||
width: parent.width;
|
||||
height: 64 * root.u;
|
||||
n: 1;
|
||||
label: "Vidd a távirányítót a TV közelébe.";
|
||||
}
|
||||
@@ -239,33 +235,34 @@ export component PairingGuide inherits Rectangle {
|
||||
u: root.u;
|
||||
accent: root.accent;
|
||||
x: 0;
|
||||
y: 226 * root.u;
|
||||
y: root.steps[1];
|
||||
width: parent.width;
|
||||
height: 100 * root.u;
|
||||
n: 2;
|
||||
label: "Tartsd nyomva egyszerre a Vissza (‹) és a Hangerő + gombot kb. 5 másodpercig.";
|
||||
label: "Tartsd nyomva egyszerre a Vissza és a Hangerő + gombot, kb. 5 másodpercig.";
|
||||
}
|
||||
Step {
|
||||
u: root.u;
|
||||
accent: root.accent;
|
||||
x: 0;
|
||||
y: 330 * root.u;
|
||||
y: root.steps[2];
|
||||
width: parent.width;
|
||||
height: 64 * root.u;
|
||||
n: 3;
|
||||
label: "Engedd el. A TV magától megtalálja és párosítja.";
|
||||
}
|
||||
|
||||
// Live status.
|
||||
// Live status, on the glass pill drawn by app.slint (520 x 64).
|
||||
Rectangle {
|
||||
x: 0;
|
||||
y: parent.height - 70 * root.u;
|
||||
y: root.pill-y;
|
||||
width: 520 * root.u;
|
||||
height: 64 * root.u;
|
||||
// Glass pill (tinted by state) is drawn by the glass layer (app.slint).
|
||||
|
||||
// Searching: three breathing dots. Done: check mark. Error: "!".
|
||||
// Searching: three breathing dots. Done: check mark. Error: alert.
|
||||
if !root.ok && !root.broken: HorizontalLayout {
|
||||
x: 26 * root.u;
|
||||
width: 60 * root.u;
|
||||
x: 0;
|
||||
width: 56 * root.u;
|
||||
spacing: 8 * root.u;
|
||||
alignment: start;
|
||||
for i in 3: Rectangle {
|
||||
@@ -278,41 +275,47 @@ export component PairingGuide inherits Rectangle {
|
||||
opacity: 0.25 + 0.75 * abs(sin(self.p * 180deg));
|
||||
}
|
||||
}
|
||||
if root.ok || root.broken: Text {
|
||||
x: 26 * root.u;
|
||||
width: 40 * root.u;
|
||||
height: parent.height;
|
||||
text: root.ok ? "✓" : "!";
|
||||
color: root.ok ? #34c759 : #ff9f0a;
|
||||
font-size: 30 * root.u;
|
||||
font-weight: 800;
|
||||
vertical-alignment: center;
|
||||
if root.ok: CheckIcon {
|
||||
x: 24 * root.u;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 32 * root.u;
|
||||
height: 32 * root.u;
|
||||
ink: #34c759;
|
||||
}
|
||||
if root.broken: AlertIcon {
|
||||
x: 24 * root.u;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 32 * root.u;
|
||||
height: 32 * root.u;
|
||||
ink: #ff9f0a;
|
||||
}
|
||||
Text {
|
||||
x: 92 * root.u;
|
||||
width: parent.width - 110 * root.u;
|
||||
x: root.ok || root.broken ? 72 * root.u : 64 * root.u;
|
||||
width: parent.width - 96 * root.u;
|
||||
height: parent.height;
|
||||
vertical-alignment: center;
|
||||
font-size: 24 * root.u;
|
||||
font-weight: 500;
|
||||
color: #ffffff;
|
||||
text: root.ok ? "Sikeres párosítás!"
|
||||
overflow: elide;
|
||||
text: root.ok ? "Sikeres párosítás"
|
||||
: root.broken ? "Nem található Bluetooth adapter"
|
||||
: root.state == "pairing" ? "Párosítás…"
|
||||
: "Távirányító keresése…";
|
||||
}
|
||||
}
|
||||
// Skip chip (glass in app.slint, 200 x 64).
|
||||
Text {
|
||||
x: 556 * root.u;
|
||||
y: parent.height - 68 * root.u;
|
||||
width: 204 * root.u;
|
||||
height: 60 * root.u;
|
||||
x: 544 * root.u;
|
||||
y: root.pill-y;
|
||||
width: 200 * root.u;
|
||||
height: 64 * root.u;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
text: "Kihagyás · Esc";
|
||||
font-size: 21 * root.u;
|
||||
font-weight: 500;
|
||||
color: #ffffffc0;
|
||||
text: "Kihagyás";
|
||||
font-size: 24 * root.u;
|
||||
font-weight: 600;
|
||||
color: #ffffffd0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Settings screen: categories on the left, rows on the right.
|
||||
// Settings screen: categories on the left, the selected page's rows on one
|
||||
// grouped platter on the right.
|
||||
//
|
||||
// Only text and icons are drawn here. The glass (pane, rows, chips) comes from
|
||||
// `settings_screen::glass` in Rust, which mirrors the geometry below: keep the
|
||||
// row/nav formulas (position, focus `f`, visibility `vis`) in sync with it.
|
||||
// Only text and icons are drawn here. The glass (platter, focus pills) comes
|
||||
// from `settings_screen::glass` in Rust, which mirrors the geometry below: keep
|
||||
// the row/nav formulas (position, focus `f`, visibility `vis`) in sync with it.
|
||||
|
||||
import { WifiIcon, BluetoothIcon, InfoIcon, DisplayIcon, PowerIcon, SignalIcon, LockIcon } from "icons.slint";
|
||||
import { WifiIcon, BluetoothIcon, InfoIcon, DisplayIcon, AudioIcon, PowerIcon, SignalIcon, LockIcon, ChevronIcon, StoreIcon, CheckIcon, LinkIcon } from "icons.slint";
|
||||
|
||||
export struct SettingRow {
|
||||
title: string,
|
||||
@@ -22,9 +23,14 @@ component NavIcon inherits Rectangle {
|
||||
in property <color> ink;
|
||||
if root.index == 0: DisplayIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 1: BluetoothIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 2: WifiIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 3: PowerIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 4: InfoIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 2: AudioIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 3: WifiIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 4: PowerIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 5: InfoIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
// App Store mode: Felfedezés, Telepítve, Források.
|
||||
if root.index == 6: StoreIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 7: CheckIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
if root.index == 8: LinkIcon { width: 100%; height: 100%; ink: root.ink; }
|
||||
}
|
||||
|
||||
export component SettingsView inherits Rectangle {
|
||||
@@ -52,38 +58,47 @@ export component SettingsView inherits Rectangle {
|
||||
in property <string> subtitle;
|
||||
in property <[SettingRow]> rows;
|
||||
in property <[string]> categories;
|
||||
// The same pane serves the App Store (app.slint set-mode).
|
||||
in property <string> heading: "Beállítások";
|
||||
in property <int> icon-base: 0;
|
||||
|
||||
// Row text is inset from the platter edge by the focus pill's margin.
|
||||
property <length> inset: 8 * root.u;
|
||||
property <length> pad: 28 * root.u;
|
||||
|
||||
// ---- left column ----------------------------------------------------
|
||||
Text {
|
||||
x: root.nav-x + 8 * root.u;
|
||||
y: root.pane-y + 50 * root.u;
|
||||
text: "Beállítások";
|
||||
font-family: "Inter Display";
|
||||
font-weight: 800;
|
||||
font-size: 50 * root.u;
|
||||
letter-spacing: -1.5 * root.u;
|
||||
x: root.nav-x;
|
||||
y: root.pane-y;
|
||||
width: root.nav-w;
|
||||
height: 88 * root.u;
|
||||
vertical-alignment: center;
|
||||
text: root.heading;
|
||||
font-weight: 700;
|
||||
font-size: 56 * root.u;
|
||||
letter-spacing: -1 * root.u;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
for name[i] in root.categories: Rectangle {
|
||||
property <float> f: max(0, 1 - abs(root.nav-pos - i)) * root.nav-active;
|
||||
property <float> sel: max(0, 1 - abs(root.nav-pos - i));
|
||||
property <color> ink: self.f > 0.5 ? #121317 : #ffffff.with-alpha(0.72 + 0.28 * self.sel);
|
||||
property <color> ink: self.f > 0.5 ? #121317 : #ffffff.with-alpha(0.62 + 0.38 * self.sel);
|
||||
x: root.nav-x;
|
||||
y: root.nav-y + i * root.nav-step;
|
||||
width: root.nav-w;
|
||||
height: root.nav-h;
|
||||
NavIcon {
|
||||
x: 28 * root.u;
|
||||
x: 24 * root.u;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 34 * root.u;
|
||||
height: 34 * root.u;
|
||||
index: i;
|
||||
width: 32 * root.u;
|
||||
height: 32 * root.u;
|
||||
index: i + root.icon-base;
|
||||
ink: parent.ink;
|
||||
}
|
||||
Text {
|
||||
x: 82 * root.u;
|
||||
width: parent.width - 100 * root.u;
|
||||
x: 76 * root.u;
|
||||
width: parent.width - 96 * root.u;
|
||||
height: parent.height;
|
||||
vertical-alignment: center;
|
||||
text: name;
|
||||
@@ -94,46 +109,35 @@ export component SettingsView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
x: root.nav-x;
|
||||
y: root.pane-y + root.pane-h - 92 * root.u;
|
||||
width: 300 * root.u;
|
||||
height: 56 * root.u;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
text: "‹ Vissza · Esc";
|
||||
font-size: 21 * root.u;
|
||||
font-weight: 500;
|
||||
color: #ffffffc0;
|
||||
}
|
||||
|
||||
// ---- right column ---------------------------------------------------
|
||||
Text {
|
||||
x: root.rows-x + 8 * root.u;
|
||||
y: root.pane-y + 44 * root.u;
|
||||
width: root.rows-w - 16 * root.u;
|
||||
x: root.rows-x + root.inset + root.pad;
|
||||
y: root.nav-y;
|
||||
width: root.rows-w - 2 * (root.inset + root.pad);
|
||||
height: root.nav-h;
|
||||
vertical-alignment: center;
|
||||
text: root.title;
|
||||
font-family: "Inter Display";
|
||||
font-weight: 800;
|
||||
font-weight: 700;
|
||||
font-size: 40 * root.u;
|
||||
letter-spacing: -1 * root.u;
|
||||
color: #ffffff;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
x: root.rows-x + 8 * root.u;
|
||||
y: root.pane-y + 102 * root.u;
|
||||
width: root.rows-w - 16 * root.u;
|
||||
height: 64 * root.u;
|
||||
x: root.rows-x + root.inset + root.pad;
|
||||
y: root.nav-y + root.nav-h;
|
||||
width: root.rows-w - 2 * (root.inset + root.pad);
|
||||
height: root.rows-y - root.nav-y - root.nav-h - 24 * root.u;
|
||||
text: root.subtitle;
|
||||
wrap: word-wrap;
|
||||
overflow: elide;
|
||||
font-size: 21 * root.u;
|
||||
font-size: 24 * root.u;
|
||||
color: #ffffffa8;
|
||||
}
|
||||
|
||||
for row[j] in root.rows: r := Rectangle {
|
||||
property <float> f: max(0, 1 - abs(root.row-pos - j)) * root.content-active;
|
||||
// Focus on this row or the one above hides the hairline between them.
|
||||
property <float> f-above: max(0, 1 - abs(root.row-pos - (j - 1))) * root.content-active;
|
||||
property <length> top: root.rows-y + j * root.row-step - root.rows-scroll;
|
||||
property <float> over: max(root.rows-y - self.top, self.top + root.row-h - (root.rows-y + root.rows-view-h)) / root.row-h;
|
||||
property <float> vis: clamp(1 - self.over, 0, 1);
|
||||
@@ -143,17 +147,25 @@ export component SettingsView inherits Rectangle {
|
||||
property <color> ink-dim: self.hot ? (self.danger ? #ffffffd0 : #121317b0) : #ffffff99;
|
||||
property <bool> chevron: row.kind == "choice" || row.kind == "device";
|
||||
property <bool> network: row.kind == "network";
|
||||
x: root.rows-x;
|
||||
x: root.rows-x + root.inset;
|
||||
y: self.top;
|
||||
width: root.rows-w;
|
||||
width: root.rows-w - 2 * root.inset;
|
||||
height: root.row-h;
|
||||
opacity: self.vis;
|
||||
visible: self.vis > 0.01;
|
||||
|
||||
if j > 0: Rectangle {
|
||||
x: root.pad;
|
||||
y: 0;
|
||||
width: parent.width - 2 * root.pad;
|
||||
height: 1.5 * root.u;
|
||||
background: #ffffff1f;
|
||||
opacity: 1 - clamp(max(r.f, r.f-above) * 2, 0, 1);
|
||||
}
|
||||
Text {
|
||||
x: 30 * root.u;
|
||||
y: row.detail == "" ? (parent.height - self.height) / 2 : 15 * root.u;
|
||||
width: parent.width * 0.55;
|
||||
x: root.pad;
|
||||
y: row.detail == "" ? (parent.height - self.height) / 2 : 14 * root.u;
|
||||
width: parent.width * 0.56;
|
||||
text: row.title;
|
||||
font-size: 26 * root.u;
|
||||
font-weight: 600;
|
||||
@@ -161,45 +173,43 @@ export component SettingsView inherits Rectangle {
|
||||
overflow: elide;
|
||||
}
|
||||
if row.detail != "": Text {
|
||||
x: 30 * root.u;
|
||||
y: 51 * root.u;
|
||||
width: parent.width * 0.55;
|
||||
x: root.pad;
|
||||
y: 50 * root.u;
|
||||
width: parent.width * 0.56;
|
||||
text: row.detail;
|
||||
font-size: 19 * root.u;
|
||||
font-size: 21 * root.u;
|
||||
color: r.ink-dim;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
x: parent.width * 0.4;
|
||||
width: parent.width * 0.6 - (r.network ? 124 : r.chevron ? 64 : 32) * root.u;
|
||||
width: parent.width * 0.6 - (r.network ? 120 : r.chevron ? 64 : root.pad / root.u) * root.u;
|
||||
height: parent.height;
|
||||
horizontal-alignment: right;
|
||||
vertical-alignment: center;
|
||||
text: row.value;
|
||||
font-size: row.kind == "option" ? 30 * root.u : 23 * root.u;
|
||||
font-size: row.kind == "option" ? 28 * root.u : 24 * root.u;
|
||||
font-weight: row.kind == "option" ? 700 : 400;
|
||||
color: row.kind == "option" ? (r.hot ? #121317 : #ff9a5c) : r.ink-dim;
|
||||
overflow: elide;
|
||||
}
|
||||
if r.chevron: Text {
|
||||
x: parent.width - 50 * root.u;
|
||||
if r.chevron: ChevronIcon {
|
||||
x: parent.width - root.pad - self.width + 4 * root.u;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 24 * root.u;
|
||||
height: parent.height;
|
||||
vertical-alignment: center;
|
||||
text: "›";
|
||||
font-size: 36 * root.u;
|
||||
color: r.ink-dim;
|
||||
height: 24 * root.u;
|
||||
ink: r.ink-dim;
|
||||
}
|
||||
// Wi-Fi network: lock (protected) and signal strength on the right.
|
||||
if r.network && row.lock: LockIcon {
|
||||
x: parent.width - 104 * root.u;
|
||||
x: parent.width - root.pad - 34 * root.u - 16 * root.u - self.width;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 24 * root.u;
|
||||
height: 24 * root.u;
|
||||
ink: r.ink-dim;
|
||||
}
|
||||
if r.network: SignalIcon {
|
||||
x: parent.width - 66 * root.u;
|
||||
x: parent.width - root.pad - self.width;
|
||||
y: (parent.height - self.height) / 2;
|
||||
width: 34 * root.u;
|
||||
height: 34 * root.u;
|
||||
|
||||
Reference in New Issue
Block a user