// Spotify for Fennec OS: the root window. // // Screens: "message" (start-up, errors), "signin" (QR code / Spotify app), // "page" (every browsing screen: a LinePage built by src/page.rs), // "nowplaying". Over them: the text input, the picker, the toast. // // Rust owns state and focus: every key goes to the `key` callback, except // while a keyboard has the focus (the input overlay, the search keyboard). import { TvWindow, Tv, SfText, GlassRect, MenuItem } from "@sf-ui/sf-ui.slint"; import { Line, Chip, Card, Check, QueueItem } from "types.slint"; import { LinePage } from "page.slint"; import { NowPlayingScreen } from "nowplaying.slint"; import { ConnectScreen, InputScreen, MessageScreen, KeyScreen } from "signin.slint"; import { SelectOverlay, Toast } from "overlays.slint"; export { Tv, SfText, MenuItem, Line, Chip, Card, Check, QueueItem } export component App inherits TvWindow { title: "Spotify"; forward-focus: keys; // "message", "signin", "solokey", "page", "nowplaying" in property screen: "message"; // The key text (Slint's Key codes) and whether it repeats; true = handled. callback key(string, bool) -> bool; out property message-t: self.screen == "message" ? 1 : 0; animate message-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property signin-t: self.screen == "signin" ? 1 : 0; animate signin-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property solokey-t: self.screen == "solokey" ? 1 : 0; animate solokey-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property page-t: self.screen == "page" ? 1 : 0; animate page-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property np-t: self.screen == "nowplaying" ? 1 : 0; animate np-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property input-t: self.input-open ? 1 : 0; animate input-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property select-t: self.select-open ? 1 : 0; animate select-t { duration: 300ms; easing: cubic-bezier(0.3, 1.18, 0.4, 1); } // Whatever an overlay would cover goes away first. property under: max(0, 1 - 1.6 * max(self.input-t, self.select-t)); // The outgoing screen goes first, the incoming one follows. function vis(t: float) -> float { clamp(t * 2 - 1, 0, 1) } keys := FocusScope { key-pressed(event) => { if root.input-open { return input.key(event); } if root.screen == "page" && root.page-kb-focused && !root.select-open { return page.kb-key(event); } if root.key(event.text, event.repeat) { return accept; } reject } } // ---- message ---- in property message-busy <=> message.busy; in property message-title <=> message.title; in property message-text <=> message.text; message := MessageScreen { alpha: root.vis(root.message-t); visible: self.alpha > 0.001; } // ---- sign-in ---- in property signin-device <=> signin.device; in property signin-code <=> signin.code; in property signin-qr <=> signin.qr; in property signin-busy <=> signin.busy; in property signin-error <=> signin.error; signin := ConnectScreen { alpha: root.vis(root.signin-t); visible: self.alpha > 0.001; } // ---- Soloist key ---- in property solokey-qr <=> solokey.qr; in property solokey-url <=> solokey.url; solokey := KeyScreen { alpha: root.vis(root.solokey-t) * root.under; visible: root.solokey-t > 0.001; } // ---- page ---- in property <[Line]> page-lines <=> page.lines; in property page-focus <=> page.focus-line; in property page-scroll <=> page.scroll; in property page-show-nav <=> page.show-nav; in property <[string]> page-nav-items <=> page.nav-items; in property page-nav-index <=> page.nav-index; in property page-nav-focused <=> page.nav-focused; in property page-np-title <=> page.np-title; in property page-np-artist <=> page.np-artist; in property page-np-playing <=> page.np-playing; in property page-np-focused <=> page.np-focused; in property page-user-image <=> page.user-image; in property page-user-initial <=> page.user-initial; in property page-kb-y <=> page.kb-y; in property page-kb-focused <=> page.kb-focused; in property page-kb-placeholder <=> page.kb-placeholder; in-out property page-query <=> page.query; callback search-submitted(string); callback search-changed(string); changed page-query => { root.search-changed(self.page-query); } callback search-exit-down(); callback search-exit-up(); callback search-cancelled(); public function page-kb-reset() { page.kb-reset(); } page := LinePage { alpha: root.vis(root.page-t) * root.under; visible: root.page-t > 0.001; search-submitted(t) => { root.search-submitted(t); } search-exit-down => { root.search-exit-down(); } search-exit-up => { root.search-exit-up(); } search-cancelled => { root.search-cancelled(); } } // ---- now playing ---- in property np-title <=> np.title; in property np-artist <=> np.artist; in property np-album <=> np.album; in property np-cover <=> np.art; in property np-explicit <=> np.explicit; in property np-episode <=> np.episode; in property np-playing <=> np.playing; in property np-loading <=> np.loading; in property np-progress <=> np.progress; in property np-time <=> np.time; in property np-duration <=> np.duration; in property np-shuffle <=> np.shuffle; in property np-repeat <=> np.repeat; in property np-liked <=> np.liked; in property np-focus <=> np.button; in property np-area <=> np.area; in property np-panel <=> np.panel; in property <[string]> np-lyrics <=> np.lyrics; in property np-lyric-line <=> np.lyric-line; in property np-lyrics-synced <=> np.lyrics-synced; in property np-lyrics-note <=> np.lyrics-note; in property <[QueueItem]> np-queue <=> np.queue; in property np-queue-note <=> np.queue-note; in property np-device <=> np.device; np := NowPlayingScreen { alpha: root.vis(root.np-t) * root.under; visible: root.np-t > 0.001; } // ---- text input ---- in property input-open; in property input-title <=> input.title; in property input-subtitle <=> input.subtitle; in property input-placeholder <=> input.placeholder; in property input-submit-label <=> input.submit-label; in property input-min-length <=> input.min-length; in-out property input-text <=> input.text; in-out property input-error <=> input.error; callback input-submitted(string); callback input-cancelled(); public function input-reset() { input.reset(); } input := InputScreen { alpha: root.vis(root.input-t); visible: root.input-t > 0.001; submitted(t) => { root.input-submitted(t); } cancelled => { root.input-cancelled(); } } // ---- picker ---- in property select-open; in property select-title <=> select.title; in property <[MenuItem]> select-items <=> select.items; in property select-focus <=> select.focus-index; select := SelectOverlay { alpha: root.select-t; visible: root.select-t > 0.001; } // ---- toast ---- in property toast-text <=> toast.text; in property toast-bad <=> toast.bad; toast := Toast { } // ---- glass, in drawing order (listed by src/main.rs) ---- out property <[GlassRect]> glass-signin: signin.glass; out property <[GlassRect]> glass-solokey: solokey.glass; out property <[GlassRect]> glass-page: page.glass; out property <[GlassRect]> glass-page-keyboard: page.glass-keyboard; out property <[GlassRect]> glass-np: np.glass; out property <[GlassRect]> glass-input: input.glass; out property <[GlassRect]> glass-input-keyboard: input.glass-keyboard; out property <[GlassRect]> glass-select: select.glass; out property <[GlassRect]> glass-toast: toast.glass; }